rumtk_web/components/form/
props.rs

1/*
2 * rumtk attempts to implement HL7 and medical protocols for interoperability in medicine.
3 * This toolkit aims to be reliable, simple, performant, and standards compliant.
4 * Copyright (C) 2025  Luis M. Santos, M.D.
5 * Copyright (C) 2025  Nick Stephenson
6 * Copyright (C) 2025  Ethan Dixon
7 * Copyright (C) 2025  MedicalMasses L.L.C.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 */
23use rumtk_core::strings::{rumtk_format, RUMString};
24
25#[derive(Debug, Clone, Default)]
26pub struct InputProps {
27    pub name: Option<RUMString>,
28    pub typ: Option<RUMString>,
29    pub value: Option<RUMString>,
30    pub placeholder: Option<RUMString>,
31    pub max_length: Option<usize>,
32    pub min_length: Option<usize>,
33    pub autocapitalize: bool,
34    pub autocomplete: bool,
35    pub autocorrect: bool,
36    pub autofocus: bool,
37    pub disabled: bool,
38    pub required: bool,
39}
40
41impl InputProps {
42    pub fn to_rumstring(&self) -> RUMString {
43        let default_text = RUMString::default();
44        rumtk_format!(
45            "{} {} {} {} {} {} {} {} {} {} {} {} {} ",
46            match &self.name {
47                Some(name) => rumtk_format!("id='{}'", name),
48                None => default_text.clone(),
49            },
50            match &self.name {
51                Some(name) => rumtk_format!("name='{}'", name),
52                None => default_text.clone(),
53            },
54            match &self.typ {
55                Some(typ) => rumtk_format!("type='{}'", typ),
56                None => default_text.clone(),
57            },
58            match &self.value {
59                Some(val) => rumtk_format!("value='{}'", val),
60                None => default_text.clone(),
61            },
62            match &self.placeholder {
63                Some(placeholder) => rumtk_format!("placeholder='{}'", placeholder),
64                None => default_text.clone(),
65            },
66            match self.max_length {
67                Some(max_length) => rumtk_format!("maxlength='{}'", max_length),
68                None => default_text.clone(),
69            },
70            match self.min_length {
71                Some(min_length) => rumtk_format!("minlength='{}'", min_length),
72                None => default_text.clone(),
73            },
74            match self.autocapitalize {
75                true => rumtk_format!("autocapitalize"),
76                false => default_text.clone(),
77            },
78            match self.autocomplete {
79                true => rumtk_format!("autocomplete"),
80                false => default_text.clone(),
81            },
82            match self.autocorrect {
83                true => rumtk_format!("autocorrect"),
84                false => default_text.clone(),
85            },
86            match self.autofocus {
87                true => rumtk_format!("autofocus"),
88                false => default_text.clone(),
89            },
90            match self.disabled {
91                true => rumtk_format!("disabled"),
92                false => default_text.clone(),
93            },
94            match self.required {
95                true => rumtk_format!("required"),
96                false => default_text.clone(),
97            },
98        )
99    }
100
101    pub fn to_string(&self) -> String {
102        self.to_rumstring().to_string()
103    }
104}