UNPKG

@heycar-uikit/core

Version:
74 lines (71 loc) 3.27 kB
import { _ as __assign, a as __spreadArray } from '../tslib.es6-4ac54363.js'; import { SUBNAV_CONFIG, LANG_OPTIONS, BURGER_MENU_SUBNAV_MAX_ITEMS } from '../constants/Header.constants.js'; import { getCurrentLang } from './headerItemHelpers.js'; import 'react'; import '../../../icons'; var getConfigType = function (groupIndex, totalGroups) { if (totalGroups === 1) return SUBNAV_CONFIG.full; if (totalGroups === 2 && groupIndex === 0) return SUBNAV_CONFIG.quarter; if (totalGroups === 2 && groupIndex > 0) return SUBNAV_CONFIG.half; if (totalGroups === 3 || (totalGroups === 2 && groupIndex === 0)) return SUBNAV_CONFIG.third; return SUBNAV_CONFIG.quarter; }; // Returns config details for each SubNavGroup when given the total number of groups in a subnav // max groups is 4 var getSubNavGroupDetails = function (groups, isDropdownMenu) { var noOfGroups = groups.length; if (noOfGroups < 1 || noOfGroups > 4) return []; return groups.map(function (group, i) { var _a; // NOTE: this makes an assumption that if there are going to be descriptions, all items in the list will have them. // This is a limitation of the design var hasCaption = (_a = group.items[0]) === null || _a === void 0 ? void 0 : _a.desc; var groupDetails = getConfigType(i, noOfGroups); // the max items we can display in a group varies based on the breakpoint, groups width and if the items have captions var correctMaxItem = hasCaption ? groupDetails.maxCaptionItem : groupDetails.maxItem; if (!isDropdownMenu) correctMaxItem = BURGER_MENU_SUBNAV_MAX_ITEMS; return __assign(__assign({}, groupDetails), { maxItem: correctMaxItem }); }); }; // in Burger menu mode (mobile) some of the header items are moved into the navigation // this function takes the header item data and adds it to the navigation array in the correct format var extendNavigation = function (navigation, locale, langItemConfig, accountItemConfig) { var extendedNav = __spreadArray([], navigation, true); if (langItemConfig && !langItemConfig.hide) { var langOptions = langItemConfig.options || LANG_OPTIONS; var currentLang = getCurrentLang(langItemConfig.currentLang, langOptions); var items = langOptions.map(function (lang) { return ({ href: lang.href, label: lang.label, }); }); var langListNavItem = { isBurgerMenuOnly: true, label: (currentLang === null || currentLang === void 0 ? void 0 : currentLang.label) || locale.langListHeading, subNavGroups: [ { heading: locale.langListHeading, items: items, }, ], }; extendedNav.push(langListNavItem); } if (accountItemConfig && !accountItemConfig.hide) { var accountListNavItem = { isBurgerMenuOnly: true, label: accountItemConfig.label, onClick: accountItemConfig.onClick, }; extendedNav.push(accountListNavItem); } return extendedNav; }; export { extendNavigation, getConfigType, getSubNavGroupDetails };