UNPKG

@heycar-uikit/core

Version:
78 lines (74 loc) 3.6 kB
Object.defineProperty(exports, '__esModule', { value: true }); var tslib_es6 = require('../tslib.es6-7299ae33.js'); var constants_Header_constants = require('../constants/Header.constants.js'); var utils_headerItemHelpers = require('./headerItemHelpers.js'); require('react'); require('../../icons'); var getConfigType = function (groupIndex, totalGroups) { if (totalGroups === 1) return constants_Header_constants.SUBNAV_CONFIG.full; if (totalGroups === 2 && groupIndex === 0) return constants_Header_constants.SUBNAV_CONFIG.quarter; if (totalGroups === 2 && groupIndex > 0) return constants_Header_constants.SUBNAV_CONFIG.half; if (totalGroups === 3 || (totalGroups === 2 && groupIndex === 0)) return constants_Header_constants.SUBNAV_CONFIG.third; return constants_Header_constants.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 = constants_Header_constants.BURGER_MENU_SUBNAV_MAX_ITEMS; return tslib_es6.__assign(tslib_es6.__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 = tslib_es6.__spreadArray([], navigation, true); if (langItemConfig && !langItemConfig.hide) { var langOptions = langItemConfig.options || constants_Header_constants.LANG_OPTIONS; var currentLang = utils_headerItemHelpers.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; }; exports.extendNavigation = extendNavigation; exports.getConfigType = getConfigType; exports.getSubNavGroupDetails = getSubNavGroupDetails;