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

41 lines
1.3 KiB
Svelte
Raw Normal View History

2024-04-08 17:12:39 +02:00
<script lang="ts">
2025-06-08 16:32:41 +02:00
import { DropdownMenu as DropdownMenuPrimitive, type WithoutChildrenOrChild } from "bits-ui";
import Check from "@lucide/svelte/icons/check";
import Minus from "@lucide/svelte/icons/minus";
2024-04-08 17:12:39 +02:00
import { cn } 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
2024-04-08 17:12:39 +02:00
class={cn(
2025-06-08 16:32:41 +02:00
"data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
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 })}
<span class="absolute left-2 flex size-3.5 items-center justify-center">
{#if indeterminate}
<Minus class="size-4" />
{:else}
<Check class={cn("size-4", !checked && "text-transparent")} />
{/if}
</span>
{@render childrenProp?.()}
{/snippet}
2024-04-08 17:12:39 +02:00
</DropdownMenuPrimitive.CheckboxItem>