rumtk_web/components/html/button.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::title::{title, Title};
21use crate::utils::types::SharedAppState;
22use crate::{rumtk_web_params_map, ComponentResult, RUMWebTemplate, RUMWebTemplateSafe, PARAMS_TITLE};
23use rumtk_core::strings::RUMString;
24
25#[derive(RUMWebTemplate, Debug, Clone)]
26#[template(
27 source = "
28 <button onclick='{{ function }}({{args}})'>
29 {{title | safe}}
30 </button>
31 ",
32 ext = "html"
33)]
34pub struct Button {
35 title: Title,
36 function: RUMString,
37 args: RUMString,
38}
39
40impl RUMWebTemplateSafe for Button {}
41
42pub fn button<'a>(text: &str, function: &str, args: &str, state: SharedAppState) -> ComponentResult<Button> {
43 let params = rumtk_web_params_map!([(PARAMS_TITLE, text)]);
44 let title = title(&[], params.get_inner(), state)?;
45
46 Ok(Button {
47 title,
48 function: function.to_string(),
49 args: args.to_string(),
50 })
51}