Slider
One value or a range, with marks, named detents that pull the thumb, a live cost tag, a vertical form and a value bubble.
oxyn add sliderlet mut effort = SliderModel::new(1.0, 0.0, 3.0, 0.01);
effort.snap = 0.25; // pulls to the named detents
effort.marks = ["Low", "Medium", "High", "Max"].iter().enumerate()
.map(|(i, l)| Mark { value: i as f64, label: (*l).into(), detent: true }).collect();
rsx! {
Slider {
slider: effort,
label: "Effort",
tag: "≈ $0.42 / run",
on_commit: move |v: Vec<f64>| save(v),
}
}Rendered from Rust at build time · goes live when visible
When to use
- Pick a value or a range on a track that follows the finger: temperature, effort, budget, volume.
When not to use
- How hard the model thinks: use Effort control instead.
- Numbers that roll digit by digit like an odometer, or count up through the values in between: use Number Ticker instead.
- On or off for things that apply right away: use Switch instead.
Installation
Slider is free and MIT. The oxyn CLI copies its code, and the components it needs, into src/oxyn/ of your Dioxus or GPUI project, so it is yours to change.
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add slideruse crate::oxyn::{Slider, PRIMITIVES_CSS};Rather depend on the crate? cargo add oxyn-dioxus oxyn-core --git https://github.com/ismailqureshi72/Oxyn, then use oxyn_dioxus::{Slider, PRIMITIVES_CSS};
Usage
let mut effort = SliderModel::new(1.0, 0.0, 3.0, 0.01);
effort.snap = 0.25; // pulls to the named detents
effort.marks = ["Low", "Medium", "High", "Max"].iter().enumerate()
.map(|(i, l)| Mark { value: i as f64, label: (*l).into(), detent: true }).collect();
rsx! {
Slider {
slider: effort,
label: "Effort",
tag: "≈ $0.42 / run",
on_commit: move |v: Vec<f64>| save(v),
}
}Examples
Detents
Effort with named stops and a cost tag.
Code
let mut effort = SliderModel::new(1.0, 0.0, 3.0, 0.01);
effort.snap = 0.25; // pulls to the named detents
effort.marks = ["Low", "Medium", "High", "Max"].iter().enumerate()
.map(|(i, l)| Mark { value: i as f64, label: (*l).into(), detent: true }).collect();
rsx! {
Slider {
slider: effort,
label: "Effort",
tag: "≈ $0.42 / run",
on_commit: move |v: Vec<f64>| save(v),
}
}Single
Temperature with marks.
Code
let temperature = SliderModel::new(0.7, 0.0, 2.0, 0.1);
rsx! {
Slider {
slider: temperature,
label: "Temperature",
decimals: 1,
on_commit: move |v: Vec<f64>| save(v),
}
}Range
Two thumbs for a budget.
Code
let mut budget = SliderModel::range(20.0, 60.0, 0.0, 100.0, 5.0);
budget.min_steps_between = 2;
rsx! {
Slider {
slider: budget,
label: "Monthly budget",
format: "$#",
thumb_labels: vec!["Minimum".into(), "Maximum".into()],
on_commit: move |v: Vec<f64>| save(v),
}
}Vertical
Vertical volume.
Code
let mut volume = SliderModel::new(60.0, 0.0, 100.0, 1.0);
volume.vertical = true;
rsx! {
Slider {
slider: volume,
label: "Volume",
format: "#%",
on_commit: move |v: Vec<f64>| save(v),
}
}Icons
Start and end content around the track (Arc start / end).
Code
let temperature = SliderModel::new(0.7, 0.0, 2.0, 0.1);
rsx! {
Slider {
slider: temperature,
label: "Temperature",
decimals: 1,
on_commit: move |v: Vec<f64>| save(v),
}
}API reference
Slider
| Prop | Type | Default | Description |
|---|---|---|---|
sliderrequired | SliderModel | — | Model. |
labelrequired | String | — | Accessible name. |
format | String | "#" | Readout format: `#` is replaced by the value (`"#%"`, `"$#"`). |
decimals | usize | Default::default() | Decimals in the readout. |
show_value | bool | true | Show the value next to the label. |
thumb_labels | Vec<String> | Default::default() | Thumb labels for a range ("Min", "Max"). |
tag | Option<String> | Default::default() | Oxyn plus: a live tag after the readout ("≈ $0.42 / run"). |
active | Option<usize> | Default::default() | Review sheets: show the bubble over thumb `i`. |
on_change | EventHandler<Vec<f64>> | — | Value changed. |
on_commit | EventHandler<Vec<f64>> | — | Committed (released / key up). |
start | Option<String> | Default::default() | Icon before the track (Arc `start`). |
end | Option<String> | Default::default() | Icon after the track (Arc `end`). |
Read from the Rust signature and doc comments.
Keyboard interactions
| Key | Action |
|---|---|
| ←or↓ and →or↑ | One step |
| ShiftarrowsorPage UporDown | Ten steps |
| HomeorEnd | Min / max |
Accessibility
- Each thumb is a role=slider with min, max, now and a formatted aria-valuetext.
- Range thumbs are named by thumb_labels ("Minimum", "Maximum").
From the spec
Each thumb is focusable with role=slider, min / max / now and a formatted aria-valuetext; range thumbs are named by thumb_labels ("Minimum", "Maximum"). Changes fire on keys as well as drags.
Motion & interaction
Released drags carry a little momentum (≤ 180 ms) before snapping to the step; the bubble springs up over the active thumb; digits roll in the readout. At a limit the thumb strains (rubber band 6 × (1 − e^(−over/40)) px) and springs back (Arc). Keyboard moves glide on spring.snap.
Timing
| Transition | Duration | Easing | Reduced motion |
|---|---|---|---|
| Thumb glide (click / key) | 214 ms | spring.snap | instant |
| Bubble | 120 ms in / out | ease.out | fade 80 ms |
| Momentum | ≤ 180 ms | ease.out | none |
| Strain return | 214 ms | spring.snap | none |
| Readout digit roll | 280 ms | ease.out | swap |
| Hover grow | 80 ms | ease.out | none |
Responsive behaviour
- The track fills its container.
- Very small tracks keep a 16 px thumb and a 20 px hit height.
Edge cases (spec)
Floating steps (0.1) are rounded so values never read 0.30000000000000004. min == max renders a full fill at 0. A press exactly between range thumbs goes to the first. Very small tracks keep a 16 px thumb and 20 px hit height. Marks without labels are ticks; labelled marks reserve 14 px below.
Notes for AI
- Import
Sliderfromoxyn_dioxusand includePRIMITIVES_CSSplus the token stylesheet once. - A GPUI version exists:
SliderElinoxyn_gpui. - Props to set first:
slider,label. - Keep its states and timings as they ship; restyle it through the CSS variables rather than by hand.