dioxus_bootstrap_css/
progress.rs1use dioxus::prelude::*;
2
3use crate::types::Color;
4
5#[derive(Clone, PartialEq, Props)]
42pub struct ProgressProps {
43 #[props(default)]
45 pub class: String,
46 #[props(extends = GlobalAttributes)]
48 attributes: Vec<Attribute>,
49 pub children: Element,
51}
52
53#[component]
54pub fn Progress(props: ProgressProps) -> Element {
55 let full_class = if props.class.is_empty() {
56 "progress".to_string()
57 } else {
58 format!("progress {}", props.class)
59 };
60
61 rsx! {
62 div { class: "{full_class}", ..props.attributes, {props.children} }
63 }
64}
65
66#[derive(Clone, PartialEq, Props)]
68pub struct ProgressBarProps {
69 #[props(default)]
71 pub value: f64,
72 #[props(default)]
74 pub color: Option<Color>,
75 #[props(default)]
77 pub striped: bool,
78 #[props(default)]
80 pub animated: bool,
81 #[props(default)]
83 pub show_label: bool,
84 #[props(default)]
87 pub children: Option<Element>,
88 #[props(default)]
90 pub class: String,
91 #[props(extends = GlobalAttributes)]
93 attributes: Vec<Attribute>,
94}
95
96#[component]
97pub fn ProgressBar(props: ProgressBarProps) -> Element {
98 let color_class = match &props.color {
99 Some(c) => format!(" bg-{c}"),
100 None => String::new(),
101 };
102 let striped = if props.striped || props.animated {
103 " progress-bar-striped"
104 } else {
105 ""
106 };
107 let animated = if props.animated {
108 " progress-bar-animated"
109 } else {
110 ""
111 };
112
113 let full_class = if props.class.is_empty() {
114 format!("progress-bar{color_class}{striped}{animated}")
115 } else {
116 format!(
117 "progress-bar{color_class}{striped}{animated} {}",
118 props.class
119 )
120 };
121
122 let width = format!("width: {}%", props.value);
123 let label = if props.show_label {
124 format!("{}%", props.value as u32)
125 } else {
126 String::new()
127 };
128
129 rsx! {
130 div {
131 class: "{full_class}",
132 role: "progressbar",
133 style: "{width}",
134 "aria-valuenow": "{props.value}",
135 "aria-valuemin": "0",
136 "aria-valuemax": "100",
137 ..props.attributes,
138 if let Some(children) = props.children {
139 {children}
140 } else {
141 "{label}"
142 }
143 }
144 }
145}