Files
gpx.studio/website/src/lib/components/ui/dropdown-menu/dropdown-menu-checkbox-item.svelte

42 lines
1.4 KiB
Svelte
Raw Normal View History

2024-04-08 17:12:39 +02:00
<script lang="ts">
2025-06-21 21:07:36 +02:00
import { DropdownMenu as DropdownMenuPrimitive } 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";
2025-06-08 16:32:41 +02:00
import type { Snippet } from "svelte";
2024-04-08 17:12:39 +02:00
2025-06-08 16:32:41 +02:00
let {
ref = $bindable(null),
checked = $bindable(false),
indeterminate = $bindable(false),
class: className,
children: childrenProp,
...restProps
}: WithoutChildrenOrChild<DropdownMenuPrimitive.CheckboxItemProps> & {
children?: Snippet;
} = $props();
2024-04-08 17:12:39 +02:00
</script>
<DropdownMenuPrimitive.CheckboxItem
2025-06-08 16:32:41 +02:00
bind:ref
2024-04-08 17:12:39 +02:00
bind:checked
2025-06-08 16:32:41 +02:00
bind:indeterminate
2025-06-21 21:07:36 +02:00
data-slot="dropdown-menu-checkbox-item"
2024-04-08 17:12:39 +02:00
class={cn(
2025-06-21 21:07:36 +02:00
"focus:bg-accent focus:text-accent-foreground outline-hidden relative flex cursor-default select-none items-center gap-2 rounded-sm py-1.5 pl-8 pr-2 text-sm data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
2024-04-08 17:12:39 +02:00
className
)}
2025-06-08 16:32:41 +02:00
{...restProps}
2024-04-08 17:12:39 +02:00
>
2025-06-08 16:32:41 +02:00
{#snippet children({ checked, indeterminate })}
2025-06-21 21:07:36 +02:00
<span class="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
2025-06-08 16:32:41 +02:00
{#if indeterminate}
2025-06-21 21:07:36 +02:00
<MinusIcon class="size-4" />
2025-06-08 16:32:41 +02:00
{:else}
2025-06-21 21:07:36 +02:00
<CheckIcon class={cn("size-4", !checked && "text-transparent")} />
2025-06-08 16:32:41 +02:00
{/if}
</span>
{@render childrenProp?.()}
{/snippet}
2024-04-08 17:12:39 +02:00
</DropdownMenuPrimitive.CheckboxItem>