Skip to content

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 slider
MCP
EffortMedium≈ $0.42 / run
Dioxus
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),
    }
}

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.

Terminal
cargo install --git https://github.com/ismailqureshi72/Oxyn oxyn-cli
oxyn init
oxyn add slider
Rust
use 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

Dioxus · rust
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.

EffortMedium≈ $0.42 / run
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.

Temperature0.7
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.

Monthly budget$20 – $60
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.

Volume60%
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).

Temperature0.7
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

PropTypeDefaultDescription
sliderrequiredSliderModel—Model.
labelrequiredString—Accessible name.
formatString"#"Readout format: `#` is replaced by the value (`"#%"`, `"$#"`).
decimalsusizeDefault::default()Decimals in the readout.
show_valuebooltrueShow the value next to the label.
thumb_labelsVec<String>Default::default()Thumb labels for a range ("Min", "Max").
tagOption<String>Default::default()Oxyn plus: a live tag after the readout ("≈ $0.42 / run").
activeOption<usize>Default::default()Review sheets: show the bubble over thumb `i`.
on_changeEventHandler<Vec<f64>>—Value changed.
on_commitEventHandler<Vec<f64>>—Committed (released / key up).
startOption<String>Default::default()Icon before the track (Arc `start`).
endOption<String>Default::default()Icon after the track (Arc `end`).

Read from the Rust signature and doc comments.

Keyboard interactions

KeyAction
←or↓ and →or↑One step
ShiftarrowsorPage UporDownTen steps
HomeorEndMin / 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
TransitionDurationEasingReduced motion
Thumb glide (click / key)214 msspring.snapinstant
Bubble120 ms in / outease.outfade 80 ms
Momentum≤ 180 msease.outnone
Strain return214 msspring.snapnone
Readout digit roll280 msease.outswap
Hover grow80 msease.outnone

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 Slider from oxyn_dioxus and include PRIMITIVES_CSS plus the token stylesheet once.
  • A GPUI version exists: SliderEl in oxyn_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.

Guides

Oxyn · 74 free components · 264 Pro components · 96 screens · 20 blocks · Dioxus and GPUI