import type { CSSProperties, MouseEvent, ReactNode } from 'react'; import type { CellProps } from 'react-table'; import type { Column } from '../ReactTable.js'; export type CustomColumn = Column & { index: number }; export type ControlCustomColumn = CustomColumn & { showWhen: string; }; export default function addCustomColumn( array: any, options: CustomColumn, ) { const { index, Header = () => null, accessor = null, Cell = null, sortType = 'basic', enableRowSpan = false, style = {}, id, } = options || {}; array.push({ index, ...(id && { id }), ...(accessor && { accessor }), ...(Cell && { Cell }), Header, sortType, enableRowSpan, style, }); } interface CreateActionColumnOptions { onClick: (row: T | object, even?: MouseEvent) => void; icon: ReactNode; style?: CSSProperties; index: number; } export function createActionColumn( options: CreateActionColumnOptions, ): CustomColumn { const { onClick, icon, index, style = {} } = options; return { index, Header: '', style: { width: '1%', maxWidth: '20px', minWidth: '20px', padding: '0px', textAlign: 'center', ...style, }, id: crypto.randomUUID(), Cell: (cell: CellProps) => ( ), }; }