diff --git a/src/components/Button.svelte b/src/components/Button.svelte index 1652c91..4907c08 100644 --- a/src/components/Button.svelte +++ b/src/components/Button.svelte @@ -9,6 +9,7 @@ rounded?: boolean; type?: 'button' | 'submit' | 'reset'; label?: string; + loading?: boolean; onclick?: () => void; }; @@ -18,12 +19,29 @@ rounded, type = 'button', label = '', + loading = false, onclick }: Props = $props(); - const buttonClass = buildButtonClass(variant, rounded); + const buttonClass = $derived(buildButtonClass(variant, rounded, loading)); - diff --git a/src/lib/button.ts b/src/lib/button.ts index cdc074c..4aefde4 100644 --- a/src/lib/button.ts +++ b/src/lib/button.ts @@ -1,16 +1,6 @@ export type Variant = 'primary' | 'secondary' | 'tertiary' | 'ghost'; -const baseClasses = `flex - min-h-11 - min-w-[44px] - items-center - justify-center - gap-2 - px-4 py-2 - transition-all - duration-150 - hover:scale-105 - focus:outline-none`; +const baseClasses = `flex min-h-11 min-w-[44px] items-center justify-center gap-2 px-4 py-2 transition-all duration-150 hover:scale-105 focus:outline-none`; const variantClasses = { primary: 'bg-primary hover:bg-primary/90 text-white border-none', @@ -19,7 +9,8 @@ const variantClasses = { ghost: 'dark:hover:bg-slate-800 hover:ring-2' } as const; -export const buildButtonClass = (variant: Variant, round = false) => { +export const buildButtonClass = (variant: Variant, round = false, loading = false) => { const roundedClass = round ? 'rounded-full' : 'rounded-xl'; - return `${baseClasses} ${variantClasses[variant]} ${roundedClass}`; + const loadingClass = loading ? 'opacity-50 pointer-events-none' : ''; + return `${loadingClass} ${baseClasses} ${variantClasses[variant]} ${roundedClass}`; }; diff --git a/src/routes/my/friends/add/+page.svelte b/src/routes/my/friends/add/+page.svelte index 4366046..58894f8 100644 --- a/src/routes/my/friends/add/+page.svelte +++ b/src/routes/my/friends/add/+page.svelte @@ -1,15 +1,17 @@
@@ -20,17 +22,28 @@

Invite friend

Adding a friend allows you select notes for them to see.

-
+ { + loading = true; + return async ({ result }) => { + loading = false; + if (result.type === 'failure') { + error = result.data?.message as string; + } + }; + }} +>
- +
- +
- {#if formError} -

Email is required

+ {#if error} +

{error}

{/if}
- +