wix-storybook-utils
Version:
Utilities for automated component documentation within Storybook
25 lines • 1.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var falsy = function () { return false; };
var categorizeProps = function (props, categories) {
if (props === void 0) { props = {}; }
if (categories === void 0) { categories = {}; }
var sortedCategories = Object.entries(categories).sort(function (_a, _b) {
var _c = _a[1].order, aOrder = _c === void 0 ? -1 : _c;
var _d = _b[1].order, bOrder = _d === void 0 ? -1 : _d;
return aOrder - bOrder;
});
return Object.entries(props).reduce(function (result, _a) {
var _b, _c;
var propName = _a[0], prop = _a[1];
var categoryName = (sortedCategories.find(function (_a) {
var _b = _a[1].matcher, matcher = _b === void 0 ? falsy : _b;
return matcher(propName, prop);
}) || ['primary'])[0];
var category = result[categoryName] || categories[categoryName] || {};
return tslib_1.__assign(tslib_1.__assign({}, result), (_b = {}, _b[categoryName] = tslib_1.__assign(tslib_1.__assign({}, category), { props: tslib_1.__assign(tslib_1.__assign({}, (category.props || {})), (_c = {}, _c[propName] = prop, _c)) }), _b));
}, {});
};
exports.default = categorizeProps;
//# sourceMappingURL=categorize-props.js.map