jattac.libs.web.responsive-table 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +631 -581
- package/dist/Data/IResponsiveTableColumnDefinition.d.ts +4 -0
- package/dist/Plugins/SortPlugin.d.ts +29 -0
- package/dist/UI/ResponsiveTable.d.ts +5 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +136 -6
- package/dist/index.js.map +1 -1
- package/package.json +66 -60
- package/.eslintrc.json +0 -8
- package/.prettierrc +0 -5
- package/gemini/commit_message.txt +0 -1
- package/gemini/index.md +0 -1
- package/gemini/project_analysis.md +0 -41
- package/gemini/release_git_steps.md +0 -80
- package/rollup.config.js +0 -23
- package/set-origin-urls.sh +0 -32
- package/src/Data/IFooterColumnDefinition.ts +0 -21
- package/src/Data/IFooterRowDefinition.ts +0 -5
- package/src/Data/IResponsiveTableColumnDefinition.tsx +0 -12
- package/src/Plugins/FilterPlugin.tsx +0 -71
- package/src/Plugins/IResponsiveTablePlugin.ts +0 -48
- package/src/Plugins/InfiniteScrollPlugin.tsx +0 -73
- package/src/Styles/ResponsiveTable.module.css +0 -253
- package/src/UI/ResponsiveTable.tsx +0 -532
- package/src/index.tsx +0 -10
- package/src/typings.d.ts +0 -14
- package/tsconfig.json +0 -22
- package/update-dependancies.sh +0 -4
|
@@ -1,532 +0,0 @@
|
|
|
1
|
-
import React, { CSSProperties, Component, ReactNode, createRef } from 'react';
|
|
2
|
-
import styles from '../Styles/ResponsiveTable.module.css';
|
|
3
|
-
import IResponsiveTableColumnDefinition from '../Data/IResponsiveTableColumnDefinition';
|
|
4
|
-
import IFooterRowDefinition from '../Data/IFooterRowDefinition';
|
|
5
|
-
import { IResponsiveTablePlugin } from '../Plugins/IResponsiveTablePlugin';
|
|
6
|
-
import { FilterPlugin } from '../Plugins/FilterPlugin';
|
|
7
|
-
import { InfiniteScrollPlugin } from '../Plugins/InfiniteScrollPlugin';
|
|
8
|
-
import { FixedSizeList as List } from 'react-window';
|
|
9
|
-
|
|
10
|
-
export type ColumnDefinition<TData> =
|
|
11
|
-
| IResponsiveTableColumnDefinition<TData>
|
|
12
|
-
| ((data: TData, rowIndex?: number) => IResponsiveTableColumnDefinition<TData>);
|
|
13
|
-
interface IProps<TData> {
|
|
14
|
-
columnDefinitions: ColumnDefinition<TData>[];
|
|
15
|
-
data: TData[];
|
|
16
|
-
noDataComponent?: ReactNode;
|
|
17
|
-
maxHeight?: string;
|
|
18
|
-
onRowClick?: (item: TData) => void;
|
|
19
|
-
footerRows?: IFooterRowDefinition[];
|
|
20
|
-
mobileBreakpoint?: number;
|
|
21
|
-
plugins?: IResponsiveTablePlugin<TData>[];
|
|
22
|
-
infiniteScrollProps?: {
|
|
23
|
-
enableInfiniteScroll?: boolean;
|
|
24
|
-
onLoadMore?: (currentData: TData[]) => Promise<TData[] | null>;
|
|
25
|
-
hasMore?: boolean;
|
|
26
|
-
loadingMoreComponent?: ReactNode;
|
|
27
|
-
noMoreDataComponent?: ReactNode;
|
|
28
|
-
};
|
|
29
|
-
filterProps?: {
|
|
30
|
-
showFilter?: boolean;
|
|
31
|
-
filterPlaceholder?: string;
|
|
32
|
-
};
|
|
33
|
-
animationProps?: {
|
|
34
|
-
isLoading?: boolean;
|
|
35
|
-
animateOnLoad?: boolean;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
interface IState<TData> {
|
|
40
|
-
isMobile: boolean;
|
|
41
|
-
processedData: TData[];
|
|
42
|
-
isLoadingMore: boolean;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Class component
|
|
46
|
-
class ResponsiveTable<TData> extends Component<IProps<TData>, IState<TData>> {
|
|
47
|
-
private debouncedResize: () => void;
|
|
48
|
-
private tableContainerRef = createRef<HTMLDivElement>();
|
|
49
|
-
|
|
50
|
-
constructor(props: IProps<TData>) {
|
|
51
|
-
super(props);
|
|
52
|
-
this.state = {
|
|
53
|
-
isMobile: false,
|
|
54
|
-
processedData: props.data,
|
|
55
|
-
isLoadingMore: false,
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
this.debouncedResize = this.debounce(this.handleResize, 200);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private get mobileBreakpoint(): number {
|
|
62
|
-
return this.props.mobileBreakpoint || 600;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
private debounce(func: () => void, delay: number): () => void {
|
|
66
|
-
let timeout: NodeJS.Timeout;
|
|
67
|
-
return () => {
|
|
68
|
-
clearTimeout(timeout);
|
|
69
|
-
timeout = setTimeout(() => func(), delay);
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
private get data(): TData[] {
|
|
74
|
-
if (Array.isArray(this.state.processedData) && this.state.processedData.length > 0) {
|
|
75
|
-
return this.state.processedData;
|
|
76
|
-
} else {
|
|
77
|
-
return [];
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
private get noDataSvg(): ReactNode {
|
|
82
|
-
return (
|
|
83
|
-
<svg xmlns="http://www.w3.org/2000/svg" fill="#ccc" height="40" width="40" viewBox="0 0 24 24">
|
|
84
|
-
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm-1-14h2v6h-2zm0 8h2v2h-2z" />
|
|
85
|
-
</svg>
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
private get hasData(): boolean {
|
|
90
|
-
return this.data.length > 0;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
private get noDataComponent(): ReactNode {
|
|
94
|
-
return (
|
|
95
|
-
this.props.noDataComponent || (
|
|
96
|
-
<div className={styles.noDataWrapper}>
|
|
97
|
-
{this.noDataSvg}
|
|
98
|
-
<div className={styles.noData}>No data</div>
|
|
99
|
-
</div>
|
|
100
|
-
)
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
componentDidMount(): void {
|
|
105
|
-
this.handleResize(); // Initial check
|
|
106
|
-
window.addEventListener('resize', this.debouncedResize);
|
|
107
|
-
this.initializePlugins();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
componentWillUnmount(): void {
|
|
111
|
-
window.removeEventListener('resize', this.debouncedResize);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
componentDidUpdate(prevProps: IProps<TData>) {
|
|
115
|
-
if (prevProps.data !== this.props.data) {
|
|
116
|
-
this.processData();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Handle infinite scroll loading
|
|
120
|
-
if (this.props.infiniteScrollProps?.enableInfiniteScroll && this.props.infiniteScrollProps?.hasMore && !this.state.isLoadingMore && this.props.infiniteScrollProps?.onLoadMore) {
|
|
121
|
-
// This condition will be met when the parent component updates `data` and `hasMore`
|
|
122
|
-
// after a successful load, or when `hasMore` becomes true.
|
|
123
|
-
// The actual load trigger is within the InfiniteScrollPlugin via `onItemsRendered`
|
|
124
|
-
// or `handleScroll`.
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
private initializePlugins() {
|
|
130
|
-
const activePlugins: IResponsiveTablePlugin<TData>[] = [];
|
|
131
|
-
|
|
132
|
-
// Add explicitly provided plugins first
|
|
133
|
-
if (this.props.plugins) {
|
|
134
|
-
activePlugins.push(...this.props.plugins);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Automatically add FilterPlugin if filterProps are provided and not already present
|
|
138
|
-
if (this.props.filterProps?.showFilter && !activePlugins.some(p => p.id === 'filter')) {
|
|
139
|
-
activePlugins.push(new FilterPlugin());
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Automatically add InfiniteScrollPlugin if infiniteScrollProps are provided and not already present
|
|
143
|
-
if (this.props.infiniteScrollProps?.enableInfiniteScroll && !activePlugins.some(p => p.id === 'infinite-scroll')) {
|
|
144
|
-
activePlugins.push(new InfiniteScrollPlugin());
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
activePlugins.forEach((plugin) => {
|
|
148
|
-
if (plugin.onPluginInit) {
|
|
149
|
-
plugin.onPluginInit({
|
|
150
|
-
getData: () => this.props.data,
|
|
151
|
-
forceUpdate: () => this.processData(),
|
|
152
|
-
getScrollableElement: () => this.tableContainerRef.current,
|
|
153
|
-
infiniteScrollProps: this.props.infiniteScrollProps,
|
|
154
|
-
filterProps: this.props.filterProps,
|
|
155
|
-
columnDefinitions: this.props.columnDefinitions,
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
// Process data with all active plugins
|
|
161
|
-
let processedData = [...this.props.data];
|
|
162
|
-
activePlugins.forEach((plugin) => {
|
|
163
|
-
if (plugin.processData) {
|
|
164
|
-
processedData = plugin.processData(processedData);
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
this.setState({ processedData });
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
private processData() {
|
|
171
|
-
let processedData = [...this.props.data];
|
|
172
|
-
if (this.props.plugins) {
|
|
173
|
-
this.props.plugins.forEach((plugin) => {
|
|
174
|
-
if (plugin.processData) {
|
|
175
|
-
processedData = plugin.processData(processedData);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
this.setState({ processedData });
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
handleResize = (): void => {
|
|
183
|
-
this.setState({
|
|
184
|
-
isMobile: window.innerWidth <= this.mobileBreakpoint,
|
|
185
|
-
});
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
private getColumnDefinition(
|
|
189
|
-
columnDefinition: ColumnDefinition<TData>,
|
|
190
|
-
rowIndex: number,
|
|
191
|
-
): IResponsiveTableColumnDefinition<TData> {
|
|
192
|
-
if (!this.hasData) {
|
|
193
|
-
return { displayLabel: '', cellRenderer: () => '' };
|
|
194
|
-
}
|
|
195
|
-
return columnDefinition instanceof Function ? columnDefinition(this.data[0], rowIndex) : columnDefinition;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
private getRawColumnDefinition(columnDefinition: ColumnDefinition<TData>): IResponsiveTableColumnDefinition<TData> {
|
|
199
|
-
let rawColumnDefinition: IResponsiveTableColumnDefinition<TData> = {} as IResponsiveTableColumnDefinition<TData>;
|
|
200
|
-
if (columnDefinition instanceof Function) {
|
|
201
|
-
rawColumnDefinition = columnDefinition(this.data[0], 0);
|
|
202
|
-
} else {
|
|
203
|
-
rawColumnDefinition = columnDefinition as IResponsiveTableColumnDefinition<TData>;
|
|
204
|
-
}
|
|
205
|
-
return rawColumnDefinition;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
private onHeaderClickCallback(columnDefinition: ColumnDefinition<TData>): ((id: string) => void) | undefined {
|
|
209
|
-
const rawColumnDefinition = this.getRawColumnDefinition(columnDefinition);
|
|
210
|
-
if (rawColumnDefinition.interactivity && rawColumnDefinition.interactivity.onHeaderClick) {
|
|
211
|
-
return rawColumnDefinition.interactivity.onHeaderClick;
|
|
212
|
-
} else {
|
|
213
|
-
return undefined;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
private getClickableHeaderClassName(
|
|
218
|
-
onHeaderClickCallback: ((id: string) => void) | undefined,
|
|
219
|
-
colDef: ColumnDefinition<TData>,
|
|
220
|
-
): string {
|
|
221
|
-
const rawColumnDefinition = this.getRawColumnDefinition(colDef);
|
|
222
|
-
const clickableHeaderClassName = onHeaderClickCallback
|
|
223
|
-
? rawColumnDefinition.interactivity!.className || styles.clickableHeader
|
|
224
|
-
: '';
|
|
225
|
-
return clickableHeaderClassName;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
private get rowClickFunction(): (item: TData) => void {
|
|
229
|
-
if (this.props.onRowClick) {
|
|
230
|
-
return this.props.onRowClick;
|
|
231
|
-
} else {
|
|
232
|
-
return () => {};
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
private get rowClickStyle(): CSSProperties {
|
|
237
|
-
if (this.props.onRowClick) {
|
|
238
|
-
return { cursor: 'pointer' } as CSSProperties;
|
|
239
|
-
} else {
|
|
240
|
-
return {};
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
private get tableFooter(): ReactNode {
|
|
245
|
-
if (!this.props.footerRows || this.props.footerRows.length === 0) {
|
|
246
|
-
return null;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return (
|
|
250
|
-
<tfoot>
|
|
251
|
-
{this.props.footerRows.map((row, rowIndex) => (
|
|
252
|
-
<tr key={rowIndex}>
|
|
253
|
-
{row.columns.map((col, colIndex) => (
|
|
254
|
-
<td
|
|
255
|
-
key={colIndex}
|
|
256
|
-
colSpan={col.colSpan}
|
|
257
|
-
className={`${styles.footerCell} ${col.className || ''} ${col.onCellClick ? styles.clickableFooterCell : ''}`}
|
|
258
|
-
onClick={col.onCellClick}
|
|
259
|
-
>
|
|
260
|
-
{col.cellRenderer()}
|
|
261
|
-
</td>
|
|
262
|
-
))}
|
|
263
|
-
</tr>
|
|
264
|
-
))}
|
|
265
|
-
</tfoot>
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
private get mobileFooter(): ReactNode {
|
|
270
|
-
if (!this.props.footerRows || this.props.footerRows.length === 0) {
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return (
|
|
275
|
-
<div className={styles.footerCard}>
|
|
276
|
-
<div className={styles['footer-card-body']}>
|
|
277
|
-
{this.props.footerRows.map((row, rowIndex) => {
|
|
278
|
-
let currentColumnIndex = 0;
|
|
279
|
-
return (
|
|
280
|
-
<div key={rowIndex}>
|
|
281
|
-
{row.columns.map((col, colIndex) => {
|
|
282
|
-
let label = col.displayLabel;
|
|
283
|
-
if (!label && col.colSpan === 1) {
|
|
284
|
-
const header = this.props.columnDefinitions[currentColumnIndex];
|
|
285
|
-
if (header) {
|
|
286
|
-
label = this.getRawColumnDefinition(header).displayLabel;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
currentColumnIndex += col.colSpan;
|
|
290
|
-
return (
|
|
291
|
-
<p
|
|
292
|
-
key={colIndex}
|
|
293
|
-
className={`${styles['footer-card-row']} ${col.className || ''} ${
|
|
294
|
-
col.onCellClick ? styles.clickableFooterCell : ''
|
|
295
|
-
}`}
|
|
296
|
-
onClick={col.onCellClick}
|
|
297
|
-
>
|
|
298
|
-
{label && <span className={styles['card-label']}>{label}</span>}
|
|
299
|
-
<span className={styles['card-value']}>{col.cellRenderer()}</span>
|
|
300
|
-
</p>
|
|
301
|
-
);
|
|
302
|
-
})}
|
|
303
|
-
</div>
|
|
304
|
-
);
|
|
305
|
-
})}
|
|
306
|
-
</div>
|
|
307
|
-
</div>
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
private get skeletonView(): ReactNode {
|
|
312
|
-
const skeletonRowCount = 5; // Or make this configurable
|
|
313
|
-
const columnCount = this.props.columnDefinitions.length;
|
|
314
|
-
|
|
315
|
-
if (this.state.isMobile) {
|
|
316
|
-
return (
|
|
317
|
-
<div>
|
|
318
|
-
{[...Array(skeletonRowCount)].map((_, i) => (
|
|
319
|
-
<div key={i} className={styles.skeletonCard}>
|
|
320
|
-
{[...Array(columnCount)].map((_, j) => (
|
|
321
|
-
<div key={j} className={`${styles.skeleton} ${styles.skeletonText}`} style={{ marginBottom: '0.5rem' }} />
|
|
322
|
-
))}
|
|
323
|
-
</div>
|
|
324
|
-
))}
|
|
325
|
-
</div>
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
return (
|
|
330
|
-
<table className={styles.responsiveTable}>
|
|
331
|
-
<thead>
|
|
332
|
-
<tr>
|
|
333
|
-
{[...Array(columnCount)].map((_, i) => (
|
|
334
|
-
<th key={i}>
|
|
335
|
-
<div className={`${styles.skeleton} ${styles.skeletonText}`} />
|
|
336
|
-
</th>
|
|
337
|
-
))}
|
|
338
|
-
</tr>
|
|
339
|
-
</thead>
|
|
340
|
-
<tbody>
|
|
341
|
-
{[...Array(skeletonRowCount)].map((_, i) => (
|
|
342
|
-
<tr key={i}>
|
|
343
|
-
{[...Array(columnCount)].map((_, j) => (
|
|
344
|
-
<td key={j}>
|
|
345
|
-
<div className={`${styles.skeleton} ${styles.skeletonText}`} />
|
|
346
|
-
</td>
|
|
347
|
-
))}
|
|
348
|
-
</tr>
|
|
349
|
-
))}
|
|
350
|
-
</tbody>
|
|
351
|
-
</table>
|
|
352
|
-
);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
private get mobileView(): ReactNode {
|
|
356
|
-
return (
|
|
357
|
-
<div>
|
|
358
|
-
{this.data.map((row, rowIndex) => (
|
|
359
|
-
<div
|
|
360
|
-
key={rowIndex}
|
|
361
|
-
className={`${styles['card']} ${this.props.animationProps?.animateOnLoad ? styles.animatedRow : ''}`}
|
|
362
|
-
style={{ animationDelay: `${rowIndex * 0.05}s` }}
|
|
363
|
-
onClick={(e) => {
|
|
364
|
-
this.rowClickFunction(row);
|
|
365
|
-
e.stopPropagation();
|
|
366
|
-
e.preventDefault();
|
|
367
|
-
}}
|
|
368
|
-
>
|
|
369
|
-
<div className={styles['card-header']}> </div>
|
|
370
|
-
<div className={styles['card-body']}>
|
|
371
|
-
{this.props.columnDefinitions.map((columnDefinition, colIndex) => {
|
|
372
|
-
const colDef = this.getColumnDefinition(columnDefinition, rowIndex);
|
|
373
|
-
const onHeaderClickCallback = this.onHeaderClickCallback(colDef);
|
|
374
|
-
const clickableHeaderClassName = this.getClickableHeaderClassName(onHeaderClickCallback, colDef);
|
|
375
|
-
return (
|
|
376
|
-
<div key={colIndex} className={styles['card-row']}>
|
|
377
|
-
<p>
|
|
378
|
-
<span
|
|
379
|
-
className={`${styles['card-label']} ${clickableHeaderClassName}`}
|
|
380
|
-
onClick={
|
|
381
|
-
onHeaderClickCallback ? () => onHeaderClickCallback(colDef.interactivity!.id) : undefined
|
|
382
|
-
}
|
|
383
|
-
>
|
|
384
|
-
{colDef.displayLabel}
|
|
385
|
-
</span>
|
|
386
|
-
<span className={styles['card-value']}>{colDef.cellRenderer(row)}</span>
|
|
387
|
-
</p>
|
|
388
|
-
</div>
|
|
389
|
-
);
|
|
390
|
-
})}
|
|
391
|
-
</div>
|
|
392
|
-
</div>
|
|
393
|
-
))}
|
|
394
|
-
{this.mobileFooter}
|
|
395
|
-
</div>
|
|
396
|
-
);
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
private get largeScreenView(): ReactNode {
|
|
400
|
-
const useFixedHeaders = this.props.maxHeight ? true : false;
|
|
401
|
-
|
|
402
|
-
const fixedHeadersStyle = useFixedHeaders
|
|
403
|
-
? ({ maxHeight: this.props.maxHeight, overflowY: 'auto' } as CSSProperties)
|
|
404
|
-
: {};
|
|
405
|
-
|
|
406
|
-
const Row = ({ index, style }: { index: number; style: CSSProperties }) => {
|
|
407
|
-
const row = this.data[index];
|
|
408
|
-
if (!row) return null; // Should not happen with correct item count
|
|
409
|
-
|
|
410
|
-
return (
|
|
411
|
-
<tr
|
|
412
|
-
key={index}
|
|
413
|
-
className={this.props.animationProps?.animateOnLoad ? styles.animatedRow : ''}
|
|
414
|
-
style={{ ...style, animationDelay: `${index * 0.05}s` }}
|
|
415
|
-
>
|
|
416
|
-
{this.props.columnDefinitions.map((columnDefinition, colIndex) => (
|
|
417
|
-
<td onClick={() => this.rowClickFunction(row)} key={colIndex}>
|
|
418
|
-
<span style={{ ...this.rowClickStyle }}>
|
|
419
|
-
{this.getColumnDefinition(columnDefinition, index).cellRenderer(row)}
|
|
420
|
-
</span>
|
|
421
|
-
</td>
|
|
422
|
-
))}
|
|
423
|
-
</tr>
|
|
424
|
-
);
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
return (
|
|
428
|
-
<div style={fixedHeadersStyle} ref={this.tableContainerRef}>
|
|
429
|
-
<table className={styles['responsiveTable']}>
|
|
430
|
-
<thead>
|
|
431
|
-
<tr>
|
|
432
|
-
{this.props.columnDefinitions.map((columnDefinition, colIndex) => {
|
|
433
|
-
const onHeaderClickCallback = this.onHeaderClickCallback(columnDefinition);
|
|
434
|
-
const clickableHeaderClassName = this.getClickableHeaderClassName(
|
|
435
|
-
onHeaderClickCallback,
|
|
436
|
-
columnDefinition,
|
|
437
|
-
);
|
|
438
|
-
return (
|
|
439
|
-
<th
|
|
440
|
-
key={colIndex}
|
|
441
|
-
className={`${clickableHeaderClassName}`}
|
|
442
|
-
onClick={
|
|
443
|
-
onHeaderClickCallback
|
|
444
|
-
? () => onHeaderClickCallback(this.getColumnDefinition(columnDefinition, 0).interactivity!.id)
|
|
445
|
-
: undefined
|
|
446
|
-
}
|
|
447
|
-
>
|
|
448
|
-
{this.getColumnDefinition(columnDefinition, 0).displayLabel}
|
|
449
|
-
</th>
|
|
450
|
-
);
|
|
451
|
-
})}
|
|
452
|
-
</tr>
|
|
453
|
-
</thead>
|
|
454
|
-
<tbody>
|
|
455
|
-
{this.props.infiniteScrollProps?.enableInfiniteScroll ? (
|
|
456
|
-
<List
|
|
457
|
-
height={fixedHeadersStyle.maxHeight ? (typeof fixedHeadersStyle.maxHeight === 'string' ? parseFloat(fixedHeadersStyle.maxHeight) : fixedHeadersStyle.maxHeight) : 500} // Default height if not provided
|
|
458
|
-
itemCount={this.data.length}
|
|
459
|
-
itemSize={50} // Average row height, can be made configurable
|
|
460
|
-
width={'100%'}
|
|
461
|
-
outerRef={this.tableContainerRef} // Pass ref to outer element for scroll events
|
|
462
|
-
>
|
|
463
|
-
{Row}
|
|
464
|
-
</List>
|
|
465
|
-
) : (
|
|
466
|
-
this.data.map((row, rowIndex) => (
|
|
467
|
-
<tr
|
|
468
|
-
key={rowIndex}
|
|
469
|
-
className={this.props.animationProps?.animateOnLoad ? styles.animatedRow : ''}
|
|
470
|
-
style={{ animationDelay: `${rowIndex * 0.05}s` }}
|
|
471
|
-
>
|
|
472
|
-
{this.props.columnDefinitions.map((columnDefinition, colIndex) => (
|
|
473
|
-
<td onClick={() => this.rowClickFunction(row)} key={colIndex}>
|
|
474
|
-
<span style={{ ...this.rowClickStyle }}>
|
|
475
|
-
{this.getColumnDefinition(columnDefinition, rowIndex).cellRenderer(row)}
|
|
476
|
-
</span>
|
|
477
|
-
</td>
|
|
478
|
-
))}
|
|
479
|
-
</tr>
|
|
480
|
-
))
|
|
481
|
-
)}
|
|
482
|
-
</tbody>
|
|
483
|
-
{this.tableFooter}
|
|
484
|
-
</table>
|
|
485
|
-
{this.renderPluginFooters()}
|
|
486
|
-
</div>
|
|
487
|
-
);
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
private renderPluginHeaders() {
|
|
491
|
-
if (!this.props.plugins) {
|
|
492
|
-
return null;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
return this.props.plugins.map((plugin) => {
|
|
496
|
-
if (plugin.renderHeader) {
|
|
497
|
-
return <div key={plugin.id}>{plugin.renderHeader()}</div>;
|
|
498
|
-
}
|
|
499
|
-
return null;
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
private renderPluginFooters() {
|
|
504
|
-
if (!this.props.plugins) {
|
|
505
|
-
return null;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
return this.props.plugins.map((plugin) => {
|
|
509
|
-
if (plugin.renderFooter) {
|
|
510
|
-
return <div key={plugin.id + '-footer'}>{plugin.renderFooter()}</div>;
|
|
511
|
-
}
|
|
512
|
-
return null;
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
render() {
|
|
517
|
-
if (this.props.animationProps?.isLoading) {
|
|
518
|
-
return this.skeletonView;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
return (
|
|
522
|
-
<div>
|
|
523
|
-
{this.renderPluginHeaders()}
|
|
524
|
-
{!this.hasData && this.noDataComponent}
|
|
525
|
-
{this.hasData && this.state.isMobile && this.mobileView}
|
|
526
|
-
{this.hasData && !this.state.isMobile && this.largeScreenView}
|
|
527
|
-
</div>
|
|
528
|
-
);
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
export default ResponsiveTable;
|
package/src/index.tsx
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import IFooterColumnDefinition from './Data/IFooterColumnDefinition';
|
|
2
|
-
import IFooterRowDefinition from './Data/IFooterRowDefinition';
|
|
3
|
-
import IResponsiveTableColumnDefinition from './Data/IResponsiveTableColumnDefinition';
|
|
4
|
-
import ResponsiveTable, { ColumnDefinition } from './UI/ResponsiveTable';
|
|
5
|
-
import { FilterPlugin } from './Plugins/FilterPlugin';
|
|
6
|
-
import { InfiniteScrollPlugin } from './Plugins/InfiniteScrollPlugin';
|
|
7
|
-
import { IResponsiveTablePlugin } from './Plugins/IResponsiveTablePlugin';
|
|
8
|
-
|
|
9
|
-
export { IResponsiveTableColumnDefinition, ColumnDefinition, IFooterColumnDefinition, IFooterRowDefinition, FilterPlugin, InfiniteScrollPlugin, IResponsiveTablePlugin };
|
|
10
|
-
export default ResponsiveTable;
|
package/src/typings.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
declare module '*.css' {
|
|
2
|
-
const content: { [className: string]: string };
|
|
3
|
-
export default content;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
7
|
-
interface SvgrComponent extends React.StatelessComponent<React.SVGAttributes<SVGElement>> {}
|
|
8
|
-
|
|
9
|
-
declare module '*.svg' {
|
|
10
|
-
const svgUrl: string;
|
|
11
|
-
const svgComponent: SvgrComponent;
|
|
12
|
-
export default svgUrl;
|
|
13
|
-
export { svgComponent as ReactComponent };
|
|
14
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"outDir": "dist",
|
|
4
|
-
"module": "esnext",
|
|
5
|
-
"target": "es2015",
|
|
6
|
-
"lib": ["dom", "esnext"],
|
|
7
|
-
"moduleResolution": "node",
|
|
8
|
-
"jsx": "react",
|
|
9
|
-
"sourceMap": true,
|
|
10
|
-
"declaration": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"noImplicitReturns": true,
|
|
13
|
-
"noImplicitThis": true,
|
|
14
|
-
"noImplicitAny": true,
|
|
15
|
-
"strictNullChecks": true,
|
|
16
|
-
"noUnusedLocals": true,
|
|
17
|
-
"noUnusedParameters": true,
|
|
18
|
-
"allowSyntheticDefaultImports": true
|
|
19
|
-
},
|
|
20
|
-
"include": ["src"],
|
|
21
|
-
"exclude": ["node_modules", "dist"]
|
|
22
|
-
}
|
package/update-dependancies.sh
DELETED