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