@equinor/eds-data-grid-react 0.3.0-rc → 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 +79 -18
- package/dist/esm/EdsDataGrid.js +53 -14
- package/dist/esm/components/TableBodyCell.js +1 -2
- package/dist/esm/components/TableHeaderCell.js +2 -3
- package/dist/esm/utils.js +27 -0
- package/dist/types/EdsDataGrid.d.ts +1 -1
- package/dist/types/EdsDataGridProps.d.ts +15 -2
- package/dist/types/utils.d.ts +18 -0
- package/package.json +6 -6
|
@@ -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({
|
|
@@ -386,6 +384,32 @@ const StyledTableRow = styled__default.default(edsCoreReact.Table.Row).withConfi
|
|
|
386
384
|
componentId: "sc-1vjfq5p-0"
|
|
387
385
|
})(["background-color:inherit;"]);
|
|
388
386
|
|
|
387
|
+
/**
|
|
388
|
+
* Function returning wether a string only contains number. Allows leading or trailing spaces.
|
|
389
|
+
*
|
|
390
|
+
* Examples:
|
|
391
|
+
*
|
|
392
|
+
* ```
|
|
393
|
+
* isNumberOnlyString("10") // true
|
|
394
|
+
* isNumberOnlyString("10.10") // true
|
|
395
|
+
* isNumberOnlyString("10px") // false
|
|
396
|
+
* isNumberOnlyString("10%") // false
|
|
397
|
+
* isNumberOnlyString("10 ") // true
|
|
398
|
+
* ```
|
|
399
|
+
*
|
|
400
|
+
* @param number
|
|
401
|
+
* @returns
|
|
402
|
+
*/
|
|
403
|
+
function isNumberOnlyString(number) {
|
|
404
|
+
return !isNaN(Number(number)) && !isNaN(parseFloat(number));
|
|
405
|
+
}
|
|
406
|
+
function addPxSuffixIfInputHasNoPrefix(size) {
|
|
407
|
+
if (typeof size === 'number' || isNumberOnlyString(size)) {
|
|
408
|
+
return `${size}px`;
|
|
409
|
+
}
|
|
410
|
+
return size;
|
|
411
|
+
}
|
|
412
|
+
|
|
389
413
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
390
414
|
function EdsDataGrid({
|
|
391
415
|
rows,
|
|
@@ -423,12 +447,19 @@ function EdsDataGrid({
|
|
|
423
447
|
minWidth,
|
|
424
448
|
height,
|
|
425
449
|
getRowId,
|
|
426
|
-
rowVirtualizerInstanceRef
|
|
450
|
+
rowVirtualizerInstanceRef,
|
|
451
|
+
columnSizing,
|
|
452
|
+
onColumnResize,
|
|
453
|
+
expansionState,
|
|
454
|
+
setExpansionState,
|
|
455
|
+
getSubRows,
|
|
456
|
+
defaultColumn
|
|
427
457
|
}) {
|
|
428
458
|
const [sorting, setSorting] = react.useState(sortingState ?? []);
|
|
429
459
|
const [selection, setSelection] = react.useState(selectedRows ?? {});
|
|
430
460
|
const [columnPin, setColumnPin] = react.useState(columnPinState ?? {});
|
|
431
461
|
const [columnFilters, setColumnFilters] = react.useState([]);
|
|
462
|
+
const [internalColumnSize, setInternalColumnSize] = react.useState(columnSizing ?? {});
|
|
432
463
|
const [visible, setVisible] = react.useState(columnVisibility ?? {});
|
|
433
464
|
const [globalFilter, setGlobalFilter] = react.useState('');
|
|
434
465
|
const [columnOrderState, setColumnOrderState] = react.useState([]);
|
|
@@ -436,6 +467,11 @@ function EdsDataGrid({
|
|
|
436
467
|
pageIndex: 0,
|
|
437
468
|
pageSize: pageSize ?? 25
|
|
438
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]);
|
|
439
475
|
react.useEffect(() => {
|
|
440
476
|
setVisible(columnVisibility ?? {});
|
|
441
477
|
}, [columnVisibility, setVisible]);
|
|
@@ -491,7 +527,8 @@ function EdsDataGrid({
|
|
|
491
527
|
const options = {
|
|
492
528
|
data: rows,
|
|
493
529
|
columns: _columns,
|
|
494
|
-
defaultColumn: {
|
|
530
|
+
defaultColumn: defaultColumn ?? {
|
|
531
|
+
size: 150,
|
|
495
532
|
cell: context => {
|
|
496
533
|
return /*#__PURE__*/jsxRuntime.jsx(edsCoreReact.Typography, {
|
|
497
534
|
style: {
|
|
@@ -506,12 +543,27 @@ function EdsDataGrid({
|
|
|
506
543
|
}
|
|
507
544
|
},
|
|
508
545
|
columnResizeMode: columnResizeMode,
|
|
546
|
+
onColumnSizingChange: change => {
|
|
547
|
+
if (typeof change === 'function') {
|
|
548
|
+
setInternalColumnSize(change(internalColumnSize));
|
|
549
|
+
} else {
|
|
550
|
+
setInternalColumnSize(change);
|
|
551
|
+
}
|
|
552
|
+
if (onColumnResize) {
|
|
553
|
+
onColumnResize(internalColumnSize);
|
|
554
|
+
}
|
|
555
|
+
},
|
|
509
556
|
state: {
|
|
510
557
|
sorting,
|
|
511
558
|
columnPinning: columnPin,
|
|
512
559
|
rowSelection: selection,
|
|
513
|
-
columnOrder: columnOrderState
|
|
560
|
+
columnOrder: columnOrderState,
|
|
561
|
+
columnSizing: columnSizing ?? internalColumnSize,
|
|
562
|
+
expanded: expansionState
|
|
514
563
|
},
|
|
564
|
+
getSubRows: getSubRows,
|
|
565
|
+
onExpandedChange: setExpansionState,
|
|
566
|
+
getExpandedRowModel: reactTable.getExpandedRowModel(),
|
|
515
567
|
onSortingChange: changes => {
|
|
516
568
|
if (onSortingChange) {
|
|
517
569
|
onSortingChange(changes);
|
|
@@ -596,14 +648,14 @@ function EdsDataGrid({
|
|
|
596
648
|
}));
|
|
597
649
|
}, [pageSize]);
|
|
598
650
|
const table = reactTable.useReactTable(options);
|
|
599
|
-
let
|
|
651
|
+
let tableWrapperStyle = {};
|
|
600
652
|
|
|
601
653
|
/**
|
|
602
654
|
* Style the parent container to enable virtualization.
|
|
603
655
|
* By not setting this, the virtual-scroll will always render every row, reducing computational overhead if turned off.
|
|
604
656
|
*/
|
|
605
657
|
if (enableVirtual) {
|
|
606
|
-
|
|
658
|
+
tableWrapperStyle = {
|
|
607
659
|
height: height ?? virtualHeight ?? 500,
|
|
608
660
|
overflow: 'auto',
|
|
609
661
|
position: 'relative'
|
|
@@ -647,16 +699,13 @@ function EdsDataGrid({
|
|
|
647
699
|
enableSorting: !!enableSorting,
|
|
648
700
|
enableColumnFiltering: !!enableColumnFiltering,
|
|
649
701
|
stickyHeader: !!stickyHeader,
|
|
650
|
-
children: [/*#__PURE__*/jsxRuntime.jsxs(
|
|
702
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs(TableWrapper, {
|
|
651
703
|
className: "table-wrapper",
|
|
652
|
-
style:
|
|
653
|
-
height: height ?? 'auto',
|
|
654
|
-
...parentRefStyle,
|
|
655
|
-
width: scrollbarHorizontal ? width ?? '100%' : 'auto',
|
|
656
|
-
overflow: 'auto',
|
|
657
|
-
contain: 'layout paint style'
|
|
658
|
-
},
|
|
704
|
+
style: tableWrapperStyle,
|
|
659
705
|
ref: parentRef,
|
|
706
|
+
$height: height,
|
|
707
|
+
$width: width,
|
|
708
|
+
$scrollbarHorizontal: scrollbarHorizontal,
|
|
660
709
|
children: [/*#__PURE__*/jsxRuntime.jsxs(edsCoreReact.Table, {
|
|
661
710
|
className: Object.entries(classList).filter(([, k]) => k).map(([k]) => k).join(' '),
|
|
662
711
|
style: {
|
|
@@ -733,5 +782,17 @@ function EdsDataGrid({
|
|
|
733
782
|
})]
|
|
734
783
|
});
|
|
735
784
|
}
|
|
785
|
+
const TableWrapper = styled__default.default.div.withConfig({
|
|
786
|
+
displayName: "EdsDataGrid__TableWrapper",
|
|
787
|
+
componentId: "sc-82fj3f-0"
|
|
788
|
+
})(["height:", ";width:", ";overflow:auto;contain:", ";"], ({
|
|
789
|
+
$height
|
|
790
|
+
}) => addPxSuffixIfInputHasNoPrefix($height) ?? 'auto', ({
|
|
791
|
+
$scrollbarHorizontal,
|
|
792
|
+
$width
|
|
793
|
+
}) => $scrollbarHorizontal ? addPxSuffixIfInputHasNoPrefix($width) ?? '100%' : 'auto', ({
|
|
794
|
+
$height,
|
|
795
|
+
$width
|
|
796
|
+
}) => Boolean($height) && Boolean($width) ? 'strict' : 'unset');
|
|
736
797
|
|
|
737
798
|
exports.EdsDataGrid = EdsDataGrid;
|
package/dist/esm/EdsDataGrid.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
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';
|
|
6
6
|
import { TableRow } from './components/TableRow.js';
|
|
7
7
|
import { TableProvider } from './EdsDataGridContext.js';
|
|
8
|
+
import styled from 'styled-components';
|
|
9
|
+
import { addPxSuffixIfInputHasNoPrefix } from './utils.js';
|
|
8
10
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
9
11
|
|
|
10
12
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
@@ -44,12 +46,19 @@ function EdsDataGrid({
|
|
|
44
46
|
minWidth,
|
|
45
47
|
height,
|
|
46
48
|
getRowId,
|
|
47
|
-
rowVirtualizerInstanceRef
|
|
49
|
+
rowVirtualizerInstanceRef,
|
|
50
|
+
columnSizing,
|
|
51
|
+
onColumnResize,
|
|
52
|
+
expansionState,
|
|
53
|
+
setExpansionState,
|
|
54
|
+
getSubRows,
|
|
55
|
+
defaultColumn
|
|
48
56
|
}) {
|
|
49
57
|
const [sorting, setSorting] = useState(sortingState ?? []);
|
|
50
58
|
const [selection, setSelection] = useState(selectedRows ?? {});
|
|
51
59
|
const [columnPin, setColumnPin] = useState(columnPinState ?? {});
|
|
52
60
|
const [columnFilters, setColumnFilters] = useState([]);
|
|
61
|
+
const [internalColumnSize, setInternalColumnSize] = useState(columnSizing ?? {});
|
|
53
62
|
const [visible, setVisible] = useState(columnVisibility ?? {});
|
|
54
63
|
const [globalFilter, setGlobalFilter] = useState('');
|
|
55
64
|
const [columnOrderState, setColumnOrderState] = useState([]);
|
|
@@ -57,6 +66,11 @@ function EdsDataGrid({
|
|
|
57
66
|
pageIndex: 0,
|
|
58
67
|
pageSize: pageSize ?? 25
|
|
59
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]);
|
|
60
74
|
useEffect(() => {
|
|
61
75
|
setVisible(columnVisibility ?? {});
|
|
62
76
|
}, [columnVisibility, setVisible]);
|
|
@@ -112,7 +126,8 @@ function EdsDataGrid({
|
|
|
112
126
|
const options = {
|
|
113
127
|
data: rows,
|
|
114
128
|
columns: _columns,
|
|
115
|
-
defaultColumn: {
|
|
129
|
+
defaultColumn: defaultColumn ?? {
|
|
130
|
+
size: 150,
|
|
116
131
|
cell: context => {
|
|
117
132
|
return /*#__PURE__*/jsx(Typography, {
|
|
118
133
|
style: {
|
|
@@ -127,12 +142,27 @@ function EdsDataGrid({
|
|
|
127
142
|
}
|
|
128
143
|
},
|
|
129
144
|
columnResizeMode: columnResizeMode,
|
|
145
|
+
onColumnSizingChange: change => {
|
|
146
|
+
if (typeof change === 'function') {
|
|
147
|
+
setInternalColumnSize(change(internalColumnSize));
|
|
148
|
+
} else {
|
|
149
|
+
setInternalColumnSize(change);
|
|
150
|
+
}
|
|
151
|
+
if (onColumnResize) {
|
|
152
|
+
onColumnResize(internalColumnSize);
|
|
153
|
+
}
|
|
154
|
+
},
|
|
130
155
|
state: {
|
|
131
156
|
sorting,
|
|
132
157
|
columnPinning: columnPin,
|
|
133
158
|
rowSelection: selection,
|
|
134
|
-
columnOrder: columnOrderState
|
|
159
|
+
columnOrder: columnOrderState,
|
|
160
|
+
columnSizing: columnSizing ?? internalColumnSize,
|
|
161
|
+
expanded: expansionState
|
|
135
162
|
},
|
|
163
|
+
getSubRows: getSubRows,
|
|
164
|
+
onExpandedChange: setExpansionState,
|
|
165
|
+
getExpandedRowModel: getExpandedRowModel(),
|
|
136
166
|
onSortingChange: changes => {
|
|
137
167
|
if (onSortingChange) {
|
|
138
168
|
onSortingChange(changes);
|
|
@@ -217,14 +247,14 @@ function EdsDataGrid({
|
|
|
217
247
|
}));
|
|
218
248
|
}, [pageSize]);
|
|
219
249
|
const table = useReactTable(options);
|
|
220
|
-
let
|
|
250
|
+
let tableWrapperStyle = {};
|
|
221
251
|
|
|
222
252
|
/**
|
|
223
253
|
* Style the parent container to enable virtualization.
|
|
224
254
|
* By not setting this, the virtual-scroll will always render every row, reducing computational overhead if turned off.
|
|
225
255
|
*/
|
|
226
256
|
if (enableVirtual) {
|
|
227
|
-
|
|
257
|
+
tableWrapperStyle = {
|
|
228
258
|
height: height ?? virtualHeight ?? 500,
|
|
229
259
|
overflow: 'auto',
|
|
230
260
|
position: 'relative'
|
|
@@ -268,16 +298,13 @@ function EdsDataGrid({
|
|
|
268
298
|
enableSorting: !!enableSorting,
|
|
269
299
|
enableColumnFiltering: !!enableColumnFiltering,
|
|
270
300
|
stickyHeader: !!stickyHeader,
|
|
271
|
-
children: [/*#__PURE__*/jsxs(
|
|
301
|
+
children: [/*#__PURE__*/jsxs(TableWrapper, {
|
|
272
302
|
className: "table-wrapper",
|
|
273
|
-
style:
|
|
274
|
-
height: height ?? 'auto',
|
|
275
|
-
...parentRefStyle,
|
|
276
|
-
width: scrollbarHorizontal ? width ?? '100%' : 'auto',
|
|
277
|
-
overflow: 'auto',
|
|
278
|
-
contain: 'layout paint style'
|
|
279
|
-
},
|
|
303
|
+
style: tableWrapperStyle,
|
|
280
304
|
ref: parentRef,
|
|
305
|
+
$height: height,
|
|
306
|
+
$width: width,
|
|
307
|
+
$scrollbarHorizontal: scrollbarHorizontal,
|
|
281
308
|
children: [/*#__PURE__*/jsxs(Table, {
|
|
282
309
|
className: Object.entries(classList).filter(([, k]) => k).map(([k]) => k).join(' '),
|
|
283
310
|
style: {
|
|
@@ -354,5 +381,17 @@ function EdsDataGrid({
|
|
|
354
381
|
})]
|
|
355
382
|
});
|
|
356
383
|
}
|
|
384
|
+
const TableWrapper = styled.div.withConfig({
|
|
385
|
+
displayName: "EdsDataGrid__TableWrapper",
|
|
386
|
+
componentId: "sc-82fj3f-0"
|
|
387
|
+
})(["height:", ";width:", ";overflow:auto;contain:", ";"], ({
|
|
388
|
+
$height
|
|
389
|
+
}) => addPxSuffixIfInputHasNoPrefix($height) ?? 'auto', ({
|
|
390
|
+
$scrollbarHorizontal,
|
|
391
|
+
$width
|
|
392
|
+
}) => $scrollbarHorizontal ? addPxSuffixIfInputHasNoPrefix($width) ?? '100%' : 'auto', ({
|
|
393
|
+
$height,
|
|
394
|
+
$width
|
|
395
|
+
}) => Boolean($height) && Boolean($width) ? 'strict' : 'unset');
|
|
357
396
|
|
|
358
397
|
export { EdsDataGrid };
|
|
@@ -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 };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function returning wether a string only contains number. Allows leading or trailing spaces.
|
|
3
|
+
*
|
|
4
|
+
* Examples:
|
|
5
|
+
*
|
|
6
|
+
* ```
|
|
7
|
+
* isNumberOnlyString("10") // true
|
|
8
|
+
* isNumberOnlyString("10.10") // true
|
|
9
|
+
* isNumberOnlyString("10px") // false
|
|
10
|
+
* isNumberOnlyString("10%") // false
|
|
11
|
+
* isNumberOnlyString("10 ") // true
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @param number
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
function isNumberOnlyString(number) {
|
|
18
|
+
return !isNaN(Number(number)) && !isNaN(parseFloat(number));
|
|
19
|
+
}
|
|
20
|
+
function addPxSuffixIfInputHasNoPrefix(size) {
|
|
21
|
+
if (typeof size === 'number' || isNumberOnlyString(size)) {
|
|
22
|
+
return `${size}px`;
|
|
23
|
+
}
|
|
24
|
+
return size;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { addPxSuffixIfInputHasNoPrefix, isNumberOnlyString };
|
|
@@ -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, }: 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, 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;
|
|
@@ -181,11 +187,18 @@ type SortProps = {
|
|
|
181
187
|
};
|
|
182
188
|
type ColumnProps = {
|
|
183
189
|
columnPinState?: ColumnPinningState;
|
|
190
|
+
columnSizing?: ColumnSizingState;
|
|
191
|
+
onColumnResize?: (e: ColumnSizingState) => void;
|
|
184
192
|
};
|
|
185
193
|
type RefProps = {
|
|
186
194
|
rowVirtualizerInstanceRef?: MutableRefObject<Virtualizer<HTMLDivElement, Element> | null>;
|
|
187
195
|
};
|
|
188
|
-
|
|
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> & {
|
|
189
202
|
/**
|
|
190
203
|
* Which columns are visible. If not set, all columns are visible. undefined means that the column is visible.
|
|
191
204
|
* @default undefined
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function returning wether a string only contains number. Allows leading or trailing spaces.
|
|
3
|
+
*
|
|
4
|
+
* Examples:
|
|
5
|
+
*
|
|
6
|
+
* ```
|
|
7
|
+
* isNumberOnlyString("10") // true
|
|
8
|
+
* isNumberOnlyString("10.10") // true
|
|
9
|
+
* isNumberOnlyString("10px") // false
|
|
10
|
+
* isNumberOnlyString("10%") // false
|
|
11
|
+
* isNumberOnlyString("10 ") // true
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @param number
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare function isNumberOnlyString(number: string): boolean;
|
|
18
|
+
export declare function addPxSuffixIfInputHasNoPrefix(size: number | string): string;
|
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",
|
|
@@ -14,17 +14,17 @@
|
|
|
14
14
|
"email": "fg_eds@equinor.com"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
+
"@equinor/eds-core-react": ">=0.36.0",
|
|
17
18
|
"react": ">=16.8",
|
|
18
19
|
"react-dom": ">=16.8",
|
|
19
|
-
"styled-components": ">=4.2"
|
|
20
|
-
"@equinor/eds-core-react": "^0.35.1"
|
|
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
26
|
"@equinor/eds-tokens": "0.9.2",
|
|
27
|
-
"@equinor/eds-utils": "^0.8.
|
|
27
|
+
"@equinor/eds-utils": "^0.8.4"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@mdx-js/react": "2.3.0",
|