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

53 lines
1.7 KiB
Svelte
Raw Normal View History

2024-06-10 20:03:57 +02:00
<script lang="ts">
2025-06-21 21:07:36 +02:00
import { Slider as SliderPrimitive } from "bits-ui";
import { cn, type WithoutChildrenOrChild } from "$lib/utils.js";
2024-06-10 20:03:57 +02:00
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}
2025-06-21 21:07:36 +02:00
data-slot="slider"
2025-06-08 16:32:41 +02:00
{orientation}
class={cn(
2025-06-21 21:07:36 +02:00
"relative flex w-full touch-none select-none items-center data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col data-[disabled]:opacity-50",
2025-06-08 16:32:41 +02:00
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}
2025-06-21 21:07:36 +02:00
data-slot="slider-track"
class={cn(
"bg-muted relative grow overflow-hidden rounded-full data-[orientation=horizontal]:h-1.5 data-[orientation=vertical]:h-full data-[orientation=horizontal]:w-full data-[orientation=vertical]:w-1.5"
)}
2025-06-08 16:32:41 +02:00
>
<SliderPrimitive.Range
2025-06-21 21:07:36 +02:00
data-slot="slider-range"
class={cn(
"bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full"
)}
2025-06-08 16:32:41 +02:00
/>
</span>
{#each thumbs as thumb (thumb)}
<SliderPrimitive.Thumb
2025-06-21 21:07:36 +02:00
data-slot="slider-thumb"
2025-06-08 16:32:41 +02:00
index={thumb}
2025-06-21 21:07:36 +02:00
class="border-primary bg-background ring-ring/50 focus-visible:outline-hidden block size-4 shrink-0 rounded-full border shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 disabled:pointer-events-none disabled:opacity-50"
2025-06-08 16:32:41 +02:00
/>
{/each}
{/snippet}
2024-06-10 20:03:57 +02:00
</SliderPrimitive.Root>