@awsui/components-react
Version:
AWS UI is a collection of [React](https://reactjs.org/) components that help create intuitive, responsive, and accessible user experiences for web applications. It is developed by Amazon Web Services (AWS). This work is available under the terms of the [A
47 lines (46 loc) • 1.82 kB
JavaScript
import { warnOnce } from '../internal/logging';
export function hasActiveLink(items, activeHref) {
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
var item = items_1[_i];
if ((item.type === 'link' || item.type === 'link-group' || item.type === 'expandable-link-group') &&
item.href === activeHref) {
return true;
}
if ((item.type === 'section' || item.type === 'link-group' || item.type === 'expandable-link-group') &&
hasActiveLink(item.items, activeHref)) {
return true;
}
}
return false;
}
export function generateExpandableItemsMapping(items, mapping, expandableParents) {
if (mapping === void 0) { mapping = new WeakMap(); }
if (expandableParents === void 0) { expandableParents = []; }
items.forEach(function (item) {
var nextLevelParents = expandableParents.slice();
if (item.type === 'section' || item.type === 'expandable-link-group') {
mapping.set(item, expandableParents);
nextLevelParents.unshift(item);
}
if (item.type === 'section' || item.type === 'link-group' || item.type === 'expandable-link-group') {
generateExpandableItemsMapping(item.items, mapping, nextLevelParents);
}
});
return mapping;
}
export function checkDuplicateHrefs(items) {
var hrefs = new Set();
var queue = items.slice();
while (queue.length > 0) {
var item = queue.shift();
if ('href' in item) {
if (hrefs.has(item.href)) {
warnOnce('SideNavigation', "duplicate href in \"" + item.text + "\": " + item.href);
}
hrefs.add(item.href);
}
if ('items' in item) {
queue.push.apply(queue, item.items);
}
}
}