ohif-viewer/platform/ui/src/components/TableRow/TableRow.jsx

54 lines
1.4 KiB
React
Raw Normal View History

2020-03-20 22:56:27 +01:00
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
const TableRow = ({ children, className, isTableHead, style }) => {
const childrens = React.Children.map(children, child => {
const isValidReactElement = React.isValidElement(child);
return isValidReactElement
? React.cloneElement(child, { isTableHead })
: children;
});
2020-03-20 22:56:27 +01:00
return (
<div className={classnames('w-full flex', className)} style={style}>
{childrens}
2020-03-20 22:56:27 +01:00
</div>
);
};
TableRow.defaultProps = {
isTableHead: false,
className: '',
style: {},
};
TableRow.propTypes = {
isTableHead: PropTypes.bool,
children: function(props, propName, componentName) {
const elements = React.Children.toArray(props.children);
const isString = elements.some(child => typeof child === 'string');
if (isString) {
return new Error(
`Failed prop type: Invalid prop ${propName} supplied to ${componentName}, expected a valid element instead of a string.`
);
}
const isInvalidElement = elements.some(
child => !React.isValidElement(child)
);
if (isInvalidElement) {
return new Error(
`Failed prop type: Invalid prop ${propName} supplied to ${componentName}, expected a valid node element.`
);
}
},
2020-03-20 22:56:27 +01:00
className: PropTypes.string,
style: PropTypes.object,
};
export default TableRow;