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

45 lines
1.6 KiB
Svelte
Raw Normal View History

2024-06-10 20:03:57 +02:00
<script lang="ts">
2025-06-08 16:32:41 +02:00
import { Slider as SliderPrimitive, type WithoutChildrenOrChild } from "bits-ui";
2024-06-10 20:03:57 +02:00
import { cn } from "$lib/utils.js";
2025-06-08 16:32:41 +02:00
let {
ref = $bindable(null),
value = $bindable(),
orientation = "horizontal",
class: className,
...restProps
}: WithoutChildrenOrChild<SliderPrimitive.RootProps> = $props();
2024-06-10 20:03:57 +02:00
</script>
2025-06-08 16:32:41 +02:00
<!--
Discriminated Unions + Destructing (required for bindable) do not
get along, so we shut typescript up by casting `value` to `never`.
-->
2024-06-10 20:03:57 +02:00
<SliderPrimitive.Root
2025-06-08 16:32:41 +02:00
bind:ref
bind:value={value as never}
{orientation}
class={cn(
"relative flex touch-none select-none items-center data-[orientation='vertical']:h-full data-[orientation='vertical']:min-h-44 data-[orientation='horizontal']:w-full data-[orientation='vertical']:w-auto data-[orientation='vertical']:flex-col",
className
)}
{...restProps}
2024-06-10 20:03:57 +02:00
>
2025-06-08 16:32:41 +02:00
{#snippet children({ thumbs })}
<span
data-orientation={orientation}
class="bg-secondary relative grow overflow-hidden rounded-full data-[orientation='horizontal']:h-2 data-[orientation='vertical']:h-full data-[orientation='horizontal']:w-full data-[orientation='vertical']:w-2"
>
<SliderPrimitive.Range
class="bg-primary absolute data-[orientation='horizontal']:h-full data-[orientation='vertical']:w-full"
/>
</span>
{#each thumbs as thumb (thumb)}
<SliderPrimitive.Thumb
index={thumb}
class="border-primary bg-background ring-offset-background focus-visible:ring-ring block size-5 rounded-full border-2 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"
/>
{/each}
{/snippet}
2024-06-10 20:03:57 +02:00
</SliderPrimitive.Root>