-
-
Notifications
You must be signed in to change notification settings - Fork 421
Expand file tree
/
Copy pathtypes.ts
More file actions
383 lines (352 loc) · 9.68 KB
/
types.ts
File metadata and controls
383 lines (352 loc) · 9.68 KB
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
import { Alignment, Direction, Media } from './constants';
import { CSSObject } from 'styled-components';
export enum SortOrder {
ASC = 'asc',
DESC = 'desc',
}
export type Primitive = string | number | boolean;
export type ColumnSortFunction<T> = (a: T, b: T) => number;
export type ExpandRowToggled<T> = (expanded: boolean, row: T) => void;
export type Format<T> = (row: T, rowIndex: number) => React.ReactNode;
export type RowState<T> = ((row: T) => boolean) | null;
export type Selector<T> = (row: T, rowIndex?: number) => Primitive;
export type SortFunction<T> = (rows: T[], field: Selector<T>, sortDirection: SortOrder) => T[];
export type TableRow = Record<string, unknown>;
export type ComponentProps = Record<string, unknown>;
export type ExpanderComponentProps<T> = { data: T };
export type ExpandableRowsComponent<T> = React.ComponentType<ExpanderComponentProps<T>>;
export type PaginationChangePage = (page: number, totalRows: number) => void;
export type PaginationChangeRowsPerPage = (currentRowsPerPage: number, currentPage: number) => void;
export type PaginationComponentProps = {
rowsPerPage: number;
rowCount: number;
currentPage: number;
onChangePage: PaginationChangePage;
onChangeRowsPerPage: PaginationChangeRowsPerPage;
};
export type PaginationComponent = React.ComponentType<PaginationComponentProps>;
export type TableProps<T> = {
actions?: React.ReactNode | React.ReactNode[];
className?: string;
clearSelectedRows?: boolean;
columns: TableColumn<T>[];
conditionalRowStyles?: ConditionalStyles<T>[];
contextActions?: React.ReactNode | React.ReactNode[];
contextComponent?: React.ReactNode;
contextMessage?: ContextMessage;
customStyles?: TableStyles;
data: T[];
defaultSortAsc?: boolean;
defaultSortFieldId?: string | number | null | undefined;
dense?: boolean;
direction?: Direction;
disabled?: boolean;
expandableIcon?: ExpandableIcon;
expandableInheritConditionalStyles?: boolean;
expandableRowDisabled?: RowState<T>;
expandableRowExpanded?: RowState<T>;
expandableRows?: boolean;
expandableRowsComponent?: ExpandableRowsComponent<T>;
expandableRowsComponentProps?: ComponentProps;
expandableRowsHideExpander?: boolean;
expandOnRowClicked?: boolean;
expandOnRowDoubleClicked?: boolean;
fixedHeader?: boolean;
fixedHeaderScrollHeight?: string;
highlightOnHover?: boolean;
keyField?: string;
noContextMenu?: boolean;
noDataComponent?: React.ReactNode;
noHeader?: boolean;
noTableHead?: boolean;
onChangePage?: PaginationChangePage;
onChangeRowsPerPage?: PaginationChangeRowsPerPage;
onRowClicked?: (row: T, e: React.MouseEvent) => void;
onRowDoubleClicked?: (row: T, e: React.MouseEvent) => void;
onRowMouseEnter?: (row: T, e: React.MouseEvent) => void;
onRowMouseLeave?: (row: T, e: React.MouseEvent) => void;
onRowExpandToggled?: ExpandRowToggled<T>;
onSelectedRowsChange?: (selected: { allSelected: boolean; selectedCount: number; selectedRows: T[] }) => void;
onSort?: (selectedColumn: TableColumn<T>, sortDirection: SortOrder, sortedRows: T[]) => void;
onColumnOrderChange?: (nextOrder: TableColumn<T>[]) => void;
pagination?: boolean;
paginationComponent?: PaginationComponent;
paginationComponentOptions?: PaginationOptions;
paginationDefaultPage?: number;
paginationIconFirstPage?: React.ReactNode;
paginationIconLastPage?: React.ReactNode;
paginationIconNext?: React.ReactNode;
paginationIconPrevious?: React.ReactNode;
paginationPerPage?: number;
paginationResetDefaultPage?: boolean;
paginationRowsPerPageOptions?: number[];
paginationServer?: boolean;
paginationServerOptions?: PaginationServerOptions;
paginationTotalRows?: number;
persistTableHead?: boolean;
pointerOnHover?: boolean;
progressComponent?: React.ReactNode;
progressPending?: boolean;
responsive?: boolean;
selectableRowDisabled?: RowState<T>;
selectableRows?: boolean;
selectableRowsComponent?: 'input' | React.ReactNode;
selectableRowsComponentProps?: ComponentProps;
selectableRowSelected?: RowState<T>;
selectableRowsHighlight?: boolean;
selectableRowsNoSelectAll?: boolean;
selectableRowsVisibleOnly?: boolean;
selectableRowsSingle?: boolean;
sortFunction?: SortFunction<T> | null;
sortIcon?: React.ReactNode;
sortServer?: boolean;
striped?: boolean;
style?: CSSObject;
subHeader?: React.ReactNode | React.ReactNode[];
subHeaderAlign?: Alignment;
subHeaderComponent?: React.ReactNode | React.ReactNode[];
subHeaderWrap?: boolean;
theme?: Themes;
/**
* Shows and displays a header with a title
* */
title?: string | React.ReactNode;
};
export type TableColumnBase = {
allowOverflow?: boolean;
button?: boolean;
center?: boolean;
compact?: boolean;
reorder?: boolean;
grow?: number;
hide?: number | ((value: number) => CSSObject) | Media;
id?: string | number;
ignoreRowClick?: boolean;
maxWidth?: string;
minWidth?: string;
name?: string | number | React.ReactNode;
omit?: boolean;
right?: boolean;
sortable?: boolean;
style?: CSSObject;
width?: string;
wrap?: boolean;
};
export interface TableColumn<T> extends TableColumnBase {
name?: string | number | React.ReactNode;
sortField?: string;
cell?: (row: T, rowIndex: number, column: TableColumn<T>, id: string | number) => React.ReactNode;
conditionalCellStyles?: ConditionalStyles<T>[];
format?: Format<T> | undefined;
selector?: Selector<T>;
sortFunction?: ColumnSortFunction<T>;
}
export interface ConditionalStyles<T> {
when: (row: T) => boolean;
style?: CSSObject | ((row: T) => CSSObject);
classNames?: string[];
}
export interface TableStyles {
table?: {
style: CSSObject;
};
tableWrapper?: {
style: CSSObject;
};
responsiveWrapper?: {
style: CSSObject;
};
header?: {
style: CSSObject;
};
subHeader?: {
style: CSSObject;
};
head?: {
style: CSSObject;
};
headRow?: {
style?: CSSObject;
denseStyle?: CSSObject;
};
headCells?: {
style?: CSSObject;
draggingStyle?: CSSObject;
};
contextMenu?: {
style?: CSSObject;
activeStyle?: CSSObject;
};
cells?: {
style: CSSObject;
draggingStyle?: CSSObject;
};
rows?: {
style?: CSSObject;
selectedHighlightStyle?: CSSObject;
denseStyle?: CSSObject;
highlightOnHoverStyle?: CSSObject;
stripedStyle?: CSSObject;
};
expanderRow?: {
style: CSSObject;
};
expanderCell?: {
style: CSSObject;
};
expanderButton?: {
style: CSSObject;
};
pagination?: {
style?: CSSObject;
pageButtonsStyle?: CSSObject;
};
noData?: {
style: CSSObject;
};
progress?: {
style: CSSObject;
};
}
export interface PaginationOptions {
noRowsPerPage?: boolean;
// If non-null, the "rows per page" dropdown will be hidden when the window width is less than
// this value. SMALL == 599 is the default (if this property is undefined); pass `null` to always
// show the dropdown (useful for ensuring SSR matches client).
minWindowWidth?: number | null;
rowsPerPageText?: string;
rangeSeparatorText?: string;
selectAllRowsItem?: boolean;
selectAllRowsItemText?: string;
}
export interface PaginationServerOptions {
persistSelectedOnSort?: boolean;
persistSelectedOnPageChange?: boolean;
}
export interface ExpandableIcon {
collapsed: React.ReactNode;
expanded: React.ReactNode;
}
export interface ContextMessage {
singular: string;
plural: string;
message?: string;
}
export type TableState<T> = {
allSelected: boolean;
contextMessage: ContextMessage;
selectedCount: number;
selectedRows: T[];
selectedColumn: TableColumn<T>;
sortDirection: SortOrder;
currentPage: number;
rowsPerPage: number;
selectedRowsFlag: boolean;
/* server-side pagination and server-side sorting will cause selectedRows to change
because of this behavior onSelectedRowsChange useEffect is triggered (by design it should notify if there was a change)
however, when using selectableRowsSingle
*/
toggleOnSelectedRowsChange: boolean;
};
// Theming
type ThemeText = {
primary: string;
secondary: string;
disabled: string;
};
type ThemeBackground = {
default: string;
};
type ThemeContext = {
background: string;
text: string;
};
type ThemeDivider = {
default: string;
};
type ThemeButton = {
default: string;
focus: string;
hover: string;
disabled: string;
};
type ThemeSelected = {
default: string;
text: string;
};
type ThemeHighlightOnHover = {
default: string;
text: string;
};
type ThemeStriped = {
default: string;
text: string;
};
export type Themes = string;
export interface Theme {
text: ThemeText;
background: ThemeBackground;
context: ThemeContext;
divider: ThemeDivider;
button: ThemeButton;
selected: ThemeSelected;
highlightOnHover: ThemeHighlightOnHover;
striped: ThemeStriped;
}
// Reducer Actions
export interface AllRowsAction<T> {
type: 'SELECT_ALL_ROWS';
keyField: string;
rows: T[];
rowCount: number;
mergeSelections: boolean;
}
export interface SingleRowAction<T> {
type: 'SELECT_SINGLE_ROW';
keyField: string;
row: T;
isSelected: boolean;
rowCount: number;
singleSelect: boolean;
}
export interface MultiRowAction<T> {
type: 'SELECT_MULTIPLE_ROWS';
keyField: string;
selectedRows: T[];
totalRows: number;
mergeSelections: boolean;
}
export interface SortAction<T> {
type: 'SORT_CHANGE';
sortDirection: SortOrder;
selectedColumn: TableColumn<T>;
clearSelectedOnSort: boolean;
}
export interface PaginationPageAction {
type: 'CHANGE_PAGE';
page: number;
paginationServer: boolean;
visibleOnly: boolean;
persistSelectedOnPageChange: boolean;
}
export interface PaginationRowsPerPageAction {
type: 'CHANGE_ROWS_PER_PAGE';
rowsPerPage: number;
page: number;
}
export interface ClearSelectedRowsAction {
type: 'CLEAR_SELECTED_ROWS';
selectedRowsFlag: boolean;
}
export interface ColumnsAction<T> {
type: 'UPDATE_COLUMNS';
cols: TableColumn<T>[];
}
export type Action<T> =
| AllRowsAction<T>
| SingleRowAction<T>
| MultiRowAction<T>
| SortAction<T>
| PaginationPageAction
| PaginationRowsPerPageAction
| ClearSelectedRowsAction;