react-toggle-pattern
Version:
React Component that provide toggle pattern
49 lines (48 loc) • 1.57 kB
JavaScript
// LICENSE : MIT
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.matchAnd = matchAnd;
exports.matchOr = matchOr;
function matchAnd(keys, parentProps, childProps) {
var childKeys = childProps ? Object.keys(childProps) : [];
// all match
return keys.every(function (parentKey) {
return childKeys.some(function (childKey) {
if (parentKey !== childKey) {
return false;
}
var parentValue = parentProps[parentKey];
var childValue = childProps[childKey];
if (childValue === parentValue) {
return true;
} else if (childValue === undefined && parentKey === true) {
// <X attr />
return true;
}
return false;
});
});
}
function matchOr(keys, parentProps, childProps) {
var childKeys = childProps ? Object.keys(childProps) : [];
// some match
return keys.some(function (parentKey) {
return childKeys.some(function (childKey) {
if (parentKey !== childKey) {
return false;
}
var parentValue = parentProps[parentKey];
var childValue = childProps[childKey];
if (childValue === parentValue) {
return true;
} else if (childValue === undefined && parentKey === true) {
// <X attr />
return true;
}
return false;
});
});
}
//# sourceMappingURL=match-props.js.map