ohif-viewer/platform/ui/src/components/TableBody/TableBody.tsx

44 lines
1.2 KiB
TypeScript
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 TableBody = ({ children, className = '', style = {} }) => {
2020-03-20 22:56:27 +01:00
return (
<div
className={classnames('ohif-scrollbar mt-2 max-h-48 overflow-y-scroll', className)}
2020-03-20 22:56:27 +01:00
style={style}
>
2020-03-24 22:16:47 +01:00
{React.isValidElement(children)
? React.cloneElement(children, {
isTableHead: false,
})
: children}
2020-03-20 22:56:27 +01:00
</div>
);
};
TableBody.propTypes = {
children: function (props, propName, componentName) {
2020-03-24 22:16:47 +01:00
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));
2020-03-24 22:16:47 +01:00
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 TableBody;