Skip to content

Commit 11f1d5d

Browse files
committed
add responsive menu
1 parent 48cfcab commit 11f1d5d

3 files changed

Lines changed: 46 additions & 4 deletions

File tree

ui/app/components/HankoAuthButton.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React from "react";
22

3+
const MOBILE_BREAKPOINT = 768;
4+
35
/**
46
* React 15 wrapper for the <hotosm-auth> web component.
57
*
@@ -8,14 +10,30 @@ import React from "react";
810
* and configure the web component imperatively via a ref.
911
*/
1012
class HankoAuthButton extends React.Component {
13+
constructor(props) {
14+
super(props);
15+
this.state = {
16+
isMobile: window.innerWidth < MOBILE_BREAKPOINT,
17+
};
18+
this._handleResize = this._handleResize.bind(this);
19+
}
20+
1121
componentDidMount() {
22+
window.addEventListener("resize", this._handleResize);
1223
this._renderWebComponent();
1324
}
1425

1526
componentDidUpdate() {
1627
this._renderWebComponent();
1728
}
1829

30+
_handleResize() {
31+
const isMobile = window.innerWidth < MOBILE_BREAKPOINT;
32+
if (isMobile !== this.state.isMobile) {
33+
this.setState({ isMobile });
34+
}
35+
}
36+
1937
_renderWebComponent() {
2038
if (!this._container) return;
2139

@@ -59,9 +77,12 @@ class HankoAuthButton extends React.Component {
5977
if (lang) {
6078
el.setAttribute("lang", lang);
6179
}
80+
81+
el.setAttribute("display", this.state.isMobile ? "bar" : "default");
6282
}
6383

6484
componentWillUnmount() {
85+
window.removeEventListener("resize", this._handleResize);
6586
if (this._element && this._container) {
6687
this._container.removeChild(this._element);
6788
this._element = null;

ui/app/components/NavBar.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ const NavBar = ({ isLoggedIn, login, logout, locale }) => (
2121
<span>Export Tool</span>
2222
</Link>
2323
</Navbar.Brand>
24+
<Navbar.Toggle />
2425
</Navbar.Header>
26+
<Navbar.Collapse>
2527
<Nav className="pull-right">
2628
<RequirePermission>
2729
<li>
@@ -155,6 +157,7 @@ const NavBar = ({ isLoggedIn, login, logout, locale }) => (
155157
</NavItem>
156158
)}
157159
</Nav>
160+
</Navbar.Collapse>
158161
</Navbar>
159162
);
160163

ui/app/css/style.css

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ a {
4545

4646
/* nav styles */
4747

48+
@media (max-width: 767px) {
49+
.navbar-nav.pull-right {
50+
float: none !important;
51+
}
52+
}
53+
4854
.navbar-header {
4955
padding-right: 21px;
5056
height: 63px;
@@ -1465,11 +1471,18 @@ p {
14651471
margin-right: auto;
14661472
justify-content: space-between;
14671473
}
1474+
1475+
1476+
/* mobile menu */
1477+
.navbar-toggle {
1478+
border: 0;
1479+
margin-top: 16px;
1480+
}
14681481
/* hanko auth and tool menu */
14691482
.navbar-nav > li > a.hotosm-tool-menu {
14701483
display: none;
1471-
padding-top: 7px;
1472-
padding-bottom: 7px;
1484+
padding-top: 8px;
1485+
padding-bottom: 8px;
14731486
padding-left: 0;
14741487
padding-right: 0;
14751488
}
@@ -1479,7 +1492,12 @@ p {
14791492
}
14801493
}
14811494
.navbar-nav > li > a.hotosm-auth {
1482-
padding-top: 7px;
1483-
padding-bottom: 7px;
1495+
padding: 0px;
1496+
}
1497+
@media (min-width: 992px) {
1498+
.navbar-nav > li > a.hotosm-auth {
1499+
padding-top: 7px;
1500+
padding-bottom: 7px;
1501+
}
14841502
}
14851503

0 commit comments

Comments
 (0)