-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtypes.ts
138 lines (114 loc) · 4.59 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { ButtonProps, InputProps, ModalProps } from "antd";
import { ColumnType as AntColumnType } from "antd/lib/table";
import { TableProps as AntTableProps } from "antd/lib/table";
import { ReactNode } from "react";
import Fuse from "fuse.js";
import { UnparseConfig } from "papaparse";
export type DataSource = any;
export type CustomDataSourceType<T> = TableProps<T>["dataSource"];
export type ExportColumnValue<T> = (
fieldValue: any,
record: T,
index: number
) => string | number;
export interface ObjectColumnExporter<T> {
header: string | number;
formatter: ExportColumnValue<T>;
}
export type ColumnExporter<T> = ExportColumnValue<T> | ObjectColumnExporter<T>;
export type ColumnType<T> = AntColumnType<T> & {
exporter?: ColumnExporter<T>;
};
// export type ColumnsType<T> = ColumnType<T>[];
export type ColumnsType<T> = (ColumnGroupType<T> | ColumnType<T>)[];
export interface ColumnGroupType<T> extends Omit<ColumnType<T>, "dataIndex"> {
children: ColumnsType<T>;
}
export interface ExportFieldButtonProps<T = DataSource> {
/** Ant table's dataSource */
dataSource?: TableProps<T>["dataSource"];
/** Ant table's columns */
columns?: TableProps<T>["columns"];
/** File name to use when exporting to csv */
fileName?: string;
/** Customize csv file like column header names, fields to include/exclude. More on this below. */
fields?: TableExportFields;
/** Disables export button. Useful when you want to disable when dataSource is loading. */
disabled?: boolean;
/** Any of Ant Button component props as object. */
btnProps?: ButtonProps;
modalProps?: ModalProps;
/** Can be used to change text in button. */
children?: ReactNode;
/** Shows a modal to pick which columns to include exported file. Default: false */
showColumnPicker?: boolean;
/** If true, all columns will be selected to export by default including nested columns. Default: true */
autoPickAllColumns?: boolean;
/** Papaparse config */
papaparseConfig?: UnparseConfig;
}
export interface TableProps<T> extends AntTableProps<T> {
/** Exportable Table */
exportable?: boolean;
/** Props object to customize export button */
exportableProps?: ExportFieldButtonProps<T>;
/** Searchable Table */
searchable?: boolean;
/** Props object to customize export button */
searchableProps?: SearchTableInputProps;
}
export interface TableExportFields<T = DataSource> {
[dataIndex: string | number]: string | number | ObjectColumnExporter<T>;
}
/**@deprecated Removed `I` prefix for interfaces. Use TableExportFields. */
export type ITableExportFields = TableExportFields;
/**@deprecated Removed `I` prefix for interfaces. Use ExportFieldButtonProps. */
export type IExportFieldButtonProps = ExportFieldButtonProps;
export type ColumnWithDataIndex<T = DataSource> = (
| ColumnGroupType<T>
| ColumnType<T>
) & {
dataIndex?: string | string[];
};
export type SearchFunction<T> = (
dataSource: CustomDataSourceType<T>,
searchTerm: string
) => CustomDataSourceType<T>;
export interface SearchTableInputProps<T = DataSource> {
/** Custom function to search if you want to use your own search.
* Takes dataSource and searchTerm and should return filtered dataSource.
*/
searchFunction?: SearchFunction<T>;
/** Ant table's dataSource. */
dataSource?: CustomDataSourceType<T>;
/** Ant table's columns */
columns?: TableProps<T>["columns"];
/** `setState` style function which updates dataSource. */
setDataSource?: (dataSource: CustomDataSourceType<T>) => void;
/** Debounces search */
debounce?: boolean;
/** Any of Ant Input component's props as object. */
inputProps?: InputProps;
/** Allow fuzzy search or search for exact search term. */
fuzzySearch?: boolean;
/** Uses Fuse.js for search. Pass any of fuse.js options here as object. */
fuseProps?: Fuse.IFuseOptions<T>;
}
/**@deprecated Removed `I` prefix for interfaces. Use SearchTableInputProps. */
export type ISearchTableInputProps = SearchTableInputProps;
export type ExportableTableProps<T = DataSource> = TableProps<T> &
ExportFieldButtonProps<T>;
/**@deprecated Removed `I` prefix for interfaces. Use ExportableTableProps. */
export type IExportableTableProps = ExportableTableProps;
export type ITableUtils<T = DataSource> = {
/** Exportable Table */
exportable?: boolean;
/** Props object to customize export button */
exportableProps?: ExportFieldButtonProps<T>;
/** Searchable Table */
searchable?: boolean;
/** Props object to customize export button */
searchableProps?: SearchTableInputProps;
};
/**@deprecated Removed `I` prefix for interfaces. Use TableProps. */
export type ITableProps<T> = TableProps<T>;