@equinor/eds-core-react 2.0.1 → 2.2.0-beta.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.
Files changed (47) hide show
  1. package/README.md +50 -5
  2. package/dist/eds-core-react.cjs +755 -500
  3. package/dist/esm/components/Autocomplete/AddNewOption.js +31 -14
  4. package/dist/esm/components/Autocomplete/Autocomplete.js +54 -874
  5. package/dist/esm/components/Autocomplete/AutocompleteContext.js +12 -0
  6. package/dist/esm/components/Autocomplete/EmptyOption.js +21 -0
  7. package/dist/esm/components/Autocomplete/MultipleInput.js +85 -0
  8. package/dist/esm/components/Autocomplete/Option.js +42 -23
  9. package/dist/esm/components/Autocomplete/OptionList.js +124 -0
  10. package/dist/esm/components/Autocomplete/RightAdornments.js +48 -0
  11. package/dist/esm/components/Autocomplete/SelectAllOption.js +63 -0
  12. package/dist/esm/components/Autocomplete/SingleInput.js +28 -0
  13. package/dist/esm/components/Autocomplete/useAutocomplete.js +605 -0
  14. package/dist/esm/components/Autocomplete/utils.js +93 -0
  15. package/dist/esm/components/Datepicker/fields/FieldWrapper.js +10 -0
  16. package/dist/esm/components/Dialog/Dialog.js +6 -4
  17. package/dist/esm/components/Typography/Typography.new.js +1 -1
  18. package/dist/esm/components/next/Icon/Icon.js +57 -0
  19. package/dist/esm/components/next/Icon/icon.css.js +6 -0
  20. package/dist/esm/components/next/Placeholder/Placeholder.js +17 -0
  21. package/dist/esm/index.js +1 -1
  22. package/dist/esm/index.next.js +2 -0
  23. package/dist/esm/node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js +26 -0
  24. package/dist/index.next.cjs +101 -0
  25. package/dist/types/components/Autocomplete/AddNewOption.d.ts +4 -12
  26. package/dist/types/components/Autocomplete/Autocomplete.d.ts +33 -11
  27. package/dist/types/components/Autocomplete/AutocompleteContext.d.ts +228 -0
  28. package/dist/types/components/Autocomplete/EmptyOption.d.ts +1 -0
  29. package/dist/types/components/Autocomplete/MultipleInput.d.ts +1 -0
  30. package/dist/types/components/Autocomplete/Option.d.ts +7 -15
  31. package/dist/types/components/Autocomplete/OptionList.d.ts +2 -0
  32. package/dist/types/components/Autocomplete/RightAdornments.d.ts +1 -0
  33. package/dist/types/components/Autocomplete/SelectAllOption.d.ts +6 -0
  34. package/dist/types/components/Autocomplete/SingleInput.d.ts +1 -0
  35. package/dist/types/components/Autocomplete/useAutocomplete.d.ts +122 -0
  36. package/dist/types/components/Autocomplete/utils.d.ts +13 -0
  37. package/dist/types/components/Datepicker/DateRangePicker.d.ts +1 -1
  38. package/dist/types/components/SideBar/SideBarButton/index.d.ts +1 -1
  39. package/dist/types/components/next/Icon/Icon.d.ts +29 -0
  40. package/dist/types/components/next/Icon/Icon.types.d.ts +19 -0
  41. package/dist/types/components/next/Icon/index.d.ts +2 -0
  42. package/dist/types/components/next/Placeholder/Placeholder.d.ts +9 -0
  43. package/dist/types/components/next/Placeholder/Placeholder.figma.d.ts +16 -0
  44. package/dist/types/components/next/Placeholder/index.d.ts +2 -0
  45. package/dist/types/components/next/index.d.ts +4 -0
  46. package/dist/types/index.next.d.ts +11 -0
  47. package/package.json +13 -8
@@ -9,8 +9,8 @@ var jsxRuntime = require('react/jsx-runtime');
9
9
  var reactDom = require('react-dom');
10
10
  var react$1 = require('@floating-ui/react');
11
11
  var edsIcons = require('@equinor/eds-icons');
12
- var downshift = require('downshift');
13
12
  var reactVirtual = require('@tanstack/react-virtual');
13
+ var downshift = require('downshift');
14
14
  var reactAria = require('react-aria');
15
15
  var calendar = require('@react-stately/calendar');
16
16
  var date = require('@internationalized/date');
@@ -1531,7 +1531,7 @@ const TypographyNext = /*#__PURE__*/react.forwardRef(({
1531
1531
  return /*#__PURE__*/jsxRuntime.jsx(Component, {
1532
1532
  ref: ref,
1533
1533
  "data-font-family": family,
1534
- "data-text-size": size,
1534
+ "data-font-size": size,
1535
1535
  "data-baseline": baseline || undefined,
1536
1536
  "data-line-height": lineHeight || undefined,
1537
1537
  "data-font-weight": weight || undefined,
@@ -3042,7 +3042,7 @@ const LeftAdornments = styled__default.default(Adornments).withConfig({
3042
3042
  })(({
3043
3043
  $token
3044
3044
  }) => styled.css(["left:0;padding-left:", ";"], $token.entities.adornment.spacings.left));
3045
- const RightAdornments = styled__default.default(Adornments).withConfig({
3045
+ const RightAdornments$1 = styled__default.default(Adornments).withConfig({
3046
3046
  displayName: "Input__RightAdornments",
3047
3047
  componentId: "sc-1ykv024-4"
3048
3048
  })(({
@@ -3124,7 +3124,7 @@ const Input$4 = /*#__PURE__*/react.forwardRef(function Input({
3124
3124
  $paddingLeft: token.spacings.left,
3125
3125
  $paddingRight: token.spacings.right,
3126
3126
  ...inputProps
3127
- }), rightAdornments ? /*#__PURE__*/jsxRuntime.jsx(RightAdornments, {
3127
+ }), rightAdornments ? /*#__PURE__*/jsxRuntime.jsx(RightAdornments$1, {
3128
3128
  ..._rightAdornmentProps,
3129
3129
  children: rightAdornments
3130
3130
  }) : null]
@@ -4853,17 +4853,19 @@ const Dialog$1 = /*#__PURE__*/react.forwardRef(function Dialog({
4853
4853
  onClose && onClose();
4854
4854
  }
4855
4855
  };
4856
- edsUtils.useGlobalKeyPress('Escape', e => {
4856
+ const handleKeyDown = e => {
4857
+ if (e.key !== 'Escape') return;
4857
4858
  e.preventDefault();
4858
4859
  if (isDismissable && onClose && open) {
4859
- onClose && onClose();
4860
+ onClose();
4860
4861
  }
4861
- });
4862
+ };
4862
4863
  return /*#__PURE__*/jsxRuntime.jsx(styled.ThemeProvider, {
4863
4864
  theme: token,
4864
4865
  children: /*#__PURE__*/jsxRuntime.jsx(StyledNativeDialog, {
4865
4866
  ref: combinedDialogRef,
4866
4867
  onMouseDown: handleDismiss,
4868
+ onKeyDown: handleKeyDown,
4867
4869
  children: open && /*#__PURE__*/jsxRuntime.jsx(StyledDialog, {
4868
4870
  ...props,
4869
4871
  ref: ref,
@@ -9508,146 +9510,130 @@ const Switch = /*#__PURE__*/react.forwardRef(function Switch({
9508
9510
  });
9509
9511
  Switch.displayName = 'Switch';
9510
9512
 
9511
- const {
9512
- typography,
9513
- colors,
9514
- shape: {
9515
- corners: {
9516
- borderRadius
9517
- }
9518
- },
9519
- spacings: {
9520
- comfortable: {
9521
- small: spacingSmall,
9522
- medium_small: spacingMediumSmall,
9523
- medium: spacingMedium,
9524
- large: spacingLarge,
9525
- x_large,
9526
- xxx_large
9527
- }
9528
- },
9529
- elevation: {
9530
- temporary_nav: boxShadow
9513
+ const AutocompleteContext = /*#__PURE__*/react.createContext(null);
9514
+ const useAutocompleteContext = () => {
9515
+ const context = react.use(AutocompleteContext);
9516
+ if (!context) {
9517
+ throw new Error('Autocomplete compound components must be used within an Autocomplete component');
9531
9518
  }
9532
- } = edsTokens.tokens;
9533
- const selectTokens = {
9534
- background: colors.ui.background__default.rgba,
9535
- boxShadow,
9536
- spacings: {
9537
- top: '0',
9538
- right: spacingLarge,
9539
- bottom: '0',
9540
- left: spacingLarge
9541
- },
9542
- typography: {
9543
- ...typography.navigation.menu_title,
9544
- color: colors.text.static_icons__default.rgba
9545
- },
9546
- border: {
9547
- type: 'border',
9548
- radius: borderRadius
9549
- },
9550
- states: {
9551
- hover: {
9552
- background: colors.ui.background__medium.rgba
9553
- },
9554
- active: {
9555
- background: colors.interactive.primary__selected_highlight.rgba
9556
- },
9557
- disabled: {
9558
- typography: {
9559
- color: colors.interactive.disabled__text.rgba
9560
- }
9561
- }
9562
- },
9563
- variants: {
9564
- error: {
9565
- typography: {
9566
- color: colors.interactive.danger__text.rgba
9567
- }
9568
- },
9569
- warning: {
9570
- typography: {
9571
- color: colors.interactive.warning__text.rgba
9572
- }
9573
- },
9574
- success: {
9575
- typography: {
9576
- color: colors.interactive.success__text.rgba
9577
- }
9578
- }
9579
- },
9580
- entities: {
9581
- button: {
9582
- height: '24px',
9583
- width: '24px',
9584
- spacings: {
9585
- left: spacingSmall,
9586
- right: spacingSmall,
9587
- top: '6px'
9588
- }
9589
- },
9590
- label: {
9591
- minHeight: xxx_large,
9592
- spacings: {
9593
- left: '0',
9594
- right: '0',
9595
- top: spacingMedium,
9596
- bottom: spacingMedium
9597
- }
9519
+ return context;
9520
+ };
9521
+
9522
+ const RightAdornments = () => {
9523
+ const {
9524
+ readOnly,
9525
+ selectedItems,
9526
+ inputValue,
9527
+ loading,
9528
+ disabled,
9529
+ getToggleButtonProps,
9530
+ hideClearButton,
9531
+ isOpen,
9532
+ clear
9533
+ } = useAutocompleteContext();
9534
+ const showClearButton = (selectedItems.length > 0 || inputValue) && !readOnly && !hideClearButton;
9535
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
9536
+ children: [loading && /*#__PURE__*/jsxRuntime.jsx(Progress.Circular, {
9537
+ size: 16
9538
+ }), showClearButton && /*#__PURE__*/jsxRuntime.jsx(StyledButton$1, {
9539
+ variant: "ghost_icon",
9540
+ disabled: disabled || readOnly,
9541
+ "aria-label": 'clear options',
9542
+ title: "clear",
9543
+ onClick: clear,
9544
+ children: /*#__PURE__*/jsxRuntime.jsx(Icon$1, {
9545
+ data: edsIcons.close,
9546
+ size: 16
9547
+ })
9548
+ }), !readOnly && /*#__PURE__*/jsxRuntime.jsx(StyledButton$1, {
9549
+ variant: "ghost_icon",
9550
+ ...getToggleButtonProps({
9551
+ disabled: disabled || readOnly
9552
+ }),
9553
+ "aria-label": 'toggle options',
9554
+ title: "open",
9555
+ children: /*#__PURE__*/jsxRuntime.jsx(Icon$1, {
9556
+ data: isOpen ? edsIcons.arrow_drop_up : edsIcons.arrow_drop_down
9557
+ })
9558
+ })]
9559
+ });
9560
+ };
9561
+
9562
+ const UnstyledInput = styled__default.default.input.withConfig({
9563
+ displayName: "MultipleInput__UnstyledInput",
9564
+ componentId: "sc-1evc1aa-0"
9565
+ })(["flex:1;min-width:6rem;font-size:1rem;border:none;padding:0;background:inherit;&:focus-visible{outline:none;}"]);
9566
+ const ChipContainer = styled__default.default.div.withConfig({
9567
+ displayName: "MultipleInput__ChipContainer",
9568
+ componentId: "sc-1evc1aa-1"
9569
+ })(["display:flex;flex-wrap:wrap;gap:0.5rem;height:100%;"]);
9570
+ const MultipleInput = () => {
9571
+ const {
9572
+ selectedItems,
9573
+ selectionDisplay,
9574
+ getLabel,
9575
+ removeSelectedItem,
9576
+ readOnly,
9577
+ inputProps,
9578
+ placeholderText,
9579
+ variant,
9580
+ hideClearButton,
9581
+ restHtmlProps,
9582
+ consolidatedEvents,
9583
+ inputRef
9584
+ } = useAutocompleteContext();
9585
+ const chipRefs = react.useRef(new Map());
9586
+ const handleChipRemove = (item, index, isKeyboardEvent) => {
9587
+ if (isKeyboardEvent && selectedItems.length > 1) {
9588
+ const isLastChip = index === selectedItems.length - 1;
9589
+ const nextItem = selectedItems[isLastChip ? index - 1 : index + 1];
9590
+ chipRefs.current.get(getLabel(nextItem))?.focus();
9591
+ } else if (!isKeyboardEvent) {
9592
+ inputRef.current?.focus();
9593
+ }
9594
+ removeSelectedItem(item);
9595
+ };
9596
+ const handleChipDelete = (item, index) => e => {
9597
+ const isKeyboard = 'key' in e && e.key === 'Enter';
9598
+ handleChipRemove(item, index, isKeyboard);
9599
+ };
9600
+ const handleChipClick = (item, index) => e => {
9601
+ e.preventDefault();
9602
+ e.stopPropagation();
9603
+ handleChipRemove(item, index, false);
9604
+ };
9605
+ return /*#__PURE__*/jsxRuntime.jsx(Input$4, {
9606
+ as: 'div',
9607
+ variant: variant,
9608
+ rightAdornmentsWidth: hideClearButton ? 24 + 8 : 24 * 2 + 8,
9609
+ rightAdornments: /*#__PURE__*/jsxRuntime.jsx(RightAdornments, {}),
9610
+ readOnly: readOnly,
9611
+ style: {
9612
+ height: 'auto',
9613
+ minHeight: '36px'
9598
9614
  },
9599
- noOptions: {
9600
- typography: {
9601
- color: colors.text.static_icons__tertiary.rgba
9602
- }
9603
- }
9604
- },
9605
- modes: {
9606
- compact: {
9607
- spacings: {
9608
- left: spacingSmall,
9609
- right: spacingSmall,
9610
- top: '0',
9611
- bottom: '0'
9612
- },
9613
- entities: {
9614
- button: {
9615
- spacings: {
9616
- left: spacingSmall,
9617
- right: spacingSmall,
9618
- top: '0'
9619
- }
9615
+ children: /*#__PURE__*/jsxRuntime.jsxs(ChipContainer, {
9616
+ children: [selectionDisplay === 'chips' && selectedItems.map((item, index) => /*#__PURE__*/jsxRuntime.jsx(Chip, {
9617
+ ref: el => {
9618
+ if (el) chipRefs.current.set(getLabel(item), el);else chipRefs.current.delete(getLabel(item));
9620
9619
  },
9621
- label: {
9622
- minHeight: x_large,
9623
- spacings: {
9624
- left: '0',
9625
- right: '0',
9626
- top: spacingSmall,
9627
- bottom: spacingSmall
9628
- }
9629
- }
9630
- }
9631
- }
9632
- }
9620
+ style: {
9621
+ outline: '1px solid var(--eds-color-accent-12)'
9622
+ },
9623
+ onDelete: handleChipDelete(item, index),
9624
+ onClick: handleChipClick(item, index),
9625
+ disabled: readOnly,
9626
+ children: getLabel(item)
9627
+ }, getLabel(item))), /*#__PURE__*/jsxRuntime.jsx(UnstyledInput, {
9628
+ ...restHtmlProps,
9629
+ ...inputProps,
9630
+ ...consolidatedEvents,
9631
+ placeholder: placeholderText,
9632
+ readOnly: readOnly
9633
+ })]
9634
+ })
9635
+ });
9633
9636
  };
9634
- const multiSelect = mergeDeepRight(selectTokens, {
9635
- spacings: {
9636
- top: '0',
9637
- bottom: '0',
9638
- left: spacingMediumSmall,
9639
- right: spacingLarge
9640
- },
9641
- modes: {
9642
- compact: {
9643
- spacings: {
9644
- top: '0',
9645
- //xx_small,
9646
- bottom: '0'
9647
- }
9648
- }
9649
- }
9650
- });
9651
9637
 
9652
9638
  const StyledListItem = styled__default.default.li.withConfig({
9653
9639
  displayName: "Option__StyledListItem",
@@ -9670,36 +9656,56 @@ const AutocompleteOptionLabel = styled__default.default.span.withConfig({
9670
9656
  }) => {
9671
9657
  return styled.css(["", " text-overflow:ellipsis;white-space:", ";overflow:", ";overflow-wrap:anywhere;@supports (-moz-appearance:none){overflow:", ";}"], edsUtils.spacingsTemplate(theme.entities.label.spacings), $multiline ? 'normal' : 'nowrap', $multiline ? 'initial' : 'hidden', $multiline ? 'initial' : 'clip');
9672
9658
  });
9673
- function AutocompleteOptionInner(props, ref) {
9659
+ function Option({
9660
+ indeterminate,
9661
+ index,
9662
+ item,
9663
+ virtualItem
9664
+ }) {
9674
9665
  const {
9675
- value,
9676
- optionComponent,
9677
9666
  multiple,
9678
- isSelected,
9679
- indeterminate,
9680
- isDisabled,
9667
+ availableItems,
9668
+ highlightedIndex,
9681
9669
  multiline,
9682
- highlighted,
9683
- onClick,
9684
- 'aria-selected': ariaSelected,
9685
- ...other
9686
- } = props;
9670
+ optionDisabled,
9671
+ selectedItemsLabels,
9672
+ getLabel,
9673
+ getItemProps,
9674
+ optionComponent: _optionComponent,
9675
+ rowVirtualizer
9676
+ } = useAutocompleteContext();
9677
+ const isDisabled = optionDisabled(item);
9678
+ const label = getLabel(item);
9679
+ const isSelected = selectedItemsLabels.includes(label);
9680
+ const optionComponent = _optionComponent?.(item, isSelected);
9681
+ const highlighted = highlightedIndex === index && !isDisabled ? 'true' : 'false';
9682
+ const itemProps = getItemProps({
9683
+ ...(multiline && {
9684
+ ref: rowVirtualizer.measureElement
9685
+ }),
9686
+ item,
9687
+ index,
9688
+ style: {
9689
+ transform: `translateY(${virtualItem.start}px)`,
9690
+ ...(!multiline && {
9691
+ height: `${virtualItem.size}px`
9692
+ })
9693
+ }
9694
+ });
9687
9695
  return /*#__PURE__*/jsxRuntime.jsxs(StyledListItem, {
9688
- ref: ref,
9689
9696
  $isdisabled: isDisabled ? 'true' : 'false',
9690
9697
  $highlighted: highlighted,
9691
9698
  "aria-hidden": isDisabled,
9692
9699
  $active: !multiple && isSelected ? 'true' : 'false',
9693
- onClick: e => {
9694
- !isDisabled && onClick(e);
9695
- },
9696
- "aria-selected": multiple ? isSelected : ariaSelected,
9697
- ...other,
9700
+ "aria-setsize": availableItems.length,
9701
+ "data-index": index,
9702
+ "aria-posinset": index + 1,
9703
+ ...itemProps,
9698
9704
  children: [multiple && /*#__PURE__*/jsxRuntime.jsx(Checkbox, {
9699
9705
  disabled: isDisabled,
9700
9706
  checked: isSelected,
9701
9707
  indeterminate: indeterminate,
9702
- value: value,
9708
+ value: label,
9703
9709
  onChange: () => {
9704
9710
  return null;
9705
9711
  }
@@ -9707,11 +9713,10 @@ function AutocompleteOptionInner(props, ref) {
9707
9713
  children: optionComponent
9708
9714
  }) : /*#__PURE__*/jsxRuntime.jsx(AutocompleteOptionLabel, {
9709
9715
  $multiline: multiline,
9710
- children: value
9716
+ children: label
9711
9717
  })]
9712
9718
  });
9713
9719
  }
9714
- const AutocompleteOption = /*#__PURE__*/react.forwardRef(AutocompleteOptionInner);
9715
9720
 
9716
9721
  const StyledAddItemIcon = styled__default.default(Icon$1).withConfig({
9717
9722
  displayName: "AddNewOption__StyledAddItemIcon",
@@ -9725,25 +9730,43 @@ const StyledPlaceholder = styled__default.default.span.withConfig({
9725
9730
  displayName: "AddNewOption__StyledPlaceholder",
9726
9731
  componentId: "sc-8xtrxx-1"
9727
9732
  })(["color:", ";"], input$1.entities.placeholder.typography.color);
9728
- function AddNewOptionInner(props, ref) {
9733
+ function AddNewOption({
9734
+ index,
9735
+ item
9736
+ }) {
9729
9737
  const {
9730
- value,
9731
- multiline,
9738
+ availableItems,
9732
9739
  multiple,
9733
- highlighted,
9734
- onClick,
9735
- ...other
9736
- } = props;
9740
+ typedInputValue,
9741
+ highlightedIndex,
9742
+ multiline,
9743
+ rowVirtualizer,
9744
+ getItemProps
9745
+ } = useAutocompleteContext();
9746
+ const value = typedInputValue.trim();
9747
+ const isDisabled = !typedInputValue.trim();
9748
+ const highlighted = highlightedIndex === index && !isDisabled ? 'true' : 'false';
9749
+ const itemProps = getItemProps({
9750
+ ...(multiline && {
9751
+ ref: rowVirtualizer.measureElement
9752
+ }),
9753
+ item,
9754
+ index: index
9755
+ });
9737
9756
  return /*#__PURE__*/jsxRuntime.jsxs(StyledListItem, {
9738
- ref: ref,
9739
9757
  $highlighted: highlighted,
9740
- onClick: e => {
9741
- onClick(e);
9758
+ style: {
9759
+ position: 'sticky',
9760
+ top: 0,
9761
+ zIndex: 99
9742
9762
  },
9743
- ...other,
9763
+ ...itemProps,
9744
9764
  "aria-label": `Add new option: ${value}`,
9765
+ "data-index": 0,
9766
+ "data-testid": 'add-item',
9745
9767
  "aria-live": "polite",
9746
9768
  "aria-selected": false,
9769
+ "aria-setsize": availableItems.length,
9747
9770
  children: [/*#__PURE__*/jsxRuntime.jsx(StyledAddItemIcon, {
9748
9771
  multiple: multiple,
9749
9772
  data: edsIcons.add_box
@@ -9755,57 +9778,68 @@ function AddNewOptionInner(props, ref) {
9755
9778
  })]
9756
9779
  });
9757
9780
  }
9758
- const AddNewOption = /*#__PURE__*/react.forwardRef(AddNewOptionInner);
9759
-
9760
- const Container$2 = styled__default.default.div.withConfig({
9761
- displayName: "Autocomplete__Container",
9762
- componentId: "sc-yvif0e-0"
9763
- })(["position:relative;"]);
9764
- const AllSymbol = Symbol('Select all');
9765
- const AddSymbol = Symbol('Add new');
9766
-
9767
- // MARK: styled components
9768
- const StyledList = styled__default.default(List$1).withConfig({
9769
- displayName: "Autocomplete__StyledList",
9770
- componentId: "sc-yvif0e-1"
9771
- })(({
9772
- theme
9773
- }) => styled.css(["background-color:", ";box-shadow:", ";", " overflow-y:auto;overflow-x:hidden;padding:0;display:grid;@supports (-moz-appearance:none){scrollbar-width:thin;}"], theme.background, theme.boxShadow, edsUtils.bordersTemplate(theme.border)));
9774
- const StyledPopover = styled__default.default('div').withConfig({
9775
- shouldForwardProp: () => true //workaround to avoid warning until popover gets added to react types
9776
- }).withConfig({
9777
- displayName: "Autocomplete__StyledPopover",
9778
- componentId: "sc-yvif0e-2"
9779
- })(["inset:unset;border:0;padding:0;margin:0;overflow:visible;&::backdrop{background-color:transparent;}"]);
9780
- const HelperText = styled__default.default(TextfieldHelperText).withConfig({
9781
- displayName: "Autocomplete__HelperText",
9782
- componentId: "sc-yvif0e-3"
9783
- })(["margin-top:8px;margin-left:8px;"]);
9784
- const AutocompleteNoOptions = styled__default.default(AutocompleteOption).withConfig({
9785
- displayName: "Autocomplete__AutocompleteNoOptions",
9786
- componentId: "sc-yvif0e-4"
9787
- })(({
9788
- theme
9789
- }) => styled.css(["color:", ";"], theme.entities.noOptions.typography.color));
9790
- const StyledButton$1 = styled__default.default(Button$1).withConfig({
9791
- displayName: "Autocomplete__StyledButton",
9792
- componentId: "sc-yvif0e-5"
9793
- })(({
9794
- theme: {
9795
- entities: {
9796
- button
9797
- }
9798
- }
9799
- }) => styled.css(["height:", ";width:", ";"], button.height, button.height));
9800
- // MARK: outside functions
9801
- // Typescript can struggle with parsing generic arrow functions in a .tsx file (see https://github.com/microsoft/TypeScript/issues/15713)
9802
- // Workaround is to add a trailing , after T, which tricks the compiler, but also have to ignore prettier rule.
9803
- // prettier-ignore
9804
9781
 
9805
- const findIndex = ({
9806
- calc,
9782
+ function SelectAllOption({
9783
+ item,
9807
9784
  index,
9808
- optionDisabled,
9785
+ ref
9786
+ }) {
9787
+ const {
9788
+ availableItems,
9789
+ allSelectedState,
9790
+ highlightedIndex,
9791
+ optionDisabled,
9792
+ multiline,
9793
+ getItemProps,
9794
+ rowVirtualizer
9795
+ } = useAutocompleteContext();
9796
+ const value = 'Select all';
9797
+ const isSelected = allSelectedState === 'ALL';
9798
+ const isDisabled = optionDisabled(item);
9799
+ const indeterminate = allSelectedState === 'SOME';
9800
+ const highlighted = highlightedIndex === index && !isDisabled ? 'true' : 'false';
9801
+ const itemProps = getItemProps({
9802
+ ...(multiline && {
9803
+ ref: rowVirtualizer.measureElement
9804
+ }),
9805
+ item,
9806
+ index: index
9807
+ });
9808
+ return /*#__PURE__*/jsxRuntime.jsxs(StyledListItem, {
9809
+ ref: ref,
9810
+ $isdisabled: isDisabled ? 'true' : 'false',
9811
+ $highlighted: highlighted,
9812
+ "aria-hidden": isDisabled,
9813
+ $active: "false",
9814
+ "aria-selected": isSelected,
9815
+ "data-index": 0,
9816
+ "data-testid": 'select-all',
9817
+ "aria-setsize": availableItems.length,
9818
+ style: {
9819
+ position: 'sticky',
9820
+ top: 0,
9821
+ zIndex: 99
9822
+ },
9823
+ ...itemProps,
9824
+ children: [/*#__PURE__*/jsxRuntime.jsx(Checkbox, {
9825
+ disabled: isDisabled,
9826
+ checked: isSelected,
9827
+ indeterminate: indeterminate,
9828
+ value: value,
9829
+ onChange: () => {
9830
+ return null;
9831
+ }
9832
+ }), /*#__PURE__*/jsxRuntime.jsx(AutocompleteOptionLabel, {
9833
+ $multiline: multiline,
9834
+ children: value
9835
+ })]
9836
+ });
9837
+ }
9838
+
9839
+ const findIndex = ({
9840
+ calc,
9841
+ index,
9842
+ optionDisabled,
9809
9843
  availableItems
9810
9844
  }) => {
9811
9845
  const nextItem = availableItems[index];
@@ -9820,17 +9854,6 @@ const findIndex = ({
9820
9854
  }
9821
9855
  return index;
9822
9856
  };
9823
- const isEvent = (val, key) => /^on[A-Z](.*)/.test(key) && typeof val === 'function';
9824
- function mergeEventsFromRight(props1, props2) {
9825
- const events1 = pickBy(isEvent, props1);
9826
- const events2 = pickBy(isEvent, props2);
9827
- return mergeWith((event1, event2) => {
9828
- return (...args) => {
9829
- event1(...args);
9830
- event2(...args);
9831
- };
9832
- }, events1, events2);
9833
- }
9834
9857
  const findNextIndex = ({
9835
9858
  index,
9836
9859
  optionDisabled,
@@ -9877,8 +9900,19 @@ const findPrevIndex = ({
9877
9900
  }
9878
9901
  return prevIndex;
9879
9902
  };
9903
+ const isEvent = (val, key) => /^on[A-Z](.*)/.test(key) && typeof val === 'function';
9904
+ function mergeEventsFromRight(props1, props2) {
9905
+ const events1 = pickBy(isEvent, props1);
9906
+ const events2 = pickBy(isEvent, props2);
9907
+ return mergeWith((event1, event2) => {
9908
+ return (...args) => {
9909
+ event1(...args);
9910
+ event2(...args);
9911
+ };
9912
+ }, events1, events2);
9913
+ }
9880
9914
 
9881
- /*When a user clicks the StyledList scrollbar, the input looses focus which breaks downshift
9915
+ /*When a user clicks the StyledList scrollbar, the input loses focus which breaks downshift
9882
9916
  * keyboard navigation in the list. This code returns focus to the input on mouseUp
9883
9917
  */
9884
9918
  const handleListFocus = e => {
@@ -9890,49 +9924,335 @@ const handleListFocus = e => {
9890
9924
  once: true
9891
9925
  });
9892
9926
  };
9893
- const defaultOptionDisabled = () => false;
9894
- // MARK: types
9895
9927
 
9896
- // MARK: component
9897
- function AutocompleteInner(props, ref) {
9898
- const [controlledHighlightedIndex, setControlledHighlightedIndex] = react.useState(0);
9899
- const [lastScrollOffset, setLastScrollOffset] = react.useState(0);
9928
+ function EmptyOption() {
9900
9929
  const {
9901
- options = [],
9902
- totalOptions,
9903
- label,
9904
- meta,
9905
- className,
9906
- style,
9907
- disabled = false,
9908
- readOnly = false,
9909
- loading = false,
9910
- hideClearButton = false,
9911
- onOptionsChange,
9912
- onAddNewOption,
9913
- onInputChange,
9914
- selectedOptions: _selectedOptions,
9930
+ noOptionsText
9931
+ } = useAutocompleteContext();
9932
+ return /*#__PURE__*/jsxRuntime.jsx(StyledListItem, {
9933
+ $isdisabled: "true",
9934
+ $highlighted: "false",
9935
+ "aria-hidden": true,
9936
+ $active: "false",
9937
+ children: /*#__PURE__*/jsxRuntime.jsx(AutocompleteOptionLabel, {
9938
+ $multiline: false,
9939
+ children: noOptionsText
9940
+ })
9941
+ });
9942
+ }
9943
+
9944
+ const OptionList = ({
9945
+ refs,
9946
+ strategy,
9947
+ x,
9948
+ y,
9949
+ update
9950
+ }) => {
9951
+ const {
9952
+ getFloatingProps
9953
+ } = react$1.useInteractions([]);
9954
+ const {
9955
+ isOpen,
9956
+ getMenuProps,
9915
9957
  multiple,
9916
- itemToKey: _itemToKey,
9917
- itemCompare: _itemCompare,
9918
- allowSelectAll,
9919
- initialSelectedOptions: _initialSelectedOptions = [],
9920
- optionDisabled = defaultOptionDisabled,
9921
- optionsFilter,
9922
- autoWidth,
9923
- placeholder,
9924
- optionLabel,
9925
- clearSearchOnChange = true,
9926
- multiline = false,
9927
- dropdownHeight = 300,
9928
- optionComponent,
9929
- helperText,
9930
- helperIcon,
9931
- noOptionsText = 'No options',
9958
+ scrollContainer,
9959
+ dropdownHeight,
9960
+ availableItems,
9961
+ noOptionsText,
9962
+ rowVirtualizer,
9963
+ onAddNewOption
9964
+ } = useAutocompleteContext();
9965
+ react.useEffect(() => {
9966
+ if (refs.reference.current && refs.floating.current && isOpen) {
9967
+ return react$1.autoUpdate(refs.reference.current, refs.floating.current, update);
9968
+ }
9969
+ }, [refs.reference, refs.floating, update, isOpen]);
9970
+
9971
+ // MARK: popover toggle
9972
+ edsUtils.useIsomorphicLayoutEffect(() => {
9973
+ if (isOpen) {
9974
+ refs.floating.current?.showPopover();
9975
+ } else {
9976
+ refs.floating.current?.hidePopover();
9977
+ }
9978
+ }, [isOpen, refs.floating]);
9979
+ const showNoOptions = isOpen && !availableItems.length && noOptionsText.length > 0;
9980
+ const floatingProps = getFloatingProps({
9981
+ ref: refs.setFloating,
9982
+ onFocus: handleListFocus,
9983
+ style: {
9984
+ position: strategy,
9985
+ top: y || 0,
9986
+ left: x || 0
9987
+ }
9988
+ });
9989
+ const menuProps = getMenuProps({
9990
+ 'aria-multiselectable': multiple ? 'true' : null,
9991
+ ref: scrollContainer,
9992
+ style: {
9993
+ maxHeight: `${dropdownHeight}px`
9994
+ }
9995
+ }, {
9996
+ suppressRefError: true
9997
+ });
9998
+ return /*#__PURE__*/jsxRuntime.jsx(StyledPopover, {
9999
+ popover: "manual",
10000
+ ...floatingProps,
10001
+ children: /*#__PURE__*/jsxRuntime.jsxs(StyledList, {
10002
+ ...menuProps,
10003
+ children: [showNoOptions && /*#__PURE__*/jsxRuntime.jsx(AutocompleteNoOptions, {}), isOpen && /*#__PURE__*/jsxRuntime.jsx("li", {
10004
+ role: "presentation",
10005
+ style: {
10006
+ height: `${rowVirtualizer.getTotalSize()}px`,
10007
+ margin: '0',
10008
+ gridArea: '1 / -1'
10009
+ }
10010
+ }, "total-size"), !isOpen ? null : rowVirtualizer.getVirtualItems().map(virtualItem => {
10011
+ const index = virtualItem.index;
10012
+ const item = availableItems[index];
10013
+ if (item === AllSymbol) {
10014
+ return /*#__PURE__*/jsxRuntime.jsx(SelectAllOption, {
10015
+ item: item,
10016
+ index: index
10017
+ }, "select-all");
10018
+ }
10019
+ if (item === AddSymbol && onAddNewOption) {
10020
+ return /*#__PURE__*/jsxRuntime.jsx(AddNewOption, {
10021
+ item: item,
10022
+ index: index
10023
+ }, "add-item");
10024
+ }
10025
+ return /*#__PURE__*/jsxRuntime.jsx(Option, {
10026
+ item: item,
10027
+ virtualItem: virtualItem,
10028
+ index: index
10029
+ }, virtualItem.key);
10030
+ })]
10031
+ })
10032
+ });
10033
+ };
10034
+ const StyledPopover = styled__default.default('div').withConfig({
10035
+ shouldForwardProp: () => true //workaround to avoid warning until popover gets added to react types
10036
+ }).withConfig({
10037
+ displayName: "OptionList__StyledPopover",
10038
+ componentId: "sc-t6tp7k-0"
10039
+ })(["inset:unset;border:0;padding:0;margin:0;overflow:visible;&::backdrop{background-color:transparent;}"]);
10040
+ const StyledList = styled__default.default(List$1).withConfig({
10041
+ displayName: "OptionList__StyledList",
10042
+ componentId: "sc-t6tp7k-1"
10043
+ })(({
10044
+ theme
10045
+ }) => styled.css(["background-color:", ";box-shadow:", ";", " overflow-y:auto;overflow-x:hidden;padding:0;display:grid;@supports (-moz-appearance:none){scrollbar-width:thin;}"], theme.background, theme.boxShadow, edsUtils.bordersTemplate(theme.border)));
10046
+ const AutocompleteNoOptions = styled__default.default(EmptyOption).withConfig({
10047
+ displayName: "OptionList__AutocompleteNoOptions",
10048
+ componentId: "sc-t6tp7k-2"
10049
+ })(({
10050
+ theme
10051
+ }) => styled.css(["color:", ";"], theme.entities.noOptions.typography.color));
10052
+
10053
+ const SingleInput = () => {
10054
+ const {
10055
+ consolidatedEvents,
10056
+ inputProps,
9932
10057
  variant,
9933
- onClear,
9934
- ...other
9935
- } = props;
10058
+ hideClearButton,
10059
+ restHtmlProps,
10060
+ placeholder,
10061
+ readOnly
10062
+ } = useAutocompleteContext();
10063
+ return /*#__PURE__*/jsxRuntime.jsx(Input$4, {
10064
+ variant: variant,
10065
+ placeholder: placeholder,
10066
+ readOnly: readOnly,
10067
+ rightAdornmentsWidth: hideClearButton ? 24 + 8 : 24 * 2 + 8,
10068
+ rightAdornments: /*#__PURE__*/jsxRuntime.jsx(RightAdornments, {}),
10069
+ ...restHtmlProps,
10070
+ ...consolidatedEvents,
10071
+ ...inputProps
10072
+ });
10073
+ };
10074
+
10075
+ const {
10076
+ typography,
10077
+ colors,
10078
+ shape: {
10079
+ corners: {
10080
+ borderRadius
10081
+ }
10082
+ },
10083
+ spacings: {
10084
+ comfortable: {
10085
+ small: spacingSmall,
10086
+ medium_small: spacingMediumSmall,
10087
+ medium: spacingMedium,
10088
+ large: spacingLarge,
10089
+ x_large,
10090
+ xxx_large
10091
+ }
10092
+ },
10093
+ elevation: {
10094
+ temporary_nav: boxShadow
10095
+ }
10096
+ } = edsTokens.tokens;
10097
+ const selectTokens = {
10098
+ background: colors.ui.background__default.rgba,
10099
+ boxShadow,
10100
+ spacings: {
10101
+ top: '0',
10102
+ right: spacingLarge,
10103
+ bottom: '0',
10104
+ left: spacingLarge
10105
+ },
10106
+ typography: {
10107
+ ...typography.navigation.menu_title,
10108
+ color: colors.text.static_icons__default.rgba
10109
+ },
10110
+ border: {
10111
+ type: 'border',
10112
+ radius: borderRadius
10113
+ },
10114
+ states: {
10115
+ hover: {
10116
+ background: colors.ui.background__medium.rgba
10117
+ },
10118
+ active: {
10119
+ background: colors.interactive.primary__selected_highlight.rgba
10120
+ },
10121
+ disabled: {
10122
+ typography: {
10123
+ color: colors.interactive.disabled__text.rgba
10124
+ }
10125
+ }
10126
+ },
10127
+ variants: {
10128
+ error: {
10129
+ typography: {
10130
+ color: colors.interactive.danger__text.rgba
10131
+ }
10132
+ },
10133
+ warning: {
10134
+ typography: {
10135
+ color: colors.interactive.warning__text.rgba
10136
+ }
10137
+ },
10138
+ success: {
10139
+ typography: {
10140
+ color: colors.interactive.success__text.rgba
10141
+ }
10142
+ }
10143
+ },
10144
+ entities: {
10145
+ button: {
10146
+ height: '24px',
10147
+ width: '24px',
10148
+ spacings: {
10149
+ left: spacingSmall,
10150
+ right: spacingSmall,
10151
+ top: '6px'
10152
+ }
10153
+ },
10154
+ label: {
10155
+ minHeight: xxx_large,
10156
+ spacings: {
10157
+ left: '0',
10158
+ right: '0',
10159
+ top: spacingMedium,
10160
+ bottom: spacingMedium
10161
+ }
10162
+ },
10163
+ noOptions: {
10164
+ typography: {
10165
+ color: colors.text.static_icons__tertiary.rgba
10166
+ }
10167
+ }
10168
+ },
10169
+ modes: {
10170
+ compact: {
10171
+ spacings: {
10172
+ left: spacingSmall,
10173
+ right: spacingSmall,
10174
+ top: '0',
10175
+ bottom: '0'
10176
+ },
10177
+ entities: {
10178
+ button: {
10179
+ spacings: {
10180
+ left: spacingSmall,
10181
+ right: spacingSmall,
10182
+ top: '0'
10183
+ }
10184
+ },
10185
+ label: {
10186
+ minHeight: x_large,
10187
+ spacings: {
10188
+ left: '0',
10189
+ right: '0',
10190
+ top: spacingSmall,
10191
+ bottom: spacingSmall
10192
+ }
10193
+ }
10194
+ }
10195
+ }
10196
+ }
10197
+ };
10198
+ const multiSelect = mergeDeepRight(selectTokens, {
10199
+ spacings: {
10200
+ top: '0',
10201
+ bottom: '0',
10202
+ left: spacingMediumSmall,
10203
+ right: spacingLarge
10204
+ },
10205
+ modes: {
10206
+ compact: {
10207
+ spacings: {
10208
+ top: '0',
10209
+ //xx_small,
10210
+ bottom: '0'
10211
+ }
10212
+ }
10213
+ }
10214
+ });
10215
+
10216
+ const useAutocomplete = ({
10217
+ options = [],
10218
+ totalOptions,
10219
+ label,
10220
+ meta,
10221
+ className,
10222
+ style,
10223
+ disabled = false,
10224
+ readOnly = false,
10225
+ loading = false,
10226
+ hideClearButton = false,
10227
+ onOptionsChange,
10228
+ onAddNewOption,
10229
+ onInputChange,
10230
+ selectedOptions: _selectedOptions,
10231
+ selectionDisplay = 'summary',
10232
+ multiple,
10233
+ itemToKey: _itemToKey,
10234
+ itemCompare: _itemCompare,
10235
+ allowSelectAll,
10236
+ initialSelectedOptions: _initialSelectedOptions = [],
10237
+ optionDisabled = defaultOptionDisabled,
10238
+ optionsFilter,
10239
+ autoWidth,
10240
+ placeholder,
10241
+ optionLabel,
10242
+ clearSearchOnChange = true,
10243
+ multiline = false,
10244
+ dropdownHeight = 300,
10245
+ optionComponent,
10246
+ helperText,
10247
+ helperIcon,
10248
+ noOptionsText = 'No options',
10249
+ variant,
10250
+ onClear,
10251
+ ref,
10252
+ ...other
10253
+ }) => {
10254
+ const [lastScrollOffset, setLastScrollOffset] = react.useState(0);
10255
+ const [controlledHighlightedIndex, setControlledHighlightedIndex] = react.useState(0);
9936
10256
  const itemCompare = react.useMemo(() => {
9937
10257
  if (_itemCompare && _itemToKey) {
9938
10258
  console.error('Error: Specifying both itemCompare and itemToKey. itemCompare is deprecated, while itemToKey should be used instead of it. Please only use one.');
@@ -10022,7 +10342,6 @@ function AutocompleteInner(props, ref) {
10022
10342
  selectedItems,
10023
10343
  setSelectedItems
10024
10344
  } = downshift.useMultipleSelection(multipleSelectionProps);
10025
-
10026
10345
  // MARK: select all logic
10027
10346
  const enabledItems = react.useMemo(() => {
10028
10347
  const disabledItemsSet = new Set(inputOptions.filter(optionDisabled));
@@ -10330,6 +10649,7 @@ function AutocompleteInner(props, ref) {
10330
10649
  const showPlaceholder = placeholderText && selectedItems.length === 0;
10331
10650
  const optionCount = totalOptions || inputOptions.length;
10332
10651
  placeholderText = showPlaceholder ? placeholderText : `${selectedItems.length}/${optionCount} selected`;
10652
+ if (selectionDisplay === 'chips') placeholderText = placeholder;
10333
10653
  comboBoxProps = {
10334
10654
  ...comboBoxProps,
10335
10655
  selectedItem: null,
@@ -10412,26 +10732,131 @@ function AutocompleteInner(props, ref) {
10412
10732
  }
10413
10733
  };
10414
10734
  }
10735
+ const _comboBoxProps = downshift.useCombobox(comboBoxProps);
10736
+ const clear = () => {
10737
+ if (onClear) onClear();
10738
+ _comboBoxProps.reset();
10739
+ //dont clear items if they are selected and disabled
10740
+ setSelectedItems([...selectedDisabledItemsSet]);
10741
+ setTypedInputValue('');
10742
+ inputRef.current?.focus();
10743
+ };
10744
+ const inputProps = _comboBoxProps.getInputProps(getDropdownProps({
10745
+ preventKeyAction: multiple ? _comboBoxProps.isOpen : undefined,
10746
+ disabled,
10747
+ ref: inputRef
10748
+ }));
10749
+ const consolidatedEvents = mergeEventsFromRight(other, inputProps);
10750
+ const selectedItemsLabels = react.useMemo(() => selectedItems.map(getLabel), [selectedItems, getLabel]);
10751
+ return {
10752
+ ..._comboBoxProps,
10753
+ getDropdownProps,
10754
+ addSelectedItem,
10755
+ removeSelectedItem,
10756
+ selectedItems,
10757
+ setSelectedItems,
10758
+ clear,
10759
+ availableItems,
10760
+ getLabel,
10761
+ scrollContainer,
10762
+ rowVirtualizer,
10763
+ allSelectedState,
10764
+ toggleAllSelected,
10765
+ typedInputValue,
10766
+ inputRef,
10767
+ token,
10768
+ tokens,
10769
+ placeholderText,
10770
+ readOnly,
10771
+ inputProps,
10772
+ consolidatedEvents,
10773
+ multiple,
10774
+ disabled,
10775
+ optionDisabled,
10776
+ onAddNewOption,
10777
+ options,
10778
+ totalOptions,
10779
+ label,
10780
+ meta,
10781
+ className,
10782
+ style,
10783
+ loading,
10784
+ hideClearButton,
10785
+ onOptionsChange,
10786
+ onInputChange,
10787
+ selectedOptions,
10788
+ selectionDisplay,
10789
+ itemToKey,
10790
+ itemCompare,
10791
+ allowSelectAll,
10792
+ initialSelectedOptions,
10793
+ optionsFilter,
10794
+ autoWidth,
10795
+ placeholder,
10796
+ optionLabel,
10797
+ clearSearchOnChange,
10798
+ multiline,
10799
+ dropdownHeight,
10800
+ optionComponent,
10801
+ helperText,
10802
+ helperIcon,
10803
+ noOptionsText,
10804
+ variant,
10805
+ onClear,
10806
+ selectedItemsLabels,
10807
+ restHtmlProps: other
10808
+ };
10809
+ };
10810
+
10811
+ const Container$2 = styled__default.default.div.withConfig({
10812
+ displayName: "Autocomplete__Container",
10813
+ componentId: "sc-yvif0e-0"
10814
+ })(["position:relative;"]);
10815
+ const AllSymbol = Symbol('Select all');
10816
+ const AddSymbol = Symbol('Add new');
10817
+ const HelperText = styled__default.default(TextfieldHelperText).withConfig({
10818
+ displayName: "Autocomplete__HelperText",
10819
+ componentId: "sc-yvif0e-1"
10820
+ })(["margin-top:8px;margin-left:8px;"]);
10821
+ const StyledButton$1 = styled__default.default(Button$1).withConfig({
10822
+ displayName: "Autocomplete__StyledButton",
10823
+ componentId: "sc-yvif0e-2"
10824
+ })(({
10825
+ theme: {
10826
+ entities: {
10827
+ button
10828
+ }
10829
+ }
10830
+ }) => styled.css(["height:", ";width:", ";"], button.height, button.height));
10831
+ const defaultOptionDisabled = () => false;
10832
+ // MARK: types
10833
+
10834
+ // MARK: component
10835
+ function Autocomplete({
10836
+ ...props
10837
+ }) {
10838
+ const autocompleteProps = useAutocomplete({
10839
+ ...props,
10840
+ ref: props.ref
10841
+ });
10415
10842
  const {
10416
- isOpen,
10417
- getToggleButtonProps,
10418
10843
  getLabelProps,
10419
- getMenuProps,
10420
- getInputProps,
10421
- highlightedIndex,
10422
- getItemProps,
10423
- inputValue,
10424
- reset: resetCombobox
10425
- } = downshift.useCombobox(comboBoxProps);
10844
+ token,
10845
+ tokens,
10846
+ autoWidth,
10847
+ className,
10848
+ style,
10849
+ label,
10850
+ meta,
10851
+ multiple,
10852
+ disabled,
10853
+ variant,
10854
+ helperIcon,
10855
+ helperText
10856
+ } = autocompleteProps;
10426
10857
 
10427
10858
  // MARK: floating-ui setup
10428
- const {
10429
- x,
10430
- y,
10431
- refs,
10432
- update,
10433
- strategy
10434
- } = react$1.useFloating({
10859
+ const floatingProps = react$1.useFloating({
10435
10860
  placement: 'bottom-start',
10436
10861
  middleware: [react$1.offset(4), react$1.flip({
10437
10862
  boundary: typeof document === 'undefined' ? undefined : document?.body
@@ -10448,220 +10873,36 @@ function AutocompleteInner(props, ref) {
10448
10873
  padding: 10
10449
10874
  })]
10450
10875
  });
10451
- const {
10452
- getFloatingProps
10453
- } = react$1.useInteractions([]);
10454
- react.useEffect(() => {
10455
- if (refs.reference.current && refs.floating.current && isOpen) {
10456
- return react$1.autoUpdate(refs.reference.current, refs.floating.current, update);
10457
- }
10458
- }, [refs.reference, refs.floating, update, isOpen]);
10459
-
10460
- // MARK: popover toggle
10461
- edsUtils.useIsomorphicLayoutEffect(() => {
10462
- if (isOpen) {
10463
- refs.floating.current?.showPopover();
10464
- } else {
10465
- refs.floating.current?.hidePopover();
10466
- }
10467
- }, [isOpen, refs.floating]);
10468
- const clear = () => {
10469
- if (onClear) onClear();
10470
- resetCombobox();
10471
- //dont clear items if they are selected and disabled
10472
- setSelectedItems([...selectedDisabledItemsSet]);
10473
- setTypedInputValue('');
10474
- inputRef.current?.focus();
10475
- };
10476
- const showClearButton = (selectedItems.length > 0 || inputValue) && !readOnly && !hideClearButton;
10477
- const showNoOptions = isOpen && !availableItems.length && noOptionsText.length > 0;
10478
- const selectedItemsLabels = react.useMemo(() => selectedItems.map(getLabel), [selectedItems, getLabel]);
10479
-
10480
- // MARK: optionsList
10481
- const optionsList = /*#__PURE__*/jsxRuntime.jsx(StyledPopover, {
10482
- popover: "manual",
10483
- ...getFloatingProps({
10484
- ref: refs.setFloating,
10485
- onFocus: handleListFocus,
10486
- style: {
10487
- position: strategy,
10488
- top: y || 0,
10489
- left: x || 0
10490
- }
10491
- }),
10492
- children: /*#__PURE__*/jsxRuntime.jsxs(StyledList, {
10493
- ...getMenuProps({
10494
- 'aria-multiselectable': multiple ? 'true' : null,
10495
- ref: scrollContainer,
10496
- style: {
10497
- maxHeight: `${dropdownHeight}px`
10498
- }
10499
- }, {
10500
- suppressRefError: true
10501
- }),
10502
- children: [showNoOptions && /*#__PURE__*/jsxRuntime.jsx(AutocompleteNoOptions, {
10503
- value: noOptionsText,
10504
- multiple: false,
10505
- multiline: false,
10506
- highlighted: 'false',
10507
- isSelected: false,
10508
- isDisabled: true
10509
- }), isOpen && /*#__PURE__*/jsxRuntime.jsx("li", {
10510
- role: "presentation",
10511
- style: {
10512
- height: `${rowVirtualizer.getTotalSize()}px`,
10513
- margin: '0',
10514
- gridArea: '1 / -1'
10515
- }
10516
- }, "total-size"), !isOpen ? null : rowVirtualizer.getVirtualItems().map(virtualItem => {
10517
- const index = virtualItem.index;
10518
- const item = availableItems[index];
10519
- const label = getLabel(item);
10520
- const isDisabled = optionDisabled(item);
10521
- const isSelected = selectedItemsLabels.includes(label);
10522
- if (item === AllSymbol) {
10523
- return /*#__PURE__*/jsxRuntime.jsx(AutocompleteOption, {
10524
- "data-index": 0,
10525
- "data-testid": 'select-all',
10526
- value: 'Select all',
10527
- "aria-setsize": availableItems.length,
10528
- multiple: true,
10529
- isSelected: allSelectedState === 'ALL',
10530
- indeterminate: allSelectedState === 'SOME',
10531
- highlighted: highlightedIndex === index && !isDisabled ? 'true' : 'false',
10532
- isDisabled: false,
10533
- multiline: multiline,
10534
- onClick: toggleAllSelected,
10535
- style: {
10536
- position: 'sticky',
10537
- top: 0,
10538
- zIndex: 99
10539
- },
10540
- ...getItemProps({
10541
- ...(multiline && {
10542
- ref: rowVirtualizer.measureElement
10543
- }),
10544
- item,
10545
- index: index
10546
- })
10547
- }, 'select-all');
10548
- }
10549
- if (item === AddSymbol && onAddNewOption) {
10550
- const isDisabled = !typedInputValue.trim();
10551
- return /*#__PURE__*/jsxRuntime.jsx(AddNewOption, {
10552
- "data-index": 0,
10553
- "data-testid": 'add-item',
10554
- "aria-setsize": availableItems.length,
10555
- multiple: multiple,
10556
- highlighted: highlightedIndex === index && !isDisabled ? 'true' : 'false',
10557
- multiline: multiline,
10558
- style: {
10559
- position: 'sticky',
10560
- top: 0,
10561
- zIndex: 99
10562
- },
10563
- ...getItemProps({
10564
- ...(multiline && {
10565
- ref: rowVirtualizer.measureElement
10566
- }),
10567
- item,
10568
- index: index
10569
- }),
10570
- value: typedInputValue.trim()
10571
- }, 'add-item');
10572
- }
10573
- return /*#__PURE__*/jsxRuntime.jsx(AutocompleteOption, {
10574
- "data-index": index,
10575
- "aria-setsize": availableItems.length,
10576
- "aria-posinset": index + 1,
10577
- value: label,
10578
- multiple: multiple,
10579
- highlighted: highlightedIndex === index && !isDisabled ? 'true' : 'false',
10580
- isSelected: isSelected,
10581
- isDisabled: isDisabled,
10582
- multiline: multiline,
10583
- optionComponent: optionComponent?.(item, isSelected),
10584
- ...getItemProps({
10585
- ...(multiline && {
10586
- ref: rowVirtualizer.measureElement
10587
- }),
10588
- item,
10589
- index,
10590
- style: {
10591
- transform: `translateY(${virtualItem.start}px)`,
10592
- ...(!multiline && {
10593
- height: `${virtualItem.size}px`
10594
- })
10595
- }
10596
- })
10597
- }, virtualItem.key);
10598
- })]
10599
- })
10600
- });
10601
- const inputProps = getInputProps(getDropdownProps({
10602
- preventKeyAction: multiple ? isOpen : undefined,
10603
- disabled,
10604
- ref: inputRef
10605
- }));
10606
- const consolidatedEvents = mergeEventsFromRight(other, inputProps);
10607
10876
 
10608
10877
  // MARK: input
10609
- return /*#__PURE__*/jsxRuntime.jsx(styled.ThemeProvider, {
10610
- theme: token,
10611
- children: /*#__PURE__*/jsxRuntime.jsxs(Container$2, {
10612
- className: className,
10613
- style: style,
10614
- children: [/*#__PURE__*/jsxRuntime.jsx(Label$2, {
10615
- ...getLabelProps(),
10616
- label: label,
10617
- meta: meta,
10618
- disabled: disabled
10619
- }), /*#__PURE__*/jsxRuntime.jsx(Container$2, {
10620
- ref: refs.setReference,
10621
- children: /*#__PURE__*/jsxRuntime.jsx(Input$4, {
10622
- ...inputProps,
10623
- variant: variant,
10624
- placeholder: placeholderText,
10625
- readOnly: readOnly,
10626
- rightAdornmentsWidth: hideClearButton ? 24 + 8 : 24 * 2 + 8,
10627
- rightAdornments: /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
10628
- children: [loading && /*#__PURE__*/jsxRuntime.jsx(Progress.Circular, {
10629
- size: 16
10630
- }), showClearButton && /*#__PURE__*/jsxRuntime.jsx(StyledButton$1, {
10631
- variant: "ghost_icon",
10632
- disabled: disabled || readOnly,
10633
- "aria-label": 'clear options',
10634
- title: "clear",
10635
- onClick: clear,
10636
- children: /*#__PURE__*/jsxRuntime.jsx(Icon$1, {
10637
- data: edsIcons.close,
10638
- size: 16
10639
- })
10640
- }), !readOnly && /*#__PURE__*/jsxRuntime.jsx(StyledButton$1, {
10641
- variant: "ghost_icon",
10642
- ...getToggleButtonProps({
10643
- disabled: disabled || readOnly
10644
- }),
10645
- "aria-label": 'toggle options',
10646
- title: "open",
10647
- children: /*#__PURE__*/jsxRuntime.jsx(Icon$1, {
10648
- data: isOpen ? edsIcons.arrow_drop_up : edsIcons.arrow_drop_down
10649
- })
10650
- })]
10651
- }),
10652
- ...other,
10653
- ...consolidatedEvents
10654
- })
10655
- }), helperText && /*#__PURE__*/jsxRuntime.jsx(HelperText, {
10656
- color: variant ? tokens.variants[variant].typography.color : undefined,
10657
- text: helperText,
10658
- icon: helperIcon
10659
- }), optionsList]
10878
+ return /*#__PURE__*/jsxRuntime.jsx(AutocompleteContext.Provider, {
10879
+ value: {
10880
+ ...autocompleteProps
10881
+ },
10882
+ children: /*#__PURE__*/jsxRuntime.jsx(styled.ThemeProvider, {
10883
+ theme: token,
10884
+ children: /*#__PURE__*/jsxRuntime.jsxs(Container$2, {
10885
+ className: className,
10886
+ style: style,
10887
+ children: [/*#__PURE__*/jsxRuntime.jsx(Label$2, {
10888
+ ...getLabelProps(),
10889
+ label: label,
10890
+ meta: meta,
10891
+ disabled: disabled
10892
+ }), /*#__PURE__*/jsxRuntime.jsx(Container$2, {
10893
+ ref: floatingProps.refs.setReference,
10894
+ children: multiple ? /*#__PURE__*/jsxRuntime.jsx(MultipleInput, {}) : /*#__PURE__*/jsxRuntime.jsx(SingleInput, {})
10895
+ }), helperText && /*#__PURE__*/jsxRuntime.jsx(HelperText, {
10896
+ color: variant ? tokens.variants[variant].typography.color : undefined,
10897
+ text: helperText,
10898
+ icon: helperIcon
10899
+ }), /*#__PURE__*/jsxRuntime.jsx(OptionList, {
10900
+ ...floatingProps
10901
+ })]
10902
+ })
10660
10903
  })
10661
10904
  });
10662
10905
  }
10663
- // MARK: exported component
10664
- const Autocomplete = /*#__PURE__*/react.forwardRef(AutocompleteInner);
10665
10906
 
10666
10907
  const {
10667
10908
  colors: {
@@ -12156,12 +12397,22 @@ const FieldWrapper = /*#__PURE__*/react.forwardRef(({
12156
12397
  if (!isIconTarget && (event.code === 'Space' || event.code === 'Enter')) {
12157
12398
  setIsOpen(true);
12158
12399
  }
12400
+ if (event.key === 'Escape' && isOpen) {
12401
+ event.stopPropagation();
12402
+ event.preventDefault();
12403
+ setIsOpen(false);
12404
+ }
12159
12405
  },
12160
12406
  ...props,
12161
12407
  children: children
12162
12408
  }), /*#__PURE__*/jsxRuntime.jsx(Popover, {
12163
12409
  open: isOpen ?? false,
12164
12410
  onClose: () => setIsOpen(false),
12411
+ onKeyDown: e => {
12412
+ if (e.key !== 'Escape') return;
12413
+ e.stopPropagation();
12414
+ e.preventDefault();
12415
+ },
12165
12416
  anchorEl: anchorEl,
12166
12417
  placement: 'bottom-start',
12167
12418
  children: calendar
@@ -12837,6 +13088,8 @@ exports.AccordionHeaderActions = AccordionHeaderActions;
12837
13088
  exports.AccordionHeaderTitle = AccordionHeaderTitle;
12838
13089
  exports.AccordionItem = AccordionItem;
12839
13090
  exports.AccordionPanel = AccordionPanel;
13091
+ exports.AddSymbol = AddSymbol;
13092
+ exports.AllSymbol = AllSymbol;
12840
13093
  exports.Autocomplete = Autocomplete;
12841
13094
  exports.Avatar = Avatar;
12842
13095
  exports.Banner = Banner;
@@ -12903,6 +13156,7 @@ exports.Slider = Slider;
12903
13156
  exports.Snackbar = Snackbar;
12904
13157
  exports.SnackbarAction = SnackbarAction;
12905
13158
  exports.StarProgress = StarProgress;
13159
+ exports.StyledButton = StyledButton$1;
12906
13160
  exports.Switch = Switch;
12907
13161
  exports.Tab = Tab;
12908
13162
  exports.TabList = TabList;
@@ -12928,6 +13182,7 @@ exports.TopbarCustomContent = CustomContent;
12928
13182
  exports.TopbarHeader = Header$2;
12929
13183
  exports.Typography = Typography;
12930
13184
  exports.TypographyNext = TypographyNext;
13185
+ exports.defaultOptionDisabled = defaultOptionDisabled;
12931
13186
  exports.useEds = useEds;
12932
13187
  exports.useInputField = useInputField;
12933
13188
  exports.useSideBar = useSideBar;