windjammer_ui/components/generated/
checkbox.rs1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Clone, Debug, PartialEq, Copy)]
6pub enum CheckboxSize {
7 Small,
8 Medium,
9 Large,
10}
11
12#[derive(Debug, Clone, PartialEq)]
13pub struct Checkbox {
14 pub label: String,
15 pub checked: bool,
16 pub disabled: bool,
17 pub size: CheckboxSize,
18}
19
20impl Checkbox {
21 #[inline]
22 pub fn new(label: String) -> Checkbox {
23 Checkbox {
24 label,
25 checked: false,
26 disabled: false,
27 size: CheckboxSize::Medium,
28 }
29 }
30 #[inline]
31 pub fn checked(mut self, checked: bool) -> Checkbox {
32 self.checked = checked;
33 self
34 }
35 #[inline]
36 pub fn disabled(mut self, disabled: bool) -> Checkbox {
37 self.disabled = disabled;
38 self
39 }
40 #[inline]
41 pub fn size(mut self, size: CheckboxSize) -> Checkbox {
42 self.size = size;
43 self
44 }
45}
46
47impl Renderable for Checkbox {
48 #[inline]
49 fn render(self) -> String {
50 let size_class = match self.size {
51 CheckboxSize::Small => "sm".to_string(),
52 CheckboxSize::Medium => "md".to_string(),
53 CheckboxSize::Large => "lg".to_string(),
54 };
55 let checked_attr = {
56 if self.checked {
57 " checked".to_string()
58 } else {
59 "".to_string()
60 }
61 };
62 let disabled_attr = {
63 if self.disabled {
64 " disabled".to_string()
65 } else {
66 "".to_string()
67 }
68 };
69 format!("<label class='wj-checkbox wj-checkbox-{}'><input type='checkbox'{}{}/><span>{}</span></label>", size_class, checked_attr, disabled_attr, self.label)
70 }
71}