@bianic-ui/utils
Version:
Common utilties and types for Bianic UI
35 lines (30 loc) • 1.3 kB
JavaScript
import { callAllHandlers } from "./function";
import { cx } from "./dom";
import { isFunction, isString } from "./assertion";
export function mergeProps() {
var result = {};
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
for (var props of args) {
for (var _key2 in result) {
// Chain events
if (/^on[A-Z]/.test(_key2) && isFunction(result[_key2]) && isFunction(props[_key2])) {
result[_key2] = callAllHandlers(result[_key2], props[_key2]); // Merge classnames, sometimes classNames are empty string which eval to false, so we just need to do a type check
} else if (_key2 === "className" && isString(result.className) && isString(props.className)) {
result[_key2] = cx(result.className, props.className);
} else if (_key2 === "id" && result.id && props.id) {
result.id = cx(result.id, props.id); // Override others
} else {
result[_key2] = props[_key2] !== undefined ? props[_key2] : result[_key2];
}
} // Add props from b that are not in a
for (var _key3 in props) {
if (result[_key3] === undefined) {
result[_key3] = props[_key3];
}
}
}
return result;
}
//# sourceMappingURL=merge-props.js.map