Slider
SwiftUI's Slider. Press the thumb and it lifts into a glass droplet; drag it, past the ends or off the track, and let go moving and it runs on. The track itself takes no touch.
import { Slider } from "@adamexu/glass";Basic
onChange runs on every frame of a drag and of the run-on after it. onEditingChanged is SwiftUI's: true at the first change of a drag, false once the value has stopped.
const [value, setValue] = useState(0.6);
const [editing, setEditing] = useState(false);
<Slider
aria-label="Brightness"
value={value}
onChange={setValue}
onEditingChanged={setEditing}
minimumValueLabel={<SunDim size={22} className="glass-slider__icon" />}
maximumValueLabel={<Sun size={22} className="glass-slider__icon" />}
/>Ticks, steps and a neutral value
Ticks are marks the thumb snaps to. step rounds the value and puts a tick at every step, as on iOS. neutralValue is where the fill starts, so it can grow either way. thumbHidden draws the track alone.
const [rating, setRating] = useState(3);
<Slider aria-label="Size" defaultValue={0.5} ticks={[0, 0.25, 0.5, 0.75, 1]} tint="#ff5a1f" />
<Slider aria-label="Rating" in={[1, 5]} step={1} value={rating} onChange={setRating} />
<Slider aria-label="Balance" defaultValue={0.7} neutralValue={0.5} />
<Slider aria-label="Progress" defaultValue={0.6} thumbHidden />Props
| Prop | Type | Default | Description |
|---|---|---|---|
| value | number | - | SwiftUI value: controlled. Leave it out and the slider keeps its own. |
| defaultValue | number | the middle | The initial value when uncontrolled. |
| onChange | (value: number) => void | - | Every frame of a drag and of the run-on after it. |
| onEditingChanged | (editing: boolean) => void | - | True at the first change of a drag (a press alone reports nothing), false when the value has stopped. |
| in | [number, number] | [0, 1] | SwiftUI in: the range. |
| step | number | - | SwiftUI step: rounds the value, with a tick at every step. |
| ticks | number[] | - | SwiftUI ticks: marks at these values, which the thumb snaps to. |
| neutralValue | number | - | SwiftUI neutralValue: the fill runs from here to the thumb. |
| enabledBounds | [number, number] | - | SwiftUI enabledBounds. Only the upper bound stops a drag, as on iOS 27.2. |
| minimumValueLabel | ReactNode | - | Drawn before the track. |
| maximumValueLabel | ReactNode | - | Drawn after the track. |
| label | string | - | SwiftUI label: only spoken, the accessible name when there is no aria-label. |
| currentValueLabel | string | - | Spoken as the value's text (aria-valuetext). |
| tint | string | - | SwiftUI .tint(_:): the fill colour. |
| thumbHidden | boolean | false | SwiftUI .sliderThumbVisibility(.hidden). |
| disabled | boolean | false | SwiftUI .disabled(_:). |
| animated | boolean | false | withAnimation: a new value from outside springs there instead of jumping. |
| idiom | "phone" | "pad" | "duo" | "phone" | The device whose feel to match. The look is the same; on iPad a drag holds a moment longer. |
| id, aria-label | string | - | Go on the role="slider" element. |
| className, style | string, CSSProperties | - | On the outer box. |
Behaviour
The slider is a role="slider" element: the arrow keys step it (by step, or a hundredth of the range), Page Up and Page Down move a tenth, Home and End jump to the ends. It is drawn for Chromium, where the lifted thumb refracts the track and whatever is behind it.
SwiftUI
| SwiftUI | @adamexu/glass |
|---|---|
| Slider(value:in:step:) | <Slider value onChange in step> |
| Slider(...) minimumValueLabel: maximumValueLabel: | <Slider minimumValueLabel maximumValueLabel> |
| Slider(..., onEditingChanged:) | onEditingChanged |
| Slider(..., neutralValue:) | neutralValue |
| Slider(...) ticks: | ticks |
| .sliderThumbVisibility(.hidden) | thumbHidden |
| .tint(.orange) | tint="orange" |