@equinor/eds-data-grid-react 0.3.0 → 0.4.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/eds-data-grid-react.cjs +19 -8
- package/dist/esm/EdsDataGrid.js +17 -4
- package/dist/esm/components/TableBodyCell.js +1 -2
- package/dist/esm/components/TableHeaderCell.js +2 -3
- package/dist/types/EdsDataGrid.d.ts +1 -1
- package/dist/types/EdsDataGridProps.d.ts +13 -2
- package/package.json +5 -5
|
@@ -219,7 +219,7 @@ const Resizer = styled__default.default.div.withConfig({
|
|
|
219
219
|
const Cell = styled__default.default(edsCoreReact.Table.Cell).withConfig({
|
|
220
220
|
displayName: "TableHeaderCell__Cell",
|
|
221
221
|
componentId: "sc-1n0j3v0-2"
|
|
222
|
-
})(["font-weight:bold;
|
|
222
|
+
})(["font-weight:bold;position:", ";top:0;", " ", ";&:hover ", "{background:", ";opacity:1;}"], p => p.$sticky || p.$pinned ? 'sticky' : 'relative', p => {
|
|
223
223
|
if (p.$pinned) {
|
|
224
224
|
return `${p.$pinned}: ${p.$offset}px;`;
|
|
225
225
|
}
|
|
@@ -257,7 +257,6 @@ function TableHeaderCell({
|
|
|
257
257
|
className: ctx.headerClass ? ctx.headerClass(header.column) : '',
|
|
258
258
|
"aria-sort": getSortLabel(header.column.getIsSorted()),
|
|
259
259
|
onClick: header.column.getToggleSortingHandler(),
|
|
260
|
-
key: header.id,
|
|
261
260
|
colSpan: header.colSpan,
|
|
262
261
|
style: {
|
|
263
262
|
width: header.getSize(),
|
|
@@ -302,7 +301,7 @@ function TableHeaderCell({
|
|
|
302
301
|
"data-testid": 'resize-handle',
|
|
303
302
|
children: /*#__PURE__*/jsxRuntime.jsx(ResizeInner, {})
|
|
304
303
|
})]
|
|
305
|
-
});
|
|
304
|
+
}, header.id);
|
|
306
305
|
}
|
|
307
306
|
|
|
308
307
|
function TableHeaderRow({
|
|
@@ -350,14 +349,13 @@ function TableBodyCell({
|
|
|
350
349
|
$pinned: pinned,
|
|
351
350
|
$offset: pinnedOffset,
|
|
352
351
|
className: cellClass ? cellClass(cell.row, cell.column.id) : '',
|
|
353
|
-
key: cell.id,
|
|
354
352
|
style: {
|
|
355
353
|
width: cell.column.getSize(),
|
|
356
354
|
maxWidth: cell.column.getSize(),
|
|
357
355
|
...(cellStyle?.(cell.row, cell.column.id) ?? {})
|
|
358
356
|
},
|
|
359
357
|
children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
360
|
-
});
|
|
358
|
+
}, cell.id);
|
|
361
359
|
}
|
|
362
360
|
|
|
363
361
|
function TableRow({
|
|
@@ -451,7 +449,11 @@ function EdsDataGrid({
|
|
|
451
449
|
getRowId,
|
|
452
450
|
rowVirtualizerInstanceRef,
|
|
453
451
|
columnSizing,
|
|
454
|
-
onColumnResize
|
|
452
|
+
onColumnResize,
|
|
453
|
+
expansionState,
|
|
454
|
+
setExpansionState,
|
|
455
|
+
getSubRows,
|
|
456
|
+
defaultColumn
|
|
455
457
|
}) {
|
|
456
458
|
const [sorting, setSorting] = react.useState(sortingState ?? []);
|
|
457
459
|
const [selection, setSelection] = react.useState(selectedRows ?? {});
|
|
@@ -465,6 +467,11 @@ function EdsDataGrid({
|
|
|
465
467
|
pageIndex: 0,
|
|
466
468
|
pageSize: pageSize ?? 25
|
|
467
469
|
});
|
|
470
|
+
react.useEffect(() => {
|
|
471
|
+
if (virtualHeight) {
|
|
472
|
+
console.warn(`virtualHeight prop is deprecated and will be removed in a later version. Please update your code to use height instead.`);
|
|
473
|
+
}
|
|
474
|
+
}, [virtualHeight]);
|
|
468
475
|
react.useEffect(() => {
|
|
469
476
|
setVisible(columnVisibility ?? {});
|
|
470
477
|
}, [columnVisibility, setVisible]);
|
|
@@ -520,7 +527,7 @@ function EdsDataGrid({
|
|
|
520
527
|
const options = {
|
|
521
528
|
data: rows,
|
|
522
529
|
columns: _columns,
|
|
523
|
-
defaultColumn: {
|
|
530
|
+
defaultColumn: defaultColumn ?? {
|
|
524
531
|
size: 150,
|
|
525
532
|
cell: context => {
|
|
526
533
|
return /*#__PURE__*/jsxRuntime.jsx(edsCoreReact.Typography, {
|
|
@@ -551,8 +558,12 @@ function EdsDataGrid({
|
|
|
551
558
|
columnPinning: columnPin,
|
|
552
559
|
rowSelection: selection,
|
|
553
560
|
columnOrder: columnOrderState,
|
|
554
|
-
columnSizing: columnSizing ?? internalColumnSize
|
|
561
|
+
columnSizing: columnSizing ?? internalColumnSize,
|
|
562
|
+
expanded: expansionState
|
|
555
563
|
},
|
|
564
|
+
getSubRows: getSubRows,
|
|
565
|
+
onExpandedChange: setExpansionState,
|
|
566
|
+
getExpandedRowModel: reactTable.getExpandedRowModel(),
|
|
556
567
|
onSortingChange: changes => {
|
|
557
568
|
if (onSortingChange) {
|
|
558
569
|
onSortingChange(changes);
|
package/dist/esm/EdsDataGrid.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Typography, useEds, Table, Pagination } from '@equinor/eds-core-react';
|
|
2
|
-
import { getCoreRowModel, getSortedRowModel, getFacetedRowModel, getFacetedUniqueValues, getFacetedMinMaxValues, getFilteredRowModel, getPaginationRowModel, useReactTable } from '@tanstack/react-table';
|
|
2
|
+
import { getExpandedRowModel, getCoreRowModel, getSortedRowModel, getFacetedRowModel, getFacetedUniqueValues, getFacetedMinMaxValues, getFilteredRowModel, getPaginationRowModel, useReactTable } from '@tanstack/react-table';
|
|
3
3
|
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
4
4
|
import { useState, useEffect, useMemo, useRef, useCallback } from 'react';
|
|
5
5
|
import { TableHeaderRow } from './components/TableHeaderRow.js';
|
|
@@ -48,7 +48,11 @@ function EdsDataGrid({
|
|
|
48
48
|
getRowId,
|
|
49
49
|
rowVirtualizerInstanceRef,
|
|
50
50
|
columnSizing,
|
|
51
|
-
onColumnResize
|
|
51
|
+
onColumnResize,
|
|
52
|
+
expansionState,
|
|
53
|
+
setExpansionState,
|
|
54
|
+
getSubRows,
|
|
55
|
+
defaultColumn
|
|
52
56
|
}) {
|
|
53
57
|
const [sorting, setSorting] = useState(sortingState ?? []);
|
|
54
58
|
const [selection, setSelection] = useState(selectedRows ?? {});
|
|
@@ -62,6 +66,11 @@ function EdsDataGrid({
|
|
|
62
66
|
pageIndex: 0,
|
|
63
67
|
pageSize: pageSize ?? 25
|
|
64
68
|
});
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (virtualHeight) {
|
|
71
|
+
console.warn(`virtualHeight prop is deprecated and will be removed in a later version. Please update your code to use height instead.`);
|
|
72
|
+
}
|
|
73
|
+
}, [virtualHeight]);
|
|
65
74
|
useEffect(() => {
|
|
66
75
|
setVisible(columnVisibility ?? {});
|
|
67
76
|
}, [columnVisibility, setVisible]);
|
|
@@ -117,7 +126,7 @@ function EdsDataGrid({
|
|
|
117
126
|
const options = {
|
|
118
127
|
data: rows,
|
|
119
128
|
columns: _columns,
|
|
120
|
-
defaultColumn: {
|
|
129
|
+
defaultColumn: defaultColumn ?? {
|
|
121
130
|
size: 150,
|
|
122
131
|
cell: context => {
|
|
123
132
|
return /*#__PURE__*/jsx(Typography, {
|
|
@@ -148,8 +157,12 @@ function EdsDataGrid({
|
|
|
148
157
|
columnPinning: columnPin,
|
|
149
158
|
rowSelection: selection,
|
|
150
159
|
columnOrder: columnOrderState,
|
|
151
|
-
columnSizing: columnSizing ?? internalColumnSize
|
|
160
|
+
columnSizing: columnSizing ?? internalColumnSize,
|
|
161
|
+
expanded: expansionState
|
|
152
162
|
},
|
|
163
|
+
getSubRows: getSubRows,
|
|
164
|
+
onExpandedChange: setExpansionState,
|
|
165
|
+
getExpandedRowModel: getExpandedRowModel(),
|
|
153
166
|
onSortingChange: changes => {
|
|
154
167
|
if (onSortingChange) {
|
|
155
168
|
onSortingChange(changes);
|
|
@@ -34,14 +34,13 @@ function TableBodyCell({
|
|
|
34
34
|
$pinned: pinned,
|
|
35
35
|
$offset: pinnedOffset,
|
|
36
36
|
className: cellClass ? cellClass(cell.row, cell.column.id) : '',
|
|
37
|
-
key: cell.id,
|
|
38
37
|
style: {
|
|
39
38
|
width: cell.column.getSize(),
|
|
40
39
|
maxWidth: cell.column.getSize(),
|
|
41
40
|
...(cellStyle?.(cell.row, cell.column.id) ?? {})
|
|
42
41
|
},
|
|
43
42
|
children: flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
44
|
-
});
|
|
43
|
+
}, cell.id);
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
export { TableBodyCell };
|
|
@@ -25,7 +25,7 @@ const Resizer = styled.div.withConfig({
|
|
|
25
25
|
const Cell = styled(Table.Cell).withConfig({
|
|
26
26
|
displayName: "TableHeaderCell__Cell",
|
|
27
27
|
componentId: "sc-1n0j3v0-2"
|
|
28
|
-
})(["font-weight:bold;
|
|
28
|
+
})(["font-weight:bold;position:", ";top:0;", " ", ";&:hover ", "{background:", ";opacity:1;}"], p => p.$sticky || p.$pinned ? 'sticky' : 'relative', p => {
|
|
29
29
|
if (p.$pinned) {
|
|
30
30
|
return `${p.$pinned}: ${p.$offset}px;`;
|
|
31
31
|
}
|
|
@@ -63,7 +63,6 @@ function TableHeaderCell({
|
|
|
63
63
|
className: ctx.headerClass ? ctx.headerClass(header.column) : '',
|
|
64
64
|
"aria-sort": getSortLabel(header.column.getIsSorted()),
|
|
65
65
|
onClick: header.column.getToggleSortingHandler(),
|
|
66
|
-
key: header.id,
|
|
67
66
|
colSpan: header.colSpan,
|
|
68
67
|
style: {
|
|
69
68
|
width: header.getSize(),
|
|
@@ -108,7 +107,7 @@ function TableHeaderCell({
|
|
|
108
107
|
"data-testid": 'resize-handle',
|
|
109
108
|
children: /*#__PURE__*/jsx(ResizeInner, {})
|
|
110
109
|
})]
|
|
111
|
-
});
|
|
110
|
+
}, header.id);
|
|
112
111
|
}
|
|
113
112
|
|
|
114
113
|
export { TableHeaderCell };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { EdsDataGridProps } from './EdsDataGridProps';
|
|
2
|
-
export declare function EdsDataGrid<T>({ rows, columns, columnResizeMode, pageSize, rowSelection, selectedRows, enableColumnFiltering, debug, enablePagination, enableSorting, stickyHeader, onSelectRow, caption, enableVirtual, virtualHeight, columnVisibility, columnVisibilityChange, emptyMessage, columnOrder, cellClass, cellStyle, rowClass, rowStyle, headerClass, headerStyle, externalPaginator, onSortingChange, manualSorting, sortingState, columnPinState, scrollbarHorizontal, width, minWidth, height, getRowId, rowVirtualizerInstanceRef, columnSizing, onColumnResize, }: EdsDataGridProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export declare function EdsDataGrid<T>({ rows, columns, columnResizeMode, pageSize, rowSelection, selectedRows, enableColumnFiltering, debug, enablePagination, enableSorting, stickyHeader, onSelectRow, caption, enableVirtual, virtualHeight, columnVisibility, columnVisibilityChange, emptyMessage, columnOrder, cellClass, cellStyle, rowClass, rowStyle, headerClass, headerStyle, externalPaginator, onSortingChange, manualSorting, sortingState, columnPinState, scrollbarHorizontal, width, minWidth, height, getRowId, rowVirtualizerInstanceRef, columnSizing, onColumnResize, expansionState, setExpansionState, getSubRows, defaultColumn, }: EdsDataGridProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Column, ColumnDef, ColumnPinningState, ColumnResizeMode, ColumnSizingState, OnChangeFn, Row, RowSelectionState, SortingState, TableOptions } from '@tanstack/react-table';
|
|
1
|
+
import { Column, ColumnDef, ColumnPinningState, ColumnResizeMode, ColumnSizingState, ExpandedState, OnChangeFn, Row, RowSelectionState, SortingState, TableOptions } from '@tanstack/react-table';
|
|
2
2
|
import { Virtualizer } from '@tanstack/react-virtual';
|
|
3
3
|
import { CSSProperties, MutableRefObject, ReactElement } from 'react';
|
|
4
4
|
type BaseProps<T> = {
|
|
@@ -84,6 +84,11 @@ type BaseProps<T> = {
|
|
|
84
84
|
* @link [Guide](https://tanstack.com/table/v8/docs/guide/tables)
|
|
85
85
|
*/
|
|
86
86
|
getRowId?: TableOptions<T>['getRowId'];
|
|
87
|
+
/**
|
|
88
|
+
* Optional prop to override the default column setup (cell, header, size etc.)
|
|
89
|
+
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#defaultcolumn)
|
|
90
|
+
*/
|
|
91
|
+
defaultColumn?: Partial<ColumnDef<T, unknown>>;
|
|
87
92
|
};
|
|
88
93
|
type StyleProps<T> = {
|
|
89
94
|
/**
|
|
@@ -155,6 +160,7 @@ type VirtualProps = {
|
|
|
155
160
|
enableVirtual?: boolean;
|
|
156
161
|
/**
|
|
157
162
|
* The height of the virtualized table in pixels.
|
|
163
|
+
* @deprecated Use `height` prop over virtualHeight, this will be removed in a later version
|
|
158
164
|
* @default 500
|
|
159
165
|
*/
|
|
160
166
|
virtualHeight?: number;
|
|
@@ -187,7 +193,12 @@ type ColumnProps = {
|
|
|
187
193
|
type RefProps = {
|
|
188
194
|
rowVirtualizerInstanceRef?: MutableRefObject<Virtualizer<HTMLDivElement, Element> | null>;
|
|
189
195
|
};
|
|
190
|
-
|
|
196
|
+
type ExpansionProps<T> = {
|
|
197
|
+
expansionState?: ExpandedState;
|
|
198
|
+
setExpansionState?: React.Dispatch<React.SetStateAction<ExpandedState>>;
|
|
199
|
+
getSubRows?: (row: T, rowIndex: number) => Array<T>;
|
|
200
|
+
};
|
|
201
|
+
export type EdsDataGridProps<T> = BaseProps<T> & StyleProps<T> & SortProps & FilterProps & PagingProps & ColumnProps & VirtualProps & RefProps & ExpansionProps<T> & {
|
|
191
202
|
/**
|
|
192
203
|
* Which columns are visible. If not set, all columns are visible. undefined means that the column is visible.
|
|
193
204
|
* @default undefined
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/eds-data-grid-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A feature-rich data-grid written in React, implementing the Equinor Design System",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"styled-components": ">=4.2"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@tanstack/react-table": "^8.
|
|
24
|
-
"@tanstack/react-virtual": "^3.
|
|
23
|
+
"@tanstack/react-table": "^8.13.2",
|
|
24
|
+
"@tanstack/react-virtual": "^3.1.3",
|
|
25
25
|
"@equinor/eds-icons": "^0.21.0",
|
|
26
|
-
"@equinor/eds-
|
|
27
|
-
"@equinor/eds-
|
|
26
|
+
"@equinor/eds-tokens": "0.9.2",
|
|
27
|
+
"@equinor/eds-utils": "^0.8.4"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@mdx-js/react": "2.3.0",
|