1<script lang="ts">
2 import { Checkbox as CheckboxPrimitive } from 'bits-ui';
3 import CheckIcon from '@lucide/svelte/icons/check';
4 import MinusIcon from '@lucide/svelte/icons/minus';
5 import { cn, type WithoutChildrenOrChild } from '$lib/components/ui/utils.js';
6
7 let {
8 ref = $bindable(null),
9 checked = $bindable(false),
10 indeterminate = $bindable(false),
11 class: className,
12 ...restProps
13 }: WithoutChildrenOrChild<CheckboxPrimitive.RootProps> = $props();
14</script>
15
16<CheckboxPrimitive.Root
17 bind:ref
18 data-slot="checkbox"
19 class={cn(
20 'peer flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:bg-input/30 dark:aria-invalid:ring-destructive/40 dark:data-[state=checked]:bg-primary',
21 className
22 )}
23 bind:checked
24 bind:indeterminate
25 {...restProps}
26>
27 {#snippet children({ checked, indeterminate })}
28 <div data-slot="checkbox-indicator" class="text-current transition-none">
29 {#if checked}
30 <CheckIcon class="size-3.5" />
31 {:else if indeterminate}
32 <MinusIcon class="size-3.5" />
33 {/if}
34 </div>
35 {/snippet}
36</CheckboxPrimitive.Root>