import type { OnChangeFn } from '@tanstack/react-table'; import type { DataTableRowData } from '../../row-data-types.js'; /** @internal */ export type ExpandedState = true | Record; /** * @public */ export interface DataTableSubRowsBaseProps { /** * @defaultValue false */ subRows?: boolean | { accessor?: // With a keyof TData we would have type safety for the objects first level and would be able to suggest and ensure that the key given actually exists in the given TData row data. To support pathed accessors like 'some.nested' we need to fall back to a string. string | ((row: TData) => TData[] | undefined); /** * Allows to specify a columnId that the subRow indicator will be injected to. * By default, this will be the first visible column provided by the columns prop. */ subRowColumnId?: string; /** * Allows to specify a function that will evalute if a specific subRows trigger in a row * should be disabled. */ disableSubRow?: (row: TData) => boolean; }; /** * Callback triggered when open subrows change. */ onOpenSubRowsChange?: (openSubRows: Record) => void; } /** * @public */ export interface DataTableSubRowsControlledProps extends DataTableSubRowsBaseProps { /** * Currently open sub rows in a controlled scenario. */ openSubRows?: true | Record; /** * Initially open sub rows in an uncontrolled scenario. */ defaultOpenSubRows?: never; } /** * @public */ export interface DataTableSubRowsUncontrolledProps extends DataTableSubRowsBaseProps { /** * Currently open sub rows in a controlled scenario. */ openSubRows?: never; /** * Initially open sub rows in an uncontrolled scenario. */ defaultOpenSubRows?: true | Record; } /** * DataTable props for SubRows definition. * @public */ export type DataTableSubRowsProps = DataTableSubRowsControlledProps | DataTableSubRowsUncontrolledProps; /** * Extension interface to extend the types from the tanstack table instance. * @internal */ export interface DataTableSubRowsInstance { /** * Returns the column id that should show the subrow expand indicator. * This does not consider builtin columns and only respects consumer provided columns. */ getSubRowIndicatorColumnId: () => string | null; /** * Gets the current maximum open depth of the subrows. */ getSubRowOpenDepth: () => number; /** * Returns true, if the row or some of its ancestors can not be expanded, false otherwise. */ getIsAncestorDisabled: (row: TRow | undefined) => boolean; /** * Returns true, if the table has at least one row with at least one sub-row, false otherwise. */ getHasSubRows: () => boolean; getRowLineConfig: (rowId: string) => Array<'Line' | 'TShape' | 'LShape' | 'Empty'>; } /** * Extension interface to extend the types from the tanstack table options. * @internal */ export interface DataTableSubRowsOptions { /** * Defines the columnId where the subrow indicator will be injected to. */ subRowColumnId?: string; /** * Enable/disable expanding for all rows. */ enableExpanding?: boolean; /** * Control function that defines whether a subrow expand is disabled or not. */ getRowExpandDisabled?: (row: TData) => boolean; /** * This function is called when the `expanded` table state changes. */ onExpandedChange?: OnChangeFn; } /** * Extension interface to extend the types from the tanstack table instance. * @internal */ export interface DataTableSubRowsRow { /** Returns whether this row is the last expanded on its nesting level. */ getIsLastExpandedOnLevel: () => boolean; /** The last expanded sub-row of this row, depending on the order of the rows. Can be a direct sub-row or a deeper nested one. */ getLastExpandedSubRow: () => TRow | undefined; /** Determines whether the given subRow expander is disabled. */ getCanExpandDisabled: () => boolean; /** The nesting level of the (sub) row. Top level parent row will have depth: 0, it's child depth: 1 and so on. */ getSubRowDepth: () => number; }