1
0
mirror of https://github.com/yldio/copilot.git synced 2025-01-24 01:40:12 +02:00
copilot/ui/src/components/list/transfer-props.js

30 lines
727 B
JavaScript
Raw Normal View History

2017-01-09 20:58:30 +02:00
const isString = require('lodash.isstring');
const React = require('react');
const transfer = (parentProps, props) => {
// eslint-disable-next-line react/prop-types
return React.Children.map(props.children, (c) => {
return React.cloneElement(c, {
...c.props,
...parentProps.reduce((sum, name) => ({
...sum,
[name]: props[name]
}), {})
});
});
};
module.exports = (parentProps, Component) => (props) => {
// eslint-disable-next-line react/prop-types
const _children = !isString(props.children)
? transfer(parentProps, props)
// eslint-disable-next-line react/prop-types
: props.children;
return (
<Component {...props}>
{_children}
</Component>
);
};