@itwin/itwinui-react
Version:
A react component library for iTwinUI
33 lines (32 loc) • 1.05 kB
JavaScript
import * as React from 'react';
import { ExpanderColumn, EXPANDER_CELL_ID } from '../columns/index.js';
import { DefaultCell } from '../cells/DefaultCell.js';
export const useExpanderCell =
(subComponent, expanderCell, isRowDisabled) => (hooks) => {
if (!subComponent) return;
hooks.allColumns.push((columns) => {
let hasExpanderColumn = columns.find((c) => c.id === EXPANDER_CELL_ID);
if (hasExpanderColumn) return columns;
let expanderColumn = ExpanderColumn({
subComponent,
isDisabled: isRowDisabled,
});
return [
{
...expanderColumn,
cellRenderer: expanderCell
? (props) =>
React.createElement(
DefaultCell,
{
...props,
isDisabled: (rowData) => !!isRowDisabled?.(rowData),
},
expanderCell(props.cellProps),
)
: expanderColumn.cellRenderer,
},
...columns,
];
});
};