windjammer_ui/components/generated/
radio.rs1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use std::fmt::Write;
4
5use super::traits::Renderable;
6
7#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
8pub struct RadioOption {
9 pub value: String,
10 pub label: String,
11 pub disabled: bool,
12}
13
14impl RadioOption {
15 #[inline]
16 pub fn new(value: String, label: String) -> RadioOption {
17 RadioOption {
18 value,
19 label,
20 disabled: false,
21 }
22 }
23 #[inline]
24 pub fn disabled(mut self, disabled: bool) -> RadioOption {
25 self.disabled = disabled;
26 self
27 }
28}
29
30#[derive(Debug, Clone, Default)]
31pub struct RadioGroup {
32 pub name: String,
33 pub options: Vec<RadioOption>,
34 pub selected: String,
35}
36
37impl RadioGroup {
38 #[inline]
39 pub fn new(name: String) -> RadioGroup {
40 RadioGroup {
41 name,
42 options: Vec::new(),
43 selected: "".to_string(),
44 }
45 }
46 #[inline]
47 pub fn option(mut self, option: RadioOption) -> RadioGroup {
48 self.options.push(option);
49 self
50 }
51 #[inline]
52 pub fn selected(mut self, value: String) -> RadioGroup {
53 self.selected = value;
54 self
55 }
56}
57
58impl Renderable for RadioGroup {
59 #[inline]
60 fn render(self) -> String {
61 let mut html = {
62 let mut __s = String::with_capacity(64);
63 write!(
64 &mut __s,
65 "<div class='wj-radio-group' data-name='{}'>",
66 self.name
67 )
68 .unwrap();
69 __s
70 };
71 let mut i = 0;
72 while i < (self.options.len() as i64) {
73 let opt = &self.options[i as usize];
74 let checked_attr = {
75 if opt.value == self.selected {
76 " checked".to_string()
77 } else {
78 "".to_string()
79 }
80 };
81 let disabled_attr = {
82 if opt.disabled {
83 " disabled".to_string()
84 } else {
85 "".to_string()
86 }
87 };
88 html = {
89 let mut __s = String::with_capacity(64);
90 write!(&mut __s, "{}<label class='wj-radio'><input type='radio' name='{}' value='{}'{}{}><span>{}</span></label>", html, self.name, opt.value, checked_attr, disabled_attr, opt.label).unwrap();
91 __s
92 };
93 i += 1;
94 }
95 format!("{}</div>", html)
96 }
97}