/
index.d.ts
322 lines (308 loc) · 7.85 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
import { CSSProperties, ForwardedRef, ReactNode } from "react";
export type SortDirection = "ASC" | "DESC" | null;
type CacheFunction = (dataIndex: number, forceUpdate?: boolean) => void;
export interface ExpanderProps {
/**
* 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 interface 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: CacheFunction;
/**
* optional custom styles for each cell
*/
style?: CSSProperties;
}
export interface 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;
}
export interface 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 interface 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: CacheFunction;
}
export interface FooterProps<T> {
/**
* exposes the widths of each column to the footer
*/
widths: number[];
rows: T[];
}
export interface 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 interface 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);
/**
* 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) => 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);
/**
* 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;
}
export interface TableRef {
scrollTo: (scrollOffset: number) => void;
scrollToItem: (index: number, align?: string) => void;
}
export interface 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 | null, dir: SortDirection) => 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 the footer.
*/
footerStyle?: CSSProperties;
/**
* a className used to customize the footer
*/
footerClassname?: string;
/**
* 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;
/**
* The callback that gets called every time a row is clicked.
*/
onRowClick?: (event: React.MouseEvent<Element, MouseEvent>, data: { index: number }) => void;
/**
* Custom component to wrap a table row. This provides another way of providing
* more row customization options.
*/
rowRenderer?: (props: RowRenderProps<T>) => JSX.Element;
/**
* 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;