dioxus_tw_components/components/molecules/progressbar/
props.rs1use crate::attributes::*;
2use dioxus::prelude::*;
3use dioxus_tw_components_macro::UiComp;
4
5#[derive(Clone, PartialEq, Props, UiComp)]
6pub struct ProgressBarProps {
7 #[props(extends = div, extends = GlobalAttributes)]
8 attributes: Vec<Attribute>,
9
10 #[props(optional, default)]
11 pub color: ReadOnlySignal<Color>,
12 #[props(optional, default)]
13 pub size: ReadOnlySignal<Size>,
14
15 children: Element,
16}
17
18impl std::default::Default for ProgressBarProps {
19 fn default() -> Self {
20 Self {
21 attributes: Vec::<Attribute>::default(),
22 color: ReadOnlySignal::<Color>::default(),
23 size: ReadOnlySignal::<Size>::default(),
24 children: rsx! {},
25 }
26 }
27}
28
29#[component]
30pub fn ProgressBar(mut props: ProgressBarProps) -> Element {
31 props.update_class_attribute();
32
33 rsx! {
34 div { ..props.attributes,{props.children} }
35 }
36}
37
38#[derive(Clone, PartialEq, Props, UiComp)]
39pub struct ProgressBarInnerProps {
40 #[props(default = 50)]
41 progress: u8,
42
43 #[props(extends = div, extends = GlobalAttributes)]
44 attributes: Vec<Attribute>,
45
46 #[props(optional, default)]
47 pub color: ReadOnlySignal<Color>,
48
49 children: Element,
50}
51
52impl std::default::Default for ProgressBarInnerProps {
53 fn default() -> Self {
54 Self {
55 progress: 50,
56 attributes: Vec::<Attribute>::default(),
57 color: ReadOnlySignal::<Color>::default(),
58 children: rsx! {},
59 }
60 }
61}
62
63#[component]
64pub fn ProgressBarInner(mut props: ProgressBarInnerProps) -> Element {
65 props.update_class_attribute();
66
67 let progress = if props.progress > 100 {
68 100
69 } else {
70 props.progress
71 };
72
73 rsx! {
74 div { style: "width: {progress}%", ..props.attributes,
75 div { {props.children} }
76 }
77 }
78}
79
80#[derive(Clone, PartialEq, Props, UiComp)]
81pub struct ProgressLabelProps {
82 #[props(default = 50)]
83 progress: u8,
84 #[props(default = true)]
85 show_percentage: bool,
86
87 #[props(extends = span, extends = GlobalAttributes)]
88 attributes: Vec<Attribute>,
89
90 children: Element,
91}
92
93impl std::default::Default for ProgressLabelProps {
94 fn default() -> Self {
95 Self {
96 progress: 50,
97 show_percentage: true,
98 attributes: Vec::<Attribute>::default(),
99 children: rsx! {},
100 }
101 }
102}
103
104#[component]
105pub fn ProgressLabel(mut props: ProgressLabelProps) -> Element {
106 props.update_class_attribute();
107
108 rsx! {
109 span {..props.attributes,
110 "{props.progress.to_string()}"
111 if props.show_percentage {
112 "%"
113 }
114 }
115 }
116}