Skip to content

Commit

Permalink
Combine + simplify nav/masthead
Browse files Browse the repository at this point in the history
Now uses top-down drawer similar to Solid.

Does not yet address IE9 issues related to dependency on classList, but paves the way for that to be a much simpler change.

Refs: #14
  • Loading branch information
tylersticka committed Dec 28, 2015
1 parent abacefb commit 702dcfc
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 253 deletions.
73 changes: 4 additions & 69 deletions app/templates/src/assets/fabricator/scripts/fabricator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ fabricator.options = {
labels: true,
notes: true,
code: false
},
menu: false,
mq: '(min-width: 60em)'
}
};

// open menu by default if large screen
fabricator.options.menu = window.matchMedia(fabricator.options.mq).matches;

/**
* Feature detection
* @type {Object}
Expand Down Expand Up @@ -58,7 +53,7 @@ fabricator.dom = {
root: document.querySelector('html'),
primaryMenu: document.querySelector('.f-Nav'),
menuItems: document.querySelectorAll('.f-Nav-item'),
menuToggle: document.querySelector('.f-Masthead-control'),
menuToggle: document.querySelector('.f-Nav-header-toggle'),
labels: document.querySelectorAll('[data-f-toggle="labels"]'),
notes: document.querySelectorAll('[data-f-toggle="notes"]'),
code: document.querySelectorAll('[data-f-toggle="code"]')
Expand Down Expand Up @@ -155,37 +150,10 @@ fabricator.setActiveItem = function () {
*/
fabricator.menuToggle = function () {

// shortcut menu DOM
var toggle = fabricator.dom.menuToggle;

var options = fabricator.getOptions();

// toggle classes on certain elements
var toggleClasses = function () {
options.menu = !fabricator.dom.root.classList.contains('f-is-active');
fabricator.dom.root.classList.toggle('f-is-active');

if (fabricator.test.sessionStorage) {
sessionStorage.setItem('fabricator', JSON.stringify(options));
}
};

// toggle classes on click
toggle.addEventListener('click', function () {
toggleClasses();
fabricator.dom.menuToggle.addEventListener('click', function () {
fabricator.toggleClass(fabricator.dom.primaryMenu, 'f-is-open');
});

// close menu when clicking on item (for collapsed menu view)
var closeMenu = function () {
if (!window.matchMedia(fabricator.options.mq).matches) {
toggleClasses();
}
};

for (var i = 0; i < fabricator.dom.menuItems.length; i++) {
fabricator.dom.menuItems[i].addEventListener('click', closeMenu);
}

return this;

};
Expand Down Expand Up @@ -272,46 +240,13 @@ fabricator.bindCodeAutoSelect = function () {
};


/**
* Open/Close menu based on session var.
* Also attach a media query listener to close the menu when resizing to smaller screen.
*/
fabricator.setInitialMenuState = function () {

// root element
var root = document.querySelector('html');

var mq = window.matchMedia(fabricator.options.mq);

// if small screen
var mediaChangeHandler = function (list) {
if (!list.matches) {
root.classList.remove('f-is-active');
} else {
if (fabricator.getOptions().menu) {
root.classList.add('f-is-active');
} else {
root.classList.remove('f-is-active');
}
}
};

mq.addListener(mediaChangeHandler);
mediaChangeHandler(mq);

return this;

};


/**
* Initialization
*/
(function () {

// invoke
fabricator
.setInitialMenuState()
.menuToggle()
.singleItemToggle()
.setActiveItem()
Expand Down
6 changes: 4 additions & 2 deletions app/templates/src/assets/fabricator/styles/base/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

--Item-border: #ccc;

--Nav-background: #444;
--Nav-background: #fff;
--Nav-hover-background: #333;
--Nav-color: #fff;
--Nav-border: var(--Item-border);
--Nav-active-color: inherit;
--Nav-active-border: currentColor;

--Label-inprogress: #ffd739;
--Label-deprecated: #ff4136;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
@import "./item";
@import "./label";
@import "./layout";
@import "./masthead";
@import "./nav";
@import "./swatch";
74 changes: 18 additions & 56 deletions app/templates/src/assets/fabricator/styles/components/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,30 @@
margin: 0;
}

.f-Layout.f-is-active {
overflow: hidden;
}

@media (--large-viewport) {
.f-Layout.f-is-active {
overflow: auto;
}
}

.f-Layout-body {
position: relative;
.f-Layout-nav,
.f-Layout-body,
.f-Layout-main {
margin: 0;
}

.f-Layout.f-is-active .f-Layout-body {
overflow: hidden;
width: 100%;
height: 100%;
position: relative;
}

@media (--large-viewport) {
.f-Layout.f-is-active .f-Layout-body {
overflow: auto;
.f-Layout-nav {
position: fixed;
z-index: 1;
top: 0;
left: 0;
overflow-x: hidden;
overflow-y: auto;
box-sizing: border-box;
width: var(--Layout-nav-width);
height: 100%;
margin: 0;

-webkit-overflow-scrolling: touch;
}
}

.f-Layout-main {
position: relative;
z-index: 0;
box-sizing: border-box;
min-height: 100vh;
margin: 0;
}

.f-Layout.f-is-active .f-Layout-main {
transform: translate(var(--Layout-nav-width), 0);
}

@media (--large-viewport) {
.f-Layout.f-is-active .f-Layout-main {
.f-Layout-main {
margin-left: var(--Layout-nav-width);
transform: translate(0, 0);
}
}

.f-Layout-nav {
position: fixed;
z-index: 1;
top: 0;
left: 0;
overflow-x: hidden;
overflow-y: auto;
box-sizing: border-box;
width: var(--Layout-nav-width);
height: 100%;
margin: 0;
transform: translate(calc(var(--Layout-nav-width) * -1), 0);

-webkit-overflow-scrolling: touch;
}

.f-Layout.f-is-active .f-Layout-nav {
transform: translate(0, 0);
}
29 changes: 0 additions & 29 deletions app/templates/src/assets/fabricator/styles/components/masthead.css

This file was deleted.

111 changes: 80 additions & 31 deletions app/templates/src/assets/fabricator/styles/components/nav.css
Original file line number Diff line number Diff line change
@@ -1,63 +1,112 @@
.f-Nav {
color: var(--Nav-color);
background-color: var(--Nav-background);
background: var(--Nav-background);
border-color: var(--Nav-border);
border-style: solid;
border-width: 0 0 1px;
margin: 0;
}

@media (--large-viewport) {
.f-Nav {
border-width: 0 1px 0 0;
}
}

.f-Nav a,
.f-Nav a:matches(:focus, :hover, :active) {
text-decoration: none;
color: inherit;
}

.f-Nav-header {
margin: 0.5rem 1rem;
margin: 0;
padding: 1rem;
position: relative;
}

.f-Nav-header-logo {
font-weight: bold;
margin: 0;
}

.f-Nav-header-logo > img {
vertical-align: bottom;
}

.f-Nav-header svg {
width: 2rem;
height: 2rem;
.f-Nav-header-toggle {
background: transparent;
border: 0;
box-shadow: none;
cursor: pointer;
font: inherit;
margin: -1.5em 0 0;
padding: 1em;
position: absolute;
top: 50%;
right: 0;
}

.f-Nav.f-is-open .f-Nav-header-toggle {
transform: rotate(180deg);
}

@media (--large-viewport) {
.f-Nav-header-toggle {
display: none;
}
}

.f-Nav-header-toggle svg {
display: block;
fill: currentColor;
height: 1em;
opacity: 0.5;
width: 1em;
}

.f-Nav-main {
display: none;
margin: 0;
}

.f-Nav.f-is-open .f-Nav-main {
display: block;
}

@media (--large-viewport) {
.f-Nav-main {
display: block;
padding-bottom: 3rem; /* room for tota11y */
}
}

.f-Nav-menu {
margin-top: 0;
margin-bottom: 0;
padding-left: 0;
margin: 0 0 1rem;
padding: 0;
list-style: none;
}

.f-Nav-menu .f-Nav-menu {
margin-bottom: 0;
}

.f-Nav-menu > li {
margin: 0;
}

.f-Nav-item {
border-color: transparent;
border-style: solid;
border-width: 0 0 0 0.25rem;
display: block;
padding: 0.5rem 1rem;
font-size: 0.75rem;
padding: 0.5rem 1rem 0.5rem 0.75rem;
}

.f-Nav-menu .f-Nav-menu .f-Nav-item {
padding-left: 2rem;
font-size: 0.875em;
padding-left: 1.875rem;
}

.f-Nav-item.f-is-active {
box-shadow: 3px 0 0 var(--Nav-color) inset;
}

.f-Nav-item:hover,
.f-Nav-item:focus {
background-color: var(--Nav-hover-background);
}

.f-Nav-item--heading {
margin-top: 0.75rem;
font-size: 1rem;
font-weight: 300;
}

.f-Nav-footer {
margin: 2rem 1rem 1rem;
font-size: 0.75rem;
opacity: 0.5;
border-color: var(--Nav-active-border);
color: var(--Nav-active-color);
}
Loading

0 comments on commit 702dcfc

Please sign in to comment.