windjammer_ui/components/generated/
navbar.rs

1#![allow(clippy::all)]
2#![allow(noop_method_call)]
3use super::traits::Renderable;
4
5#[derive(Clone, Debug, PartialEq, Copy)]
6pub enum NavbarPosition {
7    Top,
8    Bottom,
9}
10
11#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
12pub struct NavbarItem {
13    pub label: String,
14    pub href: String,
15}
16
17impl NavbarItem {
18    #[inline]
19    pub fn new(label: String, href: String) -> NavbarItem {
20        NavbarItem { label, href }
21    }
22}
23
24#[derive(Debug, Clone)]
25pub struct Navbar {
26    pub brand: String,
27    pub items: Vec<NavbarItem>,
28    pub position: NavbarPosition,
29    pub sticky: bool,
30}
31
32impl Navbar {
33    #[inline]
34    pub fn new() -> Navbar {
35        Navbar {
36            brand: String::from(""),
37            items: Vec::new(),
38            position: NavbarPosition::Top,
39            sticky: false,
40        }
41    }
42    #[inline]
43    pub fn brand(mut self, brand: String) -> Navbar {
44        self.brand = brand;
45        self
46    }
47    #[inline]
48    pub fn item(mut self, item: NavbarItem) -> Navbar {
49        self.items.push(item);
50        self
51    }
52    #[inline]
53    pub fn position(mut self, pos: NavbarPosition) -> Navbar {
54        self.position = pos;
55        self
56    }
57    #[inline]
58    pub fn sticky(mut self, sticky: bool) -> Navbar {
59        self.sticky = sticky;
60        self
61    }
62}
63
64impl Renderable for Navbar {
65    #[inline]
66    fn render(self) -> String {
67        let mut items_html = Vec::new();
68        for item in &self.items {
69            items_html.push(format!(
70                "<a href='{}' class='wj-navbar-item'>{}</a>",
71                item.href.clone(),
72                item.label.clone()
73            ));
74        }
75        let position_class = match self.position {
76            NavbarPosition::Top => "wj-navbar-top".to_string(),
77            NavbarPosition::Bottom => "wj-navbar-bottom".to_string(),
78        };
79        let sticky_class = {
80            if self.sticky {
81                " wj-navbar-sticky".to_string()
82            } else {
83                "".to_string()
84            }
85        };
86        let brand_html = {
87            if self.brand.len() > (0 as usize) {
88                format!("<div class='wj-navbar-brand'>{}</div>", self.brand)
89            } else {
90                String::from("")
91            }
92        };
93        format!(
94            "<nav class='wj-navbar {} {}'>{}<div class='wj-navbar-items'>{}</div></nav>",
95            position_class,
96            sticky_class,
97            brand_html,
98            items_html.join("")
99        )
100    }
101}