windjammer_ui/components/generated/
dropdown.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
6pub struct DropdownItem {
7    pub label: String,
8    pub value: String,
9    pub disabled: bool,
10}
11
12impl DropdownItem {
13    #[inline]
14    pub fn new(label: String, value: String) -> DropdownItem {
15        DropdownItem {
16            label,
17            value,
18            disabled: false,
19        }
20    }
21    #[inline]
22    pub fn disabled(mut self, disabled: bool) -> DropdownItem {
23        self.disabled = disabled;
24        self
25    }
26}
27
28#[derive(Debug, Clone, Default)]
29pub struct Dropdown {
30    pub label: String,
31    pub items: Vec<DropdownItem>,
32}
33
34impl Dropdown {
35    #[inline]
36    pub fn new(label: String) -> Dropdown {
37        Dropdown {
38            label,
39            items: Vec::new(),
40        }
41    }
42    #[inline]
43    pub fn item(mut self, item: DropdownItem) -> Dropdown {
44        self.items.push(item);
45        self
46    }
47}
48
49impl Renderable for Dropdown {
50    #[inline]
51    fn render(self) -> String {
52        let mut items_html = "".to_string();
53        let mut i = 0;
54        while i < (self.items.len() as i64) {
55            let item = &self.items[i as usize];
56            let disabled_class = {
57                if item.disabled {
58                    " wj-dropdown-item-disabled".to_string()
59                } else {
60                    "".to_string()
61                }
62            };
63            items_html = format!(
64                "{}<a class='wj-dropdown-item{}' data-value='{}'>{}</a>",
65                items_html, disabled_class, item.value, item.label
66            );
67            i += 1;
68        }
69        format!(
70            "<div class='wj-dropdown'>
71  <button class='wj-dropdown-toggle'>{} ▼</button>
72  <div class='wj-dropdown-menu'>
73    {}
74  </div>
75</div>",
76            self.label, items_html
77        )
78    }
79}