Skip to content

Commit

Permalink
feat: add multiple select with chip storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
phongit-kha committed Jan 9, 2025
1 parent 6ba07e1 commit 4f01a76
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
)}
{...restProps}
>
<div class="w-full h-full overflow-hidden text-left truncate">
<div
class="w-full h-full overflow-hidden flex items-center text-left truncate"
>
{@render children?.()}
</div>
{#if arrow}
Expand Down
53 changes: 31 additions & 22 deletions packages/ui/src/components/molecule/select/select.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
label={fruit.label}
aria-label={fruit.label}
role="option"
check={true}
>
{fruit.label}
</Select.Item>
Expand All @@ -149,29 +150,36 @@

<Story name="Multiple Select with Chips">
<Select.Root type="multiple" name="favoriteFruit" bind:value={value2}>
<Select.Trigger
aria-label="Select multiple fruits"
class="w-[300px] h-12 z-0 "
placeholder="Select fruits"
>
{#if !value2.length}
เลือก
{:else}
{#each value2 as temp}
<Chip
class="z-10 mr-2"
closable
onClose={(event: MouseEvent) => {
event.stopPropagation()
value2 = value2.filter((item) => item != temp)
}}
aria-label={`Remove ${themes.find((item) => item.value === temp)?.label || temp}`}
>
{themes.find((item) => item.value === temp)?.label || temp}
</Chip>
{/each}
<div class="relative w-[300px]">
{#if value2.length}
<div
class="absolute flex max-w-[274px] w-auto pl-2 top-1/2 -translate-y-1/2 items-center gap-1 truncate"
>
{#each value2 as temp}
<Chip
class="z-10"
closable
onClose={(event: MouseEvent) => {
event.stopPropagation()
value2 = value2.filter((item) => item != temp)
}}
aria-label={`Remove ${themes.find((item) => item.value === temp)?.label || temp}`}
>
{themes.find((item) => item.value === temp)?.label || temp}
</Chip>
{/each}
</div>
{/if}
</Select.Trigger>
<Select.Trigger
aria-label="Select multiple fruits"
class="w-[300px] h-12 z-0 "
placeholder="Select fruits"
>
{#if !value2.length}
เลือก
{/if}
</Select.Trigger>
</div>
<Select.Content role="listbox">
<Select.Group>
{#each themes as fruit}
Expand All @@ -180,6 +188,7 @@
label={fruit.label}
aria-label={fruit.label}
role="option"
check={true}
>
{fruit.label}
</Select.Item>
Expand Down

0 comments on commit 4f01a76

Please sign in to comment.