import React, { useCallback } from 'react'; import clsx from 'clsx'; import TableCell from '@mui/material/TableCell'; import { makeStyles } from 'tss-react/mui'; const useStyles = makeStyles({ name: 'MUIDataTableBodyCell' })(theme => ({ root: {}, cellHide: { display: 'none', }, simpleHeader: { [theme.breakpoints.down('sm')]: { display: 'inline-block', fontWeight: 'bold', width: '100%', boxSizing: 'border-box', }, }, simpleCell: { [theme.breakpoints.down('sm')]: { display: 'inline-block', width: '100%', boxSizing: 'border-box', }, }, stackedHeader: { verticalAlign: 'top', }, stackedCommon: { [theme.breakpoints.down('md')]: { display: 'inline-block', fontSize: '16px', height: 'auto', width: 'calc(50%)', boxSizing: 'border-box', '&:last-child': { borderBottom: 'none', }, '&:nth-last-of-type(2)': { borderBottom: 'none', }, }, }, stackedCommonAlways: { display: 'inline-block', fontSize: '16px', height: 'auto', width: 'calc(50%)', boxSizing: 'border-box', '&:last-child': { borderBottom: 'none', }, '&:nth-last-of-type(2)': { borderBottom: 'none', }, }, stackedParent: { [theme.breakpoints.down('md')]: { display: 'inline-block', fontSize: '16px', height: 'auto', width: 'calc(100%)', boxSizing: 'border-box', }, }, stackedParentAlways: { display: 'inline-block', fontSize: '16px', height: 'auto', width: 'calc(100%)', boxSizing: 'border-box', }, cellStackedSmall: { [theme.breakpoints.down('md')]: { width: '50%', boxSizing: 'border-box', }, }, responsiveStackedSmall: { [theme.breakpoints.down('md')]: { width: '50%', boxSizing: 'border-box', }, }, responsiveStackedSmallParent: { [theme.breakpoints.down('md')]: { width: '100%', boxSizing: 'border-box', }, }, })); function TableBodyCell(props) { const { classes } = useStyles(); const { children, colIndex, columnHeader, options, dataIndex, rowIndex, className, print, tableId, ...otherProps } = props; const onCellClick = options.onCellClick; const handleClick = useCallback( event => { onCellClick(children, { colIndex, rowIndex, dataIndex, event }); }, [onCellClick, children, colIndex, rowIndex, dataIndex], ); // Event listeners. Avoid attaching them if they're not necessary. let methods = {}; if (onCellClick) { methods.onClick = handleClick; } let cells = [
{columnHeader}
,
{typeof children === 'function' ? children(dataIndex, rowIndex) : children}
, ]; var innerCells; if ( ['standard', 'scrollMaxHeight', 'scrollFullHeight', 'scrollFullHeightFullWidth'].indexOf(options.responsive) !== -1 ) { innerCells = cells.slice(1, 2); } else { innerCells = cells; } return ( {innerCells} ); } export default TableBodyCell;