import { memo, useMemo } from 'react'; import { css } from 'ecij'; import { RowSelectionContext, type RowSelectionContextValue } from './hooks'; import { classnames } from './utils'; import type { BaseRenderRowProps, GroupRow, Omit } from './types'; import GroupCell from './GroupCell'; import { cell, cellFrozenBase } from './style/cell'; import { rowClassname, rowActiveClassname } from './style/row'; const groupRow = css` @layer rdg.GroupedRow { &:not([aria-selected='true']) { background-color: var(--rdg-header-background-color); } > .${cell}:not(:last-child, .${cellFrozenBase}), > :nth-last-child(n + 2 of .rdg-cell-frozen-start), > :nth-last-child(n + 2 of .rdg-cell-frozen-end) { border-inline-end: none; } } `; const groupRowClassname = `rdg-group-row ${groupRow}`; interface GroupedRowProps extends Omit, 'isRowSelectionDisabled'> { row: GroupRow; groupBy: readonly string[]; toggleGroup: (expandedGroupId: string) => void; } function GroupedRow({ className, row, rowIdx, mapViewportColumns, activeCellIdx, isRowSelected, setActivePosition, gridRowStart, groupBy, toggleGroup, ...props }: GroupedRowProps) { const isPositionOnRow = activeCellIdx === -1; // the group-by columns follow the `groupBy` order, so each level has its own column const levelColumnKey = groupBy[row.level]; function handleSelectGroup() { setActivePosition({ idx: -1, rowIdx }, { shouldFocus: true }); } const selectionValue = useMemo( (): RowSelectionContextValue => ({ isRowSelectionDisabled: false, isRowSelected }), [isRowSelected] ); return (
{mapViewportColumns(activeCellIdx, undefined, (column, isCellActive) => ( ))}
); } export default memo(GroupedRow) as (props: GroupedRowProps) => React.JSX.Element;