Skip to content

Commit

Permalink
Merge pull request #128 from CityOfDetroit/fix.nav.122.2
Browse files Browse the repository at this point in the history
Support exandable offcanvas navbar
  • Loading branch information
jedgar1mx authored Dec 5, 2023
2 parents 17ba4a1 + ee6ba40 commit c5d26aa
Show file tree
Hide file tree
Showing 13 changed files with 352 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/components/atoms/OffcanvasBody/OffcanvasBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ template.innerHTML = `
`;

export default class OffcanvasBody extends HTMLElement {
static observedAttributes = ['data-expand'];

constructor() {
// Always call super first in constructor
super();
Expand All @@ -22,6 +24,10 @@ export default class OffcanvasBody extends HTMLElement {
if (node.tagName === 'COD-NAV') {
node.setAttribute('data-extra-classes', 'navbar-nav');
}
const expand = this.getAttribute('data-expand');
if (expand) {
node.setAttribute('data-expand', expand);
}
this.body.append(node);
});
});
Expand All @@ -38,11 +44,29 @@ export default class OffcanvasBody extends HTMLElement {
shadow.appendChild(itemStyles);
}

attributeChangedCallback(name, oldValue, newValue) {
switch (name) {
case 'data-expand': {
if (newValue) {
this.shadowRoot
.querySelector('cod-nav')
.setAttribute('data-expand', newValue);
}
}
}
}

connectedCallback() {
// OffcanvasBody attributes
const extraClasses = this.getAttribute('data-extra-classes');
const bodyClasses = ['offcanvas-body'];
extraClasses ? bodyClasses.push(extraClasses) : 0;
const expand = this.getAttribute('data-expand');
if (expand) {
expand === 'always'
? bodyClasses.push('navbar-expand')
: bodyClasses.push(`navbar-expand-${expand}`);
}
this.body.className = bodyClasses.join(' ');
if (!this.shadowRoot.querySelector('div')) {
this.shadowRoot.appendChild(this.body);
Expand Down
12 changes: 12 additions & 0 deletions src/components/atoms/OffcanvasBody/_offcanvasbody.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@import '../../../../node_modules/bootstrap/scss/mixins/breakpoints';

@each $breakpoint-name, $_ in $grid-breakpoints {
@include media-breakpoint-up($breakpoint-name) {
.navbar-expand-#{$breakpoint-name}.offcanvas-body {
display: flex;
flex-grow: 0;
padding: 0;
overflow-y: visible;
}
}
}
6 changes: 6 additions & 0 deletions src/components/atoms/OffcanvasHeader/OffcanvasHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export default class OffcanvasHeader extends HTMLElement {
btnDark === 'true'
? this.closeBtn.setAttribute('data-extra-classes', 'btn-close-white')
: 0;
const expand = this.getAttribute('data-expand');
if (expand) {
expand === 'always'
? offcanvasHeaderClasses.push('navbar-expand')
: offcanvasHeaderClasses.push(`navbar-expand-${expand}`);
}
this.offcanvasHeader.className = offcanvasHeaderClasses.join(' ');
this.closeBtn.addEventListener('click', this._onClick);
if (!this.shadowRoot.querySelector('div')) {
Expand Down
9 changes: 9 additions & 0 deletions src/components/atoms/OffcanvasHeader/_offcanvasheader.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@import '../../../../node_modules/bootstrap/scss/mixins/breakpoints';

@each $breakpoint-name, $_ in $grid-breakpoints {
@include media-breakpoint-up($breakpoint-name) {
.navbar-expand-#{$breakpoint-name}.offcanvas-header {
display: none;
}
}
}
6 changes: 6 additions & 0 deletions src/components/molecules/Nav/Nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ export default class Nav extends HTMLElement {
const justified = this.getAttribute('data-justified');
const extraClasses = this.getAttribute('data-extra-classes');
const navClasses = ['nav'];
const expand = this.getAttribute('data-expand');
if (expand) {
expand === 'always'
? navClasses.push('navbar-expand')
: navClasses.push(`navbar-expand-${expand}`);
}
vertical === 'true' ? navClasses.push('flex-column') : 0;
tabs === 'true' ? navClasses.push('nav-tabs') : 0;
pills === 'true' ? navClasses.push('nav-pills') : 0;
Expand Down
9 changes: 9 additions & 0 deletions src/components/molecules/Nav/_nav.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@import '../../../../node_modules/bootstrap/scss/mixins/breakpoints';

@each $breakpoint-name, $_ in $grid-breakpoints {
@include media-breakpoint-up($breakpoint-name) {
.navbar-expand-#{$breakpoint-name}.nav {
flex-direction: row;
}
}
}
7 changes: 6 additions & 1 deletion src/components/organisms/Navbar/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ export default class Navbar extends HTMLElement {
this.navbarContainer.appendChild(this.navbarBrand);
break;

case 'COD-OFFCANVAS':
case 'COD-OFFCANVAS': {
const expand = this.getAttribute('data-expand');
if (expand) {
node.setAttribute('data-expand', expand);
}
this.navbarContainer.appendChild(node);
break;
}
default: {
const nodeClasses = node.className.split(' ');
nodeClasses.includes('no-wc') ? node.remove() : 0;
Expand Down
10 changes: 10 additions & 0 deletions src/components/organisms/Offcanvas/Offcanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export default class Offcanvas extends HTMLElement {
: 0;
node.setAttribute('data-parent-id', this.getAttribute('data-id'));
}
const expand = this.getAttribute('data-expand');
if (expand) {
node.setAttribute('data-expand', expand);
}
// TODO: See CityOfDetroit/detroitmi#1099
// eslint-disable-next-line prefer-const
let nodeClasses = node.className.split(' ');
Expand Down Expand Up @@ -161,6 +165,12 @@ export default class Offcanvas extends HTMLElement {
} else {
offcanvasClasses.push('offcanvas-start');
}
const expand = this.getAttribute('data-expand');
if (expand) {
expand === 'always'
? offcanvasClasses.push('navbar-expand')
: offcanvasClasses.push(`navbar-expand-${expand}`);
}
// TODO: See CityOfDetroit/detroitmi#1099
// eslint-disable-next-line eqeqeq
if (id != undefined && id != null) {
Expand Down
18 changes: 18 additions & 0 deletions src/components/organisms/Offcanvas/_offcanvas.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@import '../../../../node_modules/bootstrap/scss/mixins/breakpoints';

@each $breakpoint-name, $_ in $grid-breakpoints {
@include media-breakpoint-up($breakpoint-name) {
.navbar-expand-#{$breakpoint-name}.offcanvas {
position: static;
z-index: auto;
flex-grow: 1;
width: auto !important;
height: auto !important;
visibility: visible !important;
background-color: transparent !important;
border: 0 !important;
transform: none !important;
transition: none;
}
}
}
4 changes: 4 additions & 0 deletions src/scss/themed-bootstrap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,7 @@ $utilities: map-merge(
@import '../components/atoms/TableRow/table-row';
@import '../components/atoms/TableCellHeader/table-cell-header';
@import '../components/atoms/TableCell/table-cell';
@import '../components/molecules/Nav/nav';
@import '../components/organisms/Offcanvas/offcanvas';
@import '../components/atoms/OffcanvasHeader/offcanvasheader';
@import '../components/atoms/OffcanvasBody/offcanvasbody';
188 changes: 188 additions & 0 deletions src/shared/themed-bootstrap.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/shared/themed-bootstrap.css.map

Large diffs are not rendered by default.

Loading

0 comments on commit c5d26aa

Please sign in to comment.