import { memo } from 'react'; import { useRovingTabIndex } from './hooks'; import { getCellClassname, getCellStyle } from './utils'; import type { RenderCellProps } from './types'; type SharedRenderCellProps = Pick< RenderCellProps, 'rowIdx' | 'column' | 'colSpan' | 'isCellActive' | 'setActivePosition' >; interface SummaryCellProps extends SharedRenderCellProps { row: SR; } function SummaryCell({ column, colSpan, row, rowIdx, isCellActive, setActivePosition }: SummaryCellProps) { const { tabIndex, childTabIndex, onFocus } = useRovingTabIndex(isCellActive); const { summaryCellClass } = column; const className = getCellClassname( column, typeof summaryCellClass === 'function' ? summaryCellClass(row) : summaryCellClass ); function onMouseDown() { setActivePosition({ idx: column.idx, rowIdx }); } return (
1 ? colSpan : undefined} aria-selected={isCellActive} tabIndex={tabIndex} className={className} style={getCellStyle(column, colSpan)} onMouseDown={onMouseDown} onFocus={onFocus} > {column.renderSummaryCell?.({ column, row, tabIndex: childTabIndex })}
); } export default memo(SummaryCell) as (props: SummaryCellProps) => React.JSX.Element;