@equinor/eds-data-grid-react 0.1.0-beta.3 → 0.3.0-rc
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 +458 -353
- package/dist/esm/EdsDataGrid.js +172 -159
- package/dist/esm/EdsDataGridContext.js +6 -9
- package/dist/esm/components/DebouncedInput.js +59 -47
- package/dist/esm/components/Filter.js +100 -46
- package/dist/esm/components/TableBodyCell.js +35 -20
- package/dist/esm/components/TableHeaderCell.js +65 -48
- package/dist/esm/components/TableHeaderRow.js +12 -13
- package/dist/esm/components/TableRow.js +23 -19
- package/dist/types/EdsDataGrid.d.ts +2 -133
- package/dist/types/EdsDataGridContext.d.ts +1 -1
- package/dist/types/EdsDataGridProps.d.ts +204 -0
- package/dist/types/components/DebouncedInput.d.ts +3 -2
- package/dist/types/components/Filter.d.ts +1 -1
- package/dist/types/components/TableBodyCell.d.ts +1 -1
- package/dist/types/components/TableHeaderCell.d.ts +1 -1
- package/dist/types/components/TableHeaderRow.d.ts +1 -1
- package/dist/types/components/TableRow.d.ts +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/types.d.ts +3 -0
- package/package.json +43 -45
package/dist/esm/EdsDataGrid.js
CHANGED
|
@@ -1,156 +1,170 @@
|
|
|
1
|
-
import
|
|
2
|
-
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
1
|
+
import { Typography, useEds, Table, Pagination } from '@equinor/eds-core-react';
|
|
3
2
|
import { getCoreRowModel, getSortedRowModel, getFacetedRowModel, getFacetedUniqueValues, getFacetedMinMaxValues, getFilteredRowModel, getPaginationRowModel, useReactTable } from '@tanstack/react-table';
|
|
4
|
-
import {
|
|
3
|
+
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
5
4
|
import { useState, useEffect, useMemo, useRef, useCallback } from 'react';
|
|
6
5
|
import { TableHeaderRow } from './components/TableHeaderRow.js';
|
|
7
6
|
import { TableRow } from './components/TableRow.js';
|
|
8
7
|
import { TableProvider } from './EdsDataGridContext.js';
|
|
9
|
-
import {
|
|
10
|
-
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
8
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
pageSize: pageSize !== null && pageSize !== void 0 ? pageSize : 25
|
|
65
|
-
}),
|
|
66
|
-
_useState14 = _slicedToArray(_useState13, 2),
|
|
67
|
-
page = _useState14[0],
|
|
68
|
-
setPage = _useState14[1];
|
|
69
|
-
useEffect(function () {
|
|
70
|
-
setVisible(columnVisibility !== null && columnVisibility !== void 0 ? columnVisibility : {});
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
11
|
+
function EdsDataGrid({
|
|
12
|
+
rows,
|
|
13
|
+
columns,
|
|
14
|
+
columnResizeMode,
|
|
15
|
+
pageSize,
|
|
16
|
+
rowSelection,
|
|
17
|
+
selectedRows,
|
|
18
|
+
enableColumnFiltering,
|
|
19
|
+
debug,
|
|
20
|
+
enablePagination,
|
|
21
|
+
enableSorting,
|
|
22
|
+
stickyHeader,
|
|
23
|
+
onSelectRow,
|
|
24
|
+
caption,
|
|
25
|
+
enableVirtual,
|
|
26
|
+
virtualHeight,
|
|
27
|
+
columnVisibility,
|
|
28
|
+
columnVisibilityChange,
|
|
29
|
+
emptyMessage,
|
|
30
|
+
columnOrder,
|
|
31
|
+
cellClass,
|
|
32
|
+
cellStyle,
|
|
33
|
+
rowClass,
|
|
34
|
+
rowStyle,
|
|
35
|
+
headerClass,
|
|
36
|
+
headerStyle,
|
|
37
|
+
externalPaginator,
|
|
38
|
+
onSortingChange,
|
|
39
|
+
manualSorting,
|
|
40
|
+
sortingState,
|
|
41
|
+
columnPinState,
|
|
42
|
+
scrollbarHorizontal,
|
|
43
|
+
width,
|
|
44
|
+
minWidth,
|
|
45
|
+
height,
|
|
46
|
+
getRowId,
|
|
47
|
+
rowVirtualizerInstanceRef
|
|
48
|
+
}) {
|
|
49
|
+
const [sorting, setSorting] = useState(sortingState ?? []);
|
|
50
|
+
const [selection, setSelection] = useState(selectedRows ?? {});
|
|
51
|
+
const [columnPin, setColumnPin] = useState(columnPinState ?? {});
|
|
52
|
+
const [columnFilters, setColumnFilters] = useState([]);
|
|
53
|
+
const [visible, setVisible] = useState(columnVisibility ?? {});
|
|
54
|
+
const [globalFilter, setGlobalFilter] = useState('');
|
|
55
|
+
const [columnOrderState, setColumnOrderState] = useState([]);
|
|
56
|
+
const [page, setPage] = useState({
|
|
57
|
+
pageIndex: 0,
|
|
58
|
+
pageSize: pageSize ?? 25
|
|
59
|
+
});
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
setVisible(columnVisibility ?? {});
|
|
71
62
|
}, [columnVisibility, setVisible]);
|
|
72
|
-
useEffect(
|
|
73
|
-
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
setColumnPin(s => columnPinState ?? s);
|
|
65
|
+
}, [columnPinState]);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
setSorting(sortingState);
|
|
68
|
+
}, [sortingState]);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
setSelection(selectedRows ?? {});
|
|
74
71
|
}, [selectedRows]);
|
|
75
72
|
|
|
76
73
|
/**
|
|
77
74
|
* By default, the filter-function accepts single-value filters. This adds multi-filter functionality out of the box.
|
|
78
75
|
*/
|
|
79
|
-
|
|
80
|
-
return columns.map(
|
|
76
|
+
const _columns = useMemo(() => {
|
|
77
|
+
return columns.map(column => {
|
|
81
78
|
if (column.filterFn || column.enableColumnFilter === false) {
|
|
82
79
|
return column;
|
|
83
80
|
}
|
|
84
81
|
/* istanbul ignore next */
|
|
85
|
-
return
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
return {
|
|
83
|
+
...column,
|
|
84
|
+
filterFn: (row, columnId, filterValue) => {
|
|
88
85
|
if (debug) {
|
|
89
86
|
console.log('filterFn', row, columnId, filterValue);
|
|
90
87
|
}
|
|
91
88
|
if (!filterValue || (Array.isArray(filterValue) || typeof filterValue === 'string') && filterValue.length === 0) {
|
|
92
89
|
return true;
|
|
93
90
|
}
|
|
94
|
-
|
|
91
|
+
const value = row.getValue(columnId) ?? 'NULL_OR_UNDEFINED';
|
|
95
92
|
if (Array.isArray(filterValue)) {
|
|
96
|
-
|
|
97
|
-
return typeof v === 'number';
|
|
98
|
-
});
|
|
93
|
+
const numeric = filterValue.some(v => typeof v === 'number');
|
|
99
94
|
if (numeric) {
|
|
100
|
-
|
|
101
|
-
_ref3 = _slicedToArray(_ref2, 2),
|
|
102
|
-
start = _ref3[0],
|
|
103
|
-
end = _ref3[1];
|
|
95
|
+
const [start, end] = filterValue;
|
|
104
96
|
return Number(value) >= (isNaN(start) ? 0 : start) && Number(value) <= (!end || isNaN(end) ? Infinity : end);
|
|
105
97
|
} else {
|
|
106
|
-
|
|
107
|
-
return !!v;
|
|
108
|
-
});
|
|
98
|
+
const validFilterValue = filterValue.filter(v => !!v);
|
|
109
99
|
if (validFilterValue.length === 0) return true;
|
|
110
100
|
return filterValue.includes(value);
|
|
111
101
|
}
|
|
112
102
|
}
|
|
113
103
|
return value === filterValue;
|
|
114
104
|
}
|
|
115
|
-
}
|
|
105
|
+
};
|
|
116
106
|
});
|
|
117
107
|
}, [debug, columns]);
|
|
118
108
|
|
|
119
109
|
/**
|
|
120
110
|
* Set up default table options
|
|
121
111
|
*/
|
|
122
|
-
|
|
112
|
+
const options = {
|
|
123
113
|
data: rows,
|
|
124
114
|
columns: _columns,
|
|
115
|
+
defaultColumn: {
|
|
116
|
+
cell: context => {
|
|
117
|
+
return /*#__PURE__*/jsx(Typography, {
|
|
118
|
+
style: {
|
|
119
|
+
overflow: 'hidden',
|
|
120
|
+
whiteSpace: 'nowrap',
|
|
121
|
+
textOverflow: 'ellipsis'
|
|
122
|
+
},
|
|
123
|
+
group: "table",
|
|
124
|
+
variant: "cell_text",
|
|
125
|
+
children: String(context.getValue() ?? '')
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
},
|
|
125
129
|
columnResizeMode: columnResizeMode,
|
|
126
130
|
state: {
|
|
127
|
-
sorting
|
|
131
|
+
sorting,
|
|
132
|
+
columnPinning: columnPin,
|
|
128
133
|
rowSelection: selection,
|
|
129
134
|
columnOrder: columnOrderState
|
|
130
135
|
},
|
|
131
|
-
onSortingChange:
|
|
136
|
+
onSortingChange: changes => {
|
|
137
|
+
if (onSortingChange) {
|
|
138
|
+
onSortingChange(changes);
|
|
139
|
+
}
|
|
140
|
+
setSorting(changes);
|
|
141
|
+
},
|
|
132
142
|
enableColumnFilters: !!enableColumnFiltering,
|
|
133
143
|
enableFilters: !!enableColumnFiltering,
|
|
134
|
-
enableSorting: enableSorting
|
|
144
|
+
enableSorting: enableSorting ?? false,
|
|
145
|
+
manualSorting: manualSorting ?? false,
|
|
135
146
|
enableColumnResizing: !!columnResizeMode,
|
|
136
147
|
getCoreRowModel: getCoreRowModel(),
|
|
137
148
|
getSortedRowModel: getSortedRowModel(),
|
|
138
149
|
debugTable: debug,
|
|
139
150
|
debugHeaders: debug,
|
|
140
151
|
debugColumns: debug,
|
|
141
|
-
enableRowSelection: rowSelection
|
|
152
|
+
enableRowSelection: rowSelection ?? false,
|
|
153
|
+
enableColumnPinning: true,
|
|
154
|
+
enablePinning: true,
|
|
155
|
+
getRowId
|
|
142
156
|
};
|
|
143
|
-
useEffect(
|
|
157
|
+
useEffect(() => {
|
|
144
158
|
if (columnOrder && columnOrder.length > 0) {
|
|
145
|
-
setColumnOrderState(columnOrder
|
|
159
|
+
setColumnOrderState(columnOrder ?? []);
|
|
146
160
|
}
|
|
147
161
|
}, [columnOrder]);
|
|
148
162
|
|
|
149
163
|
/**
|
|
150
164
|
* Set up handlers for rowSelection
|
|
151
165
|
*/
|
|
152
|
-
if (rowSelection
|
|
153
|
-
options.onRowSelectionChange =
|
|
166
|
+
if (rowSelection ?? false) {
|
|
167
|
+
options.onRowSelectionChange = updaterOrValue => {
|
|
154
168
|
if (onSelectRow) {
|
|
155
169
|
onSelectRow(updaterOrValue);
|
|
156
170
|
}
|
|
@@ -175,7 +189,7 @@ function EdsDataGrid(_ref) {
|
|
|
175
189
|
/**
|
|
176
190
|
* Set up config for pagination
|
|
177
191
|
*/
|
|
178
|
-
if (enablePagination
|
|
192
|
+
if (enablePagination ?? false) {
|
|
179
193
|
options.state.pagination = page;
|
|
180
194
|
options.getPaginationRowModel = getPaginationRowModel();
|
|
181
195
|
}
|
|
@@ -185,8 +199,8 @@ function EdsDataGrid(_ref) {
|
|
|
185
199
|
*/
|
|
186
200
|
if (columnVisibility) {
|
|
187
201
|
options.state.columnVisibility = visible;
|
|
188
|
-
options.onColumnVisibilityChange =
|
|
189
|
-
|
|
202
|
+
options.onColumnVisibilityChange = vis => {
|
|
203
|
+
let updated;
|
|
190
204
|
if (typeof vis === 'function') {
|
|
191
205
|
updated = vis(visible);
|
|
192
206
|
} else {
|
|
@@ -196,15 +210,14 @@ function EdsDataGrid(_ref) {
|
|
|
196
210
|
setVisible(updated);
|
|
197
211
|
};
|
|
198
212
|
}
|
|
199
|
-
useEffect(
|
|
200
|
-
setPage(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
});
|
|
213
|
+
useEffect(() => {
|
|
214
|
+
setPage(prev => ({
|
|
215
|
+
...prev,
|
|
216
|
+
pageSize: pageSize ?? 25
|
|
217
|
+
}));
|
|
205
218
|
}, [pageSize]);
|
|
206
|
-
|
|
207
|
-
|
|
219
|
+
const table = useReactTable(options);
|
|
220
|
+
let parentRefStyle = {};
|
|
208
221
|
|
|
209
222
|
/**
|
|
210
223
|
* Style the parent container to enable virtualization.
|
|
@@ -212,34 +225,34 @@ function EdsDataGrid(_ref) {
|
|
|
212
225
|
*/
|
|
213
226
|
if (enableVirtual) {
|
|
214
227
|
parentRefStyle = {
|
|
215
|
-
height:
|
|
228
|
+
height: height ?? virtualHeight ?? 500,
|
|
216
229
|
overflow: 'auto',
|
|
217
230
|
position: 'relative'
|
|
218
231
|
};
|
|
219
232
|
}
|
|
220
|
-
|
|
233
|
+
const parentRef = useRef(null);
|
|
221
234
|
|
|
222
235
|
/**
|
|
223
236
|
* Virtualization setup
|
|
224
237
|
*/
|
|
225
|
-
|
|
226
|
-
density
|
|
227
|
-
|
|
238
|
+
const {
|
|
239
|
+
density
|
|
240
|
+
} = useEds();
|
|
241
|
+
const estimateSize = useCallback(() => {
|
|
228
242
|
return density === 'compact' ? 32 : 48;
|
|
229
243
|
}, [density]);
|
|
230
|
-
|
|
244
|
+
const virtualizer = useVirtualizer({
|
|
231
245
|
count: table.getRowModel().rows.length,
|
|
232
|
-
getScrollElement:
|
|
233
|
-
|
|
234
|
-
},
|
|
235
|
-
estimateSize: estimateSize
|
|
246
|
+
getScrollElement: () => parentRef.current,
|
|
247
|
+
estimateSize
|
|
236
248
|
});
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
249
|
+
if (rowVirtualizerInstanceRef) rowVirtualizerInstanceRef.current = virtualizer;
|
|
250
|
+
const virtualRows = virtualizer.getVirtualItems();
|
|
251
|
+
const paddingTop = virtualRows.length ? virtualRows[0].start : 0;
|
|
252
|
+
const paddingBottom = virtualRows.length ? virtualizer.getTotalSize() - virtualRows[virtualRows.length - 1].end : 0;
|
|
240
253
|
|
|
241
254
|
// These classes are primarily used to allow for feature-detection in the test-suite
|
|
242
|
-
|
|
255
|
+
const classList = {
|
|
243
256
|
'sticky-header': !!stickyHeader,
|
|
244
257
|
virtual: !!enableVirtual,
|
|
245
258
|
paging: !!enablePagination
|
|
@@ -257,82 +270,82 @@ function EdsDataGrid(_ref) {
|
|
|
257
270
|
stickyHeader: !!stickyHeader,
|
|
258
271
|
children: [/*#__PURE__*/jsxs("div", {
|
|
259
272
|
className: "table-wrapper",
|
|
260
|
-
style:
|
|
273
|
+
style: {
|
|
274
|
+
height: height ?? 'auto',
|
|
275
|
+
...parentRefStyle,
|
|
276
|
+
width: scrollbarHorizontal ? width ?? '100%' : 'auto',
|
|
277
|
+
overflow: 'auto',
|
|
278
|
+
contain: 'layout paint style'
|
|
279
|
+
},
|
|
261
280
|
ref: parentRef,
|
|
262
281
|
children: [/*#__PURE__*/jsxs(Table, {
|
|
263
|
-
className: Object.entries(classList).filter(
|
|
264
|
-
var _ref5 = _slicedToArray(_ref4, 2),
|
|
265
|
-
k = _ref5[1];
|
|
266
|
-
return k;
|
|
267
|
-
}).map(function (_ref6) {
|
|
268
|
-
var _ref7 = _slicedToArray(_ref6, 1),
|
|
269
|
-
k = _ref7[0];
|
|
270
|
-
return k;
|
|
271
|
-
}).join(' '),
|
|
282
|
+
className: Object.entries(classList).filter(([, k]) => k).map(([k]) => k).join(' '),
|
|
272
283
|
style: {
|
|
273
|
-
|
|
284
|
+
tableLayout: scrollbarHorizontal ? 'fixed' : 'auto',
|
|
285
|
+
width: table.getTotalSize(),
|
|
286
|
+
minWidth: scrollbarHorizontal ? minWidth : 'auto'
|
|
274
287
|
},
|
|
275
288
|
children: [caption && /*#__PURE__*/jsx(Table.Caption, {
|
|
276
289
|
children: caption
|
|
277
290
|
}), /*#__PURE__*/jsx(Table.Head, {
|
|
278
291
|
sticky: stickyHeader,
|
|
279
|
-
children: table.getHeaderGroups().map(
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}, headerGroup.id);
|
|
286
|
-
})
|
|
292
|
+
children: table.getHeaderGroups().map(headerGroup => /*#__PURE__*/jsx(TableHeaderRow, {
|
|
293
|
+
table: table,
|
|
294
|
+
headerGroup: headerGroup,
|
|
295
|
+
columnResizeMode: columnResizeMode,
|
|
296
|
+
deltaOffset: table.getState().columnSizingInfo.deltaOffset
|
|
297
|
+
}, headerGroup.id))
|
|
287
298
|
}), /*#__PURE__*/jsxs(Table.Body, {
|
|
299
|
+
style: {
|
|
300
|
+
backgroundColor: 'inherit'
|
|
301
|
+
},
|
|
288
302
|
children: [table.getRowModel().rows.length === 0 && emptyMessage && /*#__PURE__*/jsx(Table.Row, {
|
|
289
303
|
children: /*#__PURE__*/jsx(Table.Cell, {
|
|
290
|
-
colSpan: table.
|
|
304
|
+
colSpan: table.getFlatHeaders().length,
|
|
291
305
|
children: emptyMessage
|
|
292
306
|
})
|
|
293
307
|
}), enableVirtual && /*#__PURE__*/jsxs(Fragment, {
|
|
294
|
-
children: [/*#__PURE__*/jsx(Table.Row, {
|
|
308
|
+
children: [paddingTop > 0 && /*#__PURE__*/jsx(Table.Row, {
|
|
295
309
|
"data-testid": "virtual-padding-top",
|
|
296
310
|
className: 'virtual-padding-top',
|
|
311
|
+
style: {
|
|
312
|
+
pointerEvents: 'none'
|
|
313
|
+
},
|
|
297
314
|
children: /*#__PURE__*/jsx(Table.Cell, {
|
|
298
315
|
style: {
|
|
299
|
-
height:
|
|
316
|
+
height: `${paddingTop}px`
|
|
300
317
|
}
|
|
301
318
|
})
|
|
302
|
-
}), virtualRows.map(
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}, row.index);
|
|
306
|
-
}), /*#__PURE__*/jsx(Table.Row, {
|
|
319
|
+
}), virtualRows.map(row => /*#__PURE__*/jsx(TableRow, {
|
|
320
|
+
row: table.getRowModel().rows[row.index]
|
|
321
|
+
}, row.index)), paddingBottom > 0 && /*#__PURE__*/jsx(Table.Row, {
|
|
307
322
|
"data-testid": "virtual-padding-bottom",
|
|
308
323
|
className: 'virtual-padding-bottom',
|
|
324
|
+
style: {
|
|
325
|
+
pointerEvents: 'none'
|
|
326
|
+
},
|
|
309
327
|
children: /*#__PURE__*/jsx(Table.Cell, {
|
|
310
328
|
style: {
|
|
311
|
-
height:
|
|
329
|
+
height: `${paddingBottom}px`
|
|
312
330
|
}
|
|
313
331
|
})
|
|
314
332
|
})]
|
|
315
|
-
}), !enableVirtual && table.getRowModel().rows.map(
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}, row.id);
|
|
319
|
-
})]
|
|
333
|
+
}), !enableVirtual && table.getRowModel().rows.map(row => /*#__PURE__*/jsx(TableRow, {
|
|
334
|
+
row: row
|
|
335
|
+
}, row.id))]
|
|
320
336
|
})]
|
|
321
|
-
}), enablePagination && /*#__PURE__*/jsx("div", {
|
|
337
|
+
}), externalPaginator ? externalPaginator : enablePagination && /*#__PURE__*/jsx("div", {
|
|
322
338
|
style: {
|
|
323
|
-
maxWidth:
|
|
339
|
+
maxWidth: `${table.getTotalSize()}px`
|
|
324
340
|
},
|
|
325
341
|
children: /*#__PURE__*/jsx(Pagination, {
|
|
326
342
|
totalItems: table.getFilteredRowModel().rows.length,
|
|
327
343
|
withItemIndicator: true,
|
|
328
344
|
itemsPerPage: page.pageSize,
|
|
329
|
-
onChange:
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
});
|
|
334
|
-
});
|
|
335
|
-
},
|
|
345
|
+
onChange: (e, p) => setPage(s => ({
|
|
346
|
+
...s,
|
|
347
|
+
pageIndex: p - 1
|
|
348
|
+
})),
|
|
336
349
|
defaultPage: 1
|
|
337
350
|
})
|
|
338
351
|
})]
|
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
2
1
|
import { createContext, useContext } from 'react';
|
|
3
2
|
import { jsx } from 'react/jsx-runtime';
|
|
4
3
|
|
|
5
|
-
var _excluded = ["children"];
|
|
6
4
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
-
|
|
5
|
+
const EdsDataGridContext = /*#__PURE__*/createContext({
|
|
8
6
|
enableSorting: false,
|
|
9
7
|
stickyHeader: false,
|
|
10
8
|
enableColumnFiltering: false,
|
|
11
9
|
table: null
|
|
12
10
|
});
|
|
13
|
-
function TableProvider(
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
function TableProvider({
|
|
12
|
+
children,
|
|
13
|
+
...props
|
|
14
|
+
}) {
|
|
16
15
|
return /*#__PURE__*/jsx(EdsDataGridContext.Provider, {
|
|
17
16
|
value: props,
|
|
18
17
|
children: children
|
|
19
18
|
});
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
return useContext(EdsDataGridContext);
|
|
23
|
-
};
|
|
20
|
+
const useTableContext = () => useContext(EdsDataGridContext);
|
|
24
21
|
|
|
25
22
|
export { EdsDataGridContext, TableProvider, useTableContext };
|
|
@@ -1,59 +1,71 @@
|
|
|
1
|
-
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
|
-
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
3
1
|
import { useState, useEffect } from 'react';
|
|
4
|
-
import {
|
|
5
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { InputWrapper, Input, Autocomplete, Chip } from '@equinor/eds-core-react';
|
|
3
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
/* istanbul ignore file */
|
|
8
6
|
// File ignored, as relevant actions are covered via Filter.test.tsx
|
|
9
|
-
function DebouncedInput(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
value = _useState2[0],
|
|
20
|
-
setValue = _useState2[1];
|
|
21
|
-
useEffect(function () {
|
|
7
|
+
function DebouncedInput({
|
|
8
|
+
value: initialValue,
|
|
9
|
+
values,
|
|
10
|
+
onChange,
|
|
11
|
+
debounce = 500,
|
|
12
|
+
label,
|
|
13
|
+
...props
|
|
14
|
+
}) {
|
|
15
|
+
const [value, setValue] = useState(initialValue);
|
|
16
|
+
useEffect(() => {
|
|
22
17
|
setValue(initialValue);
|
|
23
18
|
}, [initialValue]);
|
|
24
|
-
useEffect(
|
|
25
|
-
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const timeout = setTimeout(() => {
|
|
26
21
|
onChange(value);
|
|
27
22
|
}, debounce);
|
|
28
|
-
return
|
|
29
|
-
return clearTimeout(timeout);
|
|
30
|
-
};
|
|
23
|
+
return () => clearTimeout(timeout);
|
|
31
24
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
32
25
|
}, [value]);
|
|
33
|
-
return /*#__PURE__*/jsx(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
}) : /*#__PURE__*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
26
|
+
return /*#__PURE__*/jsx(Fragment, {
|
|
27
|
+
children: props.type === 'number' ? /*#__PURE__*/jsx(InputWrapper, {
|
|
28
|
+
label: props.placeholder,
|
|
29
|
+
children: /*#__PURE__*/jsx(Input, {
|
|
30
|
+
type: 'number',
|
|
31
|
+
placeholder: '0',
|
|
32
|
+
value: value,
|
|
33
|
+
onChange: e => setValue(e.target.valueAsNumber)
|
|
34
|
+
})
|
|
35
|
+
}) : /*#__PURE__*/jsxs(Fragment, {
|
|
36
|
+
children: [/*#__PURE__*/jsx(Autocomplete, {
|
|
37
|
+
options: values,
|
|
38
|
+
autoWidth: true,
|
|
39
|
+
multiple: true,
|
|
40
|
+
optionComponent: opt => opt === 'NULL_OR_UNDEFINED' ? '<Blank>' : opt,
|
|
41
|
+
"data-testid": 'autocomplete'
|
|
42
|
+
/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */,
|
|
43
|
+
label: `Select ${label ?? ''}`,
|
|
44
|
+
placeholder: props.placeholder ?? 'Search',
|
|
45
|
+
disablePortal: false /*TODO: Check with Oddbjørn re. sizing/position*/,
|
|
46
|
+
selectedOptions: value,
|
|
47
|
+
onOptionsChange: c => setValue(c.selectedItems),
|
|
48
|
+
multiline: true
|
|
49
|
+
}), /*#__PURE__*/jsx("div", {
|
|
50
|
+
style: {
|
|
51
|
+
display: 'flex',
|
|
52
|
+
flexWrap: 'wrap',
|
|
53
|
+
marginTop: '8px'
|
|
54
|
+
},
|
|
55
|
+
children: value.map(v => /*#__PURE__*/jsxs(Chip, {
|
|
56
|
+
title: v,
|
|
57
|
+
onKeyDownCapture: event => {
|
|
58
|
+
if (['Backspace', 'Delete'].includes(event.key)) {
|
|
59
|
+
onChange(value.filter(item => item !== v));
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
style: {
|
|
63
|
+
margin: '4px'
|
|
64
|
+
},
|
|
65
|
+
onDelete: () => onChange(value.filter(item => item !== v)),
|
|
66
|
+
children: [v.slice(0, 20), v.length > 20 ? '...' : '']
|
|
67
|
+
}, v))
|
|
68
|
+
})]
|
|
57
69
|
})
|
|
58
70
|
});
|
|
59
71
|
}
|