UNPKG

@navikt/ds-react

Version:

React components from the Norwegian Labour and Welfare Administration.

36 lines 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mergeProps = mergeProps; function mergeProps(slotProps, childProps) { // all child props should override const overrideProps = Object.assign({}, childProps); for (const propName in childProps) { const slotPropValue = slotProps[propName]; const childPropValue = childProps[propName]; const isHandler = /^on[A-Z]/.test(propName); if (isHandler) { // if the handler exists on both, we compose them if (slotPropValue && childPropValue) { overrideProps[propName] = (...args) => { childPropValue(...args); slotPropValue(...args); }; } // but if it exists only on the slot, we use only this one else if (slotPropValue) { overrideProps[propName] = slotPropValue; } } // if it's `style`, we merge them else if (propName === "style") { overrideProps[propName] = Object.assign(Object.assign({}, slotPropValue), childPropValue); } else if (propName === "className") { overrideProps[propName] = [slotPropValue, childPropValue] .filter(Boolean) .join(" "); } } return Object.assign(Object.assign({}, slotProps), overrideProps); } //# sourceMappingURL=merge-props.js.map