Files
gpx.studio/website/src/lib/components/ui/checkbox/checkbox.svelte

37 lines
1.4 KiB
Svelte
Raw Normal View History

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 CheckIcon from "@lucide/svelte/icons/check";
import MinusIcon from "@lucide/svelte/icons/minus";
import { cn, type WithoutChildrenOrChild } from "$lib/utils.js";
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(
2025-06-21 21:07:36 +02:00
"border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive shadow-xs peer flex size-4 shrink-0 items-center justify-center rounded-[4px] border outline-none transition-shadow focus-visible:ring-[3px] 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 })}
2025-06-21 21:07:36 +02:00
<div data-slot="checkbox-indicator" class="text-current transition-none">
{#if checked}
<CheckIcon class="size-3.5" />
{:else if indeterminate}
<MinusIcon class="size-3.5" />
2025-06-08 16:32:41 +02:00
{/if}
</div>
{/snippet}
2024-04-11 17:18:21 +02:00
</CheckboxPrimitive.Root>