zino_dioxus/form/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! Generic form controls.

use std::borrow::Cow;

mod button;
mod checkbox;
mod field;
mod file;
mod input;
mod progress;
mod radio;
mod select;
mod textarea;

#[cfg(feature = "clipboard")]
mod clipboard;

pub use button::{Button, ButtonProps, Buttons, ButtonsProps};
pub use checkbox::{Checkbox, CheckboxProps};
pub use field::{
    FormAddons, FormAddonsProps, FormField, FormFieldContainer, FormFieldContainerProps,
    FormFieldProps, FormGroup, FormGroupProps,
};
pub use file::{FileTree, FileTreeProps, FileUpload, FileUploadProps};
pub use input::{Input, InputProps};
pub use progress::{Progress, ProgressProps};
pub use radio::{Radio, RadioProps};
pub use select::{DataSelect, DataSelectProps};
pub use textarea::{Textarea, TextareaProps};

#[cfg(feature = "clipboard")]
pub use clipboard::{CopyToClipboard, CopyToClipboardProps};

/// An interface for the data entries.
pub trait DataEntry {
    /// Returns the unique key.
    fn key(&self) -> Cow<'_, str>;

    /// Returns the value.
    fn value(&self) -> Cow<'_, str>;

    /// Returns the label.
    fn label(&self) -> Cow<'_, str>;
}

impl DataEntry for [&str; 2] {
    #[inline]
    fn key(&self) -> Cow<'_, str> {
        self[0].into()
    }

    #[inline]
    fn value(&self) -> Cow<'_, str> {
        self[0].into()
    }

    #[inline]
    fn label(&self) -> Cow<'_, str> {
        self[1].into()
    }
}

impl<T: ToString, U: ToString> DataEntry for (T, U) {
    #[inline]
    fn key(&self) -> Cow<'_, str> {
        self.0.to_string().into()
    }

    #[inline]
    fn value(&self) -> Cow<'_, str> {
        self.0.to_string().into()
    }

    #[inline]
    fn label(&self) -> Cow<'_, str> {
        self.1.to_string().into()
    }
}