@procore/core-react
Version:
React library of Procore Design Guidelines
63 lines (61 loc) • 1.48 kB
JavaScript
export var empty = [];
export var hideKeys = {
overlay: ['Escape', 'Esc'],
target: ['Escape', 'Esc']
};
export function defaultGetGroupId(tier) {
return tier.groupId;
}
export function defaultGetId(tier) {
return tier.id;
}
export function defaultGetLabel(tier) {
return tier.label;
}
export function defaultGetNextGroupId(tier) {
return tier.nextGroupId;
}
export function defaultIsTierDisabled(tier) {
return Boolean(tier.disabled);
}
export function noop() {}
export function always() {
return true;
}
/**
* Helper function to find path in tiered structure
* @param optionsByNextGroupId
* @param item
* @param getGroupId
* @param getNextGroupId
* @returns
*/
export function findPath(optionsByNextGroupId, item, getGroupId) {
var path = [item];
var currentItem = item;
while (getGroupId(currentItem)) {
var groupId = getGroupId(currentItem);
if (groupId) {
var parent = optionsByNextGroupId[groupId];
path.push(parent);
currentItem = parent;
} else {
break;
}
}
return path.reverse();
}
/**
* Helper function to generate a path key
* @param path
* @param getLabel
* @returns
*/
export function getPathKey() {
var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var getLabel = arguments.length > 1 ? arguments[1] : undefined;
return path.map(function (node) {
return getLabel(node);
}).join(' > ');
}
//# sourceMappingURL=TieredDropdown.helpers.js.map