From 7889b7c59b015c148593c653f703840b1d6edad6 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 24 Sep 2025 02:51:23 -0700 Subject: [PATCH] fix button component renderAs logic --- src/lib/components/ui/Button.svelte | 180 ++++++++++++++++------------ 1 file changed, 105 insertions(+), 75 deletions(-) diff --git a/src/lib/components/ui/Button.svelte b/src/lib/components/ui/Button.svelte index 7e4d6b6b..00123578 100644 --- a/src/lib/components/ui/Button.svelte +++ b/src/lib/components/ui/Button.svelte @@ -15,6 +15,8 @@ contained?: boolean /** Element color theme */ element?: 'wind' | 'fire' | 'water' | 'earth' | 'dark' | 'light' + /** Use element styling (overrides variant colors) */ + elementStyle?: boolean /** Whether button is active */ active?: boolean /** Save button behavior */ @@ -56,6 +58,7 @@ size = 'medium', contained = false, element, + elementStyle = false, active = false, save = false, saved = false, @@ -77,7 +80,6 @@ // Normalize shape aliases const normalizedShape = $derived(shape === 'circle' ? 'circular' : shape) - const renderAs = $derived(as ? as : href ? 'a' : 'button') const iconSizes = { icon: 16, @@ -93,6 +95,7 @@ size, contained && 'contained', element, + elementStyle && element && 'element-styled', active && 'active', save && 'save', saved && 'saved', @@ -110,74 +113,35 @@ const hasRightIcon = $derived(icon && iconPosition === 'right') -{#if renderAs === 'button'} - - {#if leftAccessory} - - {@render leftAccessory()} - - {:else if hasLeftIcon && !iconOnly} - - - - {/if} - - {#if children && !iconOnly} - - {@render children()} - - {:else if iconOnly && icon} + + {#if leftAccessory} + + {@render leftAccessory()} + + {:else if hasLeftIcon && !iconOnly} + - {/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 children && !iconOnly} - - {@render children()} - - {:else if iconOnly && icon} + {#if rightAccessory} + + {@render rightAccessory()} + + {:else if hasRightIcon && !iconOnly} + - {/if} - - {#if rightAccessory} - - {@render rightAccessory()} - - {:else if hasRightIcon && !iconOnly} - - - - {/if} - -{/if} + + {/if} +