UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

35 lines (34 loc) 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.permutateProps = void 0; const permutateProps = (allProps, filter, remainingProps = Object.keys(allProps), values = {}) => { // When there are no more props to combine with, return result const prop = remainingProps[0]; if (!prop) { const props = {}; Object.keys(values).forEach(prop => { var _a; props[prop] = (_a = values === null || values === void 0 ? void 0 : values[prop]) === null || _a === void 0 ? void 0 : _a.value; }); if (filter && !filter(props)) { return []; } const label = Object.keys(values) .map(prop => { var _a; return (_a = values === null || values === void 0 ? void 0 : values[prop]) === null || _a === void 0 ? void 0 : _a.label; }) .join(' '); return [ { label, props, }, ]; } const possiblePropValues = allProps[prop]; const permutations = possiblePropValues === null || possiblePropValues === void 0 ? void 0 : possiblePropValues.map((value) => { const newValues = { ...values }; // Required so we don't overwrite previous references newValues[prop] = value; return (0, exports.permutateProps)(allProps, filter, remainingProps.slice(1, remainingProps.length), newValues); }); return permutations.flat(); }; exports.permutateProps = permutateProps;