dioxus_tw_components/components/organisms/form/select/
props.rs1use crate::attributes::*;
2use dioxus::prelude::*;
3use dioxus_tw_components_macro::UiComp;
4
5#[derive(Clone, PartialEq, Props, UiComp)]
6pub struct SelectGroupProps {
7 #[props(extends = select, extends = GlobalAttributes)]
8 attributes: Vec<Attribute>,
9
10 #[props(optional)]
11 oninput: EventHandler<FormEvent>,
12
13 children: Element,
14}
15
16impl std::default::Default for SelectGroupProps {
17 fn default() -> Self {
18 Self {
19 attributes: Vec::<Attribute>::default(),
20 oninput: EventHandler::<FormEvent>::default(),
21 children: rsx! {},
22 }
23 }
24}
25
26#[component]
27pub fn SelectGroup(mut props: SelectGroupProps) -> Element {
28 props.update_class_attribute();
29
30 let oninput = move |event| props.oninput.call(event);
31
32 rsx! {
33 select { oninput, ..props.attributes, {props.children} }
34 }
35}
36
37#[derive(Clone, PartialEq, Props, UiComp)]
38pub struct SelectPlaceholderProps {
39 #[props(extends = option, extends = GlobalAttributes)]
40 attributes: Vec<Attribute>,
41
42 children: Element,
43}
44
45impl std::default::Default for SelectPlaceholderProps {
46 fn default() -> Self {
47 Self {
48 attributes: Vec::<Attribute>::default(),
49 children: rsx! {},
50 }
51 }
52}
53
54#[component]
55pub fn SelectPlaceholder(mut props: SelectPlaceholderProps) -> Element {
56 props.update_class_attribute();
57
58 rsx! {
59 option { disabled: true, selected: true, value: r#"{""}"#, {props.children} }
60 }
61}
62
63#[derive(Default, Clone, PartialEq, Props, UiComp)]
64pub struct SelectLabelProps {
65 #[props(extends = optgroup, extends = GlobalAttributes)]
66 attributes: Vec<Attribute>,
67}
68
69#[component]
70pub fn SelectLabel(mut props: SelectLabelProps) -> Element {
71 props.update_class_attribute();
72
73 rsx! {
74 optgroup { ..props.attributes }
75 }
76}
77
78#[derive(Clone, PartialEq, Props, UiComp)]
79pub struct SelectItemProps {
80 #[props(extends = option, extends = GlobalAttributes)]
81 attributes: Vec<Attribute>,
82
83 #[props(optional, default = None)]
84 selected: Option<bool>,
85
86 children: Element,
87}
88
89impl std::default::Default for SelectItemProps {
90 fn default() -> Self {
91 Self {
92 attributes: Vec::<Attribute>::default(),
93 selected: None,
94 children: rsx! {},
95 }
96 }
97}
98
99#[component]
100pub fn SelectItem(mut props: SelectItemProps) -> Element {
101 props.update_class_attribute();
102
103 if let Some(selected) = props.selected {
104 rsx! {
105 option { selected, ..props.attributes, {props.children} }
106 }
107 } else {
108 rsx! {
109 option { ..props.attributes,{props.children} }
110 }
111 }
112}