leptos_bootstrap/v5/
progress.rs1use leptos::prelude::*;
2use std::fmt;
3
4pub enum ProgressBarKind {
5 Default,
6 Success,
7 Info,
8 Warning,
9 Danger,
10}
11
12impl fmt::Display for ProgressBarKind {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 let s = match self {
15 Self::Default => "",
16 Self::Success => "bg-success",
17 Self::Info => "bg-info",
18 Self::Warning => "bg-warning",
19 Self::Danger => "bg-danger",
20 };
21 write!(f, "{}", s)
22 }
23}
24
25#[component]
26pub fn ProgressBar<'a>(
27 percent: f64,
28 #[prop(default=ProgressBarKind::Default)] kind: ProgressBarKind,
29 #[prop(default = false)] striped: bool,
30 #[prop(default = false)] animated: bool,
31 #[prop(optional, into)] class: &'a str,
32) -> impl IntoView {
33 let progress = format!("progress {}", class);
34 let mut bar = format!("progress-bar {}", kind);
35 if striped {
36 bar.push_str(" progress-bar-striped");
37 }
38 if animated {
39 bar.push_str(" progress-bar-animated");
40 }
41 let style = format!("width: {}%", percent);
42 view! {
43 <div class=progress>
44 <div class=bar style=style></div>
45 </div>
46 }
47}