From c379933787c418c2dcb80d193d770f8fc9fa8661 Mon Sep 17 00:00:00 2001 From: Shibo Lyu Date: Thu, 17 Apr 2025 02:28:08 +0800 Subject: [PATCH] refactor: Refactor Button and GroupedListItem components Improve component typing with more specific HTML attribute types and implement conditional rendering based on properties. Use Svelte snippets to avoid code duplication and enhance component flexibility. --- .zed/settings.json | 9 +++ src/lib/components/Button.svelte | 55 +++++++++---------- .../GroupedList/GroupedListItem.svelte | 50 +++++++++++------ 3 files changed, 67 insertions(+), 47 deletions(-) create mode 100644 .zed/settings.json diff --git a/.zed/settings.json b/.zed/settings.json new file mode 100644 index 0000000..4980a77 --- /dev/null +++ b/.zed/settings.json @@ -0,0 +1,9 @@ +{ + "lsp": { + "tailwindcss-language-server": { + "settings": { + "classFunctions": ["tw"] + } + } + } +} diff --git a/src/lib/components/Button.svelte b/src/lib/components/Button.svelte index b0eda4c..98c016c 100644 --- a/src/lib/components/Button.svelte +++ b/src/lib/components/Button.svelte @@ -1,45 +1,40 @@ - +{#snippet content()} {#if variant === 'primary'}
{@render children?.()}
{:else} {@render children?.()} {/if} -
+{/snippet} + +{#if 'href' in rest} + {@render content()} +{:else} + +{/if} diff --git a/src/lib/components/GroupedList/GroupedListItem.svelte b/src/lib/components/GroupedList/GroupedListItem.svelte index 6f41873..f149a9a 100644 --- a/src/lib/components/GroupedList/GroupedListItem.svelte +++ b/src/lib/components/GroupedList/GroupedListItem.svelte @@ -1,29 +1,37 @@ - +{#snippet content()} {#if icon} {@render children?.()} - +{/snippet} + +{#if 'href' in rest} + {@render content()} +{:else if 'onclick' in rest} + +{:else} +
{@render content()}
+{/if}