Skip to content

Commit

Permalink
feat: Improved navigation on mobile
Browse files Browse the repository at this point in the history
This commit adds hamburger style toggling of the top menu on mobile screens.

Fixes #56
  • Loading branch information
antidecaf committed Mar 6, 2018
1 parent d61ba0c commit 6ea8fd1
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"commitmsg": "commitlint -e $GIT_PARAMS",
"postinstall": "npm run bootstrap",
"bootstrap": "lerna bootstrap",
"prebuild": "mkdirp dist/fonts",
"build": "lerna run build && npm run build:css:ffe",
"build:htdocs": "run-s build:packages build:css:* build:content build:styleguidist",
"build:htdocs": "run-s build:packages build:css:* build:assets build:content build:styleguidist",
"build:assets": "cp -r src/assets/ dist/",
"build:css:ffe": "lessc packages/ffe-all.less dist/ffe.css",
"build:css:styles": "lessc src/styles/styles.less dist/styles.css",
"build:packages": "lerna run build",
Expand Down
20 changes: 20 additions & 0 deletions src/assets/sds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(function() {
var qs = document.querySelector.bind(document);

qs('.sb1ds-top-menu__toggle-button').onclick = function() {
toggleModifier('sb1ds-top-menu__wrapper', 'visible');
toggleModifier('sb1ds-top-menu__site-nav-hamburger', 'expanded');
};

function toggleModifier(be, m) {
toggleClass(qs('.' + be), be + '--' + m);
}

function toggleClass(el, className) {
if (el.className.indexOf(className) == -1) {
el.className += ' ' + className;
} else {
el.className = el.className.replace(className, '');
}
}
})();
86 changes: 86 additions & 0 deletions src/styles/components/top-menu.less
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,111 @@
}
}

&__toggle-button {
position: absolute;
top: 10px;
right: 10px;

&::after {
border: none;
}

@media screen and (min-width: @breakpoint-md) {
display: none;
}
}

&__site-nav {
height: 100%;
}

&__wrapper {
padding: 20px 0;
transition: transform @ffe-transition-duration @ffe-ease, opacity 0.1s;

@media screen and (min-width: @breakpoint-md) {
padding: 0;
display: flex;
align-items: flex-end;
}

&:not(.sb1ds-top-menu__wrapper--visible) {
@media screen and (max-width: (@breakpoint-md - 1)) {
padding: 0;
visibility: hidden;
height: 1px;
overflow: hidden;
transform: translateY(-25px);
opacity: 0;
}
}
}

@media screen and (min-width: @breakpoint-lg) {
position: fixed;
width: 100vw;
z-index: 1;
}

&__site-nav-hamburger {
position: relative;
vertical-align: middle;
display: inline-block;
height: 25px;
width: 25px;

&__bar,
&::before,
&::after {
display: inline-block;
background: @ffe-blue-royal;
width: 25px;
height: 4px;
border-radius: 2px;
}

&__bar {
position: absolute;
left: 0;
bottom: 10px;
transition: transform @ffe-transition-duration @ffe-ease-in-out-back,
width @ffe-transition-duration @ffe-ease-in-out-back;
}

&::before {
position: absolute;
content: '';
left: 0;
bottom: 18px;
}

&::after {
position: absolute;
content: '';
left: 0;
bottom: 2px;
}

&::before,
&::after {
transition: transform @ffe-transition-duration @ffe-ease-in-out-back;
}

&--expanded {
.sb1ds-top-menu__site-nav-hamburger__bar {
width: 0;
transform: translate(12px);
}

&::before {
transform: translateY(8px) rotate(45deg);
}

&::after {
transform: translateY(-8px) rotate(-45deg);
}
}
}
}

.sb1ds-header-grid__row {
Expand Down
2 changes: 2 additions & 0 deletions src/templates/frontpage.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,7 @@
</div>
</div>
</div>

<script src="/assets/sds.js"></script>
</body>
</html>
7 changes: 7 additions & 0 deletions src/templates/header.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<div class="sb1ds-top-menu">
<button class="ffe-button ffe-tertiary-button sb1ds-top-menu__toggle-button">
<span class="sb1ds-top-menu__site-nav-hamburger">
<span class="sb1ds-top-menu__site-nav-hamburger__bar">
</span>
</span>
</button>

<div class="sb1ds-header-grid ffe-grid ffe-grid--no-top-padding">
<div class="sb1ds-header-grid__row ffe-grid__row">
<div class="
Expand Down
1 change: 1 addition & 0 deletions src/templates/page.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@
</div>
</div>

<script src="/assets/sds.js"></script>
</body>
</html>
2 changes: 2 additions & 0 deletions src/templates/styleguidist.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@

<div id="app"></div>
</body>

<script src="/assets/sds.js"></script>
</html>

0 comments on commit 6ea8fd1

Please sign in to comment.