forked from mckervinc/react-fluid-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
220 lines (205 loc) · 5.55 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
import { CSSProperties, ElementType, FC, ReactNode } from "react";
declare module "*.svg" {
const content: string;
export default content;
}
export type Text = string | number;
type KeyFunction = (row: Generic) => Text;
type CacheFunction = (dataIndex: number, forceUpdate?: boolean) => void;
type HeightFunction = (
queryParam: number | HTMLElement | null,
optionalDataIndex?: number | null
) => number;
type GenKeyFunction = (row: Generic, defaultValue: number) => Text;
type ClickFunction = (
event: React.MouseEvent<HTMLElement, MouseEvent>,
data: { index: number }
) => void;
export interface Generic {
[key: string]: any;
}
export interface ExpanderProps {
isExpanded: boolean;
onClick: Function;
style: CSSProperties;
}
export interface CellProps {
row: Generic;
index: number;
clearSizeCache: CacheFunction;
style?: CSSProperties;
}
export interface HeaderProps {
onClick: Function;
style: Generic;
sortDirection: string | null;
}
export interface ColumnProps {
/**
* 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 | ElementType<HeaderProps>;
/**
* 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;
/**
* Marks this cell as an expansion cell. The style is pre-determined, and does the
* functionalitty of collapsing/expanding a row.
*/
expander?: boolean | ElementType<ExpanderProps>;
/**
* 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 | ElementType<CellProps>;
/**
* 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?: ElementType<CellProps>;
}
export interface RowRenderProps {
row: Generic;
index: number;
style: CSSProperties;
children: ReactNode;
}
export interface RowProps {
row: Generic;
index: number;
style: CSSProperties;
borders: boolean;
rowHeight: number;
rowStyle: CSSProperties | ((index: number) => CSSProperties);
pixelWidths: number[];
useRowWidth: boolean;
clearSizeCache: CacheFunction;
calculateHeight: HeightFunction;
generateKeyFromRow: GenKeyFunction;
onRowClick: ClickFunction;
subComponent: ElementType<SubComponentProps>;
rowRenderer: ElementType<RowRenderProps>;
}
export interface SubComponentProps {
row: Generic;
index: number;
isExpanded: boolean;
clearSizeCache: CacheFunction;
}
export interface ListProps {
height: number;
width: number;
data: Generic[];
borders?: boolean;
className?: string;
rowHeight?: number;
rowStyle?: CSSProperties | ((index: number) => CSSProperties);
itemKey?: KeyFunction;
subComponent?: ElementType<SubComponentProps>;
onRowClick?: ClickFunction;
[key: string]: any;
}
export interface TableProps {
// required props
/**
* A list of rows that are to be displayed in the table.
*/
data: Generic[];
/**
* This property determines how each cell is going to be rendered.
*/
columns: ColumnProps[];
// 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: string | null) => void;
/**
* The column that is sorted by default.
*/
sortColumn?: string;
/**
* The direction that is sorted by default.
*/
sortDirection?: string;
/**
* Specify the height of the table in pixels.
*/
tableHeight?: number;
/**
* Specify the width of the table in pixels.
*/
tableWidth?: number;
/**
* Specify the minimum width of any column. Default: `80`.
*/
minColumnWidth?: number;
/**
* Enable or disable row borders. Default: `true`.
*/
borders?: boolean;
/**
* 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;
/**
* React styles used for customizing the table.
*/
tableStyle?: CSSProperties;
/**
* React styles used for customizing the header.
*/
headerStyle?: CSSProperties;
/**
* 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);
/**
* When a column has `expander`, this component will be rendered under the row.
*/
subComponent?: ElementType<SubComponentProps>;
/**
* The callback that gets called every time a row is clicked.
*/
onRowClick?: ClickFunction;
/**
* Custom component to wrap a table row. This provides another way of providing
* more row customization options.
*/
rowRenderer?: ElementType<RowRenderProps>;
}
/**
* A virtualized table build on top of `react-window`.
*/
export const Table: FC<TableProps>;