@equinor/eds-core-react 0.38.0 → 0.39.1-dev13062024
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-core-react.cjs
CHANGED
|
@@ -9420,6 +9420,7 @@ const Container$2 = styled__default.default.div.withConfig({
|
|
|
9420
9420
|
componentId: "sc-yvif0e-0"
|
|
9421
9421
|
})(["position:relative;"]);
|
|
9422
9422
|
const AllSymbol = Symbol('Select all');
|
|
9423
|
+
// MARK: styled components
|
|
9423
9424
|
const StyledList = styled__default.default(List$1).withConfig({
|
|
9424
9425
|
displayName: "Autocomplete__StyledList",
|
|
9425
9426
|
componentId: "sc-yvif0e-1"
|
|
@@ -9431,7 +9432,7 @@ const StyledPopover = styled__default.default('div').withConfig({
|
|
|
9431
9432
|
}).withConfig({
|
|
9432
9433
|
displayName: "Autocomplete__StyledPopover",
|
|
9433
9434
|
componentId: "sc-yvif0e-2"
|
|
9434
|
-
})(["inset:unset;border:0;padding:0;margin:0;overflow:visible;"]);
|
|
9435
|
+
})(["inset:unset;border:0;padding:0;margin:0;overflow:visible;&::backdrop{background-color:transparent;}"]);
|
|
9435
9436
|
const HelperText = styled__default.default(TextfieldHelperText).withConfig({
|
|
9436
9437
|
displayName: "Autocomplete__HelperText",
|
|
9437
9438
|
componentId: "sc-yvif0e-3"
|
|
@@ -9452,7 +9453,7 @@ const StyledButton$1 = styled__default.default(Button$1).withConfig({
|
|
|
9452
9453
|
}
|
|
9453
9454
|
}
|
|
9454
9455
|
}) => styled.css(["height:", ";width:", ";"], button.height, button.height));
|
|
9455
|
-
|
|
9456
|
+
// MARK: outside functions
|
|
9456
9457
|
// Typescript can struggle with parsing generic arrow functions in a .tsx file (see https://github.com/microsoft/TypeScript/issues/15713)
|
|
9457
9458
|
// Workaround is to add a trailing , after T, which tricks the compiler, but also have to ignore prettier rule.
|
|
9458
9459
|
// prettier-ignore
|
|
@@ -9542,6 +9543,9 @@ const handleListFocus = e => {
|
|
|
9542
9543
|
});
|
|
9543
9544
|
};
|
|
9544
9545
|
const defaultOptionDisabled = () => false;
|
|
9546
|
+
// MARK: types
|
|
9547
|
+
|
|
9548
|
+
// MARK: component
|
|
9545
9549
|
function AutocompleteInner(props, ref) {
|
|
9546
9550
|
const {
|
|
9547
9551
|
options = [],
|
|
@@ -9555,10 +9559,11 @@ function AutocompleteInner(props, ref) {
|
|
|
9555
9559
|
hideClearButton = false,
|
|
9556
9560
|
onOptionsChange,
|
|
9557
9561
|
onInputChange,
|
|
9558
|
-
selectedOptions,
|
|
9562
|
+
selectedOptions: _selectedOptions,
|
|
9559
9563
|
multiple,
|
|
9564
|
+
itemCompare,
|
|
9560
9565
|
allowSelectAll,
|
|
9561
|
-
initialSelectedOptions = [],
|
|
9566
|
+
initialSelectedOptions: _initialSelectedOptions = [],
|
|
9562
9567
|
disablePortal,
|
|
9563
9568
|
optionDisabled = defaultOptionDisabled,
|
|
9564
9569
|
optionsFilter,
|
|
@@ -9575,6 +9580,10 @@ function AutocompleteInner(props, ref) {
|
|
|
9575
9580
|
variant,
|
|
9576
9581
|
...other
|
|
9577
9582
|
} = props;
|
|
9583
|
+
|
|
9584
|
+
// MARK: initializing data/setup
|
|
9585
|
+
const selectedOptions = _selectedOptions ? itemCompare ? options.filter(item => _selectedOptions.some(compare => itemCompare(item, compare))) : _selectedOptions : undefined;
|
|
9586
|
+
const initialSelectedOptions = _initialSelectedOptions ? itemCompare ? options.filter(item => _initialSelectedOptions.some(compare => itemCompare(item, compare))) : _initialSelectedOptions : undefined;
|
|
9578
9587
|
if (disablePortal) {
|
|
9579
9588
|
console.warn('Autocomplete "disablePortal" prop has been deprecated. Autocomplete now uses the native popover api');
|
|
9580
9589
|
}
|
|
@@ -9620,7 +9629,10 @@ function AutocompleteInner(props, ref) {
|
|
|
9620
9629
|
...multipleSelectionProps,
|
|
9621
9630
|
onSelectedItemsChange: changes => {
|
|
9622
9631
|
if (onOptionsChange) {
|
|
9623
|
-
|
|
9632
|
+
let selectedItems = changes.selectedItems.filter(item => item !== AllSymbol);
|
|
9633
|
+
if (itemCompare) {
|
|
9634
|
+
selectedItems = inputOptions.filter(item => selectedItems.some(compare => itemCompare(item, compare)));
|
|
9635
|
+
}
|
|
9624
9636
|
onOptionsChange({
|
|
9625
9637
|
selectedItems
|
|
9626
9638
|
});
|
|
@@ -9641,6 +9653,8 @@ function AutocompleteInner(props, ref) {
|
|
|
9641
9653
|
selectedItems,
|
|
9642
9654
|
setSelectedItems
|
|
9643
9655
|
} = downshift.useMultipleSelection(multipleSelectionProps);
|
|
9656
|
+
|
|
9657
|
+
// MARK: select all logic
|
|
9644
9658
|
const enabledItems = react.useMemo(() => {
|
|
9645
9659
|
const disabledItemsSet = new Set(inputOptions.filter(optionDisabled));
|
|
9646
9660
|
return inputOptions.filter(x => !disabledItemsSet.has(x));
|
|
@@ -9660,6 +9674,8 @@ function AutocompleteInner(props, ref) {
|
|
|
9660
9674
|
setSelectedItems([...enabledItems, ...selectedDisabledItemsSet]);
|
|
9661
9675
|
}
|
|
9662
9676
|
};
|
|
9677
|
+
|
|
9678
|
+
// MARK: getLabel
|
|
9663
9679
|
const getLabel = react.useCallback(item => {
|
|
9664
9680
|
//note: non strict check for null or undefined to allow 0
|
|
9665
9681
|
if (item == null) {
|
|
@@ -9682,6 +9698,8 @@ function AutocompleteInner(props, ref) {
|
|
|
9682
9698
|
throw new Error('Unable to find label, make sure your are using options as documented');
|
|
9683
9699
|
}
|
|
9684
9700
|
}, [optionLabel]);
|
|
9701
|
+
|
|
9702
|
+
// MARK: setup virtualizer
|
|
9685
9703
|
const scrollContainer = react.useRef(null);
|
|
9686
9704
|
const rowVirtualizer = reactVirtual.useVirtualizer({
|
|
9687
9705
|
count: availableItems.length,
|
|
@@ -9696,8 +9714,11 @@ function AutocompleteInner(props, ref) {
|
|
|
9696
9714
|
edsUtils.useIsomorphicLayoutEffect(() => {
|
|
9697
9715
|
rowVirtualizer?.measure?.();
|
|
9698
9716
|
}, [rowVirtualizer, density]);
|
|
9717
|
+
|
|
9718
|
+
// MARK: downshift state
|
|
9699
9719
|
let comboBoxProps = {
|
|
9700
9720
|
items: availableItems,
|
|
9721
|
+
//can not pass readonly type to downshift so we cast it to regular T[]
|
|
9701
9722
|
initialSelectedItem: initialSelectedOptions[0],
|
|
9702
9723
|
isItemDisabled(item) {
|
|
9703
9724
|
return optionDisabled(item);
|
|
@@ -9762,14 +9783,18 @@ function AutocompleteInner(props, ref) {
|
|
|
9762
9783
|
}
|
|
9763
9784
|
}
|
|
9764
9785
|
};
|
|
9786
|
+
// MARK: singleselect specific
|
|
9765
9787
|
if (!multiple) {
|
|
9766
9788
|
comboBoxProps = {
|
|
9767
9789
|
...comboBoxProps,
|
|
9768
9790
|
onSelectedItemChange: changes => {
|
|
9769
9791
|
if (onOptionsChange) {
|
|
9770
|
-
|
|
9792
|
+
let {
|
|
9771
9793
|
selectedItem
|
|
9772
9794
|
} = changes;
|
|
9795
|
+
if (itemCompare) {
|
|
9796
|
+
selectedItem = inputOptions.find(item => itemCompare(item, selectedItem));
|
|
9797
|
+
}
|
|
9773
9798
|
onOptionsChange({
|
|
9774
9799
|
selectedItems: selectedItem ? [selectedItem] : []
|
|
9775
9800
|
});
|
|
@@ -9835,6 +9860,7 @@ function AutocompleteInner(props, ref) {
|
|
|
9835
9860
|
};
|
|
9836
9861
|
}
|
|
9837
9862
|
}
|
|
9863
|
+
// MARK: multiselect specific
|
|
9838
9864
|
if (multiple) {
|
|
9839
9865
|
placeholderText = typeof placeholderText !== 'undefined' ? placeholderText : `${selectedItems.length}/${inputOptions.length} selected`;
|
|
9840
9866
|
comboBoxProps = {
|
|
@@ -9928,6 +9954,8 @@ function AutocompleteInner(props, ref) {
|
|
|
9928
9954
|
inputValue,
|
|
9929
9955
|
reset: resetCombobox
|
|
9930
9956
|
} = downshift.useCombobox(comboBoxProps);
|
|
9957
|
+
|
|
9958
|
+
// MARK: floating-ui setup
|
|
9931
9959
|
const {
|
|
9932
9960
|
x,
|
|
9933
9961
|
y,
|
|
@@ -9959,6 +9987,8 @@ function AutocompleteInner(props, ref) {
|
|
|
9959
9987
|
return react$1.autoUpdate(refs.reference.current, refs.floating.current, update);
|
|
9960
9988
|
}
|
|
9961
9989
|
}, [refs.reference, refs.floating, update, isOpen]);
|
|
9990
|
+
|
|
9991
|
+
// MARK: popover toggle
|
|
9962
9992
|
edsUtils.useIsomorphicLayoutEffect(() => {
|
|
9963
9993
|
if (isOpen) {
|
|
9964
9994
|
refs.floating.current.showPopover();
|
|
@@ -9975,6 +10005,8 @@ function AutocompleteInner(props, ref) {
|
|
|
9975
10005
|
const showClearButton = (selectedItems.length > 0 || inputValue) && !readOnly && !hideClearButton;
|
|
9976
10006
|
const showNoOptions = isOpen && !availableItems.length && noOptionsText.length > 0;
|
|
9977
10007
|
const selectedItemsLabels = react.useMemo(() => selectedItems.map(getLabel), [selectedItems, getLabel]);
|
|
10008
|
+
|
|
10009
|
+
// MARK: optionsList
|
|
9978
10010
|
const optionsList = /*#__PURE__*/jsxRuntime.jsx(StyledPopover, {
|
|
9979
10011
|
popover: "manual",
|
|
9980
10012
|
...getFloatingProps({
|
|
@@ -10076,6 +10108,8 @@ function AutocompleteInner(props, ref) {
|
|
|
10076
10108
|
disabled
|
|
10077
10109
|
}));
|
|
10078
10110
|
const consolidatedEvents = mergeEventsFromRight(other, inputProps);
|
|
10111
|
+
|
|
10112
|
+
// MARK: input
|
|
10079
10113
|
return /*#__PURE__*/jsxRuntime.jsx(styled.ThemeProvider, {
|
|
10080
10114
|
theme: token,
|
|
10081
10115
|
children: /*#__PURE__*/jsxRuntime.jsxs(Container$2, {
|
|
@@ -10131,6 +10165,7 @@ function AutocompleteInner(props, ref) {
|
|
|
10131
10165
|
})
|
|
10132
10166
|
});
|
|
10133
10167
|
}
|
|
10168
|
+
// MARK: exported component
|
|
10134
10169
|
const Autocomplete = /*#__PURE__*/react.forwardRef(AutocompleteInner);
|
|
10135
10170
|
|
|
10136
10171
|
const {
|
|
@@ -11607,7 +11642,7 @@ function DateSegment({
|
|
|
11607
11642
|
const formatter = reactAria.useDateFormatter(formatOptions);
|
|
11608
11643
|
const parts = state.value ? formatter.formatToParts(state.value.toDate(timezone)) : [];
|
|
11609
11644
|
const part = parts.find(p => p.type === segment.type);
|
|
11610
|
-
const value = part?.value ?? segment.text;
|
|
11645
|
+
const value = segment.isPlaceholder || segment.type === 'literal' ? segment.text : part?.value ?? segment.text;
|
|
11611
11646
|
const [focus, setFocus] = react.useState(false);
|
|
11612
11647
|
const ref = react.useRef(null);
|
|
11613
11648
|
const {
|
|
@@ -24,6 +24,7 @@ const Container = styled.div.withConfig({
|
|
|
24
24
|
componentId: "sc-yvif0e-0"
|
|
25
25
|
})(["position:relative;"]);
|
|
26
26
|
const AllSymbol = Symbol('Select all');
|
|
27
|
+
// MARK: styled components
|
|
27
28
|
const StyledList = styled(List).withConfig({
|
|
28
29
|
displayName: "Autocomplete__StyledList",
|
|
29
30
|
componentId: "sc-yvif0e-1"
|
|
@@ -35,7 +36,7 @@ const StyledPopover = styled('div').withConfig({
|
|
|
35
36
|
}).withConfig({
|
|
36
37
|
displayName: "Autocomplete__StyledPopover",
|
|
37
38
|
componentId: "sc-yvif0e-2"
|
|
38
|
-
})(["inset:unset;border:0;padding:0;margin:0;overflow:visible;"]);
|
|
39
|
+
})(["inset:unset;border:0;padding:0;margin:0;overflow:visible;&::backdrop{background-color:transparent;}"]);
|
|
39
40
|
const HelperText = styled(TextfieldHelperText).withConfig({
|
|
40
41
|
displayName: "Autocomplete__HelperText",
|
|
41
42
|
componentId: "sc-yvif0e-3"
|
|
@@ -56,7 +57,7 @@ const StyledButton = styled(Button).withConfig({
|
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
}) => css(["height:", ";width:", ";"], button.height, button.height));
|
|
59
|
-
|
|
60
|
+
// MARK: outside functions
|
|
60
61
|
// Typescript can struggle with parsing generic arrow functions in a .tsx file (see https://github.com/microsoft/TypeScript/issues/15713)
|
|
61
62
|
// Workaround is to add a trailing , after T, which tricks the compiler, but also have to ignore prettier rule.
|
|
62
63
|
// prettier-ignore
|
|
@@ -146,6 +147,9 @@ const handleListFocus = e => {
|
|
|
146
147
|
});
|
|
147
148
|
};
|
|
148
149
|
const defaultOptionDisabled = () => false;
|
|
150
|
+
// MARK: types
|
|
151
|
+
|
|
152
|
+
// MARK: component
|
|
149
153
|
function AutocompleteInner(props, ref) {
|
|
150
154
|
const {
|
|
151
155
|
options = [],
|
|
@@ -159,10 +163,11 @@ function AutocompleteInner(props, ref) {
|
|
|
159
163
|
hideClearButton = false,
|
|
160
164
|
onOptionsChange,
|
|
161
165
|
onInputChange,
|
|
162
|
-
selectedOptions,
|
|
166
|
+
selectedOptions: _selectedOptions,
|
|
163
167
|
multiple,
|
|
168
|
+
itemCompare,
|
|
164
169
|
allowSelectAll,
|
|
165
|
-
initialSelectedOptions = [],
|
|
170
|
+
initialSelectedOptions: _initialSelectedOptions = [],
|
|
166
171
|
disablePortal,
|
|
167
172
|
optionDisabled = defaultOptionDisabled,
|
|
168
173
|
optionsFilter,
|
|
@@ -179,6 +184,10 @@ function AutocompleteInner(props, ref) {
|
|
|
179
184
|
variant,
|
|
180
185
|
...other
|
|
181
186
|
} = props;
|
|
187
|
+
|
|
188
|
+
// MARK: initializing data/setup
|
|
189
|
+
const selectedOptions = _selectedOptions ? itemCompare ? options.filter(item => _selectedOptions.some(compare => itemCompare(item, compare))) : _selectedOptions : undefined;
|
|
190
|
+
const initialSelectedOptions = _initialSelectedOptions ? itemCompare ? options.filter(item => _initialSelectedOptions.some(compare => itemCompare(item, compare))) : _initialSelectedOptions : undefined;
|
|
182
191
|
if (disablePortal) {
|
|
183
192
|
console.warn('Autocomplete "disablePortal" prop has been deprecated. Autocomplete now uses the native popover api');
|
|
184
193
|
}
|
|
@@ -224,7 +233,10 @@ function AutocompleteInner(props, ref) {
|
|
|
224
233
|
...multipleSelectionProps,
|
|
225
234
|
onSelectedItemsChange: changes => {
|
|
226
235
|
if (onOptionsChange) {
|
|
227
|
-
|
|
236
|
+
let selectedItems = changes.selectedItems.filter(item => item !== AllSymbol);
|
|
237
|
+
if (itemCompare) {
|
|
238
|
+
selectedItems = inputOptions.filter(item => selectedItems.some(compare => itemCompare(item, compare)));
|
|
239
|
+
}
|
|
228
240
|
onOptionsChange({
|
|
229
241
|
selectedItems
|
|
230
242
|
});
|
|
@@ -245,6 +257,8 @@ function AutocompleteInner(props, ref) {
|
|
|
245
257
|
selectedItems,
|
|
246
258
|
setSelectedItems
|
|
247
259
|
} = useMultipleSelection(multipleSelectionProps);
|
|
260
|
+
|
|
261
|
+
// MARK: select all logic
|
|
248
262
|
const enabledItems = useMemo(() => {
|
|
249
263
|
const disabledItemsSet = new Set(inputOptions.filter(optionDisabled));
|
|
250
264
|
return inputOptions.filter(x => !disabledItemsSet.has(x));
|
|
@@ -264,6 +278,8 @@ function AutocompleteInner(props, ref) {
|
|
|
264
278
|
setSelectedItems([...enabledItems, ...selectedDisabledItemsSet]);
|
|
265
279
|
}
|
|
266
280
|
};
|
|
281
|
+
|
|
282
|
+
// MARK: getLabel
|
|
267
283
|
const getLabel = useCallback(item => {
|
|
268
284
|
//note: non strict check for null or undefined to allow 0
|
|
269
285
|
if (item == null) {
|
|
@@ -286,6 +302,8 @@ function AutocompleteInner(props, ref) {
|
|
|
286
302
|
throw new Error('Unable to find label, make sure your are using options as documented');
|
|
287
303
|
}
|
|
288
304
|
}, [optionLabel]);
|
|
305
|
+
|
|
306
|
+
// MARK: setup virtualizer
|
|
289
307
|
const scrollContainer = useRef(null);
|
|
290
308
|
const rowVirtualizer = useVirtualizer({
|
|
291
309
|
count: availableItems.length,
|
|
@@ -300,8 +318,11 @@ function AutocompleteInner(props, ref) {
|
|
|
300
318
|
useIsomorphicLayoutEffect(() => {
|
|
301
319
|
rowVirtualizer?.measure?.();
|
|
302
320
|
}, [rowVirtualizer, density]);
|
|
321
|
+
|
|
322
|
+
// MARK: downshift state
|
|
303
323
|
let comboBoxProps = {
|
|
304
324
|
items: availableItems,
|
|
325
|
+
//can not pass readonly type to downshift so we cast it to regular T[]
|
|
305
326
|
initialSelectedItem: initialSelectedOptions[0],
|
|
306
327
|
isItemDisabled(item) {
|
|
307
328
|
return optionDisabled(item);
|
|
@@ -366,14 +387,18 @@ function AutocompleteInner(props, ref) {
|
|
|
366
387
|
}
|
|
367
388
|
}
|
|
368
389
|
};
|
|
390
|
+
// MARK: singleselect specific
|
|
369
391
|
if (!multiple) {
|
|
370
392
|
comboBoxProps = {
|
|
371
393
|
...comboBoxProps,
|
|
372
394
|
onSelectedItemChange: changes => {
|
|
373
395
|
if (onOptionsChange) {
|
|
374
|
-
|
|
396
|
+
let {
|
|
375
397
|
selectedItem
|
|
376
398
|
} = changes;
|
|
399
|
+
if (itemCompare) {
|
|
400
|
+
selectedItem = inputOptions.find(item => itemCompare(item, selectedItem));
|
|
401
|
+
}
|
|
377
402
|
onOptionsChange({
|
|
378
403
|
selectedItems: selectedItem ? [selectedItem] : []
|
|
379
404
|
});
|
|
@@ -439,6 +464,7 @@ function AutocompleteInner(props, ref) {
|
|
|
439
464
|
};
|
|
440
465
|
}
|
|
441
466
|
}
|
|
467
|
+
// MARK: multiselect specific
|
|
442
468
|
if (multiple) {
|
|
443
469
|
placeholderText = typeof placeholderText !== 'undefined' ? placeholderText : `${selectedItems.length}/${inputOptions.length} selected`;
|
|
444
470
|
comboBoxProps = {
|
|
@@ -532,6 +558,8 @@ function AutocompleteInner(props, ref) {
|
|
|
532
558
|
inputValue,
|
|
533
559
|
reset: resetCombobox
|
|
534
560
|
} = useCombobox(comboBoxProps);
|
|
561
|
+
|
|
562
|
+
// MARK: floating-ui setup
|
|
535
563
|
const {
|
|
536
564
|
x,
|
|
537
565
|
y,
|
|
@@ -563,6 +591,8 @@ function AutocompleteInner(props, ref) {
|
|
|
563
591
|
return autoUpdate(refs.reference.current, refs.floating.current, update);
|
|
564
592
|
}
|
|
565
593
|
}, [refs.reference, refs.floating, update, isOpen]);
|
|
594
|
+
|
|
595
|
+
// MARK: popover toggle
|
|
566
596
|
useIsomorphicLayoutEffect(() => {
|
|
567
597
|
if (isOpen) {
|
|
568
598
|
refs.floating.current.showPopover();
|
|
@@ -579,6 +609,8 @@ function AutocompleteInner(props, ref) {
|
|
|
579
609
|
const showClearButton = (selectedItems.length > 0 || inputValue) && !readOnly && !hideClearButton;
|
|
580
610
|
const showNoOptions = isOpen && !availableItems.length && noOptionsText.length > 0;
|
|
581
611
|
const selectedItemsLabels = useMemo(() => selectedItems.map(getLabel), [selectedItems, getLabel]);
|
|
612
|
+
|
|
613
|
+
// MARK: optionsList
|
|
582
614
|
const optionsList = /*#__PURE__*/jsx(StyledPopover, {
|
|
583
615
|
popover: "manual",
|
|
584
616
|
...getFloatingProps({
|
|
@@ -680,6 +712,8 @@ function AutocompleteInner(props, ref) {
|
|
|
680
712
|
disabled
|
|
681
713
|
}));
|
|
682
714
|
const consolidatedEvents = mergeEventsFromRight(other, inputProps);
|
|
715
|
+
|
|
716
|
+
// MARK: input
|
|
683
717
|
return /*#__PURE__*/jsx(ThemeProvider, {
|
|
684
718
|
theme: token,
|
|
685
719
|
children: /*#__PURE__*/jsxs(Container, {
|
|
@@ -735,6 +769,7 @@ function AutocompleteInner(props, ref) {
|
|
|
735
769
|
})
|
|
736
770
|
});
|
|
737
771
|
}
|
|
772
|
+
// MARK: exported component
|
|
738
773
|
const Autocomplete = /*#__PURE__*/forwardRef(AutocompleteInner);
|
|
739
774
|
|
|
740
775
|
export { Autocomplete };
|
|
@@ -26,7 +26,7 @@ function DateSegment({
|
|
|
26
26
|
const formatter = useDateFormatter(formatOptions);
|
|
27
27
|
const parts = state.value ? formatter.formatToParts(state.value.toDate(timezone)) : [];
|
|
28
28
|
const part = parts.find(p => p.type === segment.type);
|
|
29
|
-
const value = part?.value ?? segment.text;
|
|
29
|
+
const value = segment.isPlaceholder || segment.type === 'literal' ? segment.text : part?.value ?? segment.text;
|
|
30
30
|
const [focus, setFocus] = useState(false);
|
|
31
31
|
const ref = useRef(null);
|
|
32
32
|
const {
|
|
@@ -1,30 +1,11 @@
|
|
|
1
1
|
import { HTMLAttributes, ReactNode } from 'react';
|
|
2
2
|
import { Variants } from '../types';
|
|
3
|
-
type OptionLabelProps<T> = T extends string | number ? {
|
|
4
|
-
/** Custom option label */
|
|
5
|
-
optionLabel?: (option: T) => string;
|
|
6
|
-
/** Disable option
|
|
7
|
-
* @default () => false
|
|
8
|
-
*/
|
|
9
|
-
optionDisabled?: (option: T) => boolean;
|
|
10
|
-
/** List of options in dropdown */
|
|
11
|
-
options: (string | number)[];
|
|
12
|
-
} : {
|
|
13
|
-
/** Custom option label */
|
|
14
|
-
optionLabel: (option: T) => string;
|
|
15
|
-
/** Disable option
|
|
16
|
-
* @default () => false
|
|
17
|
-
*/
|
|
18
|
-
optionDisabled?: (option: T) => boolean;
|
|
19
|
-
/** List of options in dropdown */
|
|
20
|
-
options: T[];
|
|
21
|
-
};
|
|
22
3
|
export type AutocompleteChanges<T> = {
|
|
23
4
|
selectedItems: T[];
|
|
24
5
|
};
|
|
25
6
|
export type AutocompleteProps<T> = {
|
|
26
7
|
/** List of options in dropdown */
|
|
27
|
-
options: T[];
|
|
8
|
+
options: readonly T[];
|
|
28
9
|
/** Label for the select element */
|
|
29
10
|
label: ReactNode;
|
|
30
11
|
/** Array of initial selected items
|
|
@@ -76,12 +57,18 @@ export type AutocompleteProps<T> = {
|
|
|
76
57
|
multiple?: boolean;
|
|
77
58
|
/** Add select-all option. Throws an error if true while multiple = false */
|
|
78
59
|
allowSelectAll?: boolean;
|
|
60
|
+
/** Custom option label. NOTE: This is required when option is an object */
|
|
61
|
+
optionLabel?: (option: T) => string;
|
|
79
62
|
/** Custom option template */
|
|
80
63
|
optionComponent?: (option: T, isSelected: boolean) => ReactNode;
|
|
81
64
|
/** Disable use of react portal for dropdown
|
|
82
65
|
* @deprecated Autocomplete now uses the native popover api to render the dropdown. This prop will be removed in a future version
|
|
83
66
|
*/
|
|
84
67
|
disablePortal?: boolean;
|
|
68
|
+
/** Disable option
|
|
69
|
+
* @default () => false
|
|
70
|
+
*/
|
|
71
|
+
optionDisabled?: (option: T) => boolean;
|
|
85
72
|
/** Custom filter function for options */
|
|
86
73
|
optionsFilter?: (option: T, inputValue: string) => boolean;
|
|
87
74
|
/** If `true` the width of the dropdown will adjust to the width of the input */
|
|
@@ -100,11 +87,15 @@ export type AutocompleteProps<T> = {
|
|
|
100
87
|
* @default 300
|
|
101
88
|
*/
|
|
102
89
|
dropdownHeight?: number;
|
|
103
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Method that is used to compare objects by value. If omitted, objects are matched by reference.
|
|
92
|
+
*/
|
|
93
|
+
itemCompare?: (value: T, compare: T) => boolean;
|
|
94
|
+
} & HTMLAttributes<HTMLDivElement>;
|
|
104
95
|
declare function AutocompleteInner<T>(props: AutocompleteProps<T>, ref: React.ForwardedRef<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
|
|
105
96
|
export declare const Autocomplete: <T>(props: {
|
|
106
97
|
/** List of options in dropdown */
|
|
107
|
-
options: T[];
|
|
98
|
+
options: readonly T[];
|
|
108
99
|
/** Label for the select element */
|
|
109
100
|
label: ReactNode;
|
|
110
101
|
/** Array of initial selected items
|
|
@@ -156,12 +147,18 @@ export declare const Autocomplete: <T>(props: {
|
|
|
156
147
|
multiple?: boolean;
|
|
157
148
|
/** Add select-all option. Throws an error if true while multiple = false */
|
|
158
149
|
allowSelectAll?: boolean;
|
|
150
|
+
/** Custom option label. NOTE: This is required when option is an object */
|
|
151
|
+
optionLabel?: (option: T) => string;
|
|
159
152
|
/** Custom option template */
|
|
160
153
|
optionComponent?: (option: T, isSelected: boolean) => ReactNode;
|
|
161
154
|
/** Disable use of react portal for dropdown
|
|
162
155
|
* @deprecated Autocomplete now uses the native popover api to render the dropdown. This prop will be removed in a future version
|
|
163
156
|
*/
|
|
164
157
|
disablePortal?: boolean;
|
|
158
|
+
/** Disable option
|
|
159
|
+
* @default () => false
|
|
160
|
+
*/
|
|
161
|
+
optionDisabled?: (option: T) => boolean;
|
|
165
162
|
/** Custom filter function for options */
|
|
166
163
|
optionsFilter?: (option: T, inputValue: string) => boolean;
|
|
167
164
|
/** If `true` the width of the dropdown will adjust to the width of the input */
|
|
@@ -180,7 +177,11 @@ export declare const Autocomplete: <T>(props: {
|
|
|
180
177
|
* @default 300
|
|
181
178
|
*/
|
|
182
179
|
dropdownHeight?: number;
|
|
183
|
-
|
|
180
|
+
/**
|
|
181
|
+
* Method that is used to compare objects by value. If omitted, objects are matched by reference.
|
|
182
|
+
*/
|
|
183
|
+
itemCompare?: (value: T, compare: T) => boolean;
|
|
184
|
+
} & HTMLAttributes<HTMLDivElement> & {
|
|
184
185
|
ref?: React.ForwardedRef<HTMLDivElement>;
|
|
185
186
|
/** @ignore */
|
|
186
187
|
displayName?: string | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/eds-core-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.1-dev13062024",
|
|
4
4
|
"description": "The React implementation of the Equinor Design System",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"**/*.css"
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"peerDependencies": {
|
|
76
76
|
"react": ">=16.8",
|
|
77
77
|
"react-dom": ">=16.8",
|
|
78
|
-
"styled-components": ">=
|
|
78
|
+
"styled-components": ">=5.1"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
81
|
"@babel/runtime": "^7.24.0",
|
|
@@ -86,16 +86,12 @@
|
|
|
86
86
|
"@react-stately/datepicker": "^3.9.3",
|
|
87
87
|
"@react-types/shared": "^3.23.0",
|
|
88
88
|
"@tanstack/react-virtual": "3.5.0",
|
|
89
|
-
"downshift": "9.0.
|
|
89
|
+
"downshift": "9.0.6",
|
|
90
90
|
"react-aria": "^3.33.0",
|
|
91
91
|
"@equinor/eds-icons": "^0.21.0",
|
|
92
92
|
"@equinor/eds-tokens": "0.9.2",
|
|
93
93
|
"@equinor/eds-utils": "0.8.5"
|
|
94
94
|
},
|
|
95
|
-
"engines": {
|
|
96
|
-
"pnpm": ">=4",
|
|
97
|
-
"node": ">=10.0.0"
|
|
98
|
-
},
|
|
99
95
|
"scripts": {
|
|
100
96
|
"build": "rollup -c --bundleConfigAsCjs && tsc -p tsconfig.build.json",
|
|
101
97
|
"test": "tsc -p tsconfig.test.json && jest",
|