-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.d.ts
391 lines (376 loc) · 9.91 KB
/
index.d.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
import { CSSProperties, ForwardedRef, ReactNode } from "react";
export type SortDirection = "ASC" | "DESC";
export type ScrollAlign = "auto" | "smart" | "center" | "end" | "start";
export type ExpanderProps<T> = {
/**
* the data for the row
*/
row: T;
/**
* the index of the row
*/
index: number;
/**
* whether or not the row is expanded
*/
isExpanded: boolean;
/**
* handler for clicking the expansion button
* @param event mouse event
* @returns void
*/
onClick: (event?: React.MouseEvent<Element, MouseEvent>) => void;
/**
* required style for the expander
*/
style: CSSProperties;
};
export type ClearCacheOptions = {
/**
* this is used to skip the timeout and reset the table heights immeediately.
*/
forceUpdate?: boolean;
/**
* an optional timeout of how long to wait before resetting the table heights in ms (default: 50)
*/
timeout?: number;
};
export type CellProps<T> = {
/**
* the data for the row
*/
row: T;
/**
* the index of the row
*/
index: number;
/**
* an optional function that can be used to clear the size cache
*/
clearSizeCache: (dataIndex: number, options?: ClearCacheOptions) => void;
/**
* optional custom styles for each cell
*/
style?: CSSProperties;
};
export type HeaderProps = {
/**
* the onclick handler for the header cell
* @param e mouse event
* @returns void
*/
onClick: (e: React.MouseEvent<Element, MouseEvent>) => void;
/**
* required style for the header
*/
style: CSSProperties;
/**
* the direction of the sort, if applicable
*/
sortDirection: SortDirection | null;
};
export type RowRenderProps<T> = {
/**
* the data for the row
*/
row: T;
/**
* the index of the row
*/
index: number;
/**
* required row position styles
*/
style: CSSProperties;
/**
* the cells for the row
*/
children: ReactNode;
/**
* the className for the row-renderer
*/
className?: string;
};
export type SubComponentProps<T> = {
/**
* the data for the row
*/
row: T;
/**
* the index of the row
*/
index: number;
/**
* whether or not the row is expanded
*/
isExpanded: boolean;
/**
* an optional function that can be used to clear the size cache
*/
clearSizeCache: (dataIndex: number, options?: ClearCacheOptions) => void;
};
export type FooterProps<T> = {
/**
* exposes the widths of each column to the footer
*/
widths: number[];
/**
* the rows in the table
*/
rows: T[];
};
export type FooterCellProps<T> = {
/**
* the column that the current footer cell is pulling from
*/
column: ColumnProps<T>;
/**
* the calculated width of the cell
*/
width: number;
/**
* all the rows in the table. this can be useful for aggregation
*/
rows: T[];
};
export type ColumnProps<T> = {
/**
* The unique identifier for a particular column. This is also used as an index
* to get the particular value out of the row in order to display.
*/
key: string;
/**
* The name of the header column, or a component to return a customized header cell.
*/
header?: string | ((props: HeaderProps) => JSX.Element);
/**
* specify a custom classNsme for the header. If `header` is NOT a strins, this is ignored.
*/
headerCellClassname?: string;
/**
* The width of a column in pixels. If this is set, the column will not resize.
*/
width?: number;
/**
* The minimum width of a column in pixels. On resize, the column will never
* dip below this width.
*/
minWidth?: number;
/**
* The maximum width of a column in pixels. On resize, the column will never
* grow beyond this width.
*/
maxWidth?: number;
/**
* Determines whether or not a column is sortable.
*/
sortable?: boolean;
/**
* Determines whether or not the column is frozen during horizontal scrolling.
*/
frozen?: boolean;
/**
* Marks this cell as an expansion cell. The style is pre-determined, and does the
* functionalitty of collapsing/expanding a row.
*/
expander?: boolean | ((props: ExpanderProps<T>) => ReactNode);
/**
* Used to render custom content inside of a cell. This is useful for rendering different
* things inside of the react-fluid-table cell container.
*/
content?: string | number | ((props: CellProps<T>) => ReactNode | JSX.Element);
/**
* specify a custom classNsme for the content. If `cell` is specified, this is ignored.
*/
contentCellClassname?: string | ((props: { row: T; index: number }) => string);
/**
* An advanced feature, this is used to render an entire cell, including the cell container.
* The `content` prop is ignored if this property is enabled.
*/
cell?: (props: CellProps<T>) => JSX.Element;
/**
* specifies whether or not to display a footer cell
*/
footer?: (props: FooterCellProps<T>) => ReactNode | JSX.Element;
};
export type TableRef = {
/**
* scrolls to a specific pixel offset
* @param scrollOffset pixel offset
*/
scrollTo: (scrollOffset: number) => void;
/**
*
* @param index the index of the row to scroll to
* @param align where to align the row after scrolling
* @returns
*/
scrollToItem: (index: number, align?: ScrollAlign) => void;
};
export type TableProps<T> = {
// required props
/**
* A list of rows that are to be displayed in the table.
*/
data: T[];
/**
* This property determines how each cell is going to be rendered.
*/
columns: ColumnProps<T>[];
// optional props
/**
* The id of the table.
*/
id?: string;
/**
* Optional className to override CSS styles.
*/
className?: string;
/**
* Function that is called when a header cell is sorted.
*/
onSort?: (col: string, dir: SortDirection | null) => void;
/**
* The column that is sorted by default.
*/
sortColumn?: string;
/**
* The direction that is sorted by default.
*/
sortDirection?: SortDirection;
/**
* Specify the height of the table in pixels.
*/
tableHeight?: number;
/**
* Specify the minimum height of the table in pixels.
*/
minTableHeight?: number;
/**
* Specify the maximum height of the table in pixels.
*/
maxTableHeight?: number;
/**
* Specify the width of the table in pixels.
*/
tableWidth?: number;
/**
* Specify the minimum width of any column. Default: `80`.
*/
minColumnWidth?: number;
/**
* The fixed height of each row in pixels. If `subComponent` is specified,
* then this will be the fixed height of the portion of the row that is
* NOT the subComponent.
*/
rowHeight?: number;
/**
* specify a fixed header height
*/
headerHeight?: number;
/**
* specify a fixed footer height
*/
footerHeight?: number;
/**
* Enable or disable row borders. Default: `false`.
*/
borders?: boolean;
/**
* React styles used for customizing the table.
*/
tableStyle?: CSSProperties;
/**
* React styles used for customizing the header.
*/
headerStyle?: CSSProperties;
/**
* a className used to customize the header
*/
headerClassname?: string;
/**
* React styles used for customizing each row. Could be an object or
* a function that takes the index of the row and returns an object.
*/
rowStyle?: CSSProperties | ((index: number) => CSSProperties);
/**
* React className used for customizing each row. Could be an object or
* a function that takes the index of the row and returns an object.
*/
rowClassname?: string | ((index: number) => string);
/**
* React styles used for customizing each row container. Could be an object or
* a function that takes the index of the row and returns an object.
*/
rowContainerStyle?: CSSProperties | ((index: number) => CSSProperties);
/**
* React className used for customizing each row container. Could be an object or
* a function that takes the index of the row and returns an object.
*/
rowContainerClassname?: string | ((index: number) => string);
/**
* React styles used for customizing the footer.
*/
footerStyle?: CSSProperties;
/**
* a className used to customize the footer
*/
footerClassname?: string;
/**
* set expanded rows. Could be an object or a function that takes the index of
* the row and returns a boolean.
*/
expandedRows?: { [x: number]: boolean } | ((index: number) => boolean);
/**
* called when a row is expanded
* @param value information about the row that is expanded/shrunk
* @returns
*/
onExpandRow?: (value: { row: T; index: number; isExpanded: boolean }) => void;
/**
* generates a unique identifier for the row
* @param row the row
* @returns string or number representing the item key
*/
itemKey?: (row: T) => string | number;
/**
* controlls whether or not the footer is sticky. this is only used if
* `footerComponent` is specified.
*/
stickyFooter?: boolean;
/**
* optionally add a footer. NOTE: this overrides the `footer` prop of a
* column, so use wisely. This gives the user more control over how the
* footer is rendered. Can return any value.
*/
footerComponent?: (props: FooterProps<T>) => ReactNode;
/**
* When a column has `expander`, this component will be rendered under the row.
*/
subComponent?: (props: SubComponentProps<T>) => ReactNode | JSX.Element;
/**
* The callback that gets called every time a row is clicked.
*/
onRowClick?: (data: {
row: T;
index: number;
event: React.MouseEvent<Element, MouseEvent>;
}) => void;
/**
* Custom component to wrap a table row. This provides another way of providing
* more row customization options.
*/
rowRenderer?: (props: RowRenderProps<T>) => JSX.Element;
/**
* advanced: this may help address flicker when toggling all rows
*/
forceReset?: boolean;
/**
* a ref for specific table functions
*/
ref?: ForwardedRef<TableRef>;
};
/**
* A virtualized table build on top of `react-window`.
*/
export const Table: <T>(props: TableProps<T>) => JSX.Element;