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(
|
2026-04-06 18:22:01 +02:00
|
|
|
"data-vertical:min-h-40 relative flex w-full touch-none items-center select-none data-disabled:opacity-50 data-vertical:h-full data-vertical:w-auto data-vertical:flex-col",
|
2025-06-08 16:32:41 +02:00
|
|
|
className
|
|
|
|
|
)}
|
|
|
|
|
{...restProps}
|
2024-06-10 20:03:57 +02:00
|
|
|
>
|
2026-04-06 18:22:01 +02:00
|
|
|
{#snippet children({ thumbItems })}
|
2025-06-08 16:32:41 +02:00
|
|
|
<span
|
2025-06-21 21:07:36 +02:00
|
|
|
data-slot="slider-track"
|
2026-04-06 18:22:01 +02:00
|
|
|
data-orientation={orientation}
|
2025-06-21 21:07:36 +02:00
|
|
|
class={cn(
|
2026-04-06 18:22:01 +02:00
|
|
|
"h-1.5 bg-muted rounded-full data-horizontal:h-1 data-horizontal:w-full data-vertical:h-full data-vertical:w-1 bg-muted relative grow overflow-hidden data-horizontal:w-full data-vertical:h-full"
|
2025-06-21 21:07:36 +02:00
|
|
|
)}
|
2025-06-08 16:32:41 +02:00
|
|
|
>
|
|
|
|
|
<SliderPrimitive.Range
|
2025-06-21 21:07:36 +02:00
|
|
|
data-slot="slider-range"
|
|
|
|
|
class={cn(
|
2026-04-06 18:22:01 +02:00
|
|
|
"h-full bg-black absolute select-none data-horizontal:h-full data-vertical:w-full"
|
2025-06-21 21:07:36 +02:00
|
|
|
)}
|
2025-06-08 16:32:41 +02:00
|
|
|
/>
|
|
|
|
|
</span>
|
2026-04-06 18:22:01 +02:00
|
|
|
{#each thumbItems as thumb (thumb)}
|
2025-06-08 16:32:41 +02:00
|
|
|
<SliderPrimitive.Thumb
|
2025-06-21 21:07:36 +02:00
|
|
|
data-slot="slider-thumb"
|
2026-04-06 18:22:01 +02:00
|
|
|
index={thumb.index}
|
|
|
|
|
class="border-ring ring-ring/50 relative size-4 rounded-full border bg-white transition-[color,box-shadow] after:absolute after:-inset-2 hover:ring-3 focus-visible:ring-3 focus-visible:outline-hidden active:ring-3 block shrink-0 select-none 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>
|