A mega menu adapter is a class that implements the MegaMenuAdapter
interface and is used to create a mega menu source for the
NCIExtendedHeaderWithMegaMenu
component. The design system does not force
you to have to build your backend systems in any specific way. You can
build a mega menu adapter that fetches the data for your menus how ever
your site needs it to be fetched. The only thing we require is that you
return the HTML for the mega menu contents prebuilt using the correct
design system elements.
The header's mega menu functionality is driven by the primary navigation HTML.
The header finds all links with the nci-header-nav__primary-link class and
if the link also has a data-menu-id attribute the link will be converted
into a mega menu button. Which a user clicks a mega menu button, the
getMegaMenuContent method of your implementation
is called, passing in the data-menu-id value and expecting a Promise
resolving to the HTML of the menu to be returned.
You may use whatever you want for the data-menu-id as your adapter defines
how to fetch the HTML.
Example: Sample Mega Menu Adapter Implementation
The below html is a snippet from the full header HTML.
// This is just a method to demonstrate creating an HTMLElement from // a string. constcreateHtmlFromString = (htmlString) => { constwrapper = document.createElement('div'); wrapper.innerHtml = htmlString returnwrapper.firstElementChild; };
// Create the menus. The '... menu X html ...' strings should be replaced // with mega menu HTML. constmenu1 = createHtmlFromString('... menu 1 html ...'); constmenu2 = createHtmlFromString('... menu 2 html ...'); constmenu3 = createHtmlFromString('... menu 3 html ...');
// Sample megaMenuSource class. constmegaMenuSource = class { asyncgetMegaMenuContent(id) { if (id === "1") { returnmenu1; } elseif (id === "2") { returnmenu2; } elseif (id === "3") { returnmenu3; } } }
// Find the header HTML element. constheader = document.querySelector('.nci-header.nci-header--extended');
// Initialize the component using our megaMenuSource and the default // mobile menu source. NCIExtendedHeaderWithMegaMenu.create(header, { megaMenuSource:newmegaMenuSource(), mobileMenuSource:newDefaultMobileMenuSource(), });
In a real implementation the getMegaMenuContent method would call a web
service and generate the HTML based on the data returned, or even fetch
content from a web page.
A mega menu adapter is a class that implements the MegaMenuAdapter interface and is used to create a mega menu source for the NCIExtendedHeaderWithMegaMenu component. The design system does not force you to have to build your backend systems in any specific way. You can build a mega menu adapter that fetches the data for your menus how ever your site needs it to be fetched. The only thing we require is that you return the HTML for the mega menu contents prebuilt using the correct design system elements.
The header's mega menu functionality is driven by the primary navigation HTML. The header finds all links with the
nci-header-nav__primary-link
class and if the link also has adata-menu-id
attribute the link will be converted into a mega menu button. Which a user clicks a mega menu button, the getMegaMenuContent method of your implementation is called, passing in thedata-menu-id
value and expecting a Promise resolving to the HTML of the menu to be returned.You may use whatever you want for the
data-menu-id
as your adapter defines how to fetch the HTML.Example: Sample Mega Menu Adapter Implementation
The below html is a snippet from the full header HTML.
Below is a very simple example of a adapter that returns HTML when a requested ID is matched.
In a real implementation the getMegaMenuContent method would call a web service and generate the HTML based on the data returned, or even fetch content from a web page.