import type { AccessorFn, AccessorFnColumnDef, AccessorKeyColumnDef, CellContext, Column, ColumnDef, ColumnFilter, ColumnSort, DeepKeys, DeepValue, DisplayColumnDef, HeaderContext, IdentifiedColumnDef, IdIdentifier, PaginationState, Row, RowData, RowSelectionState, SortDirection, StringHeaderIdentifier, StringOrTemplateHeader } from "@tanstack/react-table"; export type DataTableRowData = RowData; export type DataTableRow = Row; export type DataTableAction = { label: string; onClick: (ctx: CellContext) => void; icon?: React.ReactNode; }; export interface DataTableCellContext extends CellContext { } export interface DataTableHeaderContext extends HeaderContext { } export type DataTableSortDirection = SortDirection; export interface DataTableActionColumnDef extends Pick, "meta"> { actions: DataTableAction[] | DataTableAction[][] | ((ctx: DataTableCellContext) => DataTableAction[] | DataTableAction[][]); } export interface DataTableSelectColumnDef extends Pick, "cell" | "header"> { } export type DataTableSortableColumnDef = { /** * The label to display in the sorting menu. */ sortLabel?: string; /** * The label to display in the sorting menu when sorting in ascending order. */ sortAscLabel?: string; /** * The label to display in the sorting menu when sorting in descending order. */ sortDescLabel?: string; /** * Whether the column is sortable. * @default false */ enableSorting?: boolean; }; export type DataTableHeaderAlignment = 'left' | 'center' | 'right'; export type DataTableAlignableColumnDef = { /** * The alignment of the header content. * @default 'left' */ headerAlign?: DataTableHeaderAlignment; }; export type DataTableSortableColumnDefMeta = { ___sortMetaData?: DataTableSortableColumnDef; }; export type DataTableAlignableColumnDefMeta = { ___alignMetaData?: DataTableAlignableColumnDef; }; export type DataTableActionColumnDefMeta = { ___actions?: DataTableAction[] | DataTableAction[][] | ((ctx: DataTableCellContext) => DataTableAction[]); }; export interface DataTableColumn extends Column { } export type DataTableColumnDef = ColumnDef; export type DataTableColumnSizing = { /** * The maximum size of the column. */ maxSize?: number; /** * The minimum size of the column. */ minSize?: number; /** * The size of the column. */ size?: number; }; type DataTableColumnIdentifiers = IdIdentifier | StringHeaderIdentifier; export type DataTableDisplayColumnDef = Pick, "meta" | "header" | "cell" | "minSize" | "maxSize" | "size"> & DataTableColumnIdentifiers; export interface DataTableIdentifiedColumnDef extends Pick, "meta" | "header" | "cell" | "minSize" | "maxSize" | "size"> { id?: string; header?: StringOrTemplateHeader; } export interface DataTableColumnHelper { /** * Create a accessor column. * * @param accessor The accessor to create the column for. * @param column The column to create for the accessor. * @returns The created accessor. */ accessor: | DeepKeys, TValue extends TAccessor extends AccessorFn ? TReturn : TAccessor extends DeepKeys ? DeepValue : never>(accessor: TAccessor, column: TAccessor extends AccessorFn ? DataTableDisplayColumnDef & DataTableSortableColumnDef & DataTableAlignableColumnDef : DataTableIdentifiedColumnDef & DataTableSortableColumnDef & DataTableAlignableColumnDef) => TAccessor extends AccessorFn ? AccessorFnColumnDef : AccessorKeyColumnDef; /** * Create a display column. * * @param column The column to create the display for. * @returns The created display column. */ display: (column: DataTableDisplayColumnDef) => DisplayColumnDef; /** * Create an action column. * * @param props The props to create the action column for. * @returns The created action column. */ action: (props: DataTableActionColumnDef) => DisplayColumnDef; /** * Create a select column. * * @param props The props to create the select column for. * @returns The created select column. */ select: (props?: DataTableSelectColumnDef) => DisplayColumnDef; } export interface DataTableSortingState extends ColumnSort { } export interface DataTableRowSelectionState extends RowSelectionState { } export interface DataTablePaginationState extends PaginationState { } export type DataTableFilteringState = Record> = { [K in keyof T]: T[K]; }; export type DataTableFilterType = "radio" | "select" | "date" | "multiselect" | "string" | "number" | "custom"; export type DataTableFilterOption = { label: string; value: T; }; interface DataTableBaseFilterProps { type: DataTableFilterType; label: string; } export interface DataTableRadioFilterProps extends DataTableBaseFilterProps { type: "radio"; options: DataTableFilterOption[]; } export interface DataTableSelectFilterProps extends DataTableBaseFilterProps { type: "select"; options: DataTableFilterOption[]; } export interface DataTableDateFilterProps extends DataTableBaseFilterProps { type: "date"; /** * The format of the date. * @default "date" */ format?: "date" | "date-time"; /** * The label to display for the range option. */ rangeOptionLabel?: string; /** * The label to display for the start of the range option. */ rangeOptionStartLabel?: string; /** * The label to display for the end of the range option. */ rangeOptionEndLabel?: string; /** * Whether to disable the range option. */ disableRangeOption?: boolean; /** * A function to format the date value. * * @example * ```tsx * formatDateValue={(value) => value.toLocaleDateString()} * ``` */ formatDateValue?: (value: Date) => string; /** * The options to display in the filter. * * @example * ```tsx * options: [ * { label: "Today", value: { $gte: new Date().toISOString() } }, * { label: "Yesterday", value: { $gte: new Date(new Date().getTime() - 24 * 60 * 60 * 1000).toISOString() } }, * ] * ``` */ options: DataTableFilterOption[]; } export interface DataTableMultiselectFilterProps extends DataTableBaseFilterProps { type: "multiselect"; options: DataTableFilterOption[]; /** * Whether to show a search input for the options. * @default true */ searchable?: boolean; } export interface DataTableStringFilterProps extends DataTableBaseFilterProps { type: "string"; /** * Placeholder text for the input. */ placeholder?: string; } export interface DataTableNumberFilterProps extends DataTableBaseFilterProps { type: "number"; /** * Placeholder text for the input. */ placeholder?: string; /** * Whether to include comparison operators. * @default true */ includeOperators?: boolean; } export interface DataTableCustomFilterProps extends DataTableBaseFilterProps { type: "custom"; /** * Custom render function for the filter. */ render: (props: { value: any; onChange: (value: any) => void; onRemove: () => void; }) => React.ReactNode; } export type DataTableFilterProps = DataTableRadioFilterProps | DataTableSelectFilterProps | DataTableDateFilterProps | DataTableMultiselectFilterProps | DataTableStringFilterProps | DataTableNumberFilterProps | DataTableCustomFilterProps; export type DataTableFilter = T & { id: string; }; export declare enum DataTableEmptyState { EMPTY = "EMPTY", FILTERED_EMPTY = "FILTERED_EMPTY", POPULATED = "POPULATED" } export type DataTableDateComparisonOperator = { /** * The filtered date must be greater than or equal to this value. */ $gte?: string; /** * The filtered date must be less than or equal to this value. */ $lte?: string; /** * The filtered date must be less than this value. */ $lt?: string; /** * The filtered date must be greater than this value. */ $gt?: string; }; export type DataTableNumberComparisonOperator = { /** * The filtered number must be greater than or equal to this value. */ $gte?: number; /** * The filtered number must be less than or equal to this value. */ $lte?: number; /** * The filtered number must be less than this value. */ $lt?: number; /** * The filtered number must be greater than this value. */ $gt?: number; /** * The filtered number must be equal to this value. */ $eq?: number; }; type DataTableCommandAction = (selection: DataTableRowSelectionState) => void | Promise; export interface DataTableCommand { /** * The label to display in the command bar. */ label: string; /** * The action to perform when the command is selected. */ action: DataTableCommandAction; /** * The shortcut to use for the command. * * @example "i" */ shortcut: string; } export type DataTableEmptyStateContent = { /** * The heading to display in the empty state. */ heading?: string; /** * The description to display in the empty state. */ description?: string; /** * A custom component to display in the empty state, if provided it will override the heading and description. */ custom?: React.ReactNode; }; export type DataTableEmptyStateProps = { /** * The empty state to display when the table is filtered, but no rows are found. */ filtered?: DataTableEmptyStateContent; /** * The empty state to display when the table is empty. */ empty?: DataTableEmptyStateContent; }; export interface DataTableColumnFilter extends ColumnFilter { } export {}; //# sourceMappingURL=types.d.ts.map