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

36 lines
1.2 KiB
Svelte
Raw Normal View History

2024-04-11 17:18:21 +02:00
<script lang="ts">
2025-06-08 16:32:41 +02:00
import { Checkbox as CheckboxPrimitive, type WithoutChildrenOrChild } from "bits-ui";
import Check from "@lucide/svelte/icons/check";
import Minus from "@lucide/svelte/icons/minus";
2024-04-11 17:18:21 +02:00
import { cn } from "$lib/utils.js";
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
2024-04-11 17:18:21 +02:00
class={cn(
2025-06-08 16:32:41 +02:00
"border-primary ring-offset-background focus-visible:ring-ring data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground peer box-content size-4 shrink-0 rounded-sm border focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[disabled=true]:cursor-not-allowed data-[disabled=true]: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 })}
<div class="flex size-4 items-center justify-center text-current">
{#if indeterminate}
<Minus class="size-3.5" />
{:else}
<Check class={cn("size-3.5", !checked && "text-transparent")} />
{/if}
</div>
{/snippet}
2024-04-11 17:18:21 +02:00
</CheckboxPrimitive.Root>