Skip to content

Commit

Permalink
Alter pill nav to add new variant
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbergquist committed Nov 13, 2024
1 parent 2863fb5 commit bcad5ab
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
15 changes: 13 additions & 2 deletions src/components/blocks/toggle-nav/_toggle-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if (toggleNav) {

Array.from(toggleNavBtns, (tog) => {
const tnToggees = document.querySelectorAll(tog.dataset.toggeesSelector);
const isDarkVariation = toggleNav.parentElement.classList.contains('b-toggle-nav--dark');

tog.addEventListener('click', (e) => {
e.preventDefault();
Expand All @@ -29,10 +30,20 @@ if (toggleNav) {
return true;
});
Array.from(toggleNavBtns, (el) => {
el.classList.add('u-btn--pill-dark');
if (isDarkVariation) {
el.classList.add('u-btn--pill-dark');
} else {
el.classList.add('u-btn--pill-light');
el.classList.remove('u-btn--pill-dark');
}
return true;
});
tog.classList.remove('u-btn--pill-dark');
if (isDarkVariation) {
tog.classList.remove('u-btn--pill-dark');
} else {
tog.classList.remove('u-btn--pill-light');
tog.classList.add('u-btn--pill-dark');
}
}, false);

if (tog.dataset.toggleType === qsToggleType) {
Expand Down
16 changes: 13 additions & 3 deletions src/components/blocks/toggle-nav/toggle-nav.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
title: 'Toggle Nav',
label: 'Toggle Nav',
default: 'on-light',
context: {
previewClass: 'fr-bg--dark',
modifier: ['light'],
toggles: [
'Galleries',
'Periods and styles',
Expand All @@ -11,5 +11,15 @@ module.exports = {
'Materials and techniques',
'Places'
]
}
},
variants: [
{
name: 'on-dark',
label: 'On dark',
context: {
previewClass: 'fr-bg--dark',
modifier: ['dark']
}
}
]
};
4 changes: 2 additions & 2 deletions src/components/blocks/toggle-nav/toggle-nav.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<nav class="b-toggle-nav">
<nav class="b-toggle-nav{% if modifier %} b-toggle-nav--{{ modifier }}{% endif %}">
<ol class="b-toggle-nav__list js-toggle-nav" data-toggle-type-default="type-3">
{% for toggle in toggles %}
<li class="b-toggle-nav__item">
<button class="u-btn u-btn--pill u-btn--pill-dark b-toggle-nav__button js-toggle-nav-btn" data-toggle-type="type-{{ loop.index }}" data-toggees-selector=".my-toggleables-common-class" aria-label="Only show: {{ toggle }}">
<button class="u-btn u-btn--pill {% if modifier %} u-btn--pill-{{ modifier }}{% endif %} b-toggle-nav__button js-toggle-nav-btn" data-toggle-type="type-{{ loop.index }}" data-toggees-selector=".my-toggleables-common-class" aria-label="Only show: {{ toggle }}">
{{ toggle }}
</button>
</li>
Expand Down

0 comments on commit bcad5ab

Please sign in to comment.