Skip to main content

dioxus_element_plug/components/
time_select.rs

1use dioxus::prelude::*;
2
3/// TimeSelect props
4#[derive(Props, Clone, PartialEq)]
5pub struct TimeSelectProps {
6    #[props(default)]
7    pub model_value: Option<String>,
8
9    #[props(default = "Select Time".to_string())]
10    pub placeholder: String,
11
12    #[props(default = "00:00".to_string())]
13    pub start: String,
14
15    #[props(default = "23:59".to_string())]
16    pub end: String,
17
18    #[props(default = "00:30".to_string())]
19    pub step: String,
20
21    #[props(default = false)]
22    pub disabled: bool,
23
24    #[props(default = false)]
25    pub clearable: bool,
26
27    #[props(default)]
28    pub on_change: Option<EventHandler<String>>,
29
30    #[props(default)]
31    pub class: Option<String>,
32
33    #[props(default)]
34    pub style: Option<String>,
35}
36
37/// TimeSelect component for fixed-time selection
38#[component]
39pub fn TimeSelect(props: TimeSelectProps) -> Element {
40    let mut class_names = vec!["el-time-select".to_string()];
41    if props.disabled { class_names.push("is-disabled".to_string()); }
42    if let Some(ref c) = props.class { class_names.push(c.clone()); }
43
44    rsx! {
45        div {
46            class: "{class_names.join(\" \")}",
47            style: props.style.clone().unwrap_or_default(),
48            div {
49                class: "el-input",
50                input {
51                    class: "el-input__inner",
52                    r#type: "text",
53                    placeholder: "{props.placeholder}",
54                    value: props.model_value.clone().unwrap_or_default(),
55                    disabled: props.disabled,
56                    readonly: true,
57                }
58                span {
59                    class: "el-input__prefix",
60                    i { class: "el-icon-time" }
61                }
62            }
63        }
64    }
65}