@nova-design-system/nova-react 3.17.0 → 3.18.0-beta.0
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/cjs/{index-B0fvq6nd.js → index-CQAMJPJk.js} +229 -67
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/{nv-accordion-item.entry-DSXSMuOt.js → nv-accordion-item.entry-BQ4e6YBV.js} +1 -1
- package/dist/cjs/{nv-accordion.entry-D2GTCEoF.js → nv-accordion.entry-BX5L-Gh7.js} +1 -1
- package/dist/cjs/{nv-alert.entry-CxrdJWzE.js → nv-alert.entry-GY7Xn7F6.js} +1 -1
- package/dist/cjs/{nv-avatar.entry-Boe2Bp39.js → nv-avatar.entry-j-ctCQEi.js} +1 -1
- package/dist/cjs/{nv-badge_2.entry-Cvu8cWAm.js → nv-badge_2.entry-tuEGBPUn.js} +1 -1
- package/dist/cjs/{nv-breadcrumb.entry-IBd49U13.js → nv-breadcrumb.entry-DHZpC_e3.js} +1 -1
- package/dist/cjs/{nv-breadcrumbs.entry-CxDCe3pi.js → nv-breadcrumbs.entry-2tzS_xzO.js} +1 -1
- package/dist/cjs/{nv-button.entry-veszqyTF.js → nv-button.entry-BfV4ewn0.js} +1 -1
- package/dist/cjs/{nv-buttongroup.entry-BoqH0Kje.js → nv-buttongroup.entry-BBTtBLTw.js} +1 -1
- package/dist/cjs/{nv-calendar.entry-D-Wl56-6.js → nv-calendar.entry-CTkbvFRZ.js} +1 -1
- package/dist/cjs/{nv-col.entry-BhKZwFpL.js → nv-col.entry-CsSk4Ltj.js} +1 -1
- package/dist/cjs/{nv-datagrid.entry-DnMZbymp.js → nv-datagrid.entry-DlQRC5CG.js} +2 -2
- package/dist/cjs/{nv-datagridcolumn.entry-U38uoM6D.js → nv-datagridcolumn.entry-BxSumv4Q.js} +1 -1
- package/dist/cjs/{nv-dialog.entry-BF4VplVi.js → nv-dialog.entry-BFeHCAhr.js} +1 -1
- package/dist/cjs/{nv-dialogfooter_2.entry-TqO3Mryg.js → nv-dialogfooter_2.entry-CXOzxujX.js} +1 -1
- package/dist/cjs/{nv-fieldcheckbox.entry-C_rJ7Jrf.js → nv-fieldcheckbox.entry-BMq7p1kc.js} +1 -1
- package/dist/cjs/{nv-fielddate.entry-DZdztKCP.js → nv-fielddate.entry-DmMQq5bO.js} +1 -1
- package/dist/cjs/{nv-fielddaterange.entry-CMxpi6X9.js → nv-fielddaterange.entry-BJm7_qAB.js} +1 -1
- package/dist/cjs/{nv-fielddropdown.entry-T-qNo0gM.js → nv-fielddropdown.entry-DOkzDn78.js} +1 -1
- package/dist/cjs/{nv-fielddropdownitem.entry-BfIqaxW3.js → nv-fielddropdownitem.entry-CVI8jUn4.js} +1 -1
- package/dist/cjs/{nv-fieldmultiselect.entry-rtKSNZ5F.js → nv-fieldmultiselect.entry-CWxL0xsk.js} +1 -1
- package/dist/cjs/{nv-fieldnumber.entry-BD-xCdb5.js → nv-fieldnumber.entry-bReRT-TF.js} +1 -1
- package/dist/cjs/{nv-fieldpassword.entry-Dmt91T4y.js → nv-fieldpassword.entry-BprEVABM.js} +1 -1
- package/dist/cjs/{nv-fieldradio.entry-CAoRufTW.js → nv-fieldradio.entry-T_uuPP7m.js} +1 -1
- package/dist/cjs/{nv-fieldselect.entry-2YLbIpBO.js → nv-fieldselect.entry-DB9YREaD.js} +1 -1
- package/dist/cjs/{nv-fieldslider.entry-D6g_MrUd.js → nv-fieldslider.entry-Bkj5p8jp.js} +1 -1
- package/dist/cjs/{nv-fieldtext.entry-D-SS4OPR.js → nv-fieldtext.entry-BsUZW21W.js} +1 -1
- package/dist/cjs/{nv-fieldtextarea.entry-L0XDrdHL.js → nv-fieldtextarea.entry-DtC4sL4g.js} +1 -1
- package/dist/cjs/{nv-fieldtime.entry-Hw5VOmpK.js → nv-fieldtime.entry-BW8nABK-.js} +1 -1
- package/dist/cjs/{nv-icon.entry-B7mLhu0c.js → nv-icon.entry-BFTi5BIN.js} +2 -2
- package/dist/cjs/{nv-iconbutton_2.entry-iinBJBb6.js → nv-iconbutton_2.entry-DI-3_IYV.js} +1 -1
- package/dist/cjs/{nv-menu.entry-BTW4XauN.js → nv-menu.entry-BbqP7TZx.js} +1 -1
- package/dist/cjs/{nv-menuitem.entry-CIT2_Fbe.js → nv-menuitem.entry-BxGppIvW.js} +1 -1
- package/dist/cjs/{nv-notification.entry-CVyzCsSh.js → nv-notification.entry-D1gy3PSV.js} +1 -1
- package/dist/cjs/{nv-notificationcontainer.entry-CqoyGWAa.js → nv-notificationcontainer.entry-MJPLFXsR.js} +1 -1
- package/dist/cjs/{nv-popover.entry-Bf5ihsdq.js → nv-popover.entry-CL28RbQ0.js} +1 -1
- package/dist/cjs/{nv-row.entry-Chp5QzjD.js → nv-row.entry-DkCe2B9f.js} +1 -1
- package/dist/cjs/{nv-split.entry-DSB_HMU-.js → nv-split.entry-BMVNZDwj.js} +1 -1
- package/dist/cjs/{nv-stack.entry-D6L6830W.js → nv-stack.entry-iH3La5O3.js} +1 -1
- package/dist/cjs/{nv-table.entry-B-UuWaI5.js → nv-table.entry-DFHkpLLG.js} +1 -1
- package/dist/cjs/{nv-toggle.entry-AG7sAORg.js → nv-toggle.entry-BM2Xdtvg.js} +1 -1
- package/dist/cjs/{nv-togglebutton.entry-Btlxm5gO.js → nv-togglebutton.entry-DPu3j4uH.js} +1 -1
- package/dist/cjs/{nv-togglebuttongroup.entry-CM3nWiUU.js → nv-togglebuttongroup.entry-BBUI9mSK.js} +1 -1
- package/dist/cjs/{nv-tooltip.entry-m4AYXhW3.js → nv-tooltip.entry-CEynYna7.js} +1 -1
- package/dist/components/NvDatatable.js +122 -19
- package/dist/types/components/NvDatatable.d.ts +35 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
3
|
+
var index = require('./index-CQAMJPJk.js');
|
|
4
4
|
var constants69bafca2 = require('./constants-69bafca2-DpB_ghPF.js');
|
|
5
5
|
var collapse_animation6e0b08df = require('./collapse.animation-6e0b08df-AHWzNGm_.js');
|
|
6
6
|
var fade_animation9b939939 = require('./fade.animation-9b939939-DV--bM4S.js');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var index = require('./index-
|
|
3
|
+
var index = require('./index-CQAMJPJk.js');
|
|
4
4
|
var fade_animation9b939939 = require('./fade.animation-9b939939-DV--bM4S.js');
|
|
5
5
|
var styleValueTypes_esF5d10b79 = require('./style-value-types.es-f5d10b79-D0QCM8OB.js');
|
|
6
6
|
var events_utilsFe1d907f = require('./events.utils-fe1d907f-01N__3wY.js');
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import React, { useMemo } from 'react';
|
|
2
|
-
import { flexRender, getCoreRowModel, useReactTable, } from '@tanstack/react-table';
|
|
1
|
+
import React, { useMemo, useState, useEffect, useRef, } from 'react';
|
|
2
|
+
import { flexRender, getCoreRowModel, getPaginationRowModel, useReactTable, } from '@tanstack/react-table';
|
|
3
3
|
import { NvTable } from '../generated/components';
|
|
4
|
-
const NvDatatable = ({ columns, rows, ...htmlProps }) => {
|
|
4
|
+
const NvDatatable = ({ columns, rows, pagination, renderPagination, stickyHeader, ...htmlProps }) => {
|
|
5
|
+
const [paginationState, setPaginationState] = useState({
|
|
6
|
+
pageIndex: 0,
|
|
7
|
+
pageSize: pagination?.initialPageSize || 10,
|
|
8
|
+
});
|
|
9
|
+
const lastRowRef = useRef(null);
|
|
5
10
|
const tableColumns = useMemo(() => columns
|
|
6
11
|
.filter((col) => !col.hidden)
|
|
7
12
|
.map((col) => ({
|
|
@@ -24,22 +29,120 @@ const NvDatatable = ({ columns, rows, ...htmlProps }) => {
|
|
|
24
29
|
return value;
|
|
25
30
|
},
|
|
26
31
|
})), [columns]);
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
const tableConfig = useMemo(() => {
|
|
33
|
+
const baseConfig = {
|
|
34
|
+
data: rows,
|
|
35
|
+
columns: tableColumns,
|
|
36
|
+
getCoreRowModel: getCoreRowModel(),
|
|
37
|
+
};
|
|
38
|
+
if (!pagination) {
|
|
39
|
+
return baseConfig;
|
|
40
|
+
}
|
|
41
|
+
if (pagination.mode === 'client') {
|
|
42
|
+
return {
|
|
43
|
+
...baseConfig,
|
|
44
|
+
getPaginationRowModel: getPaginationRowModel(),
|
|
45
|
+
initialState: {
|
|
46
|
+
pagination: {
|
|
47
|
+
pageIndex: 0,
|
|
48
|
+
pageSize: pagination.initialPageSize || 10,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (pagination.mode === 'server') {
|
|
54
|
+
const pageSize = paginationState.pageSize;
|
|
55
|
+
let pageCount = -1;
|
|
56
|
+
if (pagination.totalPageCount !== undefined) {
|
|
57
|
+
pageCount = pagination.totalPageCount;
|
|
58
|
+
}
|
|
59
|
+
else if (pagination.totalRowCount !== undefined) {
|
|
60
|
+
pageCount = Math.ceil(pagination.totalRowCount / pageSize);
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
...baseConfig,
|
|
64
|
+
manualPagination: true,
|
|
65
|
+
pageCount,
|
|
66
|
+
state: {
|
|
67
|
+
pagination: paginationState,
|
|
68
|
+
},
|
|
69
|
+
onPaginationChange: setPaginationState,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return baseConfig;
|
|
73
|
+
}, [rows, tableColumns, pagination, paginationState]);
|
|
74
|
+
const table = useReactTable(tableConfig);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (pagination?.mode === 'server' && pagination.onPaginationChange) {
|
|
77
|
+
pagination.onPaginationChange({
|
|
78
|
+
pageIndex: paginationState.pageIndex,
|
|
79
|
+
pageSize: paginationState.pageSize,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}, [paginationState, pagination]);
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (pagination?.mode !== 'infinite' || !lastRowRef.current) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const threshold = pagination.loadMoreThreshold || 500;
|
|
88
|
+
const observer = new IntersectionObserver((entries) => {
|
|
89
|
+
const entry = entries[0];
|
|
90
|
+
if (entry.isIntersecting &&
|
|
91
|
+
pagination.hasMore &&
|
|
92
|
+
!pagination.isLoading &&
|
|
93
|
+
pagination.onLoadMore) {
|
|
94
|
+
pagination.onLoadMore();
|
|
95
|
+
}
|
|
96
|
+
}, {
|
|
97
|
+
rootMargin: `${threshold}px`,
|
|
98
|
+
root: null,
|
|
99
|
+
});
|
|
100
|
+
observer.observe(lastRowRef.current);
|
|
101
|
+
return () => {
|
|
102
|
+
observer.disconnect();
|
|
103
|
+
};
|
|
104
|
+
}, [rows, pagination]);
|
|
105
|
+
const tablePaginationState = table.getState().pagination;
|
|
106
|
+
const paginationAPI = useMemo(() => {
|
|
107
|
+
if (!pagination) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const pageCount = table.getPageCount();
|
|
111
|
+
const rowCount = pagination.mode === 'server'
|
|
112
|
+
? pagination.totalRowCount || rows.length
|
|
113
|
+
: rows.length;
|
|
114
|
+
return {
|
|
115
|
+
pageIndex: tablePaginationState.pageIndex,
|
|
116
|
+
pageSize: tablePaginationState.pageSize,
|
|
117
|
+
pageCount,
|
|
118
|
+
rowCount,
|
|
119
|
+
firstPage: () => table.setPageIndex(0),
|
|
120
|
+
previousPage: () => table.previousPage(),
|
|
121
|
+
nextPage: () => table.nextPage(),
|
|
122
|
+
lastPage: () => table.setPageIndex(pageCount - 1),
|
|
123
|
+
setPageIndex: (index) => table.setPageIndex(index),
|
|
124
|
+
setPageSize: (size) => table.setPageSize(size),
|
|
125
|
+
canPreviousPage: table.getCanPreviousPage(),
|
|
126
|
+
canNextPage: table.getCanNextPage(),
|
|
127
|
+
isLoading: pagination.mode === 'infinite' ? pagination.isLoading : undefined,
|
|
128
|
+
hasMore: pagination.mode === 'infinite' ? pagination.hasMore : undefined,
|
|
129
|
+
};
|
|
130
|
+
}, [pagination, table, rows.length, tablePaginationState]);
|
|
131
|
+
const tableRows = table.getRowModel().rows;
|
|
132
|
+
const isInfiniteScroll = pagination?.mode === 'infinite';
|
|
133
|
+
return (React.createElement(React.Fragment, null,
|
|
134
|
+
React.createElement(NvTable, { ...htmlProps },
|
|
135
|
+
React.createElement("table", null,
|
|
136
|
+
React.createElement("thead", { "data-sticky-top": stickyHeader ? 'true' : undefined }, table.getHeaderGroups().map((headerGroup) => (React.createElement("tr", { key: headerGroup.id }, headerGroup.headers.map((header) => (React.createElement("th", { key: header.id, "data-testid": `datatable-header-${header.id}`, style: {
|
|
137
|
+
width: header.column.columnDef.size + 'px',
|
|
138
|
+
}, "data-no-resize": header.column.columnDef.enableResizing ? null : true }, header.isPlaceholder
|
|
139
|
+
? null
|
|
140
|
+
: flexRender(header.column.columnDef.header, header.getContext())))))))),
|
|
141
|
+
React.createElement("tbody", null, tableRows.map((row, index) => {
|
|
142
|
+
const isLastRow = isInfiniteScroll && index === tableRows.length - 1;
|
|
143
|
+
return (React.createElement("tr", { key: row.id, "data-testid": `datatable-row-${row.id}`, ref: isLastRow ? lastRowRef : undefined }, row.getVisibleCells().map((cell) => (React.createElement("td", { key: cell.id, "data-testid": `datatable-cell-${cell.id}` }, flexRender(cell.column.columnDef.cell, cell.getContext()))))));
|
|
144
|
+
})))),
|
|
145
|
+
paginationAPI && renderPagination && renderPagination(paginationAPI)));
|
|
43
146
|
};
|
|
44
147
|
NvDatatable.displayName = 'NvDatatable';
|
|
45
148
|
export { NvDatatable };
|
|
@@ -1,13 +1,47 @@
|
|
|
1
1
|
import React, { type ComponentProps } from 'react';
|
|
2
2
|
declare const NvDatatable: {
|
|
3
|
-
<T extends NvDatatableRow = NvDatatableRow>({ columns, rows, ...htmlProps }: NvDatatableProps<T>): React.JSX.Element;
|
|
3
|
+
<T extends NvDatatableRow = NvDatatableRow>({ columns, rows, pagination, renderPagination, stickyHeader, ...htmlProps }: NvDatatableProps<T>): React.JSX.Element;
|
|
4
4
|
displayName: string;
|
|
5
5
|
};
|
|
6
6
|
export { NvDatatable };
|
|
7
7
|
export type NvDatatableProps<T> = {
|
|
8
8
|
columns: Array<NvDatatableColumn<T>>;
|
|
9
9
|
rows: Array<T>;
|
|
10
|
+
pagination?: NvDatatablePaginationConfig;
|
|
11
|
+
renderPagination?: (api: NvDatatableRenderPaginationAPI) => React.ReactNode;
|
|
12
|
+
stickyHeader?: boolean;
|
|
10
13
|
} & Pick<ComponentProps<'div'>, 'className' | 'style'>;
|
|
14
|
+
export interface NvDatatablePaginationConfig {
|
|
15
|
+
mode: 'client' | 'server' | 'infinite';
|
|
16
|
+
initialPageSize?: number;
|
|
17
|
+
pageSizeOptions?: number[];
|
|
18
|
+
totalRowCount?: number;
|
|
19
|
+
totalPageCount?: number;
|
|
20
|
+
onPaginationChange?: (state: {
|
|
21
|
+
pageIndex: number;
|
|
22
|
+
pageSize: number;
|
|
23
|
+
}) => void;
|
|
24
|
+
hasMore?: boolean;
|
|
25
|
+
isLoading?: boolean;
|
|
26
|
+
loadMoreThreshold?: number;
|
|
27
|
+
onLoadMore?: () => void;
|
|
28
|
+
}
|
|
29
|
+
export interface NvDatatableRenderPaginationAPI {
|
|
30
|
+
pageIndex: number;
|
|
31
|
+
pageSize: number;
|
|
32
|
+
pageCount: number;
|
|
33
|
+
rowCount: number;
|
|
34
|
+
firstPage: () => void;
|
|
35
|
+
previousPage: () => void;
|
|
36
|
+
nextPage: () => void;
|
|
37
|
+
lastPage: () => void;
|
|
38
|
+
setPageIndex: (index: number) => void;
|
|
39
|
+
setPageSize: (size: number) => void;
|
|
40
|
+
canPreviousPage: boolean;
|
|
41
|
+
canNextPage: boolean;
|
|
42
|
+
isLoading?: boolean;
|
|
43
|
+
hasMore?: boolean;
|
|
44
|
+
}
|
|
11
45
|
export interface NvDatatableColumn<T> {
|
|
12
46
|
field: keyof T;
|
|
13
47
|
headerName?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nova-design-system/nova-react",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.18.0-beta.0",
|
|
4
4
|
"description": "Nova is a design system created by Elia Group to empower creators to efficiently build solutions that people love to use.",
|
|
5
5
|
"author": "Elia Group",
|
|
6
6
|
"homepage": "https://nova.eliagroup.io",
|