dioxus_tw_components/components/organisms/form/slider/
props.rs1use crate::attributes::*;
2use dioxus::prelude::*;
3use dioxus_tw_components_macro::UiComp;
4
5#[derive(Default, Clone, PartialEq, Props, UiComp)]
6pub struct SliderProps {
7 #[props(extends = input, extends = GlobalAttributes)]
8 attributes: Vec<Attribute>,
9 #[props(optional)]
10 value: String,
11
12 #[props(optional)]
13 oninput: EventHandler<FormEvent>,
14 #[props(optional)]
15 onmounted: EventHandler<Event<MountedData>>,
16
17 #[props(default)]
18 pub color: ReadOnlySignal<Color>,
19}
20
21#[component]
22pub fn Slider(mut props: SliderProps) -> Element {
23 props.update_class_attribute();
24
25 let oninput = move |event| props.oninput.call(event);
26
27 let onmounted = move |event: Event<MountedData>| props.onmounted.call(event);
28
29 rsx! {
30 input {
31 onmounted,
32 oninput,
33 r#type: "range",
34 value: props.value,
35 ..props.attributes,
36 }
37 }
38}
39
40#[derive(Clone, PartialEq, Props, UiComp)]
41pub struct SliderTicksProps {
42 #[props(optional, default = 10)]
43 step: i64,
44 #[props(optional, default = 0)]
45 min: i64,
46 #[props(optional, default = 100)]
47 max: i64,
48
49 #[props(extends = datalist, extends = GlobalAttributes)]
50 attributes: Vec<Attribute>,
51}
52
53impl std::default::Default for SliderTicksProps {
54 fn default() -> Self {
55 Self {
56 step: 10,
57 min: 0,
58 max: 100,
59 attributes: Vec::<Attribute>::default(),
60 }
61 }
62}
63
64#[component]
65pub fn SliderTicks(mut props: SliderTicksProps) -> Element {
66 props.update_class_attribute();
67
68 rsx! {
69 datalist {..props.attributes,
70 for i in props.min..props.max {
71 if i % props.step == 0 {
72 option { value: i }
73 }
74 }
75 option { value: props.max }
76 }
77 }
78}
79
80#[derive(Clone, PartialEq, Props, UiComp)]
81pub struct SliderLabelProps {
82 #[props(extends = div, extends = GlobalAttributes)]
83 attributes: Vec<Attribute>,
84
85 #[props(optional, default = 0)]
86 value: i64,
87 #[props(optional, default = 100)]
88 max: i64,
89}
90
91impl std::default::Default for SliderLabelProps {
92 fn default() -> Self {
93 Self {
94 attributes: Vec::<Attribute>::default(),
95 value: 0,
96 max: 100,
97 }
98 }
99}
100
101#[component]
102pub fn SliderLabel(mut props: SliderLabelProps) -> Element {
103 props.update_class_attribute();
104
105 rsx! {
106 div {..props.attributes,
107 {props.value.to_string()}
108 " / "
109 {props.max.to_string()}
110 }
111 }
112}