2024-04-11 17:18:21 +02:00
|
|
|
<script lang="ts">
|
2025-06-21 21:07:36 +02:00
|
|
|
import { Checkbox as CheckboxPrimitive } from "bits-ui";
|
|
|
|
|
import { cn, type WithoutChildrenOrChild } from "$lib/utils.js";
|
2026-04-06 18:22:01 +02:00
|
|
|
import CheckIcon from '@lucide/svelte/icons/check';
|
|
|
|
|
import MinusIcon from '@lucide/svelte/icons/minus';
|
2024-04-11 17:18:21 +02:00
|
|
|
|
2025-06-08 16:32:41 +02:00
|
|
|
let {
|
|
|
|
|
ref = $bindable(null),
|
|
|
|
|
checked = $bindable(false),
|
|
|
|
|
indeterminate = $bindable(false),
|
|
|
|
|
class: className,
|
|
|
|
|
...restProps
|
|
|
|
|
}: WithoutChildrenOrChild<CheckboxPrimitive.RootProps> = $props();
|
2024-04-11 17:18:21 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<CheckboxPrimitive.Root
|
2025-06-08 16:32:41 +02:00
|
|
|
bind:ref
|
2025-06-21 21:07:36 +02:00
|
|
|
data-slot="checkbox"
|
2024-04-11 17:18:21 +02:00
|
|
|
class={cn(
|
2026-04-06 18:22:01 +02:00
|
|
|
"border-input dark:bg-input/30 data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary data-checked:border-primary aria-invalid:aria-checked:border-primary aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 flex size-4 items-center justify-center rounded-[4px] border transition-colors group-has-disabled/field:opacity-50 focus-visible:ring-3 aria-invalid:ring-3 peer relative shrink-0 outline-none after:absolute after:-inset-x-3 after:-inset-y-2 disabled:cursor-not-allowed disabled:opacity-50",
|
2024-04-11 17:18:21 +02:00
|
|
|
className
|
|
|
|
|
)}
|
|
|
|
|
bind:checked
|
2025-06-08 16:32:41 +02:00
|
|
|
bind:indeterminate
|
|
|
|
|
{...restProps}
|
2024-04-11 17:18:21 +02:00
|
|
|
>
|
2025-06-08 16:32:41 +02:00
|
|
|
{#snippet children({ checked, indeterminate })}
|
2026-04-06 18:22:01 +02:00
|
|
|
<div
|
|
|
|
|
data-slot="checkbox-indicator"
|
|
|
|
|
class="[&>svg]:size-3.5 grid place-content-center text-current transition-none"
|
|
|
|
|
>
|
2025-06-21 21:07:36 +02:00
|
|
|
{#if checked}
|
2026-04-06 18:22:01 +02:00
|
|
|
<CheckIcon />
|
2025-06-21 21:07:36 +02:00
|
|
|
{:else if indeterminate}
|
2026-04-06 18:22:01 +02:00
|
|
|
<MinusIcon />
|
2025-06-08 16:32:41 +02:00
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
{/snippet}
|
2024-04-11 17:18:21 +02:00
|
|
|
</CheckboxPrimitive.Root>
|