@propellerads/table 5.0.4 → 5.1.1
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/dist/index.d.ts +5 -4
- package/dist/propsGetter.d.ts +1 -1
- package/dist/table.cjs.development.js +213 -143
- package/dist/table.cjs.development.js.map +1 -1
- package/dist/table.cjs.production.min.js +1 -1
- package/dist/table.cjs.production.min.js.map +1 -1
- package/dist/table.esm.js +213 -143
- package/dist/table.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/index.tsx +152 -128
- package/src/propsGetter.tsx +5 -7
- package/src/useTableShadow.tsx +0 -1
package/src/index.tsx
CHANGED
|
@@ -1,65 +1,62 @@
|
|
|
1
|
+
import {ArrowDown, ArrowUp, Color, Size} from '@propellerads/icon';
|
|
2
|
+
import Checkbox from '@propellerads/input-checkbox';
|
|
1
3
|
import React, {FunctionComponent, useEffect, useMemo, useRef} from 'react';
|
|
2
4
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
useRowSelect,
|
|
6
|
-
usePagination,
|
|
5
|
+
Column,
|
|
6
|
+
TableState,
|
|
7
7
|
useExpanded,
|
|
8
8
|
useFlexLayout,
|
|
9
|
+
usePagination,
|
|
9
10
|
useResizeColumns,
|
|
10
|
-
|
|
11
|
+
useRowSelect,
|
|
12
|
+
useSortBy,
|
|
13
|
+
useTable,
|
|
11
14
|
} from 'react-table';
|
|
12
|
-
|
|
13
|
-
import {ArrowDown, ArrowUp, Color, Size} from '@propellerads/icon';
|
|
14
|
-
import Checkbox from '@propellerads/input-checkbox';
|
|
15
|
-
|
|
16
|
-
import useLoadingState from './useLoadingState';
|
|
17
|
-
import useTableShadow from './useTableShadow';
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
FOOTER_PLACEMENT,
|
|
21
|
-
TableProps,
|
|
22
|
-
PaginationProps,
|
|
23
|
-
StandardHooks,
|
|
24
|
-
StandardColumn,
|
|
25
|
-
StandardRow,
|
|
26
|
-
StandardCell,
|
|
27
|
-
ColumnWithSort,
|
|
28
|
-
TableHooksInstanceProps,
|
|
29
|
-
TableOptionsProps,
|
|
30
|
-
SelectableRow,
|
|
31
|
-
DefaultObject,
|
|
32
|
-
} from './types';
|
|
33
|
-
|
|
34
15
|
import {
|
|
35
|
-
getTableProps as getTableBodyProps,
|
|
36
|
-
getTableElementProps,
|
|
37
|
-
getTableElementInternalProps,
|
|
38
16
|
cellGetter,
|
|
39
|
-
|
|
17
|
+
getTableProps as getTableBodyProps,
|
|
40
18
|
getTableCellProps,
|
|
19
|
+
getTableElementInternalProps,
|
|
20
|
+
getTableElementProps,
|
|
41
21
|
getTableRowProps,
|
|
22
|
+
mainCellGetter,
|
|
42
23
|
} from './propsGetter';
|
|
43
|
-
|
|
44
24
|
import {
|
|
45
|
-
|
|
46
|
-
TableWrapper as _TableWrapper,
|
|
47
|
-
TableContent as _TableContent,
|
|
25
|
+
EmptyStateCell as _EmptyStateCell,
|
|
48
26
|
HeadCell as _HeadCell,
|
|
27
|
+
TableContent as _TableContent,
|
|
28
|
+
TableCore as _TableCore,
|
|
49
29
|
TableLoading as _TableLoading,
|
|
50
30
|
TableLoadingInner as _TableLoadingInner,
|
|
31
|
+
TableRoot as _TableRoot,
|
|
32
|
+
TableWrapper as _TableWrapper,
|
|
33
|
+
TBody as _TBody,
|
|
51
34
|
TD as _TD,
|
|
52
|
-
|
|
35
|
+
TFoot as _TFoot,
|
|
36
|
+
TH as _TH,
|
|
53
37
|
THead as _THead,
|
|
54
38
|
TR as _TR,
|
|
55
|
-
TH as _TH,
|
|
56
|
-
TBody as _TBody,
|
|
57
|
-
TRGroup as _TRGroup,
|
|
58
|
-
TFoot as _TFoot,
|
|
59
|
-
EmptyStateCell as _EmptyStateCell,
|
|
60
39
|
TResizer as _TResizer,
|
|
40
|
+
TRGroup as _TRGroup,
|
|
61
41
|
} from './style';
|
|
62
42
|
|
|
43
|
+
import {
|
|
44
|
+
ColumnWithSort,
|
|
45
|
+
DefaultObject,
|
|
46
|
+
FOOTER_PLACEMENT,
|
|
47
|
+
PaginationProps,
|
|
48
|
+
SelectableRow,
|
|
49
|
+
StandardCell,
|
|
50
|
+
StandardColumn,
|
|
51
|
+
StandardHooks,
|
|
52
|
+
StandardRow,
|
|
53
|
+
TableHooksInstanceProps,
|
|
54
|
+
TableOptionsProps,
|
|
55
|
+
TableProps,
|
|
56
|
+
} from './types';
|
|
57
|
+
import useLoadingState from './useLoadingState';
|
|
58
|
+
import useTableShadow from './useTableShadow';
|
|
59
|
+
|
|
63
60
|
const TableRoot = _TableRoot as unknown as React.FunctionComponent<DefaultObject>;
|
|
64
61
|
const TableWrapper = _TableWrapper as unknown as React.FunctionComponent<DefaultObject>;
|
|
65
62
|
const TableContent = _TableContent as unknown as React.FunctionComponent<DefaultObject>;
|
|
@@ -77,20 +74,20 @@ const TFoot = _TFoot as unknown as React.FunctionComponent<DefaultObject>;
|
|
|
77
74
|
const EmptyStateCell = _EmptyStateCell as unknown as React.FunctionComponent<DefaultObject>;
|
|
78
75
|
const TResizer = _TResizer as unknown as React.FunctionComponent<DefaultObject>;
|
|
79
76
|
|
|
80
|
-
const isEnableRowSelectDefault: () => boolean = () => true;
|
|
77
|
+
const isEnableRowSelectDefault: (_original?: DefaultObject) => boolean = () => true;
|
|
81
78
|
const selectColumnPropsDefault = {};
|
|
82
79
|
const getRowPrePropsDefault: () => DefaultObject = () => ({});
|
|
83
80
|
|
|
84
81
|
export const defaultProps = {
|
|
85
82
|
hasDefaultPagination: false,
|
|
86
83
|
isLoading: false,
|
|
87
|
-
footerPlacement: [],
|
|
84
|
+
footerPlacement: [] as FOOTER_PLACEMENT[],
|
|
88
85
|
loadingMessage: 'loading...',
|
|
89
86
|
labelPerPage: 'Show rows',
|
|
90
87
|
parentElementId: 'parent-element',
|
|
91
88
|
tableContentId: '',
|
|
92
89
|
showLoadingState: false,
|
|
93
|
-
initialState: {}
|
|
90
|
+
initialState: {} as Partial<TableState<DefaultObject>>,
|
|
94
91
|
LoadingCellComponent: EmptyStateCell,
|
|
95
92
|
getRowPreProps: getRowPrePropsDefault,
|
|
96
93
|
isEnableRowSelect: isEnableRowSelectDefault,
|
|
@@ -149,40 +146,38 @@ function getHeadContent(column: ColumnWithSort) {
|
|
|
149
146
|
return column.render('Header');
|
|
150
147
|
}
|
|
151
148
|
|
|
152
|
-
const Table: FunctionComponent<TableProps & DefaultProps> = (
|
|
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
|
-
} = props;
|
|
185
|
-
|
|
149
|
+
const Table: FunctionComponent<TableProps & DefaultProps> = ({
|
|
150
|
+
columns,
|
|
151
|
+
data,
|
|
152
|
+
totalItems,
|
|
153
|
+
fetchData,
|
|
154
|
+
controlledPagination,
|
|
155
|
+
initialState = defaultProps.initialState,
|
|
156
|
+
isLoading = defaultProps.isLoading,
|
|
157
|
+
loadingMessage = defaultProps.loadingMessage,
|
|
158
|
+
labelPerPage = defaultProps.labelPerPage,
|
|
159
|
+
footerPlacement = defaultProps.footerPlacement,
|
|
160
|
+
onSortedChange,
|
|
161
|
+
hasDefaultPagination = defaultProps.hasDefaultPagination,
|
|
162
|
+
onSelectRowsChange,
|
|
163
|
+
parentElementId = defaultProps.parentElementId,
|
|
164
|
+
tableContentId = defaultProps.tableContentId,
|
|
165
|
+
LoadingCellComponent = defaultProps.LoadingCellComponent,
|
|
166
|
+
PaginationComponent,
|
|
167
|
+
getRowPreProps = defaultProps.getRowPreProps as NonNullable<TableProps['getRowPreProps']>,
|
|
168
|
+
getTableProps,
|
|
169
|
+
getHeaderGroupProps,
|
|
170
|
+
getHeaderProps,
|
|
171
|
+
getRowProps,
|
|
172
|
+
getCellProps,
|
|
173
|
+
getFooterProps,
|
|
174
|
+
getFooterGroupProps,
|
|
175
|
+
showLoadingState = defaultProps.showLoadingState,
|
|
176
|
+
noDataMessage = defaultProps.noDataMessage,
|
|
177
|
+
rowSubComponent,
|
|
178
|
+
isEnableRowSelect = defaultProps.isEnableRowSelect,
|
|
179
|
+
selectColumnProps = defaultProps.selectColumnProps,
|
|
180
|
+
}) => {
|
|
186
181
|
const memoColumns = useMemo(() => columns, [columns]);
|
|
187
182
|
|
|
188
183
|
const {loadingColumns, loadingData} = useLoadingState(
|
|
@@ -303,7 +298,6 @@ const Table: FunctionComponent<TableProps & DefaultProps> = (props) => {
|
|
|
303
298
|
previousPage,
|
|
304
299
|
setPageSize,
|
|
305
300
|
state: {selectedRowIds, pageIndex, pageSize},
|
|
306
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
307
301
|
// @ts-ignore
|
|
308
302
|
} = rest as TableHooksInstanceProps;
|
|
309
303
|
|
|
@@ -420,36 +414,50 @@ const Table: FunctionComponent<TableProps & DefaultProps> = (props) => {
|
|
|
420
414
|
<TableContent id={tableContentId} className="table-content">
|
|
421
415
|
<TableCore {..._getTableProps(getTableBodyProps(getTableProps))} ref={tableRef}>
|
|
422
416
|
<THead className="table-head" data-role="table-head">
|
|
423
|
-
{headerGroups.map((headerGroup) =>
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
)
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
417
|
+
{headerGroups.map((headerGroup) => {
|
|
418
|
+
const {key: headerGroupKey, ...headerGroupProps} = headerGroup.getHeaderGroupProps(
|
|
419
|
+
getTableElementProps(getHeaderGroupProps),
|
|
420
|
+
);
|
|
421
|
+
return (
|
|
422
|
+
<TR key={headerGroupKey} {...headerGroupProps}>
|
|
423
|
+
{headerGroup.headers.map((column) => {
|
|
424
|
+
const headerProps = extendSortByProps(column) as DefaultObject;
|
|
425
|
+
const {key: columnKey, ...thProps} = column.getHeaderProps(
|
|
426
|
+
getTableElementInternalProps(headerProps, getHeaderProps, mainCellGetter),
|
|
427
|
+
);
|
|
428
|
+
|
|
429
|
+
return (
|
|
430
|
+
<TH key={columnKey} {...thProps}>
|
|
431
|
+
{getHeadContent(column)}
|
|
432
|
+
{renderResizer(column)}
|
|
433
|
+
</TH>
|
|
434
|
+
);
|
|
435
|
+
})}
|
|
436
|
+
</TR>
|
|
437
|
+
);
|
|
438
|
+
})}
|
|
441
439
|
</THead>
|
|
442
440
|
{footerPlacement.includes(FOOTER_PLACEMENT.TOP) && (
|
|
443
441
|
<TFoot className="table-footer-top" data-role="table-footer-top">
|
|
444
|
-
{footerGroups.map((group) =>
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
442
|
+
{footerGroups.map((group) => {
|
|
443
|
+
const {key: footerTopGroupKey, ...footerTopGroupProps} = group.getFooterGroupProps(
|
|
444
|
+
getTableElementProps(getFooterGroupProps),
|
|
445
|
+
);
|
|
446
|
+
return (
|
|
447
|
+
<TR key={footerTopGroupKey} {...footerTopGroupProps}>
|
|
448
|
+
{group.headers.map((column) => {
|
|
449
|
+
const {key: footerTopColumnKey, ...footerTopTdProps} = column.getFooterProps(
|
|
450
|
+
getTableElementProps(getFooterProps, mainCellGetter),
|
|
451
|
+
);
|
|
452
|
+
return (
|
|
453
|
+
<TD key={footerTopColumnKey} {...footerTopTdProps}>
|
|
454
|
+
{column.render('Footer')}
|
|
455
|
+
</TD>
|
|
456
|
+
);
|
|
457
|
+
})}
|
|
458
|
+
</TR>
|
|
459
|
+
);
|
|
460
|
+
})}
|
|
453
461
|
</TFoot>
|
|
454
462
|
)}
|
|
455
463
|
<TBody className="table-body" data-role="table-body">
|
|
@@ -459,15 +467,16 @@ const Table: FunctionComponent<TableProps & DefaultProps> = (props) => {
|
|
|
459
467
|
|
|
460
468
|
if (isDelimiterTd) {
|
|
461
469
|
const cell = row.cells[0].render('Cell') as React.ReactNode;
|
|
470
|
+
const {key: delimiterRowKey, ...delimiterRowProps} = row.getRowProps(getTableRowProps(getRowProps));
|
|
471
|
+
const {key: delimiterCellKey, ...delimiterCellProps} = row.cells[0].getCellProps(
|
|
472
|
+
getTableCellProps(getCellProps, cellGetter),
|
|
473
|
+
);
|
|
462
474
|
|
|
463
475
|
return (
|
|
464
476
|
<React.Fragment key={`group_${row.index}`}>
|
|
465
477
|
<TRGroup>
|
|
466
|
-
<TR {...
|
|
467
|
-
<TD
|
|
468
|
-
colSpan={visibleColumns.length}
|
|
469
|
-
{...row.cells[0].getCellProps(getTableCellProps(getCellProps, cellGetter))}
|
|
470
|
-
>
|
|
478
|
+
<TR key={delimiterRowKey} {...delimiterRowProps}>
|
|
479
|
+
<TD key={delimiterCellKey} colSpan={visibleColumns.length} {...delimiterCellProps}>
|
|
471
480
|
<strong>{cell}</strong>
|
|
472
481
|
</TD>
|
|
473
482
|
</TR>
|
|
@@ -477,15 +486,22 @@ const Table: FunctionComponent<TableProps & DefaultProps> = (props) => {
|
|
|
477
486
|
);
|
|
478
487
|
}
|
|
479
488
|
|
|
489
|
+
const {key: rowKey, ...rowProps} = row.getRowProps(getTableRowProps(getRowProps));
|
|
490
|
+
|
|
480
491
|
return (
|
|
481
492
|
<React.Fragment key={`group_${row.index}`}>
|
|
482
493
|
<TRGroup>
|
|
483
|
-
<TR {...
|
|
484
|
-
{row.cells.map((cell: StandardCell) =>
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
494
|
+
<TR key={rowKey} {...rowProps}>
|
|
495
|
+
{row.cells.map((cell: StandardCell) => {
|
|
496
|
+
const {key: cellKey, ...cellProps} = cell.getCellProps(
|
|
497
|
+
getTableCellProps(getCellProps, cellGetter),
|
|
498
|
+
);
|
|
499
|
+
return (
|
|
500
|
+
<TD key={cellKey} {...cellProps}>
|
|
501
|
+
{cell.render('Cell')}
|
|
502
|
+
</TD>
|
|
503
|
+
);
|
|
504
|
+
})}
|
|
489
505
|
</TR>
|
|
490
506
|
</TRGroup>
|
|
491
507
|
{row?.isExpanded && rowSubComponent && rowSubComponent(row)}
|
|
@@ -495,15 +511,25 @@ const Table: FunctionComponent<TableProps & DefaultProps> = (props) => {
|
|
|
495
511
|
</TBody>
|
|
496
512
|
{footerPlacement.includes(FOOTER_PLACEMENT.BOTTOM) && (
|
|
497
513
|
<TFoot className="table-footer-bottom" data-role="table-footer-bottom">
|
|
498
|
-
{footerGroups.map((group) =>
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
514
|
+
{footerGroups.map((group) => {
|
|
515
|
+
const {key: footerBottomGroupKey, ...footerBottomGroupProps} = group.getFooterGroupProps(
|
|
516
|
+
getTableElementProps(getFooterGroupProps),
|
|
517
|
+
);
|
|
518
|
+
return (
|
|
519
|
+
<TR key={footerBottomGroupKey} {...footerBottomGroupProps}>
|
|
520
|
+
{group.headers.map((column) => {
|
|
521
|
+
const {key: footerBottomColumnKey, ...footerBottomTdProps} = column.getFooterProps(
|
|
522
|
+
getTableElementProps(getFooterProps, mainCellGetter),
|
|
523
|
+
);
|
|
524
|
+
return (
|
|
525
|
+
<TD key={footerBottomColumnKey} {...footerBottomTdProps}>
|
|
526
|
+
{column.render('Footer')}
|
|
527
|
+
</TD>
|
|
528
|
+
);
|
|
529
|
+
})}
|
|
530
|
+
</TR>
|
|
531
|
+
);
|
|
532
|
+
})}
|
|
507
533
|
</TFoot>
|
|
508
534
|
)}
|
|
509
535
|
</TableCore>
|
|
@@ -515,6 +541,4 @@ const Table: FunctionComponent<TableProps & DefaultProps> = (props) => {
|
|
|
515
541
|
);
|
|
516
542
|
};
|
|
517
543
|
|
|
518
|
-
Table.defaultProps = defaultProps;
|
|
519
|
-
|
|
520
544
|
export {Table};
|
package/src/propsGetter.tsx
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ElementGetter,
|
|
3
2
|
BaseMeta,
|
|
4
|
-
TableGetter,
|
|
5
|
-
ElementCellPropGetter,
|
|
6
|
-
ElementRowPropGetter,
|
|
7
3
|
DefaultObject,
|
|
4
|
+
ElementCellPropGetter,
|
|
5
|
+
ElementGetter,
|
|
8
6
|
ElementHeaderFooterPropGetter,
|
|
9
|
-
|
|
7
|
+
ElementRowPropGetter,
|
|
10
8
|
GetTableContainerPropsGetter,
|
|
11
9
|
GetTableElementInternalPropsGetter,
|
|
10
|
+
GetTableElementPropsGetter,
|
|
11
|
+
TableGetter,
|
|
12
12
|
} from './types';
|
|
13
13
|
|
|
14
14
|
export const defaultGetter: ElementGetter = (props) => props;
|
|
15
15
|
|
|
16
16
|
export const cellGetter: ElementGetter = (props, {cell}) => ({
|
|
17
17
|
...props,
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
19
18
|
// @ts-ignore
|
|
20
19
|
align: cell?.column?.align,
|
|
21
20
|
});
|
|
22
21
|
export const mainCellGetter: ElementGetter = (props, {column}) => ({
|
|
23
22
|
...props,
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
25
23
|
// @ts-ignore
|
|
26
24
|
align: column?.align,
|
|
27
25
|
});
|
package/src/useTableShadow.tsx
CHANGED