import type { ReactNode, JSX } from 'react'; import type { BehaviorTrackingProps } from '../../core/types/behavior-tracking-props.js'; import type { DataTestId } from '../../core/types/data-props.js'; import type { MaskingProps } from '../../core/types/masking-props.js'; import type { StylingProps } from '../../core/types/styling-props.js'; import type { WithChildren } from '../../core/types/with-children.js'; /** * @public */ export type SimpleTableRowData = unknown | object | any[]; /** * Custom cell renderer function. * @public */ export type SimpleTableCustomCell = (props: { /** Raw value of the cell that is rendered. */ value: TValue; /** Index of the row the rendered cell is in. */ rowIndex: number; /** Data of the entire row the rendered cell is in. */ rowData: TData; /** Id of the row the rendered cell is in. */ rowId: string; }) => JSX.Element; /** * Common column definition denominator. All column definitions extend from this * type. * @public */ export type SimpleTableColumnDefBase = { /** Id of the column to uniquely identify it. */ id: string; /** Header of the column. */ header?: string | (() => ReactNode); cell?: string | SimpleTableCustomCell; /** * Defines the preferred or initial width of the column. */ width?: number; minWidth?: number; maxWidth?: number; alignment?: 'left' | 'center' | 'right' | 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right'; }; /** * Column definition for display columns that render cells in the SimpleTable. * @public */ export type SimpleTableDisplayColumnDef = SimpleTableColumnDefBase & { /** * The accessor can be used to map the column to an entry in your data. */ accessor: (string & {}) | keyof TData | ((row: TData) => TValue); }; /** * Column definition for column groups that do not render cells in the SimpleTable. * @public */ export type SimpleTableGroupColumnDef = SimpleTableColumnDefBase & { /** * Defines the preferred or initial width of the column. */ width?: number | `${number}fr`; /** * A list of child display columns that this columngroup contains of. */ columns?: SimpleTableDisplayColumnDef[]; }; /** * Mapping type for the columns prop that can contain either display columns or group columns. * @public */ export type SimpleTableColumnDef = SimpleTableDisplayColumnDef | SimpleTableGroupColumnDef; /** * Basic props for the SimpleTable. * @public */ export interface SimpleTableBaseProps extends WithChildren { /** * Data given to the SimpleTable. Needs to be memoized in order to ensure * performant update cycles. */ data: TData[]; /** * Column definition given to the SimpleTable. Needs to be memoized in order * to ensure performant update cycles. */ columns: SimpleTableColumnDef[]; /** * Configures the variant on the data table, impacting the visual representation. */ variant?: { /** * rowSeparation can be set to 'horizontalDividers' which will provide lines between rows or * can be set to 'zebraStripes' which will provide alternate row coloring. * @defaultValue 'horizontalDividers' */ rowSeparation?: 'none' | 'horizontalDividers' | 'zebraStripes'; /** * If true provides vertical lines between the columns. * @defaultValue false */ verticalDividers?: boolean; /** * If true provides a border for the table. * @defaultValue true */ contained?: boolean; /** * rowDensity adds spacing around the content inside the row * with minimal space for 'condensed', maximum spacing for 'comfortable' and * 'default' being medium spacing. * @defaultValue 'default' */ rowDensity?: 'default' | 'condensed' | 'comfortable'; /** * fontStyle, sets the font style for the entire data table. * This does not overwrite any fontStyle set at the lower level, like columns etc. * @defaultValue 'text' */ fontStyle?: 'text' | 'code'; }; } /** * Combined props type for the SimpleTable component. * @public */ export type SimpleTableProps = SimpleTableBaseProps & StylingProps & DataTestId & MaskingProps & BehaviorTrackingProps;