| 1 |
/** |
| 2 |
* merge-props.js |
| 3 |
* |
| 4 |
* Forked from reactabular-table version 8.14.0 |
| 5 |
* https://github.com/reactabular/reactabular/tree/v8.14.0/packages/reactabular-table/src |
| 6 |
*/ |
| 7 |
import { cloneElement } from 'react'; |
| 8 |
import mergeWith from 'lodash/mergeWith'; |
| 9 |
import { css } from '@patternfly/react-styles'; |
| 10 |
/** |
| 11 |
* @param {any} props - Props |
| 12 |
*/ |
| 13 |
export function mergeProps(...props) { |
| 14 |
const firstProps = props[0]; |
| 15 |
const restProps = props.slice(1); |
| 16 |
if (!restProps.length) { |
| 17 |
return mergeWith({}, firstProps); |
| 18 |
} |
| 19 |
// Avoid mutating the first prop collection |
| 20 |
return mergeWith(mergeWith({}, firstProps), ...restProps, (a, b, key) => { |
| 21 |
if (key === 'children') { |
| 22 |
if (a && b) { |
| 23 |
// compose the two |
| 24 |
return cloneElement(a, { |
| 25 |
children: b |
| 26 |
}); |
| 27 |
} |
| 28 |
// Children have to be merged in reverse order for Reactabular |
| 29 |
// logic to work. |
| 30 |
return Object.assign(Object.assign({}, b), a); |
| 31 |
} |
| 32 |
if (key === 'className') { |
| 33 |
// Process class names through classNames to merge properly |
| 34 |
// as a string. |
| 35 |
return css(a, b); |
| 36 |
} |
| 37 |
return undefined; |
| 38 |
}); |
| 39 |
} |
| 40 |
//# sourceMappingURL=merge-props.js.map |