migrate: convert most components to svelte 5
This commit is contained in:
1 parent
d670f39f0a
commit
10ef4123da
225 files changed
+5441
-3341
No files matched your search
@@ -1,4 +1,4 @@
|
||||
<script context="module" lang="ts">
|
||||
<script module lang="ts">
|
||||
export type ButtonColor = keyof typeof buttonColor
|
||||
export type ButtonAlignment = keyof typeof buttonAlignment
|
||||
export type ButtonShadow = keyof typeof buttonShadow
|
||||
@@ -65,6 +65,9 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { createBubbler } from 'svelte/legacy';
|
||||
|
||||
const bubble = createBubbler();
|
||||
import Spinner from '../loader/Spinner.svelte'
|
||||
|
||||
type ButtonRoundness = 'pill' | 'xl' | 'lg' | 'md' | 'none'
|
||||
@@ -112,40 +115,66 @@
|
||||
},
|
||||
}
|
||||
|
||||
export let loading = false
|
||||
export let submit = false
|
||||
|
||||
export let color: ButtonColor = 'secondary'
|
||||
export let size: ButtonSize = 'md'
|
||||
export let rounding: ButtonRoundness = size == 'lg' ? 'xl' : 'lg'
|
||||
export let roundingSide: ButtonRoundingSide = 'all'
|
||||
export let alignment: ButtonAlignment = 'center'
|
||||
export let shadow: ButtonShadow = 'none'
|
||||
export let column: boolean = false
|
||||
export let animations = {
|
||||
scale: false,
|
||||
large: false,
|
||||
|
||||
|
||||
|
||||
interface Props {
|
||||
loading?: boolean;
|
||||
submit?: boolean;
|
||||
color?: ButtonColor;
|
||||
size?: ButtonSize;
|
||||
rounding?: ButtonRoundness;
|
||||
roundingSide?: ButtonRoundingSide;
|
||||
alignment?: ButtonAlignment;
|
||||
shadow?: ButtonShadow;
|
||||
column?: boolean;
|
||||
animations?: any;
|
||||
loaderWidth?: number | undefined;
|
||||
href?: string | undefined;
|
||||
class?: string;
|
||||
prefix?: import('svelte').Snippet;
|
||||
children?: import('svelte').Snippet;
|
||||
suffix?: import('svelte').Snippet;
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export let loaderWidth: number | undefined = undefined
|
||||
|
||||
export let href: string | undefined = undefined
|
||||
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
loading = false,
|
||||
submit = false,
|
||||
color = 'secondary',
|
||||
size = 'md',
|
||||
rounding = size == 'lg' ? 'xl' : 'lg',
|
||||
roundingSide = 'all',
|
||||
alignment = 'center',
|
||||
shadow = 'none',
|
||||
column = false,
|
||||
animations = {
|
||||
scale: false,
|
||||
large: false,
|
||||
},
|
||||
loaderWidth = undefined,
|
||||
href = undefined,
|
||||
class: clazz = '',
|
||||
prefix,
|
||||
children,
|
||||
suffix,
|
||||
...rest
|
||||
}: Props = $props();
|
||||
|
||||
</script>
|
||||
|
||||
<svelte:element
|
||||
this={href ? 'a' : 'button'}
|
||||
role={href ? 'link' : 'button'}
|
||||
{href}
|
||||
{...$$restProps}
|
||||
on:click
|
||||
on:contextmenu
|
||||
on:drag
|
||||
on:drop
|
||||
on:dragstart
|
||||
on:dragend
|
||||
{...rest}
|
||||
onclick={bubble('click')}
|
||||
oncontextmenu={bubble('contextmenu')}
|
||||
ondrag={bubble('drag')}
|
||||
ondrop={bubble('drop')}
|
||||
ondragstart={bubble('dragstart')}
|
||||
ondragend={bubble('dragend')}
|
||||
class="
|
||||
{loading ? buttonColor.secondary : buttonColor[color]}
|
||||
{buttonSize[size]}
|
||||
@@ -170,11 +199,11 @@
|
||||
>
|
||||
{#if loading}
|
||||
<Spinner width={loaderWidth ?? 16} />
|
||||
{:else if $$slots.prefix}
|
||||
<slot name="prefix" />
|
||||
{:else if prefix}
|
||||
{@render prefix?.()}
|
||||
{/if}
|
||||
<slot />
|
||||
<slot name="suffix" />
|
||||
{@render children?.()}
|
||||
{@render suffix?.()}
|
||||
</div>
|
||||
</svelte:element>
|
||||
|
||||
|
||||
Reference in new issue
Block a user