ohif-viewer/platform/ui/src/components/TableBody/TableBody.tsx
Alireza 70f2c797f4
feat(ui): move to React 18 and base for using shadcn/ui (#4174)
Co-authored-by: IbrahimCSAE <ibrahim.mdev@gmail.com>
2024-05-27 14:30:25 -04:00

44 lines
1.2 KiB
TypeScript

import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
const TableBody = ({ children, className = '', style = {} }) => {
return (
<div
className={classnames('ohif-scrollbar mt-2 max-h-48 overflow-y-scroll', className)}
style={style}
>
{React.isValidElement(children)
? React.cloneElement(children, {
isTableHead: false,
})
: children}
</div>
);
};
TableBody.propTypes = {
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.`
);
}
},
className: PropTypes.string,
style: PropTypes.object,
};
export default TableBody;