Skip to content

Commit

Permalink
Adding image support for large menu and medium menus on gnav (#3235)
Browse files Browse the repository at this point in the history
* Adding image support on gnav

* Decorating localnav only if it has one section

* Lint fix
  • Loading branch information
bandana147 committed Jan 14, 2025
1 parent ff17a03 commit c2152a0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions libs/blocks/fallback/fallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const SYNTHETIC_BLOCKS = [
'search',
'social',
'product-entry-cta',
'gnav-image',
];

// eslint-disable-next-line import/prefer-default-export
Expand Down
3 changes: 2 additions & 1 deletion libs/blocks/global-navigation/global-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,11 @@ class Gnav {
};

decorateLocalNav = async () => {
if (!this.isLocalNav()) return;
const localNavItems = this.elements.navWrapper.querySelector('.feds-nav').querySelectorAll('.feds-navItem:not(.feds-navItem--section)');
const [title, navTitle = ''] = this.getOriginalTitle(localNavItems);

if (this.elements.localNav || !this.newMobileNav || !this.isLocalNav() || isDesktop.matches) {
if (this.elements.localNav || !this.newMobileNav || isDesktop.matches) {
localNavItems[0].querySelector('a').textContent = title.trim();
} else {
const localNav = document.querySelector('.feds-localnav');
Expand Down
13 changes: 13 additions & 0 deletions libs/blocks/global-navigation/utilities/menu/menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
box-sizing: content-box;
}

.feds-localnav-items .feds-menu-headline:after {
right: 38px;
}

[dir = "rtl"] .feds-menu-headline:after {
right: unset;
left: 30px;
Expand All @@ -88,6 +92,15 @@
display: none;
}

.feds-image-wrapper {
padding: 12px 38px;
}

.gnav-image {
width: 316px;
box-sizing: content-box;
}

@media (min-width: 900px) {
.feds-menu-content {
display: flex;
Expand Down
17 changes: 17 additions & 0 deletions libs/blocks/global-navigation/utilities/menu/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ const decorateElements = ({ elem, className = 'feds-navLink', itemIndex = { posi
return elem;
};

const decorateGnavImage = (elem) => {
const linkElem = elem.querySelector('a');
const imageElem = elem.querySelector('picture');
const promoImageElem = linkElem instanceof HTMLElement
? toFragment`<a class="feds-image" href="${linkElem.href}">${imageElem}</a>`
: toFragment`<div class="feds-image">${imageElem}</div>`;

elem.replaceChildren(promoImageElem);
return toFragment`<div class="feds-image-wrapper">${elem}</div>`;
};

// Current limitation: we can only add one link
const decoratePromo = (elem, index) => {
const isDarkTheme = elem.matches('.dark');
Expand Down Expand Up @@ -251,6 +262,12 @@ const decorateColumns = async ({ content, separatorTagName = 'H5' } = {}) => {
const promoElem = decoratePromo(columnElem, itemIndex);

itemDestination.append(promoElem);
} else if (columnElem.matches('.gnav-image')) {
resetDestination();
itemIndex.position = 0;
const imageElem = decorateGnavImage(columnElem, itemIndex);

itemDestination.append(imageElem);
} else {
const decoratedElem = decorateElements({ elem: columnElem, itemIndex });
columnElem.remove();
Expand Down

0 comments on commit c2152a0

Please sign in to comment.