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