import type { HighlightMode, TableActions, TableActionsWithMinWidth, TableCollectable, TableColumn, TableColumnWithMinWidth, TableDataSource, TableDraggable, TableExpandable, TablePinnable, TableRowSelection, TableRowState, TableScroll, TableSize, TableToggleable } from '@mezzanine-ui/core/table'; import type { PartialOptions } from 'overlayscrollbars'; import type { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types'; import type { EmptyProps } from '../Empty'; import type { TablePaginationProps } from './components/TablePagination'; import type { TableTransitionState } from './hooks/useTableDataSource'; /** * Base props shared by all Table variants. */ export interface TableBaseProps extends Omit, 'children' | 'draggable' | 'summary' | 'onChange'> { /** Data source */ dataSource: T[]; /** Props for Empty component when no data */ emptyProps?: EmptyProps & { height?: number | string; }; /** Expandable row configuration */ expandable?: TableExpandable; /** Collectable row configuration (star/favorite functionality) */ collectable?: TableCollectable; /** * Whether the table should stretch to fill its container width. * When true, the table will always be 100% width of its container. * Note: If the sum of all column widths is less than the table width, * columns will be proportionally stretched to fill the remaining space. * @default false */ fullWidth?: boolean; /** Highlight mode for hover effects * @default 'row' */ highlight?: HighlightMode; /** * Loading state. While true the body renders placeholder skeleton rows * instead of data rows. * * Skeleton rows carry no record, so **no callback is ever handed a * placeholder row**. Every row-level callback — `column.render`, * `actions.render`, `rowState`, `rowSelection.getCheckboxProps`, * `expandable.rowExpandable`, `expandable.expandedRowRender`, * `toggleable.isRowDisabled`, `collectable.isRowDisabled` — is not called at * all while loading. `rowSelection.isSelectionDisabled` still runs, because * it also derives the header's select-all state, but only over the real * `dataSource`. * * All of them may therefore dereference the record freely without guarding * for the loading state. */ loading?: boolean; /** * Number of skeleton rows to display when `loading` is true. * @default 10 */ loadingRowsCount?: number; /** Minimum height of the table */ minHeight?: number | string; /** * Whether the table is nested inside an expanded row content area */ nested?: boolean; /** Pagination configuration */ pagination?: TablePaginationProps; /** * Row height preset token. */ rowHeightPreset?: 'base' | 'condensed' | 'detailed' | 'roomy'; /** Row selection configuration */ rowSelection?: TableRowSelection; /** Semantic state applied to each row. Accepts a state string or a function that receives the row data and returns a state string. */ rowState?: TableRowState | ((rowData: T) => TableRowState | undefined); /** * Options forwarded to the table's inner `Scrollbar` (OverlayScrollbars). * Merged per key over the `Scrollbar` defaults, so only the keys you pass change. * Ignored when `nested` is true, because nested tables render without a `Scrollbar`. * Do not set `overflow` to `'visible'` together with `scroll.virtualized`: * virtualization needs the table's own scroll viewport. * Memoize the object (or hoist it) to avoid re-applying options on every render. * @example * // Let an outer scroll container handle overflow instead of the table * * @example * // Keep the overlay scrollbar visible instead of hiding it after scrolling *
* @see https://kingsora.github.io/OverlayScrollbars/#!documentation/options */ scrollbarOptions?: PartialOptions; /** Row indexes where a separator border should be displayed */ separatorAtRowIndexes?: number[]; /** Show header row */ showHeader?: boolean; /** Custom size variant * @default 'main' */ size?: TableSize; /** Whether to enable sticky header * @default true */ sticky?: boolean; /** Toggleable row configuration */ toggleable?: TableToggleable; /** Transition state for row add/remove animations (from useTableDataSource hook) */ transitionState?: TableTransitionState; /** Enable zebra striping for alternating row backgrounds */ zebraStriping?: boolean; } /** * Props when resizable is enabled. * Requires minWidth on all columns. */ export interface TableResizableProps extends TableBaseProps { /** Actions column configuration - minWidth required when resizable */ actions?: TableActionsWithMinWidth; /** * Controlled column widths in pixels, keyed by column key. * When provided, these widths take precedence over `column.width` and the * table only reports drags through `onColumnWidthsChange`; pass `{}` to reset * every column back to `column.width`. * Values are clamped to each column's `minWidth`/`maxWidth`, and non-finite * or non-positive values are ignored, so stale persisted widths stay valid. * Leave undefined for uncontrolled mode (the table keeps widths internally). * @example * const [widths, setWidths] = useState>(() => * JSON.parse(localStorage.getItem('table-widths') ?? '{}'), * ); *
*/ columnWidths?: Record; /** Column configuration - minWidth required for each column when resizable */ columns: TableColumnWithMinWidth[]; /** * Called once when a column resize drag ends (mouseup), with the widths of * every column resized so far, keyed by column key. Not called if the drag * did not change any width (including a drag released at its start point). * Works in both controlled and uncontrolled mode. */ onColumnWidthsChange?: (widths: Record) => void; /** * Whether columns are resizable by user interaction */ resizable: true; } /** * Props when resizable is disabled or not specified. */ export interface TableNonResizableProps extends TableBaseProps { /** Actions column configuration */ actions?: TableActions; /** Not available when resizable is disabled */ columnWidths?: never; /** Column configuration */ columns: TableColumn[]; /** Not available when resizable is disabled */ onColumnWidthsChange?: never; /** * Whether columns are resizable by user interaction * @default false */ resizable?: false; } /** * Props when draggable is enabled. * Pinnable is not allowed when draggable is enabled. */ export type TableDraggableOnlyProps = { /** Draggable row configuration */ draggable: TableDraggable; /** Not available when draggable is enabled */ pinnable?: never; }; /** * Props when pinnable is enabled. * Draggable is not allowed when pinnable is enabled. */ export type TablePinnableOnlyProps = { /** Not available when pinnable is enabled */ draggable?: never; /** Pinnable row configuration */ pinnable: TablePinnable; }; /** * Props when neither draggable nor pinnable is enabled. */ export type TableNoDragOrPinProps = { /** Draggable row configuration */ draggable?: undefined; /** Pinnable row configuration */ pinnable?: undefined; }; /** * Combined drag or pin props - discriminated union. */ export type TableDragOrPinProps = TableDraggableOnlyProps | TablePinnableOnlyProps | TableNoDragOrPinProps; /** * Props when virtualized scrolling is enabled. * Draggable is not allowed in this mode, but pinnable is allowed. */ export type TableVirtualizedScrollProps = { /** Draggable row configuration - not available when virtualized is enabled */ draggable?: never; /** Scroll configuration with virtualized enabled */ scroll: TableScroll & { virtualized: true; y: number | string; }; }; /** * Props when virtualized scrolling is disabled or not specified. * Both draggable and pinnable are allowed. */ export type TableNonVirtualizedScrollProps = { /** Scroll configuration for scrolling (virtualized defaults to false) */ scroll?: TableScroll & { virtualized?: false; }; }; /** * Props when virtualized scrolling is enabled. * Draggable is not allowed, but pinnable is allowed. */ export type TableVirtualizedProps = (TableResizableProps | TableNonResizableProps) & TableVirtualizedScrollProps & { /** Pinnable row configuration - allowed with virtualized */ pinnable?: TablePinnable; }; /** * Props when virtualized scrolling is disabled or not specified. * Draggable and pinnable are mutually exclusive. */ export type TableNonVirtualizedProps = (TableResizableProps | TableNonResizableProps) & TableNonVirtualizedScrollProps & TableDragOrPinProps; /** * TableProps - discriminated union to ensure: * 1. Draggable and virtualized scrolling are mutually exclusive * 2. Draggable and pinnable are mutually exclusive (they share the same column position) * 3. Resizable requires minWidth on all columns */ export type TableProps = TableVirtualizedProps | TableNonVirtualizedProps;