UNPKG

8.08 kBTypeScriptView Raw
1import type * as React from 'react';
2import type { Reference } from 'rc-table';
3import type { FixedType, GetComponentProps, ColumnType as RcColumnType, RenderedCell as RcRenderedCell } from 'rc-table/lib/interface';
4import { ExpandableConfig, GetRowKey } from 'rc-table/lib/interface';
5import type { Breakpoint } from '../_util/responsiveObserver';
6import type { AnyObject } from '../_util/type';
7import type { CheckboxProps } from '../checkbox';
8import type { PaginationProps } from '../pagination';
9import type { TooltipProps } from '../tooltip';
10import type { INTERNAL_SELECTION_ITEM } from './hooks/useSelection';
11import type { InternalTableProps, TableProps } from './InternalTable';
12export type RefTable = <RecordType = AnyObject>(props: React.PropsWithChildren<TableProps<RecordType>> & React.RefAttributes<Reference>) => React.ReactElement;
13export type RefInternalTable = <RecordType = AnyObject>(props: React.PropsWithChildren<InternalTableProps<RecordType>> & React.RefAttributes<Reference>) => React.ReactElement;
14export { ExpandableConfig, GetRowKey };
15export type Key = React.Key;
16export type SafeKey = Exclude<Key, bigint>;
17export type RowSelectionType = 'checkbox' | 'radio';
18export type SelectionItemSelectFn = (currentRowKeys: Key[]) => void;
19export type ExpandType = null | 'row' | 'nest';
20export interface TableLocale {
21 filterTitle?: string;
22 filterConfirm?: React.ReactNode;
23 filterReset?: React.ReactNode;
24 filterEmptyText?: React.ReactNode;
25 filterCheckall?: React.ReactNode;
26 filterSearchPlaceholder?: string;
27 emptyText?: React.ReactNode | (() => React.ReactNode);
28 selectAll?: React.ReactNode;
29 selectNone?: React.ReactNode;
30 selectInvert?: React.ReactNode;
31 selectionAll?: React.ReactNode;
32 sortTitle?: string;
33 expand?: string;
34 collapse?: string;
35 triggerDesc?: string;
36 triggerAsc?: string;
37 cancelSort?: string;
38}
39export type SortOrder = 'descend' | 'ascend' | null;
40export type SorterTooltipTarget = 'full-header' | 'sorter-icon';
41export type SorterTooltipProps = TooltipProps & {
42 target?: SorterTooltipTarget;
43};
44declare const TableActions: readonly ["paginate", "sort", "filter"];
45export type TableAction = (typeof TableActions)[number];
46export type CompareFn<T = AnyObject> = (a: T, b: T, sortOrder?: SortOrder) => number;
47export interface ColumnFilterItem {
48 text: React.ReactNode;
49 value: React.Key | boolean;
50 children?: ColumnFilterItem[];
51}
52export interface ColumnTitleProps<RecordType = AnyObject> {
53 /** @deprecated Please use `sorterColumns` instead. */
54 sortOrder?: SortOrder;
55 /** @deprecated Please use `sorterColumns` instead. */
56 sortColumn?: ColumnType<RecordType>;
57 sortColumns?: {
58 column: ColumnType<RecordType>;
59 order: SortOrder;
60 }[];
61 filters?: Record<string, FilterValue>;
62}
63export type ColumnTitle<RecordType = AnyObject> = React.ReactNode | ((props: ColumnTitleProps<RecordType>) => React.ReactNode);
64export type FilterValue = (Key | boolean)[];
65export type FilterKey = (string | number)[] | null;
66export type FilterSearchType<RecordType = AnyObject> = boolean | ((input: string, record: RecordType) => boolean);
67export interface FilterConfirmProps {
68 closeDropdown: boolean;
69}
70export interface FilterDropdownProps {
71 prefixCls: string;
72 setSelectedKeys: (selectedKeys: React.Key[]) => void;
73 selectedKeys: React.Key[];
74 /**
75 * Confirm filter value, if you want to close dropdown before commit, you can call with
76 * {closeDropdown: true}
77 */
78 confirm: (param?: FilterConfirmProps) => void;
79 clearFilters?: () => void;
80 filters?: ColumnFilterItem[];
81 /** Only close filterDropdown */
82 close: () => void;
83 visible: boolean;
84}
85export interface ColumnType<RecordType = AnyObject> extends Omit<RcColumnType<RecordType>, 'title'> {
86 title?: ColumnTitle<RecordType>;
87 sorter?: boolean | CompareFn<RecordType> | {
88 compare?: CompareFn<RecordType>;
89 /** Config multiple sorter order priority */
90 multiple?: number;
91 };
92 sortOrder?: SortOrder;
93 defaultSortOrder?: SortOrder;
94 sortDirections?: SortOrder[];
95 sortIcon?: (props: {
96 sortOrder: SortOrder;
97 }) => React.ReactNode;
98 showSorterTooltip?: boolean | SorterTooltipProps;
99 filtered?: boolean;
100 filters?: ColumnFilterItem[];
101 filterDropdown?: React.ReactNode | ((props: FilterDropdownProps) => React.ReactNode);
102 filterOnClose?: boolean;
103 filterMultiple?: boolean;
104 filteredValue?: FilterValue | null;
105 defaultFilteredValue?: FilterValue | null;
106 filterIcon?: React.ReactNode | ((filtered: boolean) => React.ReactNode);
107 filterMode?: 'menu' | 'tree';
108 filterSearch?: FilterSearchType<ColumnFilterItem>;
109 onFilter?: (value: React.Key | boolean, record: RecordType) => boolean;
110 filterDropdownOpen?: boolean;
111 onFilterDropdownOpenChange?: (visible: boolean) => void;
112 filterResetToDefaultFilteredValue?: boolean;
113 responsive?: Breakpoint[];
114 /** @deprecated Please use `filterDropdownOpen` instead */
115 filterDropdownVisible?: boolean;
116 /** @deprecated Please use `onFilterDropdownOpenChange` instead */
117 onFilterDropdownVisibleChange?: (visible: boolean) => void;
118}
119export interface ColumnGroupType<RecordType = AnyObject> extends Omit<ColumnType<RecordType>, 'dataIndex'> {
120 children: ColumnsType<RecordType>;
121}
122export type ColumnsType<RecordType = AnyObject> = (ColumnGroupType<RecordType> | ColumnType<RecordType>)[];
123export interface SelectionItem {
124 key: string;
125 text: React.ReactNode;
126 onSelect?: SelectionItemSelectFn;
127}
128export type SelectionSelectFn<T = AnyObject> = (record: T, selected: boolean, selectedRows: T[], nativeEvent: Event) => void;
129export type RowSelectMethod = 'all' | 'none' | 'invert' | 'single' | 'multiple';
130export interface TableRowSelection<T = AnyObject> {
131 /** Keep the selection keys in list even the key not exist in `dataSource` anymore */
132 preserveSelectedRowKeys?: boolean;
133 type?: RowSelectionType;
134 selectedRowKeys?: Key[];
135 defaultSelectedRowKeys?: Key[];
136 onChange?: (selectedRowKeys: Key[], selectedRows: T[], info: {
137 type: RowSelectMethod;
138 }) => void;
139 getCheckboxProps?: (record: T) => Partial<Omit<CheckboxProps, 'checked' | 'defaultChecked'>>;
140 onSelect?: SelectionSelectFn<T>;
141 /** @deprecated This function is deprecated and should use `onChange` instead */
142 onSelectMultiple?: (selected: boolean, selectedRows: T[], changeRows: T[]) => void;
143 /** @deprecated This function is deprecated and should use `onChange` instead */
144 onSelectAll?: (selected: boolean, selectedRows: T[], changeRows: T[]) => void;
145 /** @deprecated This function is deprecated and should use `onChange` instead */
146 onSelectInvert?: (selectedRowKeys: Key[]) => void;
147 /** @deprecated This function is deprecated and should use `onChange` instead */
148 onSelectNone?: () => void;
149 selections?: INTERNAL_SELECTION_ITEM[] | boolean;
150 hideSelectAll?: boolean;
151 fixed?: FixedType;
152 columnWidth?: string | number;
153 columnTitle?: React.ReactNode | ((checkboxNode: React.ReactNode) => React.ReactNode);
154 checkStrictly?: boolean;
155 renderCell?: (value: boolean, record: T, index: number, originNode: React.ReactNode) => React.ReactNode | RcRenderedCell<T>;
156 onCell?: GetComponentProps<T>;
157}
158export type TransformColumns<RecordType = AnyObject> = (columns: ColumnsType<RecordType>) => ColumnsType<RecordType>;
159export interface TableCurrentDataSource<RecordType = AnyObject> {
160 currentDataSource: RecordType[];
161 action: TableAction;
162}
163export interface SorterResult<RecordType = AnyObject> {
164 column?: ColumnType<RecordType>;
165 order?: SortOrder;
166 field?: Key | readonly Key[];
167 columnKey?: Key;
168}
169export type GetPopupContainer = (triggerNode: HTMLElement) => HTMLElement;
170type TablePaginationPosition = 'topLeft' | 'topCenter' | 'topRight' | 'bottomLeft' | 'bottomCenter' | 'bottomRight' | 'none';
171export interface TablePaginationConfig extends PaginationProps {
172 position?: TablePaginationPosition[];
173}