From 8db94e37e7897486fbe162499188b0ea68454a6c Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 24 Sep 2025 01:53:26 -0700 Subject: [PATCH] Update Button component to have shape and element --- src/lib/components/ui/Button.svelte | 131 ++++++++++++++++++++++------ 1 file changed, 103 insertions(+), 28 deletions(-) diff --git a/src/lib/components/ui/Button.svelte b/src/lib/components/ui/Button.svelte index f963b93b..7e4d6b6b 100644 --- a/src/lib/components/ui/Button.svelte +++ b/src/lib/components/ui/Button.svelte @@ -8,7 +8,7 @@ interface Props { /** Button variant style */ - variant?: 'primary' | 'secondary' | 'ghost' | 'text' | 'destructive' | 'notice' + variant?: 'primary' | 'secondary' | 'ghost' | 'text' | 'destructive' | 'notice' | 'subtle' /** Button size */ size?: 'small' | 'medium' | 'large' | 'icon' /** Whether button is contained */ @@ -43,6 +43,10 @@ href?: string /** Click handler */ onclick?: () => void + /** Shape of the button corners */ + shape?: 'default' | 'circular' | 'circle' | 'pill' + /** Element tag override (for slots/triggers) */ + as?: 'button' | 'a' | 'span' /** Any additional HTML attributes */ [key: string]: any } @@ -66,9 +70,15 @@ disabled = false, href, onclick, + shape = 'default', + as, ...restProps }: Props = $props() + // Normalize shape aliases + const normalizedShape = $derived(shape === 'circle' ? 'circular' : shape) + const renderAs = $derived(as ? as : href ? 'a' : 'button') + const iconSizes = { icon: 16, small: 14, @@ -88,6 +98,7 @@ saved && 'saved', fullWidth && 'full', iconOnly && 'iconOnly', + normalizedShape !== 'default' && normalizedShape, className ] .filter(Boolean) @@ -99,35 +110,74 @@ const hasRightIcon = $derived(icon && iconPosition === 'right') - - {#if leftAccessory} - - {@render leftAccessory()} - - {:else if hasLeftIcon && !iconOnly} - - - - {/if} +{#if renderAs === 'button'} + + {#if leftAccessory} + + {@render leftAccessory()} + + {:else if hasLeftIcon && !iconOnly} + + + + {/if} - {#if children && !iconOnly} - - {@render children()} - - {:else if iconOnly && icon} - - {/if} - - {#if rightAccessory} - - {@render rightAccessory()} - - {:else if hasRightIcon && !iconOnly} - + {#if children && !iconOnly} + + {@render children()} + + {:else if iconOnly && icon} - - {/if} - + {/if} + + {#if rightAccessory} + + {@render rightAccessory()} + + {:else if hasRightIcon && !iconOnly} + + + + {/if} + +{:else} + + {#if leftAccessory} + + {@render leftAccessory()} + + {:else if hasLeftIcon && !iconOnly} + + + + {/if} + + {#if children && !iconOnly} + + {@render children()} + + {:else if iconOnly && icon} + + {/if} + + {#if rightAccessory} + + {@render rightAccessory()} + + {:else if hasRightIcon && !iconOnly} + + + + {/if} + +{/if}