import * as React from "react"; import { InternationalProps, ReactAttr, ReactDivAttr, ShapeOf } from "../../../typings/shared"; import { DataTableSortState, DataTableSortStates } from "./state/sorting"; import Table, { TableCarbonProps } from "./Table"; import TableActionList from "./TableActionList"; import TableBatchAction from "./TableBatchAction"; import TableBatchActions from "./TableBatchActions"; import TableBody from "./TableBody"; import TableCell from "./TableCell"; import TableContainer, { TableContainerProps } from "./TableContainer"; import TableExpandedRow from "./TableExpandedRow"; import TableExpandHeader, { TableExpandHeaderProps } from "./TableExpandHeader"; import TableExpandRow from "./TableExpandRow"; import TableHead from "./TableHead"; import TableHeader from "./TableHeader"; import TableRow from "./TableRow"; import TableSelectAll from "./TableSelectAll"; import TableSelectRow from "./TableSelectRow"; import TableToolbar, { TableToolbarProps } from "./TableToolbar"; import TableToolbarAction from "./TableToolbarAction"; import TableToolbarContent from "./TableToolbarContent"; import TableToolbarMenu from "./TableToolbarMenu"; import TableToolbarSearch from "./TableToolbarSearch"; // region Row Types export interface DataTableRow { disabled?: boolean | undefined; id: ID; isExpanded?: boolean | undefined; isSelected?: boolean | undefined; } export interface SortRowData { compare(a: any, b: any, locale?: string): number; key: string; locale?: string | undefined; sortDirection: DataTableSortState; sortStates: DataTableSortStates; } export interface FilterRowsData { cellsById: { [cellId: string]: DataTableCell }; headers: readonly H[]; inputValue: string; rowIds: ReadonlyArray; } export type DenormalizedRow = DataTableRow & { cells: DataTableCell[] }; export interface DataTableCustomRowData { onClick?(event: React.MouseEvent): void; row: R; } export interface DataTableCustomRowProps { ariaLabel: string; disabled: Exclude; isExpanded: Exclude; isSelected: Exclude; key: R["id"]; onExpand(event: React.MouseEvent): void; } export interface DataTableCustomSelectionData { onClick?(event: React.MouseEvent): void; row?: R | undefined; } export interface DataTableCustomSelectionProps { ariaLabel?: string | undefined; checked: R extends never ? boolean : NonNullable; disabled: R extends never ? never : R["disabled"]; id: string; indeterminate: R extends never ? boolean : never; name: string; onSelect(event: React.MouseEvent): void; radio?: R extends never ? never : (Extract) | undefined; } // endregion Row Types // region Header Types export interface DataTableHeader { header: NonNullable; key: K; } export interface DataTableCustomHeaderData { header: H; isSortable?: boolean | undefined; onClick?(event: React.MouseEvent): void; } export interface DataTableCustomHeaderProps { isSortable?: boolean | undefined; isSortHeader: boolean; key: H["key"]; onClick(event: React.MouseEvent): void; sortDirection: DataTableSortState; } // endregion Header Types // region Cell Types export interface DataTableCell { errors?: any[] | null | undefined; id: string; info: { header: H["key"]; }; isEditable: boolean; isEditing: boolean; isValid: boolean; value?: V | undefined; } // endregion CellTypes // region Batch Action Types export interface DataTableCustomBatchActionsData {} export interface DataTableCustomBatchActionsProps { onCancel(): void; shouldShowBatchActions?: boolean | undefined; totalSelected: number; } // endregion // region DataTable // Custom Render Props export interface DataTableCustomRenderProps< R extends DataTableRow = DataTableRow, H extends DataTableHeader = DataTableHeader, > { expandAll(): void; expandRow(rowId: R["id"]): void; getBatchActionProps( data?: ShapeOf, ): ShapeOf; getExpandHeaderProps(props?: TableExpandHeaderProps): TableExpandHeaderProps; getHeaderProps( data: ShapeOf, E>, ): ShapeOf, E>; getRowProps>( data: ShapeOf, ): ShapeOf; getSelectionProps( data?: ShapeOf, ): ShapeOf, E> | ShapeOf, E>; getTableContainerProps(): Pick; getTableProps(): TableCarbonProps; getToolbarProps(props?: TableToolbarProps): TableToolbarProps; headers: DataTableProps["headers"]; onInputChange(event: React.SyntheticEvent): void; radio?: DataTableProps["radio"] | undefined; rows: readonly DenormalizedRow[]; selectAll(): void; selectedRows: readonly DenormalizedRow[]; selectRow(rowId: R["id"]): void; sortBy(headerKey: H["key"]): void; } export type DataTableTranslationKey = | "carbon.table.row.expand" | "carbon.table.row.collapse" | "carbon.table.all.expand" | "carbon.table.all.collapse" | "carbon.table.all.select" | "carbon.table.all.unselect" | "carbon.table.row.select" | "carbon.table.row.unselect"; export interface DataTableProps< R extends DataTableRow = DataTableRow, H extends DataTableHeader = DataTableHeader, > extends InternationalProps, TableCarbonProps { filterRows?(data: FilterRowsData): Array; headers: H[]; locale?: string | undefined; radio?: boolean | undefined; render?(props: DataTableCustomRenderProps): React.ReactNode; rows: R[]; sortRow?(cellA: any, cellB: any, data: SortRowData): number; stickyHeader?: boolean | undefined; } declare class DataTable< R extends DataTableRow = DataTableRow, H extends DataTableHeader = DataTableHeader, > extends React.Component> { static readonly translationKeys: readonly DataTableTranslationKey[]; static readonly Table: typeof Table; static readonly TableActionList: typeof TableActionList; static readonly TableBatchAction: typeof TableBatchAction; static readonly TableBatchActions: typeof TableBatchActions; static readonly TableBody: typeof TableBody; static readonly TableCell: typeof TableCell; static readonly TableContainer: typeof TableContainer; static readonly TableExpandHeader: typeof TableExpandHeader; static readonly TableExpandRow: typeof TableExpandRow; static readonly TableExpandedRow: typeof TableExpandedRow; static readonly TableHead: typeof TableHead; static readonly TableHeader: typeof TableHeader; static readonly TableRow: typeof TableRow; static readonly TableSelectAll: typeof TableSelectAll; static readonly TableSelectRow: typeof TableSelectRow; static readonly TableToolbar: typeof TableToolbar; static readonly TableToolbarAction: typeof TableToolbarAction; static readonly TableToolbarContent: typeof TableToolbarContent; static readonly TableToolbarSearch: typeof TableToolbarSearch; static readonly TableToolbarMenu: typeof TableToolbarMenu; } // endregion DataTable export default DataTable;