1use yew::prelude::*;
2#[derive(Clone, Copy, PartialEq, Debug)]
3pub enum NavFill {
4 Fill,
5 Justified,
6}
7impl NavFill {
8 pub fn as_str(&self) -> &'static str {
9 match self {
10 NavFill::Fill => "nav-fill",
11 NavFill::Justified => "nav-justified",
12 }
13 }
14}
15#[derive(Clone, Copy, PartialEq, Debug)]
17pub enum NavAlign {
18 Start,
19 Center,
20 End,
21}
22impl NavAlign {
23 pub fn as_str(&self) -> &'static str {
24 match self {
25 NavAlign::Start => "justify-content-start",
26 NavAlign::Center => "justify-content-center",
27 NavAlign::End => "justify-content-end",
28 }
29 }
30}
31#[derive(Clone, Copy, PartialEq, Debug)]
32pub enum NavOrientation {
33 Horizontal,
34 Vertical,
35}
36impl NavOrientation {
37 pub fn as_str(&self) -> &'static str {
38 match self {
39 NavOrientation::Horizontal => "nav",
40 NavOrientation::Vertical => "flex-column",
41 }
42 }
43}
44#[derive(Properties, PartialEq)]
46pub struct NavProps {
47 #[prop_or_default]
49 pub children: Children,
50 #[prop_or_default]
52 pub pills: bool,
53 #[prop_or_default]
55 pub tabs: bool,
56 #[prop_or_default]
58 pub fill: Option<NavFill>,
59 #[prop_or_default]
61 pub align: Option<NavAlign>,
62 #[prop_or_default]
64 pub orientation: Option<NavOrientation>,
65 #[prop_or_default]
67 pub class: Option<AttrValue>,
68 #[prop_or_default]
70 pub node_ref: NodeRef,
71}
72#[function_component(Nav)]
74pub fn nav(props: &NavProps) -> Html {
75 let mut classes = Classes::new();
76 classes.push("nav");
77 if props.pills {
78 classes.push("nav-pills");
79 }
80 if props.tabs {
81 classes.push("nav-tabs");
82 }
83 if let Some(fill) = &props.fill {
84 classes.push(fill.as_str());
85 }
86 if let Some(align) = &props.align {
87 classes.push(align.as_str());
88 }
89 if let Some(orientation) = &props.orientation {
90 classes.push(orientation.as_str());
91 }
92 if let Some(class) = &props.class {
93 classes.push(class.to_string());
94 }
95 html! {
96 < ul class = { classes } ref = { props.node_ref.clone() } > { for props.children
97 .iter() } </ ul >
98 }
99}
100#[derive(Properties, PartialEq)]
102pub struct NavItemProps {
103 #[prop_or_default]
105 pub children: Children,
106 #[prop_or_default]
108 pub class: Option<AttrValue>,
109 #[prop_or_default]
111 pub node_ref: NodeRef,
112}
113#[function_component(NavItem)]
115pub fn nav_item(props: &NavItemProps) -> Html {
116 let mut classes = Classes::new();
117 classes.push("nav-item");
118 if let Some(class) = &props.class {
119 classes.push(class.to_string());
120 }
121 html! {
122 < li class = { classes } ref = { props.node_ref.clone() } > { for props.children
123 .iter() } </ li >
124 }
125}
126#[derive(Properties, PartialEq)]
128pub struct NavLinkProps {
129 #[prop_or_default]
131 pub children: Children,
132 #[prop_or_default]
134 pub active: bool,
135 #[prop_or_default]
137 pub disabled: bool,
138 #[prop_or_default]
140 pub href: Option<AttrValue>,
141 #[prop_or_default]
143 pub onclick: Option<Callback<MouseEvent>>,
144 #[prop_or_default]
146 pub class: Option<AttrValue>,
147 #[prop_or_default]
149 pub node_ref: NodeRef,
150}
151#[function_component(NavLink)]
153pub fn nav_link(props: &NavLinkProps) -> Html {
154 let mut classes = Classes::new();
155 classes.push("nav-link");
156 if props.active {
157 classes.push("active");
158 }
159 if props.disabled {
160 classes.push("disabled");
161 }
162 if let Some(class) = &props.class {
163 classes.push(class.to_string());
164 }
165 if let Some(href) = &props.href {
166 html! {
167 < a class = { classes } href = { href.clone() } onclick = { props.onclick
168 .clone() } aria - disabled = { props.disabled.to_string() } ref = { props
169 .node_ref.clone() } > { for props.children.iter() } </ a >
170 }
171 } else {
172 html! {
173 < button class = { classes } type = "button" onclick = { props.onclick
174 .clone() } disabled = { props.disabled } ref = { props.node_ref.clone() } > {
175 for props.children.iter() } </ button >
176 }
177 }
178}