jattac.libs.web.responsive-table 0.1.5 → 0.1.6

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.
@@ -1,381 +1,381 @@
1
- import React, { CSSProperties, Component, ReactNode } from 'react';
2
- import styles from '../Styles/ResponsiveTable.module.css';
3
- import IResponsiveTableColumnDefinition from '../Data/IResponsiveTableColumnDefinition';
4
- import IFooterRowDefinition from '../Data/IFooterRowDefinition';
5
-
6
- export type ColumnDefinition<TData> =
7
- | IResponsiveTableColumnDefinition<TData>
8
- | ((data: TData, rowIndex?: number) => IResponsiveTableColumnDefinition<TData>);
9
- interface IProps<TData> {
10
- columnDefinitions: ColumnDefinition<TData>[];
11
- data: TData[];
12
- noDataComponent?: ReactNode;
13
- maxHeight?: string;
14
- onRowClick?: (item: TData) => void;
15
- footerRows?: IFooterRowDefinition[];
16
- mobileBreakpoint?: number;
17
- isLoading?: boolean;
18
- animateOnLoad?: boolean;
19
- }
20
-
21
- interface IState {
22
- isMobile: boolean;
23
- }
24
-
25
- // Class component
26
- class ResponsiveTable<TData> extends Component<IProps<TData>, IState> {
27
- private debouncedResize: () => void;
28
-
29
- constructor(props: IProps<TData>) {
30
- super(props);
31
- this.state = {
32
- isMobile: false,
33
- };
34
-
35
- this.debouncedResize = this.debounce(this.handleResize, 200);
36
- }
37
-
38
- private get mobileBreakpoint(): number {
39
- return this.props.mobileBreakpoint || 600;
40
- }
41
-
42
- private debounce(func: () => void, delay: number): () => void {
43
- let timeout: NodeJS.Timeout;
44
- return () => {
45
- clearTimeout(timeout);
46
- timeout = setTimeout(() => func(), delay);
47
- };
48
- }
49
-
50
- private get data(): TData[] {
51
- if (Array.isArray(this.props.data) && this.props.data.length > 0) {
52
- return this.props.data;
53
- } else {
54
- return [];
55
- }
56
- }
57
-
58
- private get noDataSvg(): ReactNode {
59
- return (
60
- <svg xmlns="http://www.w3.org/2000/svg" fill="#ccc" height="40" width="40" viewBox="0 0 24 24">
61
- <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" />
62
- </svg>
63
- );
64
- }
65
-
66
- private get hasData(): boolean {
67
- return this.data.length > 0;
68
- }
69
-
70
- private get noDataComponent(): ReactNode {
71
- return (
72
- this.props.noDataComponent || (
73
- <div className={styles.noDataWrapper}>
74
- {this.noDataSvg}
75
- <div className={styles.noData}>No data</div>
76
- </div>
77
- )
78
- );
79
- }
80
-
81
- componentDidMount(): void {
82
- this.handleResize(); // Initial check
83
- window.addEventListener('resize', this.debouncedResize);
84
- }
85
-
86
- componentWillUnmount(): void {
87
- window.removeEventListener('resize', this.debouncedResize);
88
- }
89
-
90
- handleResize = (): void => {
91
- this.setState({
92
- isMobile: window.innerWidth <= this.mobileBreakpoint,
93
- });
94
- };
95
-
96
- private getColumnDefinition(
97
- columnDefinition: ColumnDefinition<TData>,
98
- rowIndex: number,
99
- ): IResponsiveTableColumnDefinition<TData> {
100
- if (!this.hasData) {
101
- return { displayLabel: '', cellRenderer: () => '' };
102
- }
103
- return columnDefinition instanceof Function ? columnDefinition(this.data[0], rowIndex) : columnDefinition;
104
- }
105
-
106
- private getRawColumnDefinition(columnDefinition: ColumnDefinition<TData>): IResponsiveTableColumnDefinition<TData> {
107
- let rawColumnDefinition: IResponsiveTableColumnDefinition<TData> = {} as IResponsiveTableColumnDefinition<TData>;
108
- if (columnDefinition instanceof Function) {
109
- rawColumnDefinition = columnDefinition(this.data[0], 0);
110
- } else {
111
- rawColumnDefinition = columnDefinition as IResponsiveTableColumnDefinition<TData>;
112
- }
113
- return rawColumnDefinition;
114
- }
115
-
116
- private onHeaderClickCallback(columnDefinition: ColumnDefinition<TData>): ((id: string) => void) | undefined {
117
- const rawColumnDefinition = this.getRawColumnDefinition(columnDefinition);
118
- if (rawColumnDefinition.interactivity && rawColumnDefinition.interactivity.onHeaderClick) {
119
- return rawColumnDefinition.interactivity.onHeaderClick;
120
- } else {
121
- return undefined;
122
- }
123
- }
124
-
125
- private getClickableHeaderClassName(
126
- onHeaderClickCallback: ((id: string) => void) | undefined,
127
- colDef: ColumnDefinition<TData>,
128
- ): string {
129
- const rawColumnDefinition = this.getRawColumnDefinition(colDef);
130
- const clickableHeaderClassName = onHeaderClickCallback
131
- ? rawColumnDefinition.interactivity!.className || styles.clickableHeader
132
- : '';
133
- return clickableHeaderClassName;
134
- }
135
-
136
- private get rowClickFunction(): (item: TData) => void {
137
- if (this.props.onRowClick) {
138
- return this.props.onRowClick;
139
- } else {
140
- return () => {};
141
- }
142
- }
143
-
144
- private get rowClickStyle(): CSSProperties {
145
- if (this.props.onRowClick) {
146
- return { cursor: 'pointer' } as CSSProperties;
147
- } else {
148
- return {};
149
- }
150
- }
151
-
152
- private get tableFooter(): ReactNode {
153
- if (!this.props.footerRows || this.props.footerRows.length === 0) {
154
- return null;
155
- }
156
-
157
- return (
158
- <tfoot>
159
- {this.props.footerRows.map((row, rowIndex) => (
160
- <tr key={rowIndex}>
161
- {row.columns.map((col, colIndex) => (
162
- <td
163
- key={colIndex}
164
- colSpan={col.colSpan}
165
- className={`${styles.footerCell} ${col.className || ''} ${col.onCellClick ? styles.clickableFooterCell : ''}`}
166
- onClick={col.onCellClick}
167
- >
168
- {col.cellRenderer()}
169
- </td>
170
- ))}
171
- </tr>
172
- ))}
173
- </tfoot>
174
- );
175
- }
176
-
177
- private get mobileFooter(): ReactNode {
178
- if (!this.props.footerRows || this.props.footerRows.length === 0) {
179
- return null;
180
- }
181
-
182
- return (
183
- <div className={styles.footerCard}>
184
- <div className={styles['footer-card-body']}>
185
- {this.props.footerRows.map((row, rowIndex) => {
186
- let currentColumnIndex = 0;
187
- return (
188
- <div key={rowIndex}>
189
- {row.columns.map((col, colIndex) => {
190
- let label = col.displayLabel;
191
- if (!label && col.colSpan === 1) {
192
- const header = this.props.columnDefinitions[currentColumnIndex];
193
- if (header) {
194
- label = this.getRawColumnDefinition(header).displayLabel;
195
- }
196
- }
197
- currentColumnIndex += col.colSpan;
198
- return (
199
- <p
200
- key={colIndex}
201
- className={`${styles['footer-card-row']} ${col.className || ''} ${
202
- col.onCellClick ? styles.clickableFooterCell : ''
203
- }`}
204
- onClick={col.onCellClick}
205
- >
206
- {label && <span className={styles['card-label']}>{label}</span>}
207
- <span className={styles['card-value']}>{col.cellRenderer()}</span>
208
- </p>
209
- );
210
- })}
211
- </div>
212
- );
213
- })}
214
- </div>
215
- </div>
216
- );
217
- }
218
-
219
- private get skeletonView(): ReactNode {
220
- const skeletonRowCount = 5; // Or make this configurable
221
- const columnCount = this.props.columnDefinitions.length;
222
-
223
- if (this.state.isMobile) {
224
- return (
225
- <div>
226
- {[...Array(skeletonRowCount)].map((_, i) => (
227
- <div key={i} className={styles.skeletonCard}>
228
- {[...Array(columnCount)].map((_, j) => (
229
- <div key={j} className={`${styles.skeleton} ${styles.skeletonText}`} style={{ marginBottom: '0.5rem' }} />
230
- ))}
231
- </div>
232
- ))}
233
- </div>
234
- );
235
- }
236
-
237
- return (
238
- <table className={styles.responsiveTable}>
239
- <thead>
240
- <tr>
241
- {[...Array(columnCount)].map((_, i) => (
242
- <th key={i}>
243
- <div className={`${styles.skeleton} ${styles.skeletonText}`} />
244
- </th>
245
- ))}
246
- </tr>
247
- </thead>
248
- <tbody>
249
- {[...Array(skeletonRowCount)].map((_, i) => (
250
- <tr key={i}>
251
- {[...Array(columnCount)].map((_, j) => (
252
- <td key={j}>
253
- <div className={`${styles.skeleton} ${styles.skeletonText}`} />
254
- </td>
255
- ))}
256
- </tr>
257
- ))}
258
- </tbody>
259
- </table>
260
- );
261
- }
262
-
263
- private get mobileView(): ReactNode {
264
- return (
265
- <div>
266
- {this.data.map((row, rowIndex) => (
267
- <div
268
- key={rowIndex}
269
- className={`${styles['card']} ${this.props.animateOnLoad ? styles.animatedRow : ''}`}
270
- style={{ animationDelay: `${rowIndex * 0.05}s` }}
271
- onClick={(e) => {
272
- this.rowClickFunction(row);
273
- e.stopPropagation();
274
- e.preventDefault();
275
- }}
276
- >
277
- <div className={styles['card-header']}> </div>
278
- <div className={styles['card-body']}>
279
- {this.props.columnDefinitions.map((columnDefinition, colIndex) => {
280
- const colDef = this.getColumnDefinition(columnDefinition, rowIndex);
281
- const onHeaderClickCallback = this.onHeaderClickCallback(colDef);
282
- const clickableHeaderClassName = this.getClickableHeaderClassName(onHeaderClickCallback, colDef);
283
- return (
284
- <div key={colIndex} className={styles['card-row']}>
285
- <p>
286
- <span
287
- className={`${styles['card-label']} ${clickableHeaderClassName}`}
288
- onClick={
289
- onHeaderClickCallback ? () => onHeaderClickCallback(colDef.interactivity!.id) : undefined
290
- }
291
- >
292
- {colDef.displayLabel}
293
- </span>
294
- <span className={styles['card-value']}>{colDef.cellRenderer(row)}</span>
295
- </p>
296
- </div>
297
- );
298
- })}
299
- </div>
300
- </div>
301
- ))}
302
- {this.mobileFooter}
303
- </div>
304
- );
305
- }
306
-
307
- private get largeScreenView(): ReactNode {
308
- const useFixedHeaders = this.props.maxHeight ? true : false;
309
-
310
- const fixedHeadersStyle = useFixedHeaders
311
- ? ({ maxHeight: this.props.maxHeight, overflowY: 'auto' } as CSSProperties)
312
- : {};
313
-
314
- return (
315
- <div style={fixedHeadersStyle}>
316
- <table className={styles['responsiveTable']} style={{ zIndex: -1 }}>
317
- <thead>
318
- <tr>
319
- {this.props.columnDefinitions.map((columnDefinition, colIndex) => {
320
- const onHeaderClickCallback = this.onHeaderClickCallback(columnDefinition);
321
- const clickableHeaderClassName = this.getClickableHeaderClassName(
322
- onHeaderClickCallback,
323
- columnDefinition,
324
- );
325
- return (
326
- <th
327
- key={colIndex}
328
- className={`${clickableHeaderClassName}`}
329
- style={{ zIndex: 0 }}
330
- onClick={
331
- onHeaderClickCallback
332
- ? () => onHeaderClickCallback(this.getColumnDefinition(columnDefinition, 0).interactivity!.id)
333
- : undefined
334
- }
335
- >
336
- {this.getColumnDefinition(columnDefinition, 0).displayLabel}
337
- </th>
338
- );
339
- })}
340
- </tr>
341
- </thead>
342
- <tbody>
343
- {this.data.map((row, rowIndex) => (
344
- <tr
345
- key={rowIndex}
346
- className={this.props.animateOnLoad ? styles.animatedRow : ''}
347
- style={{ animationDelay: `${rowIndex * 0.05}s` }}
348
- >
349
- {this.props.columnDefinitions.map((columnDefinition, colIndex) => (
350
- <td onClick={() => this.rowClickFunction(row)} key={colIndex}>
351
- <span style={{ ...this.rowClickStyle }}>
352
- {this.getColumnDefinition(columnDefinition, rowIndex).cellRenderer(row)}
353
- </span>
354
- </td>
355
- ))}
356
- </tr>
357
- ))}
358
- </tbody>
359
- {this.tableFooter}
360
- </table>
361
- </div>
362
- );
363
- }
364
-
365
- render() {
366
- if (this.props.isLoading) {
367
- return this.skeletonView;
368
- }
369
-
370
- if (!this.hasData) {
371
- return this.noDataComponent;
372
- }
373
- if (this.state.isMobile) {
374
- return this.mobileView;
375
- }
376
-
377
- return this.largeScreenView;
378
- }
379
- }
380
-
381
- export default ResponsiveTable;
1
+ import React, { CSSProperties, Component, ReactNode } from 'react';
2
+ import styles from '../Styles/ResponsiveTable.module.css';
3
+ import IResponsiveTableColumnDefinition from '../Data/IResponsiveTableColumnDefinition';
4
+ import IFooterRowDefinition from '../Data/IFooterRowDefinition';
5
+
6
+ export type ColumnDefinition<TData> =
7
+ | IResponsiveTableColumnDefinition<TData>
8
+ | ((data: TData, rowIndex?: number) => IResponsiveTableColumnDefinition<TData>);
9
+ interface IProps<TData> {
10
+ columnDefinitions: ColumnDefinition<TData>[];
11
+ data: TData[];
12
+ noDataComponent?: ReactNode;
13
+ maxHeight?: string;
14
+ onRowClick?: (item: TData) => void;
15
+ footerRows?: IFooterRowDefinition[];
16
+ mobileBreakpoint?: number;
17
+ isLoading?: boolean;
18
+ animateOnLoad?: boolean;
19
+ }
20
+
21
+ interface IState {
22
+ isMobile: boolean;
23
+ }
24
+
25
+ // Class component
26
+ class ResponsiveTable<TData> extends Component<IProps<TData>, IState> {
27
+ private debouncedResize: () => void;
28
+
29
+ constructor(props: IProps<TData>) {
30
+ super(props);
31
+ this.state = {
32
+ isMobile: false,
33
+ };
34
+
35
+ this.debouncedResize = this.debounce(this.handleResize, 200);
36
+ }
37
+
38
+ private get mobileBreakpoint(): number {
39
+ return this.props.mobileBreakpoint || 600;
40
+ }
41
+
42
+ private debounce(func: () => void, delay: number): () => void {
43
+ let timeout: NodeJS.Timeout;
44
+ return () => {
45
+ clearTimeout(timeout);
46
+ timeout = setTimeout(() => func(), delay);
47
+ };
48
+ }
49
+
50
+ private get data(): TData[] {
51
+ if (Array.isArray(this.props.data) && this.props.data.length > 0) {
52
+ return this.props.data;
53
+ } else {
54
+ return [];
55
+ }
56
+ }
57
+
58
+ private get noDataSvg(): ReactNode {
59
+ return (
60
+ <svg xmlns="http://www.w3.org/2000/svg" fill="#ccc" height="40" width="40" viewBox="0 0 24 24">
61
+ <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" />
62
+ </svg>
63
+ );
64
+ }
65
+
66
+ private get hasData(): boolean {
67
+ return this.data.length > 0;
68
+ }
69
+
70
+ private get noDataComponent(): ReactNode {
71
+ return (
72
+ this.props.noDataComponent || (
73
+ <div className={styles.noDataWrapper}>
74
+ {this.noDataSvg}
75
+ <div className={styles.noData}>No data</div>
76
+ </div>
77
+ )
78
+ );
79
+ }
80
+
81
+ componentDidMount(): void {
82
+ this.handleResize(); // Initial check
83
+ window.addEventListener('resize', this.debouncedResize);
84
+ }
85
+
86
+ componentWillUnmount(): void {
87
+ window.removeEventListener('resize', this.debouncedResize);
88
+ }
89
+
90
+ handleResize = (): void => {
91
+ this.setState({
92
+ isMobile: window.innerWidth <= this.mobileBreakpoint,
93
+ });
94
+ };
95
+
96
+ private getColumnDefinition(
97
+ columnDefinition: ColumnDefinition<TData>,
98
+ rowIndex: number,
99
+ ): IResponsiveTableColumnDefinition<TData> {
100
+ if (!this.hasData) {
101
+ return { displayLabel: '', cellRenderer: () => '' };
102
+ }
103
+ return columnDefinition instanceof Function ? columnDefinition(this.data[0], rowIndex) : columnDefinition;
104
+ }
105
+
106
+ private getRawColumnDefinition(columnDefinition: ColumnDefinition<TData>): IResponsiveTableColumnDefinition<TData> {
107
+ let rawColumnDefinition: IResponsiveTableColumnDefinition<TData> = {} as IResponsiveTableColumnDefinition<TData>;
108
+ if (columnDefinition instanceof Function) {
109
+ rawColumnDefinition = columnDefinition(this.data[0], 0);
110
+ } else {
111
+ rawColumnDefinition = columnDefinition as IResponsiveTableColumnDefinition<TData>;
112
+ }
113
+ return rawColumnDefinition;
114
+ }
115
+
116
+ private onHeaderClickCallback(columnDefinition: ColumnDefinition<TData>): ((id: string) => void) | undefined {
117
+ const rawColumnDefinition = this.getRawColumnDefinition(columnDefinition);
118
+ if (rawColumnDefinition.interactivity && rawColumnDefinition.interactivity.onHeaderClick) {
119
+ return rawColumnDefinition.interactivity.onHeaderClick;
120
+ } else {
121
+ return undefined;
122
+ }
123
+ }
124
+
125
+ private getClickableHeaderClassName(
126
+ onHeaderClickCallback: ((id: string) => void) | undefined,
127
+ colDef: ColumnDefinition<TData>,
128
+ ): string {
129
+ const rawColumnDefinition = this.getRawColumnDefinition(colDef);
130
+ const clickableHeaderClassName = onHeaderClickCallback
131
+ ? rawColumnDefinition.interactivity!.className || styles.clickableHeader
132
+ : '';
133
+ return clickableHeaderClassName;
134
+ }
135
+
136
+ private get rowClickFunction(): (item: TData) => void {
137
+ if (this.props.onRowClick) {
138
+ return this.props.onRowClick;
139
+ } else {
140
+ return () => {};
141
+ }
142
+ }
143
+
144
+ private get rowClickStyle(): CSSProperties {
145
+ if (this.props.onRowClick) {
146
+ return { cursor: 'pointer' } as CSSProperties;
147
+ } else {
148
+ return {};
149
+ }
150
+ }
151
+
152
+ private get tableFooter(): ReactNode {
153
+ if (!this.props.footerRows || this.props.footerRows.length === 0) {
154
+ return null;
155
+ }
156
+
157
+ return (
158
+ <tfoot>
159
+ {this.props.footerRows.map((row, rowIndex) => (
160
+ <tr key={rowIndex}>
161
+ {row.columns.map((col, colIndex) => (
162
+ <td
163
+ key={colIndex}
164
+ colSpan={col.colSpan}
165
+ className={`${styles.footerCell} ${col.className || ''} ${col.onCellClick ? styles.clickableFooterCell : ''}`}
166
+ onClick={col.onCellClick}
167
+ >
168
+ {col.cellRenderer()}
169
+ </td>
170
+ ))}
171
+ </tr>
172
+ ))}
173
+ </tfoot>
174
+ );
175
+ }
176
+
177
+ private get mobileFooter(): ReactNode {
178
+ if (!this.props.footerRows || this.props.footerRows.length === 0) {
179
+ return null;
180
+ }
181
+
182
+ return (
183
+ <div className={styles.footerCard}>
184
+ <div className={styles['footer-card-body']}>
185
+ {this.props.footerRows.map((row, rowIndex) => {
186
+ let currentColumnIndex = 0;
187
+ return (
188
+ <div key={rowIndex}>
189
+ {row.columns.map((col, colIndex) => {
190
+ let label = col.displayLabel;
191
+ if (!label && col.colSpan === 1) {
192
+ const header = this.props.columnDefinitions[currentColumnIndex];
193
+ if (header) {
194
+ label = this.getRawColumnDefinition(header).displayLabel;
195
+ }
196
+ }
197
+ currentColumnIndex += col.colSpan;
198
+ return (
199
+ <p
200
+ key={colIndex}
201
+ className={`${styles['footer-card-row']} ${col.className || ''} ${
202
+ col.onCellClick ? styles.clickableFooterCell : ''
203
+ }`}
204
+ onClick={col.onCellClick}
205
+ >
206
+ {label && <span className={styles['card-label']}>{label}</span>}
207
+ <span className={styles['card-value']}>{col.cellRenderer()}</span>
208
+ </p>
209
+ );
210
+ })}
211
+ </div>
212
+ );
213
+ })}
214
+ </div>
215
+ </div>
216
+ );
217
+ }
218
+
219
+ private get skeletonView(): ReactNode {
220
+ const skeletonRowCount = 5; // Or make this configurable
221
+ const columnCount = this.props.columnDefinitions.length;
222
+
223
+ if (this.state.isMobile) {
224
+ return (
225
+ <div>
226
+ {[...Array(skeletonRowCount)].map((_, i) => (
227
+ <div key={i} className={styles.skeletonCard}>
228
+ {[...Array(columnCount)].map((_, j) => (
229
+ <div key={j} className={`${styles.skeleton} ${styles.skeletonText}`} style={{ marginBottom: '0.5rem' }} />
230
+ ))}
231
+ </div>
232
+ ))}
233
+ </div>
234
+ );
235
+ }
236
+
237
+ return (
238
+ <table className={styles.responsiveTable}>
239
+ <thead>
240
+ <tr>
241
+ {[...Array(columnCount)].map((_, i) => (
242
+ <th key={i}>
243
+ <div className={`${styles.skeleton} ${styles.skeletonText}`} />
244
+ </th>
245
+ ))}
246
+ </tr>
247
+ </thead>
248
+ <tbody>
249
+ {[...Array(skeletonRowCount)].map((_, i) => (
250
+ <tr key={i}>
251
+ {[...Array(columnCount)].map((_, j) => (
252
+ <td key={j}>
253
+ <div className={`${styles.skeleton} ${styles.skeletonText}`} />
254
+ </td>
255
+ ))}
256
+ </tr>
257
+ ))}
258
+ </tbody>
259
+ </table>
260
+ );
261
+ }
262
+
263
+ private get mobileView(): ReactNode {
264
+ return (
265
+ <div>
266
+ {this.data.map((row, rowIndex) => (
267
+ <div
268
+ key={rowIndex}
269
+ className={`${styles['card']} ${this.props.animateOnLoad ? styles.animatedRow : ''}`}
270
+ style={{ animationDelay: `${rowIndex * 0.05}s` }}
271
+ onClick={(e) => {
272
+ this.rowClickFunction(row);
273
+ e.stopPropagation();
274
+ e.preventDefault();
275
+ }}
276
+ >
277
+ <div className={styles['card-header']}> </div>
278
+ <div className={styles['card-body']}>
279
+ {this.props.columnDefinitions.map((columnDefinition, colIndex) => {
280
+ const colDef = this.getColumnDefinition(columnDefinition, rowIndex);
281
+ const onHeaderClickCallback = this.onHeaderClickCallback(colDef);
282
+ const clickableHeaderClassName = this.getClickableHeaderClassName(onHeaderClickCallback, colDef);
283
+ return (
284
+ <div key={colIndex} className={styles['card-row']}>
285
+ <p>
286
+ <span
287
+ className={`${styles['card-label']} ${clickableHeaderClassName}`}
288
+ onClick={
289
+ onHeaderClickCallback ? () => onHeaderClickCallback(colDef.interactivity!.id) : undefined
290
+ }
291
+ >
292
+ {colDef.displayLabel}
293
+ </span>
294
+ <span className={styles['card-value']}>{colDef.cellRenderer(row)}</span>
295
+ </p>
296
+ </div>
297
+ );
298
+ })}
299
+ </div>
300
+ </div>
301
+ ))}
302
+ {this.mobileFooter}
303
+ </div>
304
+ );
305
+ }
306
+
307
+ private get largeScreenView(): ReactNode {
308
+ const useFixedHeaders = this.props.maxHeight ? true : false;
309
+
310
+ const fixedHeadersStyle = useFixedHeaders
311
+ ? ({ maxHeight: this.props.maxHeight, overflowY: 'auto' } as CSSProperties)
312
+ : {};
313
+
314
+ return (
315
+ <div style={fixedHeadersStyle}>
316
+ <table className={styles['responsiveTable']} style={{ zIndex: -1 }}>
317
+ <thead>
318
+ <tr>
319
+ {this.props.columnDefinitions.map((columnDefinition, colIndex) => {
320
+ const onHeaderClickCallback = this.onHeaderClickCallback(columnDefinition);
321
+ const clickableHeaderClassName = this.getClickableHeaderClassName(
322
+ onHeaderClickCallback,
323
+ columnDefinition,
324
+ );
325
+ return (
326
+ <th
327
+ key={colIndex}
328
+ className={`${clickableHeaderClassName}`}
329
+ style={{ zIndex: 0 }}
330
+ onClick={
331
+ onHeaderClickCallback
332
+ ? () => onHeaderClickCallback(this.getColumnDefinition(columnDefinition, 0).interactivity!.id)
333
+ : undefined
334
+ }
335
+ >
336
+ {this.getColumnDefinition(columnDefinition, 0).displayLabel}
337
+ </th>
338
+ );
339
+ })}
340
+ </tr>
341
+ </thead>
342
+ <tbody>
343
+ {this.data.map((row, rowIndex) => (
344
+ <tr
345
+ key={rowIndex}
346
+ className={this.props.animateOnLoad ? styles.animatedRow : ''}
347
+ style={{ animationDelay: `${rowIndex * 0.05}s` }}
348
+ >
349
+ {this.props.columnDefinitions.map((columnDefinition, colIndex) => (
350
+ <td onClick={() => this.rowClickFunction(row)} key={colIndex}>
351
+ <span style={{ ...this.rowClickStyle }}>
352
+ {this.getColumnDefinition(columnDefinition, rowIndex).cellRenderer(row)}
353
+ </span>
354
+ </td>
355
+ ))}
356
+ </tr>
357
+ ))}
358
+ </tbody>
359
+ {this.tableFooter}
360
+ </table>
361
+ </div>
362
+ );
363
+ }
364
+
365
+ render() {
366
+ if (this.props.isLoading) {
367
+ return this.skeletonView;
368
+ }
369
+
370
+ if (!this.hasData) {
371
+ return this.noDataComponent;
372
+ }
373
+ if (this.state.isMobile) {
374
+ return this.mobileView;
375
+ }
376
+
377
+ return this.largeScreenView;
378
+ }
379
+ }
380
+
381
+ export default ResponsiveTable;