import { type Table } from '@tanstack/react-table'; import React, { type ReactNode } from 'react'; import type { IconOrContent } from '../../util/utility-types'; import type { EDSBase, Size, Status, Align } from '../../util/variant-types'; export type DataTableProps = EDSBase & { /** * Collection of buttons/menus to control the table contents */ actions?: React.ReactNode; /** * Set whether the table has interactive rows * * **Default is `false`**. */ isInteractive?: boolean; /** * Data table controller for rendering the contents of the table * * See Doc.s: https://tanstack.com/table/latest/docs/framework/react/guide/table-state */ table?: Table; /** * Classes to add to the table to control height, width, and other non-stylistic behaviors */ tableClassName?: string; /** * Method to call when content is entered into the search field. Also causes the field * to appear. * @returns void */ onSearchChange?: () => void; /** * Main caption text to use for the table. Will show a visible title, and add text for * the accessible caption within the table. */ caption?: string; /** * Controls whether the table allows rows for a status color/icon treatment. */ isStatusEligible?: boolean; /** * Controls the treatment of alternating rows in the table. * * **Default is `"striped"`**. */ rowStyle?: 'striped' | 'lined'; /** * Size of the padding for the table * * **Default is `"md"`**. */ size?: Extract; /** * Sub-caption text to use for the table. This text should be used with `caption` and is not * meant to be standalone. */ subCaption?: string; /** * Controls the treatment of the table container. * * **Default is `"basic"`**. */ tableStyle?: 'basic' | 'border'; }; export type DataTableTableProps = EDSBase & Pick; export type DataTableRowProps = Pick & StatusColumn & { 'aria-label'?: string; isInteractive?: boolean; isSelected?: boolean; }; export type DataTableHeaderCellProps = EDSBase & { /** * Handler for clicking on the individual column header sort buttons. */ onSortClick?: React.MouseEventHandler; /** * Determines the edge alignment of content within the cell */ alignment?: Extract; /** * Whether the cell has a divider between adjacent cells */ hasHorizontalDivider?: boolean; /** * Marks the header cell as sortable (used in conjunction with `sortDirection`) */ isSortable?: boolean; /** * Content that prefixes the cell text. Pass an EDS icon name to render a decorative * icon, or a node to render it as-is. */ leadingContent?: IconOrContent; /** * SubLabel to use next to table cell text content * * ---- * * **Note**: Will warn when used in the wrong context */ subLabel?: ReactNode; /** * The direction to apply to the icon (for visual treatment) * * **Default is `"default"`**. */ sortDirection?: DataTableSortDirection; }; type StatusColumn = { status?: Extract; }; export declare const SORT_DIRECTION: { ascending: string; descending: string; default: string; }; export type DataTableSortDirection = keyof typeof SORT_DIRECTION; export type DataTableDataCellProps = DataTableHeaderCellProps & { children: React.ReactNode; }; export type DataTableStatusCellProps = StatusColumn & { 'aria-label'?: string; }; export type DataTableWithStatus = S & StatusColumn; /** * ## Usage * * | Type/Use | Description | Example | * |----------|-------------|---------| * | Basic | Simple table layout with rows and columns; no interactivity. | Static reports. Read-only data display. | * | Selectable rows | Allows row selection via checkboxes or row click. | Bulk actions. Item management. | * | Editable | Inline cell or row editing capabilities. | Spreadsheet-like tools. Admin controls. | * | Expandable rows | Rows can expand to show nested or detailed data. | Order summaries. Transaction breakdowns. | * | Column customization | Users can show/hide or reorder columns. | Power-user features. Data-heavy interfaces. | * | Loading & empty states | Shows skeletons or messaging when data is loading or unavailable. | Dynamic data tables. | * * ### Best Practices * * * Use small tables for compact density or size-constrained containers like modals; use medium tables to balance density and whitespace. * * Use lined tables for static data and striped tables for data entered by users. * * Use section headers to organize data when there are 2 or more categories. * * Use column dividers only when they enhance clarity. * * When `isSortable`, sort by the leading (leftmost) column by default. * * Make sure to only use stable data references for columns/data passed to `useReactTable`: see Resources below. * * ## Interaction * * Tables scroll horizontally when their width exceeds the available space, and vertically when a * height is set; the first column is sticky by default. Sortable column headers reveal a sort * indicator on hover and toggle between ascending and descending on click, with only one column * sorted at a time. When selectable, a leading column of checkboxes is added; the header checkbox * selects or deselects all rows and shows an indeterminate state for partial selections. Action * cells sit on the trailing edge, contain no more than three (typically tertiary, icon-only) * buttons, and are shown on hover by default. * * ## Content & Accessibility * * ### Do's * * * Write headers that are informative, descriptive, concise, and scannable. * * Include units of measurement in headers so they aren't repeated throughout the columns. * * Use sentence case for headers and columns, and be consistent with decimals. * * Wrap important content and truncate secondary information. * * Use clear, descriptive headers and a meaningful title so screen readers can navigate the table. * * ### Don'ts * * * Use tables for layout. * * Include blank rows or columns; adjust row and column spacing instead. * * Use color as the only means of conveying meaning. * * ### Resources * * * https://tanstack.com/table/latest * * https://tanstack.com/table/latest/docs/faq * */ export declare function DataTable({ actions, children, className, caption, isInteractive, isStatusEligible, onSearchChange, rowStyle, size, subCaption, table, tableClassName, tableStyle, ...rest }: DataTableProps): React.JSX.Element; export declare namespace DataTable { var displayName: string; var Search: { (): React.JSX.Element; displayName: string; }; var Actions: { ({ children }: Pick): React.JSX.Element; displayName: string; }; var Table: { ({ children, tableClassName, tableStyle, rowStyle, size, }: DataTableTableProps): React.JSX.Element; displayName: string; }; var Header: { ({ children, ...rest }: Pick): React.JSX.Element; displayName: string; }; var Row: { ({ "aria-label": ariaLabel, children, className, isInteractive, isSelected, status, ...rest }: DataTableRowProps): React.JSX.Element; displayName: string; }; var GroupRow: { ({ colSpan, title, }: { title: string; colSpan: number; }): React.JSX.Element; displayName: string; }; var HeaderCell: { ({ alignment, children, className, hasHorizontalDivider, isSortable, leadingContent, sortDirection, onSortClick, subLabel, ...rest }: DataTableHeaderCellProps): React.JSX.Element; displayName: string; }; var DataCell: { ({ alignment, children, className, hasHorizontalDivider, leadingContent, subLabel, ...rest }: DataTableDataCellProps): React.JSX.Element; displayName: string; }; var StatusCell: { ({ "aria-label": ariaLabel, status, ...rest }: DataTableStatusCellProps): React.JSX.Element; displayName: string; }; var StatusHeaderCell: { ({ "aria-label": ariaLabel, status, ...rest }: DataTableStatusCellProps): React.JSX.Element; displayName: string; }; var __StatusColumnId__: "status"; var SORT_DIRECTION: { ascending: string; descending: string; default: string; }; } export declare const DataTableHeaderCell: { ({ alignment, children, className, hasHorizontalDivider, isSortable, leadingContent, sortDirection, onSortClick, subLabel, ...rest }: DataTableHeaderCellProps): React.JSX.Element; displayName: string; }; export declare const DataTableDataCell: { ({ alignment, children, className, hasHorizontalDivider, leadingContent, subLabel, ...rest }: DataTableDataCellProps): React.JSX.Element; displayName: string; }; export declare const DataTableStatusHeaderCell: { ({ "aria-label": ariaLabel, status, ...rest }: DataTableStatusCellProps): React.JSX.Element; displayName: string; }; export declare const DataTableStatusCell: { ({ "aria-label": ariaLabel, status, ...rest }: DataTableStatusCellProps): React.JSX.Element; displayName: string; }; export declare const DataTableTable: { ({ children, tableClassName, tableStyle, rowStyle, size, }: DataTableTableProps): React.JSX.Element; displayName: string; }; export declare const DataTableHeader: { ({ children, ...rest }: Pick): React.JSX.Element; displayName: string; }; export declare const DataTableRow: { ({ "aria-label": ariaLabel, children, className, isInteractive, isSelected, status, ...rest }: DataTableRowProps): React.JSX.Element; displayName: string; }; export declare const DataTableGroupRow: { ({ colSpan, title, }: { title: string; colSpan: number; }): React.JSX.Element; displayName: string; }; export {};