@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.
@@ -1,156 +1,170 @@
1
- import _objectSpread from '@babel/runtime/helpers/objectSpread2';
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 { useEds, Table, Pagination } from '@equinor/eds-core-react';
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 { useVirtualizer } from '@tanstack/react-virtual';
10
- import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
8
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
11
9
 
12
- function EdsDataGrid(_ref) {
13
- var rows = _ref.rows,
14
- columns = _ref.columns,
15
- columnResizeMode = _ref.columnResizeMode,
16
- pageSize = _ref.pageSize,
17
- rowSelection = _ref.rowSelection,
18
- selectedRows = _ref.selectedRows,
19
- enableColumnFiltering = _ref.enableColumnFiltering,
20
- debug = _ref.debug,
21
- enablePagination = _ref.enablePagination,
22
- enableSorting = _ref.enableSorting,
23
- stickyHeader = _ref.stickyHeader,
24
- onSelectRow = _ref.onSelectRow,
25
- caption = _ref.caption,
26
- enableVirtual = _ref.enableVirtual,
27
- virtualHeight = _ref.virtualHeight,
28
- columnVisibility = _ref.columnVisibility,
29
- columnVisibilityChange = _ref.columnVisibilityChange,
30
- emptyMessage = _ref.emptyMessage,
31
- columnOrder = _ref.columnOrder,
32
- cellClass = _ref.cellClass,
33
- cellStyle = _ref.cellStyle,
34
- rowClass = _ref.rowClass,
35
- rowStyle = _ref.rowStyle,
36
- headerClass = _ref.headerClass,
37
- headerStyle = _ref.headerStyle;
38
- var _useState = useState([]),
39
- _useState2 = _slicedToArray(_useState, 2),
40
- sorting = _useState2[0],
41
- setSorting = _useState2[1];
42
- var _useState3 = useState(selectedRows !== null && selectedRows !== void 0 ? selectedRows : {}),
43
- _useState4 = _slicedToArray(_useState3, 2),
44
- selection = _useState4[0],
45
- setSelection = _useState4[1];
46
- var _useState5 = useState([]),
47
- _useState6 = _slicedToArray(_useState5, 2),
48
- columnFilters = _useState6[0],
49
- setColumnFilters = _useState6[1];
50
- var _useState7 = useState(columnVisibility !== null && columnVisibility !== void 0 ? columnVisibility : {}),
51
- _useState8 = _slicedToArray(_useState7, 2),
52
- visible = _useState8[0],
53
- setVisible = _useState8[1];
54
- var _useState9 = useState(''),
55
- _useState10 = _slicedToArray(_useState9, 2),
56
- globalFilter = _useState10[0],
57
- setGlobalFilter = _useState10[1];
58
- var _useState11 = useState([]),
59
- _useState12 = _slicedToArray(_useState11, 2),
60
- columnOrderState = _useState12[0],
61
- setColumnOrderState = _useState12[1];
62
- var _useState13 = useState({
63
- pageIndex: 0,
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(function () {
73
- setSelection(selectedRows !== null && selectedRows !== void 0 ? selectedRows : {});
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
- var _columns = useMemo(function () {
80
- return columns.map(function (column) {
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 _objectSpread(_objectSpread({}, column), {}, {
86
- filterFn: function filterFn(row, columnId, filterValue) {
87
- var _row$getValue;
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
- var value = (_row$getValue = row.getValue(columnId)) !== null && _row$getValue !== void 0 ? _row$getValue : 'NULL_OR_UNDEFINED';
91
+ const value = row.getValue(columnId) ?? 'NULL_OR_UNDEFINED';
95
92
  if (Array.isArray(filterValue)) {
96
- var numeric = filterValue.some(function (v) {
97
- return typeof v === 'number';
98
- });
93
+ const numeric = filterValue.some(v => typeof v === 'number');
99
94
  if (numeric) {
100
- var _ref2 = filterValue,
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
- var validFilterValue = filterValue.filter(function (v) {
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
- var options = {
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: sorting,
131
+ sorting,
132
+ columnPinning: columnPin,
128
133
  rowSelection: selection,
129
134
  columnOrder: columnOrderState
130
135
  },
131
- onSortingChange: setSorting,
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 !== null && enableSorting !== void 0 ? enableSorting : false,
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 !== null && rowSelection !== void 0 ? rowSelection : false
152
+ enableRowSelection: rowSelection ?? false,
153
+ enableColumnPinning: true,
154
+ enablePinning: true,
155
+ getRowId
142
156
  };
143
- useEffect(function () {
157
+ useEffect(() => {
144
158
  if (columnOrder && columnOrder.length > 0) {
145
- setColumnOrderState(columnOrder !== null && columnOrder !== void 0 ? 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 !== null && rowSelection !== void 0 ? rowSelection : false) {
153
- options.onRowSelectionChange = function (updaterOrValue) {
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 !== null && enablePagination !== void 0 ? enablePagination : false) {
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 = function (vis) {
189
- var updated;
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(function () {
200
- setPage(function (prev) {
201
- return _objectSpread(_objectSpread({}, prev), {}, {
202
- pageSize: pageSize !== null && pageSize !== void 0 ? pageSize : 25
203
- });
204
- });
213
+ useEffect(() => {
214
+ setPage(prev => ({
215
+ ...prev,
216
+ pageSize: pageSize ?? 25
217
+ }));
205
218
  }, [pageSize]);
206
- var table = useReactTable(options);
207
- var parentRefStyle = {};
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: virtualHeight !== null && virtualHeight !== void 0 ? virtualHeight : 500,
228
+ height: height ?? virtualHeight ?? 500,
216
229
  overflow: 'auto',
217
230
  position: 'relative'
218
231
  };
219
232
  }
220
- var parentRef = useRef(null);
233
+ const parentRef = useRef(null);
221
234
 
222
235
  /**
223
236
  * Virtualization setup
224
237
  */
225
- var _useEds = useEds(),
226
- density = _useEds.density;
227
- var estimateSize = useCallback(function () {
238
+ const {
239
+ density
240
+ } = useEds();
241
+ const estimateSize = useCallback(() => {
228
242
  return density === 'compact' ? 32 : 48;
229
243
  }, [density]);
230
- var virtualizer = useVirtualizer({
244
+ const virtualizer = useVirtualizer({
231
245
  count: table.getRowModel().rows.length,
232
- getScrollElement: function getScrollElement() {
233
- return parentRef.current;
234
- },
235
- estimateSize: estimateSize
246
+ getScrollElement: () => parentRef.current,
247
+ estimateSize
236
248
  });
237
- var virtualRows = virtualizer.getVirtualItems();
238
- var paddingTop = virtualRows.length ? virtualRows[0].start : 0;
239
- var paddingBottom = virtualRows.length ? virtualizer.getTotalSize() - virtualRows[virtualRows.length - 1].end : 0;
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
- var classList = {
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: parentRefStyle,
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(function (_ref4) {
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
- width: table.getTotalSize()
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(function (headerGroup) {
280
- return /*#__PURE__*/jsx(TableHeaderRow, {
281
- table: table,
282
- headerGroup: headerGroup,
283
- columnResizeMode: columnResizeMode,
284
- deltaOffset: table.getState().columnSizingInfo.deltaOffset
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.getHeaderGroups().length,
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: "".concat(paddingTop, "px")
316
+ height: `${paddingTop}px`
300
317
  }
301
318
  })
302
- }), virtualRows.map(function (row) {
303
- return /*#__PURE__*/jsx(TableRow, {
304
- row: table.getRowModel().rows[row.index]
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: "".concat(paddingBottom, "px")
329
+ height: `${paddingBottom}px`
312
330
  }
313
331
  })
314
332
  })]
315
- }), !enableVirtual && table.getRowModel().rows.map(function (row) {
316
- return /*#__PURE__*/jsx(TableRow, {
317
- row: row
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: "".concat(table.getTotalSize(), "px")
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: function onChange(e, p) {
330
- return setPage(function (s) {
331
- return _objectSpread(_objectSpread({}, s), {}, {
332
- pageIndex: p - 1
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
- var EdsDataGridContext = /*#__PURE__*/createContext({
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(_ref) {
14
- var children = _ref.children,
15
- props = _objectWithoutProperties(_ref, _excluded);
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
- var useTableContext = function useTableContext() {
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 { EdsProvider, Input, Autocomplete } from '@equinor/eds-core-react';
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
- var _excluded = ["value", "values", "onChange", "debounce"];
5
+ /* istanbul ignore file */
8
6
  // File ignored, as relevant actions are covered via Filter.test.tsx
9
- function DebouncedInput(_ref) {
10
- var _props$placeholder, _props$placeholder2;
11
- var initialValue = _ref.value,
12
- values = _ref.values,
13
- onChange = _ref.onChange,
14
- _ref$debounce = _ref.debounce,
15
- debounce = _ref$debounce === void 0 ? 500 : _ref$debounce,
16
- props = _objectWithoutProperties(_ref, _excluded);
17
- var _useState = useState(initialValue),
18
- _useState2 = _slicedToArray(_useState, 2),
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(function () {
25
- var timeout = setTimeout(function () {
19
+ useEffect(() => {
20
+ const timeout = setTimeout(() => {
26
21
  onChange(value);
27
22
  }, debounce);
28
- return function () {
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(EdsProvider, {
34
- density: "compact",
35
- children: props.type === 'number' ? /*#__PURE__*/jsx(Input, {
36
- type: 'number',
37
- placeholder: (_props$placeholder = props.placeholder) !== null && _props$placeholder !== void 0 ? _props$placeholder : 'Search',
38
- value: value,
39
- onChange: function onChange(e) {
40
- return setValue(e.target.valueAsNumber);
41
- }
42
- }) : /*#__PURE__*/jsx(Autocomplete, {
43
- options: values,
44
- multiple: true,
45
- optionComponent: function optionComponent(opt) {
46
- return opt === 'NULL_OR_UNDEFINED' ? '<Blank>' : opt;
47
- },
48
- "data-testid": 'autocomplete'
49
- /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
50
- // @ts-ignore
51
- ,
52
- label: null,
53
- placeholder: (_props$placeholder2 = props.placeholder) !== null && _props$placeholder2 !== void 0 ? _props$placeholder2 : 'Search',
54
- onOptionsChange: function onOptionsChange(c) {
55
- return setValue(c.selectedItems);
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
  }