Skip to content

Commit 05acc44

Browse files
committed
Updates to the navbar & 0.1.6 release.
1 parent 8e6e905 commit 05acc44

File tree

3 files changed

+53
-23
lines changed

3 files changed

+53
-23
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ This changelog follows the patterns described here: https://keepachangelog.com/e
44

55
## Unreleased
66

7+
## 0.1.6
8+
### changed
9+
- Updates to the `Navbar` component:
10+
- `navbrand`, `navstart`, `navend` are now all optional.
11+
- a new `navburger: bool` property has been added. This bool controls whether or not a `navbar-burger` will be rendered inside of the navbar when being rendered within smaller viewports. This value defaults to `true`, maintaining backwards compatibility.
12+
713
## 0.1.5
814
### fixed
915
- Fixed a few of the button & button-like components to use the HTML `disabled` attribute instead of the Bulma `is-disabled` CSS class. The latter has been deprecated for some time.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ybc"
3-
version = "0.1.5"
3+
version = "0.1.6"
44
description = "A Yew component library based on the Bulma CSS framework."
55
authors = ["Anthony Dodd <[email protected]>"]
66
edition = "2018"

src/components/navbar.rs

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,18 @@ pub struct NavbarProps {
3737
/// If true, the contents of the navbar will be wrapped in a container.
3838
#[prop_or_default]
3939
pub padded: bool,
40-
pub navbrand: Html,
40+
/// The contents of the `navbar-brand` section of the navbar.
41+
#[prop_or_default]
42+
pub navbrand: Option<Html>,
4143
/// The contents of the `navbar-start` section of the navbar.
42-
pub navstart: Html,
44+
#[prop_or_default]
45+
pub navstart: Option<Html>,
4346
/// The contents of the `navbar-end` section of the navbar.
44-
pub navend: Html,
47+
#[prop_or_default]
48+
pub navend: Option<Html>,
49+
/// A bool controlling if the navbar should have a navbar burger for smaller viewports.
50+
#[prop_or_else(|| true)]
51+
pub navburger: bool,
4552
}
4653

4754
/// A responsive horizontal navbar that can support images, links, buttons, and dropdowns.
@@ -96,28 +103,45 @@ impl Component for Navbar {
96103
burgerclasses.push("is-active");
97104
}
98105
let togglecb = self.link.callback(|_| NavbarMsg::ToggleMenu);
106+
let navbrand = if let Some(navbrand) = &self.props.navbrand {
107+
html! {
108+
<div class="navbar-brand">
109+
{navbrand.clone()}
110+
{if self.props.navburger {
111+
html! {
112+
<a class=burgerclasses onclick=togglecb
113+
role="button" aria-label="menu"
114+
aria-expanded={if self.is_menu_open { "true" } else { "false" }}
115+
>
116+
<span aria-hidden="true"></span>
117+
<span aria-hidden="true"></span>
118+
<span aria-hidden="true"></span>
119+
</a>
120+
}
121+
} else {
122+
html! {}
123+
}}
124+
</div>
125+
}
126+
} else {
127+
html! {}
128+
};
129+
let navstart = if let Some(navstart) = &self.props.navstart {
130+
html! {<div class="navbar-start">{navstart.clone()}</div>}
131+
} else {
132+
html! {}
133+
};
134+
let navend = if let Some(navend) = &self.props.navend {
135+
html! {<div class="navbar-end">{navend.clone()}</div>}
136+
} else {
137+
html! {}
138+
};
99139
let contents = html! {
100140
<>
101-
<div class="navbar-brand">
102-
{self.props.navbrand.clone()}
103-
<a class=burgerclasses onclick=togglecb
104-
role="button" aria-label="menu"
105-
aria-expanded={if self.is_menu_open { "true" } else { "false" }}
106-
>
107-
<span aria-hidden="true"></span>
108-
<span aria-hidden="true"></span>
109-
<span aria-hidden="true"></span>
110-
</a>
111-
</div>
112-
141+
{navbrand}
113142
<div class=navclasses>
114-
<div class="navbar-start">
115-
{self.props.navstart.clone()}
116-
</div>
117-
118-
<div class="navbar-end">
119-
{self.props.navend.clone()}
120-
</div>
143+
{navstart}
144+
{navend}
121145
</div>
122146
</>
123147
};

0 commit comments

Comments
 (0)