mirror of
https://github.com/revanced/revanced-website.git
synced 2025-04-30 06:34:35 +02:00
refactor: use conditional types
This commit is contained in:
parent
e36417bfb2
commit
63e0d63d4a
@ -1,21 +1,36 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Component, Snippet } from 'svelte';
|
import type { Component, Snippet } from 'svelte';
|
||||||
import type { SpecialTargetValues } from '$types';
|
import type { SpecialTargetValues, Prettify } from '$types';
|
||||||
|
|
||||||
type ButtonType = 'filled' | 'tonal' | 'text' | 'outlined';
|
type ButtonType = 'filled' | 'tonal' | 'text' | 'outlined';
|
||||||
|
|
||||||
type Props = {
|
type BaseProps = {
|
||||||
type: ButtonType;
|
type: ButtonType;
|
||||||
icon?: Component;
|
icon?: Component;
|
||||||
iconSize?: number;
|
iconSize?: number;
|
||||||
iconColor?: string;
|
iconColor?: string;
|
||||||
href?: string;
|
|
||||||
target?: `${SpecialTargetValues}` | SpecialTargetValues;
|
|
||||||
label?: string;
|
label?: string;
|
||||||
children?: Snippet;
|
children?: Snippet;
|
||||||
onclick?: () => void;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type ButtonProps = Prettify<
|
||||||
|
BaseProps & {
|
||||||
|
onclick: () => void;
|
||||||
|
href: never;
|
||||||
|
target: never;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
|
||||||
|
type LinkProps = Prettify<
|
||||||
|
BaseProps & {
|
||||||
|
href: string;
|
||||||
|
target?: `${SpecialTargetValues}` | SpecialTargetValues;
|
||||||
|
onclick: never;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
|
||||||
|
type Props = ButtonProps | LinkProps;
|
||||||
|
|
||||||
let {
|
let {
|
||||||
type,
|
type,
|
||||||
// https://svelte.dev/docs/svelte/compiler-warnings#svelte_component_deprecated
|
// https://svelte.dev/docs/svelte/compiler-warnings#svelte_component_deprecated
|
||||||
|
4
src/lib/types.d.ts
vendored
4
src/lib/types.d.ts
vendored
@ -7,3 +7,7 @@ export enum SpecialTargetValues {
|
|||||||
PARENT = '_parent',
|
PARENT = '_parent',
|
||||||
TOP = '_top'
|
TOP = '_top'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Prettify<T> = {
|
||||||
|
[K in keyof T]: T[K];
|
||||||
|
} & {};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user