Skip to content

Commit 565222e

Browse files
authored
Merge pull request #7 from thedodd/navbar-padded
A few props updates to components.
2 parents fbc7fb1 + 587b7f2 commit 565222e

File tree

5 files changed

+92
-29
lines changed

5 files changed

+92
-29
lines changed

CHANGELOG.md

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

55
## Unreleased
66

7+
## 0.1.4
8+
### added
9+
- Add prop `padded` to Navbar. Setting this to true will wrap the contents of the navbar in a container to add padding to the contents under some circumstances.
10+
- The default tag type for NavbarItems is now `div`.
11+
- Added the `href`, `rel` & `target` props to the `NavbarItem` component. They will only be used when the `NavbarItemTag::A` is being used for the component.
12+
- Added the `rel` & `target` props to the `ButtonAnchor` component.
13+
- Adds an additional size for heros: `is-fullheight-with-navbar`. This one is present in the Bulma docs, but is slightly hidden.
14+
715
## 0.1.3
816
### fixed
917
- Removed `Children` props from Hero & made header & footer optional.

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.3"
3+
version = "0.1.4"
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: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::redundant_closure_call)]
2+
13
use derive_more::Display;
24
use yew::prelude::*;
35
use yewtil::NeqAssign;
@@ -32,6 +34,9 @@ pub struct NavbarProps {
3234
/// end of this content.
3335
///
3436
/// [https://bulma.io/documentation/components/navbar/#navbar-brand](https://bulma.io/documentation/components/navbar/#navbar-brand)
37+
/// If true, the contents of the navbar will be wrapped in a container.
38+
#[prop_or_default]
39+
pub padded: bool,
3540
pub navbrand: Html,
3641
/// The contents of the `navbar-start` section of the navbar.
3742
pub navstart: Html,
@@ -91,31 +96,42 @@ impl Component for Navbar {
9196
burgerclasses.push("is-active");
9297
}
9398
let togglecb = self.link.callback(|_| NavbarMsg::ToggleMenu);
99+
let contents = html! {
100+
<>
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>
94112

95-
html! {
96-
<nav class=classes role="navigation" aria-label="main navigation">
97-
<div class="navbar-brand">
98-
{self.props.navbrand.clone()}
99-
<a class=burgerclasses onclick=togglecb
100-
role="button" aria-label="menu"
101-
aria-expanded={if self.is_menu_open { "true" } else { "false" }}
102-
>
103-
<span aria-hidden="true"></span>
104-
<span aria-hidden="true"></span>
105-
<span aria-hidden="true"></span>
106-
</a>
113+
<div class=navclasses>
114+
<div class="navbar-start">
115+
{self.props.navstart.clone()}
107116
</div>
108117

109-
<div class=navclasses>
110-
<div class="navbar-start">
111-
{self.props.navstart.clone()}
112-
</div>
113-
114-
<div class="navbar-end">
115-
{self.props.navend.clone()}
116-
</div>
118+
<div class="navbar-end">
119+
{self.props.navend.clone()}
117120
</div>
118-
</nav>
121+
</div>
122+
</>
123+
};
124+
125+
if self.props.padded {
126+
html! {
127+
<nav class=classes role="navigation" aria-label="main navigation">
128+
<div class="container">{contents}</div>
129+
</nav>
130+
}
131+
} else {
132+
html! {
133+
<nav class=classes role="navigation" aria-label="main navigation">{contents}</nav>
134+
}
119135
}
120136
}
121137
}
@@ -156,6 +172,7 @@ pub struct NavbarItemProps {
156172
#[prop_or_default]
157173
pub classes: Option<String>,
158174
/// The HTML tag to use for this component.
175+
#[prop_or_else(|| NavbarItemTag::Div)]
159176
pub tag: NavbarItemTag,
160177
/// Add the `has-dropdown` class to this element, indicating that it is the parent
161178
/// of a dropdown menu.
@@ -170,6 +187,15 @@ pub struct NavbarItemProps {
170187
/// Show the bottom border when `is_tab=true`.
171188
#[prop_or_default]
172189
pub active: bool,
190+
/// An optional `href` for when this element is using the `a` tag.
191+
#[prop_or_default]
192+
pub href: Option<String>,
193+
/// An optional `rel` for when this element is using the `a` tag.
194+
#[prop_or_default]
195+
pub rel: Option<String>,
196+
/// An optional `target` for when this element is using the `a` tag.
197+
#[prop_or_default]
198+
pub target: Option<String>,
173199
}
174200

175201
/// A single element of the navbar.
@@ -213,11 +239,26 @@ impl Component for NavbarItem {
213239
if self.props.active {
214240
classes.push("is-active");
215241
}
216-
let tag = self.props.tag.to_string();
217-
html! {
218-
<@{tag} class=classes>
219-
{self.props.children.clone()}
220-
</@>
242+
match self.props.tag {
243+
NavbarItemTag::A => {
244+
html! {
245+
<a
246+
class=classes
247+
href=self.props.href.clone().unwrap_or_default()
248+
rel=self.props.rel.clone().unwrap_or_default()
249+
target=self.props.target.clone().unwrap_or_default()
250+
>
251+
{self.props.children.clone()}
252+
</a>
253+
}
254+
}
255+
NavbarItemTag::Div => {
256+
html! {
257+
<div class=classes>
258+
{self.props.children.clone()}
259+
</div>
260+
}
261+
}
221262
}
222263
}
223264
}

src/elements/button.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ pub struct ButtonAnchorProps {
283283
/// Disable this component.
284284
#[prop_or_default]
285285
pub disabled: bool,
286+
/// An optional `rel` for when this element is using the `a` tag.
287+
#[prop_or_default]
288+
pub rel: Option<String>,
289+
/// An optional `target` for when this element is using the `a` tag.
290+
#[prop_or_default]
291+
pub target: Option<String>,
286292
}
287293

288294
/// An anchor element styled as a button.
@@ -323,7 +329,13 @@ impl Component for ButtonAnchor {
323329
classes.push("is-disabled")
324330
}
325331
html! {
326-
<a class=classes onclick=self.props.onclick.clone() href=self.props.href.clone()>
332+
<a
333+
class=classes
334+
onclick=self.props.onclick.clone()
335+
href=self.props.href.clone()
336+
rel=self.props.rel.clone().unwrap_or_default()
337+
target=self.props.target.clone().unwrap_or_default()
338+
>
327339
{self.props.children.clone()}
328340
</a>
329341
}

src/layout/hero.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl Component for Hero {
9090
}
9191
}
9292

93-
/// The 3 sizes available for heros.
93+
/// The 4 sizes available for heros.
9494
///
9595
/// [https://bulma.io/documentation/layout/hero/#sizes](https://bulma.io/documentation/layout/hero/#sizes)
9696
#[derive(Clone, Debug, Display, PartialEq)]
@@ -102,4 +102,6 @@ pub enum HeroSize {
102102
Large,
103103
#[display(fmt = "fullheight")]
104104
Fullheight,
105+
#[display(fmt = "fullheight-with-navbar")]
106+
FullheightWithNavbar,
105107
}

0 commit comments

Comments
 (0)