d2-ui
Version:
26 lines (21 loc) • 969 B
JavaScript
import React, { PropTypes, Children, cloneElement } from 'react';
export default function createFlexContainer(defaultFlexStyle) {
var displayName = arguments.length <= 1 || arguments[1] === undefined ? 'FlexContainer' : arguments[1];
function FlexContainer(_ref) {
var style = _ref.style;
var _ref$flexValue = _ref.flexValue;
var flexValue = _ref$flexValue === undefined ? 1 : _ref$flexValue;
var children = _ref.children;
var flexContainerStyle = Object.assign({ display: 'flex' }, defaultFlexStyle, style);
var flexedChildren = Children.map(children, function (child) {
return cloneElement(child, { style: Object.assign({}, { flex: flexValue }, child.props.style) });
});
return React.createElement(
'div',
{ style: flexContainerStyle },
flexedChildren
);
}
FlexContainer.displayName = displayName;
return FlexContainer;
}