Skip to main content

nightshade_api/web/base/
progress.rs

1use leptos::prelude::*;
2
3/// A horizontal progress bar. The reactive `value` is divided by `max`
4/// (default `1.0`) and clamped to fill 0% to 100% of the track.
5#[component]
6pub fn Progress(
7    #[prop(into)] value: Signal<f64>,
8    #[prop(default = 1.0)] max: f64,
9) -> impl IntoView {
10    let ceiling = if max <= 0.0 { 1.0 } else { max };
11    let percent = move || (value.get() / ceiling).clamp(0.0, 1.0) * 100.0;
12    view! {
13        <div
14            class="nightshade-progress"
15            role="progressbar"
16            aria-valuemin="0"
17            aria-valuemax=ceiling.to_string()
18            aria-valuenow=move || value.get().to_string()
19        >
20            <div class="nightshade-progress-fill" style=move || format!("width:{}%", percent())></div>
21        </div>
22    }
23}