import MUITableCell, { TableCellProps as MUITableCellProps } from '@mui/material/TableCell'; import TableSortLabel from '@mui/material/TableSortLabel'; import clsx from 'clsx'; import { memo, ReactNode } from 'react'; import { Tooltip, TooltipProps } from '../../Tooltip/Tooltip'; import css from './HeaderCell.module.scss'; export interface HeaderProps { /** Label for this table header */ label: string; /** Whether this table header represents a column of numeric values */ numeric?: boolean; /** Whether the additional padding for this table header should be disabled */ disablePadding?: boolean; /** Whether this header is for a cell that contains an action button */ isActionButtonCell?: boolean; } export interface HeaderCellProps extends MUITableCellProps { /** The header data */ header: HeaderProps; /** The property to order by */ orderby: string; /** The order direction for the header */ order: 'desc' | 'asc'; /** The label for the tooltip */ tooltiplabel: ReactNode; /** The placement of the tooltip */ tooltipplacement: TooltipProps['placement']; /** The function triggered when a sort request is made */ onRequestSort: (property: T) => void; /** Data-qa tag to apply to the search bar and input element */ 'data-qa'?: string; /** Custom CSS classes to pass to the button */ customclasses?: string | string[]; /** Whether this header is for a cell that contains an action button */ isActionButtonCell?: boolean; } /** * Constructs a table header cell using pre-defined Rijkswaterstaat styling * @param props Props to pass to the TableHeader cell */ export const HeaderCell = memo((props: HeaderCellProps) => { const renderTableHeaderCell = () => { if (props.isActionButtonCell) { return ( undefined} > {props.header.label} ); } return ( props.onRequestSort(props.header.label)} > {props.header.label} ); }; return ( {renderTableHeaderCell()} ); });