Biji UI

Slider

An input where the user selects a value from within a given range.

Volume
Temperature (step: 5)
Disabled

Installation

biji-ui = { version = "0.5.0", features = ["slider"] }

Usage

use leptos::prelude::*;
use biji_ui::components::slider;

#[component]
pub fn MySlider() -> impl IntoView {
    view! {
        <slider::Root
            default_value=50.0
            class="relative flex items-center w-full h-5 touch-none select-none"
        >
            <slider::Track class="relative flex-1 h-2 overflow-hidden rounded-full bg-secondary">
                <slider::Range class="absolute h-full bg-primary" />
            </slider::Track>
            <slider::Thumb class="absolute block w-5 h-5 -translate-x-1/2 rounded-full border-2 border-primary bg-background shadow transition outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-background" />
        </slider::Root>
    }
}

RootWith

Use <RootWith> when you need direct access to SliderState inside the children. The let:s binding exposes s.value and s.percentage as reactive signals for custom rendering.

Volume50
use leptos::prelude::*;
use biji_ui::components::slider;

#[component]
pub fn LabeledSlider() -> impl IntoView {
    let thumb_class = "absolute block w-5 h-5 -translate-x-1/2 rounded-full border-2 border-primary bg-background shadow transition outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-background cursor-grab active:cursor-grabbing";

    view! {
        <slider::RootWith
            default_value=50.0
            min=0.0
            max=100.0
            class="flex flex-col gap-2 w-full"
            let:s
        >
            <div class="flex justify-between items-center text-sm">
                <span>"Volume"</span>
                <span class="tabular-nums font-medium">{move || s.value.get() as u32}</span>
            </div>
            <div class="relative flex items-center w-full h-5 touch-none select-none">
                <slider::Track class="relative h-2 w-full grow overflow-hidden rounded-full bg-secondary">
                    <slider::Range class="absolute h-full bg-primary" />
                </slider::Track>
                <slider::Thumb class={thumb_class} />
            </div>
        </slider::RootWith>
    }
}

API Reference

Root / RootWith

NameTypeDefaultDescription
classString""CSS class applied to the slider root element.
valuef640.0The initial value of the slider.
minf640.0The minimum value of the slider.
maxf64100.0The maximum value of the slider.
stepf641.0The step increment for keyboard navigation and snapping.
disabledboolfalseWhen true, prevents the slider from being interacted with.

Track

NameTypeDefaultDescription
classString""CSS class applied to the track element.

Range

NameTypeDefaultDescription
classString""CSS class applied to the range fill element.

Thumb

NameTypeDefaultDescription
classString""CSS class applied to the thumb element.

Data Attributes

AttributeDescription
data-state"enabled" when the slider is interactive; "disabled" when disabled. Present on Root.
data-disabledPresent on Root, Track, Range, and Thumb when the slider is disabled.
data-orientationAlways "horizontal". Present on Root, Track, and Range.

Keyboard Navigation

KeyDescription
ArrowRight / ArrowUpIncreases the value by one step.
ArrowLeft / ArrowDownDecreases the value by one step.
Page UpIncreases the value by ten steps.
Page DownDecreases the value by ten steps.
HomeSets the value to the minimum.
EndSets the value to the maximum.