|
11 | 11 | import { cn } from '$lib/utils';
|
12 | 12 | import IconArrowDownward from '~icons/mdi/arrow-downward';
|
13 | 13 | import IconArrowUpward from '~icons/mdi/arrow-upward';
|
| 14 | + import IconEyeOff from '~icons/mdi/eye-off-outline'; |
14 | 15 | import IconUnfoldMore from '~icons/mdi/unfold-more-horizontal';
|
15 | 16 |
|
16 |
| - type Props = HTMLAttributes<Element> & { |
| 17 | + type Props = HTMLAttributes<HTMLDivElement> & { |
17 | 18 | column: Column<TData, unknown>;
|
18 | 19 | };
|
19 | 20 |
|
20 |
| - let { children, class: className, column }: Props = $props(); |
21 |
| -
|
22 |
| - function handleAscSort(e: Event) { |
23 |
| - if (column.getIsSorted() === 'asc') { |
24 |
| - return; |
25 |
| - } |
26 |
| -
|
27 |
| - column.getToggleSortingHandler()?.(e); |
28 |
| - } |
29 |
| -
|
30 |
| - function handleDescSort(e: Event) { |
31 |
| - if (column.getIsSorted() === 'desc') { |
32 |
| - return; |
33 |
| - } |
34 |
| -
|
35 |
| - column.getToggleSortingHandler()?.(e); |
36 |
| - } |
| 21 | + let { children, class: className, column, ...restProps }: Props = $props(); |
37 | 22 | </script>
|
38 | 23 |
|
39 | 24 | {#if column.getCanSort()}
|
40 |
| - <div class={cn('flex items-center', className)}> |
| 25 | + <div class={cn('flex items-center', className)} {...restProps}> |
41 | 26 | <DropdownMenu.Root>
|
42 | 27 | <DropdownMenu.Trigger>
|
43 |
| - {#snippet children()} |
44 |
| - <Button class="-ml-3 h-8 data-[state=open]:bg-accent" variant="ghost"> |
| 28 | + {#snippet child({ props })} |
| 29 | + <Button class="-ml-3 h-8 data-[state=open]:bg-accent" variant="ghost" {...props}> |
45 | 30 | {#if children}
|
46 | 31 | {@render children()}
|
47 | 32 | {/if}
|
48 | 33 | {#if column.getIsSorted() === 'desc'}
|
49 |
| - <IconArrowDownward class="ml-2 h-4 w-4" /> |
| 34 | + <IconArrowDownward /> |
50 | 35 | {:else if column.getIsSorted() === 'asc'}
|
51 |
| - <IconArrowUpward class="ml-2 h-4 w-4" /> |
| 36 | + <IconArrowUpward /> |
52 | 37 | {:else}
|
53 |
| - <IconUnfoldMore class="ml-2 h-4 w-4" /> |
| 38 | + <IconUnfoldMore /> |
54 | 39 | {/if}
|
55 | 40 | </Button>
|
56 | 41 | {/snippet}
|
57 | 42 | </DropdownMenu.Trigger>
|
58 | 43 | <DropdownMenu.Content align="start">
|
59 |
| - <DropdownMenu.Item onclick={handleAscSort}>Asc</DropdownMenu.Item> |
60 |
| - <DropdownMenu.Item onclick={handleDescSort}>Desc</DropdownMenu.Item> |
| 44 | + <DropdownMenu.Item onclick={() => column.toggleSorting(false)} |
| 45 | + ><IconArrowUpward class="mr-2 size-3.5 text-muted-foreground/70" />Asc</DropdownMenu.Item |
| 46 | + > |
| 47 | + <DropdownMenu.Item onclick={() => column.toggleSorting(true)} |
| 48 | + ><IconArrowDownward class="mr-2 size-3.5 text-muted-foreground/70" />Desc</DropdownMenu.Item |
| 49 | + > |
| 50 | + <DropdownMenu.Separator /> |
| 51 | + <DropdownMenu.Item onclick={() => column.toggleVisibility(false)} |
| 52 | + ><IconEyeOff class="mr-2 size-3.5 text-muted-foreground/70" />Hide</DropdownMenu.Item |
| 53 | + > |
61 | 54 | </DropdownMenu.Content>
|
62 | 55 | </DropdownMenu.Root>
|
63 | 56 | </div>
|
64 | 57 | {:else if children}
|
65 |
| - {@render children()} |
| 58 | + <div class={className} {...restProps}> |
| 59 | + {@render children()} |
| 60 | + </div> |
66 | 61 | {/if}
|
0 commit comments