Inputs
Slider
Range input with a single thumb or two thumbs, plus min, max and step.
<script>
import { Slider } from "@codeatlasdev/ui";
let volume = $state(60);
let range = $state([20, 75]);
</script>
<Slider bind:value={volume} />
<Slider bind:values={range} />
value and values are independent: bind one or the other. The bare slider has no visible label or value readout: pass label so assistive tech hears “Radius” instead of “Value 40”, and use SliderField when you want the label and an editable number built in. Arrow keys move by step, Home and End jump to the bounds.
#046Single value
Binds a plain number. Default range is 0 to 100.
Reference #046 · Pick in the gallery
Code
<script lang="ts">
import { Slider } from '@codeatlasdev/ui';
let volume = $state(60);
let brightness = $state(40);
</script>
<div class="col">
<div class="row">
<span class="label">Volume</span>
<Slider bind:value={volume} min={0} max={100} />
<span class="val">{volume}</span>
</div>
<div class="row">
<span class="label">Brightness</span>
<Slider bind:value={brightness} min={0} max={100} />
<span class="val">{brightness}%</span>
</div>
</div>
<style>
.col {
display: flex;
flex-direction: column;
gap: var(--ca-space-5);
width: 100%;
max-width: 480px;
}
.row {
display: flex;
align-items: center;
gap: 14px;
}
.label {
flex-shrink: 0;
min-width: 76px;
font-size: var(--ca-font-size-body2);
color: var(--ca-text-secondary);
}
.val {
flex-shrink: 0;
min-width: 64px;
text-align: right;
font-family: var(--ca-font-mono);
font-size: var(--ca-font-size-body2);
font-weight: 600;
color: var(--ca-brand-text);
}
</style>
#045Range
Bind a [min, max] tuple to values for two thumbs.
Reference #045 · Pick in the gallery
Code
<script lang="ts">
import { Slider } from '@codeatlasdev/ui';
let range = $state<[number, number]>([20, 75]);
</script>
<div class="row">
<span class="label">Price</span>
<Slider bind:values={range} min={0} max={100} />
<span class="val">${range[0]} – ${range[1]}</span>
</div>
<style>
.row {
display: flex;
align-items: center;
gap: 14px;
width: 100%;
max-width: 480px;
}
.label {
flex-shrink: 0;
min-width: 76px;
font-size: var(--ca-font-size-body2);
color: var(--ca-text-secondary);
}
.val {
flex-shrink: 0;
min-width: 88px;
text-align: right;
font-family: var(--ca-font-mono);
font-size: var(--ca-font-size-body2);
font-weight: 600;
color: var(--ca-brand-text);
}
</style>
#047Step and disabled
step={10} snaps to increments of 10.
Reference #047 · Pick in the gallery
Code
<script lang="ts">
import { Slider } from '@codeatlasdev/ui';
let stepped = $state(50);
</script>
<div class="col">
<div class="row">
<span class="label">Step 10</span>
<Slider bind:value={stepped} min={0} max={100} step={10} />
<span class="val">{stepped}</span>
</div>
<div class="row">
<span class="label">Disabled</span>
<Slider value={35} disabled />
<span class="val">35</span>
</div>
</div>
<style>
.col {
display: flex;
flex-direction: column;
gap: var(--ca-space-5);
width: 100%;
max-width: 480px;
}
.row {
display: flex;
align-items: center;
gap: 14px;
}
.label {
flex-shrink: 0;
min-width: 76px;
font-size: var(--ca-font-size-body2);
color: var(--ca-text-secondary);
}
.val {
flex-shrink: 0;
min-width: 64px;
text-align: right;
font-family: var(--ca-font-mono);
font-size: var(--ca-font-size-body2);
font-weight: 600;
color: var(--ca-brand-text);
}
</style>
Props
| Prop | Type | Default | Description |
|---|
value | number | – | Single-value mode: bind a plain number. Defaults to the midpoint when neither value nor values is set. |
values | [number, number] | – | Range mode: bind a [min, max] tuple. |
min | number | 0 | Minimum value. |
max | number | 100 | Maximum value. |
step | number | 1 | Step increment. |
label | string | – | Accessible name of the thumb. Without it a thumb is announced as "Value 40". A range appends "minimum" and "maximum". |
disabled | boolean | false | Disables the slider. |
class | string | – | Extra classes on the root. |
onchange | (value: number[]) => void | – | Called on change. Always receives an array: one number in single mode, two in range mode. |
SliderField
A labelled slider with an editable number and an optional unit, for settings where people scrub and also type an exact value.
<script>
import { SliderField } from "@codeatlasdev/ui";
let radius = $state(0.8);
</script>
<SliderField label="Radius" bind:value={radius} min={0} max={2} step={0.05} unit="x" />
The slider scrubs, the number field types. Both write the same value. A typed value is clamped to the range and snapped to step when the field commits (Enter or blur), so 1.234 with step={0.05} becomes 1.25. The label names both controls, and Arrow, Page and Home/End keys work on the slider.
#992Label and number
Label, slider and an editable number with a unit.
Multiplies every font size.
Reference #992 · Pick in the gallery
Code
<script lang="ts">
import { SliderField } from '@codeatlasdev/ui';
let radius = $state(0.8);
let scale = $state(1);
</script>
<div class="col">
<SliderField label="Radius" bind:value={radius} min={0} max={2} step={0.05} unit="x" />
<SliderField label="Type scale" bind:value={scale} min={0.8} max={1.3} step={0.01} unit="x" description="Multiplies every font size." />
</div>
<style>
.col {
display: flex;
flex-direction: column;
gap: var(--ca-space-4);
max-inline-size: 22rem;
}
</style>
SliderField props
| Prop | Type | Default | Description |
|---|
label | string | – | Visible label and the accessible name of both controls. |
value | number | 0 | Bindable value. |
min | number | 0 | Minimum value. |
max | number | 100 | Maximum value. |
step | number | 1 | Step. Also sets the decimals shown. |
unit | string | – | Unit shown after the number (px, rem, deg, x). |
description | string | – | Hint under the slider. |
disabled | boolean | false | Disables both controls. |
class | string | – | Extra classes on the root. |
onchange | (value: number) => void | – | Called once per committed change of either control. |