Skip to main content

rumtk_web/components/
select.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) 2026  Luis M. Santos, M.D. <lsantos@medicalmasses.com>
5 * Copyright (C) 2026  MedicalMasses L.L.C. <contact@medicalmasses.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19 */
20use crate::components::form::form_node::FormNode;
21use crate::components::form::props::InputProps;
22use crate::components::form::select_element::select_element;
23use crate::defaults::{DEFAULT_NO_TEXT, DEFAULT_TEXT_ITEM, ELEMENT_SELECT, PARAMS_CONTENTS, PARAMS_CSS_CLASS};
24use crate::utils::types::{SharedAppState, URLParams, URLPath};
25use crate::{rumtk_web_get_config, rumtk_web_get_text_item, ComponentResult, RUMWebTemplate, RUMWebTemplateSafe};
26use rumtk_core::strings::RUMString;
27
28#[derive(RUMWebTemplate, Debug)]
29#[template(
30    source = "
31        {% if custom_css_enabled %}
32            <link href='/static/components/div.css' rel='stylesheet'>
33        {% endif %}
34        <div class='div-{{css_class}}'>
35        {{contents}}
36        </div>
37    ",
38    ext = "html"
39)]
40pub struct Select {
41    contents: FormNode,
42    css_class: RUMString,
43    custom_css_enabled: bool,
44}
45
46impl RUMWebTemplateSafe for Select {}
47
48pub fn select<'a>(_path_components: URLPath<'a, 'a>, params: URLParams<'a>, state: SharedAppState) -> ComponentResult<Select> {
49    let items = rumtk_web_get_text_item!(params, PARAMS_CONTENTS, DEFAULT_NO_TEXT);
50    let css_class = rumtk_web_get_text_item!(params, PARAMS_CSS_CLASS, DEFAULT_TEXT_ITEM).to_string();
51
52    let custom_css_enabled = rumtk_web_get_config!(state).flags.custom_css;
53
54    let props = InputProps::default();
55    let contents = select_element(ELEMENT_SELECT, items, props, DEFAULT_NO_TEXT)?;
56
57    Ok(Select {
58        contents,
59        css_class,
60        custom_css_enabled
61    })
62}