49 lines
1.4 KiB
Svelte
49 lines
1.4 KiB
Svelte
<script lang="ts">
|
|
import type { WithoutChildrenOrChild } from 'bits-ui';
|
|
import type { Snippet } from 'svelte';
|
|
import Check from '@lucide/svelte/icons/check';
|
|
import Minus from '@lucide/svelte/icons/minus';
|
|
import { cn } from '$lib/utils.js';
|
|
import { DropdownMenu as DropdownMenuPrimitive } from 'bits-ui';
|
|
|
|
let {
|
|
ref = $bindable(null),
|
|
checked = $bindable(false),
|
|
indeterminate = $bindable(false),
|
|
class: className,
|
|
children: childrenProp,
|
|
...restProps
|
|
}: WithoutChildrenOrChild<DropdownMenuPrimitive.CheckboxItemProps> & {
|
|
children?: Snippet;
|
|
} = $props();
|
|
</script>
|
|
|
|
<DropdownMenuPrimitive.CheckboxItem
|
|
bind:ref
|
|
bind:checked
|
|
bind:indeterminate
|
|
data-slot="dropdown-menu-checkbox-item"
|
|
class={cn(
|
|
'focus:bg-surface relative flex cursor-pointer items-center gap-2 rounded-sm py-2 pr-2 pl-8 text-sm outline-hidden select-none',
|
|
|
|
// Disabled
|
|
'data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
|
|
|
|
// Images
|
|
"[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
className
|
|
)}
|
|
{...restProps}
|
|
>
|
|
{#snippet children({ checked, indeterminate })}
|
|
<span class="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
|
{#if indeterminate}
|
|
<Minus class="size-4" />
|
|
{:else}
|
|
<Check class={cn('size-4', !checked && 'text-transparent')} />
|
|
{/if}
|
|
</span>
|
|
{@render childrenProp?.()}
|
|
{/snippet}
|
|
</DropdownMenuPrimitive.CheckboxItem>
|