Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
<script lang="ts">
import { Slider as SliderPrimitive } from 'bits-ui';
import { cn, type WithoutChildrenOrChild } from '#lib/utils.js';
let {
ref = $bindable(null),
value = $bindable(),
orientation = 'horizontal',
showTicks = false,
class: className,
...restProps
}: WithoutChildrenOrChild<SliderPrimitive.RootProps> & { showTicks?: boolean } = $props();
</script>
<!--
Discriminated Unions + Destructing (required for bindable) do not
get along, so we shut typescript up by casting `value` to `never`.
-->
<SliderPrimitive.Root
bind:ref
bind:value={value as never}
data-slot="slider"
{orientation}
class={cn(
'relative flex w-full touch-none items-center select-none data-disabled:opacity-50 data-vertical:h-full data-vertical:min-h-40 data-vertical:w-auto data-vertical:flex-col',
className
)}
{...restProps}
>
{#snippet children({ thumbItems, ticks })}
<span
data-slot="slider-track"
data-orientation={orientation}
class={cn(
'relative grow overflow-hidden rounded-full bg-muted data-horizontal:h-1 data-horizontal:w-full data-vertical:h-full data-vertical:w-1'
)}
>
<SliderPrimitive.Range
data-slot="slider-range"
class={cn('absolute bg-primary select-none data-horizontal:h-full data-vertical:w-full')}
/>
</span>
{#if showTicks && orientation === 'horizontal' && ticks.length > 1}
<span
aria-hidden="true"
data-slot="slider-ticks"
class="pointer-events-none absolute inset-x-0 top-1/2 -mt-0.5 h-1 bg-[repeating-linear-gradient(to_right,var(--muted-foreground)_0,var(--muted-foreground)_1px,transparent_1px,transparent_calc((100%_-_1px)_/_var(--tick-gaps)))]"
style="--tick-gaps: {ticks.length - 1}"
></span>
{/if}
{#each thumbItems as thumb (thumb.index)}
<SliderPrimitive.Thumb
data-slot="slider-thumb"
index={thumb.index}
class="relative block size-3 shrink-0 rounded-full border border-ring bg-white ring-ring/50 transition-[color,box-shadow] select-none after:absolute after:-inset-2 hover:ring-3 focus-visible:ring-3 focus-visible:outline-hidden active:ring-3 disabled:pointer-events-none disabled:opacity-50"
/>
{/each}
{/snippet}
</SliderPrimitive.Root>