mirror of
https://github.com/revanced/revanced-website.git
synced 2025-04-29 22:24:31 +02:00
refactor: use conditional types
This commit is contained in:
parent
e36417bfb2
commit
63e0d63d4a
@ -1,21 +1,36 @@
|
||||
<script lang="ts">
|
||||
import type { Component, Snippet } from 'svelte';
|
||||
import type { SpecialTargetValues } from '$types';
|
||||
import type { SpecialTargetValues, Prettify } from '$types';
|
||||
|
||||
type ButtonType = 'filled' | 'tonal' | 'text' | 'outlined';
|
||||
|
||||
type Props = {
|
||||
type BaseProps = {
|
||||
type: ButtonType;
|
||||
icon?: Component;
|
||||
iconSize?: number;
|
||||
iconColor?: string;
|
||||
href?: string;
|
||||
target?: `${SpecialTargetValues}` | SpecialTargetValues;
|
||||
label?: string;
|
||||
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 {
|
||||
type,
|
||||
// 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',
|
||||
TOP = '_top'
|
||||
}
|
||||
|
||||
type Prettify<T> = {
|
||||
[K in keyof T]: T[K];
|
||||
} & {};
|
||||
|
Loading…
x
Reference in New Issue
Block a user