@elliemae/ds-form-combobox 3.51.0-next.1 → 3.51.0-next.12

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 (128) hide show
  1. package/dist/cjs/ComboBoxCTX.js +4 -7
  2. package/dist/cjs/ComboBoxCTX.js.map +2 -2
  3. package/dist/cjs/ComboboxDataTestids.js +0 -4
  4. package/dist/cjs/ComboboxDataTestids.js.map +2 -2
  5. package/dist/cjs/{parts/header-list/index.js → config/useClickOutside.js} +22 -6
  6. package/dist/cjs/config/useClickOutside.js.map +7 -0
  7. package/dist/cjs/config/useComboBox.js +40 -52
  8. package/dist/cjs/config/useComboBox.js.map +2 -2
  9. package/dist/cjs/config/useCorrectOptions.js +3 -6
  10. package/dist/cjs/config/useCorrectOptions.js.map +2 -2
  11. package/dist/cjs/config/useOptionsPerSection.js +56 -0
  12. package/dist/cjs/config/useOptionsPerSection.js.map +7 -0
  13. package/dist/cjs/parts/DropdownIndicator.js +3 -2
  14. package/dist/cjs/parts/DropdownIndicator.js.map +2 -2
  15. package/dist/cjs/parts/Section.js +92 -0
  16. package/dist/cjs/parts/Section.js.map +7 -0
  17. package/dist/cjs/parts/container/Container.js +52 -41
  18. package/dist/cjs/parts/container/Container.js.map +3 -3
  19. package/dist/cjs/parts/controls/Controls.js +6 -4
  20. package/dist/cjs/parts/controls/Controls.js.map +2 -2
  21. package/dist/cjs/parts/controls/styled.js +22 -6
  22. package/dist/cjs/parts/controls/styled.js.map +2 -2
  23. package/dist/cjs/parts/controls/useOnPillsNavigation.js +3 -3
  24. package/dist/cjs/parts/controls/useOnPillsNavigation.js.map +2 -2
  25. package/dist/cjs/parts/controls-input/ControlsInput.js +21 -6
  26. package/dist/cjs/parts/controls-input/ControlsInput.js.map +2 -2
  27. package/dist/cjs/parts/controls-input/styled.js +3 -1
  28. package/dist/cjs/parts/controls-input/styled.js.map +2 -2
  29. package/dist/cjs/parts/controls-input/useKeyboardNavigation.js +15 -18
  30. package/dist/cjs/parts/controls-input/useKeyboardNavigation.js.map +2 -2
  31. package/dist/cjs/parts/controls-input/useMaskedOnChange.js +4 -5
  32. package/dist/cjs/parts/controls-input/useMaskedOnChange.js.map +2 -2
  33. package/dist/cjs/parts/menu-list/MenuList.js +31 -54
  34. package/dist/cjs/parts/menu-list/MenuList.js.map +2 -2
  35. package/dist/cjs/parts/menu-list/styled.js +3 -15
  36. package/dist/cjs/parts/menu-list/styled.js.map +2 -2
  37. package/dist/cjs/parts/menu-list/useItemRenderer.js +52 -47
  38. package/dist/cjs/parts/menu-list/useItemRenderer.js.map +2 -2
  39. package/dist/cjs/parts/multi-selected-values-container/MultiSelectedValuesContainer.js +12 -4
  40. package/dist/cjs/parts/multi-selected-values-container/MultiSelectedValuesContainer.js.map +2 -2
  41. package/dist/cjs/parts/multi-selected-values-container/RemovableSelectedValuePill.js +19 -4
  42. package/dist/cjs/parts/multi-selected-values-container/RemovableSelectedValuePill.js.map +3 -3
  43. package/dist/cjs/react-desc-prop-types.js +4 -1
  44. package/dist/cjs/react-desc-prop-types.js.map +2 -2
  45. package/dist/cjs/sharedTypes.js.map +2 -2
  46. package/dist/cjs/utils/listHelper.js +7 -23
  47. package/dist/cjs/utils/listHelper.js.map +2 -2
  48. package/dist/esm/ComboBoxCTX.js +4 -7
  49. package/dist/esm/ComboBoxCTX.js.map +2 -2
  50. package/dist/esm/ComboboxDataTestids.js +0 -4
  51. package/dist/esm/ComboboxDataTestids.js.map +2 -2
  52. package/dist/esm/config/useClickOutside.js +22 -0
  53. package/dist/esm/config/useClickOutside.js.map +7 -0
  54. package/dist/esm/config/useComboBox.js +40 -52
  55. package/dist/esm/config/useComboBox.js.map +2 -2
  56. package/dist/esm/config/useCorrectOptions.js +4 -7
  57. package/dist/esm/config/useCorrectOptions.js.map +2 -2
  58. package/dist/esm/config/useOptionsPerSection.js +26 -0
  59. package/dist/esm/config/useOptionsPerSection.js.map +7 -0
  60. package/dist/esm/parts/DropdownIndicator.js +3 -2
  61. package/dist/esm/parts/DropdownIndicator.js.map +2 -2
  62. package/dist/esm/parts/Section.js +62 -0
  63. package/dist/esm/parts/Section.js.map +7 -0
  64. package/dist/esm/parts/container/Container.js +53 -42
  65. package/dist/esm/parts/container/Container.js.map +3 -3
  66. package/dist/esm/parts/controls/Controls.js +6 -4
  67. package/dist/esm/parts/controls/Controls.js.map +2 -2
  68. package/dist/esm/parts/controls/styled.js +22 -6
  69. package/dist/esm/parts/controls/styled.js.map +2 -2
  70. package/dist/esm/parts/controls/useOnPillsNavigation.js +3 -3
  71. package/dist/esm/parts/controls/useOnPillsNavigation.js.map +2 -2
  72. package/dist/esm/parts/controls-input/ControlsInput.js +21 -6
  73. package/dist/esm/parts/controls-input/ControlsInput.js.map +2 -2
  74. package/dist/esm/parts/controls-input/styled.js +3 -1
  75. package/dist/esm/parts/controls-input/styled.js.map +2 -2
  76. package/dist/esm/parts/controls-input/useKeyboardNavigation.js +15 -18
  77. package/dist/esm/parts/controls-input/useKeyboardNavigation.js.map +2 -2
  78. package/dist/esm/parts/controls-input/useMaskedOnChange.js +4 -5
  79. package/dist/esm/parts/controls-input/useMaskedOnChange.js.map +2 -2
  80. package/dist/esm/parts/menu-list/MenuList.js +35 -58
  81. package/dist/esm/parts/menu-list/MenuList.js.map +2 -2
  82. package/dist/esm/parts/menu-list/styled.js +3 -15
  83. package/dist/esm/parts/menu-list/styled.js.map +2 -2
  84. package/dist/esm/parts/menu-list/useItemRenderer.js +54 -49
  85. package/dist/esm/parts/menu-list/useItemRenderer.js.map +2 -2
  86. package/dist/esm/parts/multi-selected-values-container/MultiSelectedValuesContainer.js +12 -4
  87. package/dist/esm/parts/multi-selected-values-container/MultiSelectedValuesContainer.js.map +2 -2
  88. package/dist/esm/parts/multi-selected-values-container/RemovableSelectedValuePill.js +19 -4
  89. package/dist/esm/parts/multi-selected-values-container/RemovableSelectedValuePill.js.map +3 -3
  90. package/dist/esm/react-desc-prop-types.js +4 -1
  91. package/dist/esm/react-desc-prop-types.js.map +2 -2
  92. package/dist/esm/sharedTypes.js.map +2 -2
  93. package/dist/esm/utils/listHelper.js +7 -23
  94. package/dist/esm/utils/listHelper.js.map +2 -2
  95. package/dist/types/ComboboxDataTestids.d.ts +0 -4
  96. package/dist/types/config/useClickOutside.d.ts +1 -0
  97. package/dist/types/config/useCorrectOptions.d.ts +1 -1
  98. package/dist/types/config/useOptionsPerSection.d.ts +2 -0
  99. package/dist/types/parts/Section.d.ts +14 -0
  100. package/dist/types/parts/controls/styled.d.ts +2 -0
  101. package/dist/types/parts/controls-input/styled.d.ts +3 -1
  102. package/dist/types/parts/menu-list/styled.d.ts +2 -7
  103. package/dist/types/parts/menu-list/useItemRenderer.d.ts +9 -1
  104. package/dist/types/parts/multi-selected-values-container/RemovableSelectedValuePill.d.ts +1 -0
  105. package/dist/types/react-desc-prop-types.d.ts +11 -1
  106. package/dist/types/sharedTypes.d.ts +4 -10
  107. package/dist/types/tests/read-only.test.d.ts +1 -0
  108. package/dist/types/utils/listHelper.d.ts +0 -1
  109. package/package.json +17 -17
  110. package/dist/cjs/parts/header-list/HeaderList.js +0 -104
  111. package/dist/cjs/parts/header-list/HeaderList.js.map +0 -7
  112. package/dist/cjs/parts/header-list/index.js.map +0 -7
  113. package/dist/cjs/parts/header-list/styled.js +0 -85
  114. package/dist/cjs/parts/header-list/styled.js.map +0 -7
  115. package/dist/cjs/parts/header-list/useHeaderListHandlers.js +0 -140
  116. package/dist/cjs/parts/header-list/useHeaderListHandlers.js.map +0 -7
  117. package/dist/esm/parts/header-list/HeaderList.js +0 -80
  118. package/dist/esm/parts/header-list/HeaderList.js.map +0 -7
  119. package/dist/esm/parts/header-list/index.js +0 -6
  120. package/dist/esm/parts/header-list/index.js.map +0 -7
  121. package/dist/esm/parts/header-list/styled.js +0 -55
  122. package/dist/esm/parts/header-list/styled.js.map +0 -7
  123. package/dist/esm/parts/header-list/useHeaderListHandlers.js +0 -110
  124. package/dist/esm/parts/header-list/useHeaderListHandlers.js.map +0 -7
  125. package/dist/types/parts/header-list/HeaderList.d.ts +0 -2
  126. package/dist/types/parts/header-list/index.d.ts +0 -1
  127. package/dist/types/parts/header-list/styled.d.ts +0 -6
  128. package/dist/types/parts/header-list/useHeaderListHandlers.d.ts +0 -11
@@ -1,29 +1,24 @@
1
1
  import * as React from "react";
2
2
  import { useMemo, useState, useRef, useCallback, useEffect } from "react";
3
- import { useVirtual } from "react-virtual";
4
3
  import { uid } from "uid";
5
4
  import { useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from "@elliemae/ds-props-helpers";
6
5
  import { defaultProps } from "../ComboBoxCTX.js";
7
6
  import { ComboboxPropTypes } from "../react-desc-prop-types.js";
8
- import { useCorrectOptions } from "./useCorrectOptions.js";
9
- import { getFirstOption } from "../utils/listHelper.js";
10
7
  import { DSComboBoxName } from "../theming.js";
11
- import { useMakeMutable } from "./useMakeMutable.js";
8
+ import { getFirstOption, isSelectedValueEmpty } from "../utils/listHelper.js";
9
+ import { useCorrectOptions } from "./useCorrectOptions.js";
10
+ import { useOptionsPerSection } from "./useOptionsPerSection.js";
12
11
  const useComboBox = (props) => {
13
12
  const propsWithDefaults = useMemoMergePropsWithDefault(props, defaultProps);
14
13
  useValidateTypescriptPropTypes(propsWithDefaults, ComboboxPropTypes, DSComboBoxName);
15
14
  const [showPopover, setShowPopover] = useState(false);
16
15
  const [referenceElement, setReferenceElement] = useState(null);
17
- const [showSelectedOptions, setShowSelectedOptions] = useState(false);
18
16
  const [inputValue, setInputValue] = useState("");
19
17
  const [hasFocus, setHasFocus] = useState(false);
20
18
  const internalRef = useRef(null);
21
- const listRef = useRef(null);
22
19
  const wrapperListRef = useRef(null);
23
20
  const selectedOptionsRef = useRef(null);
24
21
  const controlsWrapperRef = useRef(null);
25
- const selectAllCheckboxRef = useRef(null);
26
- const toggleSelectionButtonRef = useRef(null);
27
22
  const pillGroupRef = useRef(null);
28
23
  const { id, selectedValues, isMenuOpen, onMenuChange, applyAriaDisabled } = propsWithDefaults;
29
24
  const instanceUid = useMemo(() => id || uid(5), [id]);
@@ -31,69 +26,64 @@ const useComboBox = (props) => {
31
26
  if (isMenuOpen !== void 0) return isMenuOpen;
32
27
  return showPopover;
33
28
  }, [showPopover, isMenuOpen]);
34
- const setMenuState = useCallback(
35
- (newState, reason, e) => {
36
- if (applyAriaDisabled) return;
37
- if (onMenuChange !== void 0) onMenuChange(newState, reason, e);
38
- setShowPopover(newState);
39
- },
40
- [onMenuChange, applyAriaDisabled]
41
- );
42
- const correctOptions = useCorrectOptions(propsWithDefaults, inputValue, showSelectedOptions);
43
- const virtualListHelpers = useVirtual({
44
- size: correctOptions.length,
45
- parentRef: listRef,
46
- overscan: 15,
47
- paddingStart: 0
48
- });
29
+ const correctOptions = useCorrectOptions(propsWithDefaults, inputValue);
30
+ const optionsPerSection = useOptionsPerSection(correctOptions);
31
+ const actionRef = {
32
+ scrollTo: () => {
33
+ }
34
+ };
35
+ const listRef = useRef(actionRef);
49
36
  const scrollOptionIntoView = useCallback(
50
37
  (dsId, opts = { align: "center" }) => {
51
- virtualListHelpers.scrollToIndex(
38
+ listRef.current.scrollTo(
52
39
  correctOptions.findIndex((opt) => opt.dsId === dsId),
53
40
  opts
54
41
  );
42
+ requestAnimationFrame(() => {
43
+ listRef.current.scrollTo(
44
+ correctOptions.findIndex((opt) => opt.dsId === dsId),
45
+ opts
46
+ );
47
+ });
55
48
  },
56
- [correctOptions, virtualListHelpers]
49
+ [correctOptions]
57
50
  );
58
51
  const [focusOptionIdx, setFocusOptionIdx] = useState("");
52
+ const setMenuState = useCallback(
53
+ (newState, reason, e) => {
54
+ if (applyAriaDisabled) return;
55
+ if (onMenuChange !== void 0) onMenuChange(newState, reason, e);
56
+ setShowPopover(newState);
57
+ if (!inputValue && newState && !focusOptionIdx && !isSelectedValueEmpty(selectedValues)) {
58
+ const focusedValue = getFirstOption(correctOptions, selectedValues);
59
+ setFocusOptionIdx(focusedValue);
60
+ scrollOptionIntoView(focusedValue, { align: "center" });
61
+ } else {
62
+ setFocusOptionIdx("");
63
+ }
64
+ },
65
+ [applyAriaDisabled, onMenuChange, inputValue, focusOptionIdx, selectedValues, correctOptions, scrollOptionIntoView]
66
+ );
59
67
  useEffect(() => {
60
- if (!hasFocus) setFocusOptionIdx("");
61
- if (hasFocus && (!focusOptionIdx || showSelectedOptions)) {
62
- const focusedValue = getFirstOption(correctOptions, selectedValues);
63
- setFocusOptionIdx(focusedValue);
64
- scrollOptionIntoView(focusedValue, { align: "center" });
65
- }
66
- }, [showPopover, hasFocus, correctOptions, selectedValues]);
67
- const correctOptionsRef = useMakeMutable(correctOptions);
68
- useEffect(() => {
69
- setFocusOptionIdx(correctOptionsRef.current?.[0]?.dsId ?? "");
70
- }, [correctOptionsRef, inputValue]);
71
- useEffect(() => {
72
- if (!showPopover) {
73
- setFocusOptionIdx("");
74
- setShowSelectedOptions(false);
68
+ if (propsWithDefaults.inline) {
69
+ setMenuState(true, "inline");
75
70
  }
76
- }, [showPopover]);
71
+ }, []);
77
72
  const ctx = useMemo(
78
73
  () => ({
79
74
  props: { ...propsWithDefaults },
80
- virtualListHelpers,
81
75
  menuState,
82
76
  referenceElement,
83
77
  listRef,
84
78
  focusOptionIdx,
85
79
  selectedOptionsRef,
86
80
  controlsWrapperRef,
87
- selectAllCheckboxRef,
88
81
  inputValue,
89
82
  setInputValue,
90
83
  setMenuState,
91
84
  hasFocus,
92
- toggleSelectionButtonRef,
93
85
  pillGroupRef,
94
- showSelectedOptions,
95
86
  wrapperListRef,
96
- setShowSelectedOptions,
97
87
  setHasFocus,
98
88
  setFocusOptionIdx,
99
89
  scrollOptionIntoView,
@@ -101,7 +91,8 @@ const useComboBox = (props) => {
101
91
  setShowPopover,
102
92
  internalRef,
103
93
  correctOptions,
104
- instanceUid
94
+ instanceUid,
95
+ optionsPerSection
105
96
  }),
106
97
  [
107
98
  scrollOptionIntoView,
@@ -109,21 +100,18 @@ const useComboBox = (props) => {
109
100
  correctOptions,
110
101
  hasFocus,
111
102
  propsWithDefaults,
112
- virtualListHelpers,
113
103
  inputValue,
114
104
  focusOptionIdx,
115
105
  wrapperListRef,
116
- showSelectedOptions,
117
106
  menuState,
118
107
  pillGroupRef,
119
108
  referenceElement,
120
109
  selectedOptionsRef,
121
110
  controlsWrapperRef,
122
- selectAllCheckboxRef,
123
- toggleSelectionButtonRef,
124
111
  listRef,
125
112
  internalRef,
126
- instanceUid
113
+ instanceUid,
114
+ optionsPerSection
127
115
  ]
128
116
  );
129
117
  return ctx;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/config/useComboBox.tsx"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\n/* eslint-disable import/prefer-default-export */\n/* eslint-disable complexity */\n/* eslint-disable max-statements */\nimport { useMemo, useState, useRef, useCallback, useEffect } from 'react';\nimport { useVirtual, type ScrollToIndexOptions } from 'react-virtual';\nimport { uid } from 'uid';\nimport { useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from '@elliemae/ds-props-helpers';\nimport { defaultProps } from '../ComboBoxCTX.js';\nimport type { DSComboboxT } from '../react-desc-prop-types.js';\nimport { ComboboxPropTypes } from '../react-desc-prop-types.js';\nimport type { DSComboboxInternalsT } from '../sharedTypes.js';\nimport { useCorrectOptions } from './useCorrectOptions.js';\nimport { getFirstOption } from '../utils/listHelper.js';\nimport { DSComboBoxName } from '../theming.js';\nimport { useMakeMutable } from './useMakeMutable.js';\n\nexport const useComboBox = (props: DSComboboxT.Props): DSComboboxInternalsT.ComboBoxContextT => {\n const propsWithDefaults = useMemoMergePropsWithDefault<DSComboboxT.InternalProps>(props, defaultProps);\n useValidateTypescriptPropTypes(propsWithDefaults, ComboboxPropTypes, DSComboBoxName);\n const [showPopover, setShowPopover] = useState<boolean>(false);\n const [referenceElement, setReferenceElement] = useState<HTMLElement | null>(null);\n const [showSelectedOptions, setShowSelectedOptions] = useState<boolean>(false);\n\n const [inputValue, setInputValue] = useState<string>('');\n const [hasFocus, setHasFocus] = useState<boolean>(false);\n\n const internalRef = useRef<HTMLInputElement>(null);\n const listRef = useRef<HTMLDivElement>(null);\n const wrapperListRef = useRef<HTMLDivElement>(null);\n\n const selectedOptionsRef = useRef<HTMLDivElement>(null);\n const controlsWrapperRef = useRef<HTMLDivElement>(null);\n const selectAllCheckboxRef = useRef<HTMLInputElement>(null);\n const toggleSelectionButtonRef = useRef<HTMLButtonElement>(null);\n const pillGroupRef = useRef<HTMLDivElement>(null);\n\n const { id, selectedValues, isMenuOpen, onMenuChange, applyAriaDisabled } = propsWithDefaults;\n\n const instanceUid = useMemo(() => id || uid(5), [id]);\n\n const menuState = useMemo(() => {\n if (isMenuOpen !== undefined) return isMenuOpen;\n return showPopover;\n }, [showPopover, isMenuOpen]);\n\n const setMenuState = useCallback(\n (\n newState: boolean,\n reason: string,\n e?: React.KeyboardEvent | React.MouseEvent | React.ChangeEvent<HTMLInputElement>,\n ) => {\n if (applyAriaDisabled) return;\n if (onMenuChange !== undefined) onMenuChange(newState, reason, e);\n setShowPopover(newState);\n },\n [onMenuChange, applyAriaDisabled],\n );\n // ---------------------------------------------------------------------------\n // Options with creatable option + filtered by selected\n // ---------------------------------------------------------------------------\n\n const correctOptions = useCorrectOptions(propsWithDefaults, inputValue, showSelectedOptions);\n\n // ===========================================================================\n // Virtualization setup\n // ===========================================================================\n\n const virtualListHelpers: ReturnType<typeof useVirtual> = useVirtual({\n size: correctOptions.length,\n parentRef: listRef,\n overscan: 15,\n paddingStart: 0,\n });\n\n // ===========================================================================\n // Scroll into view function\n // ===========================================================================\n const scrollOptionIntoView = useCallback(\n (dsId: string, opts: ScrollToIndexOptions = { align: 'center' }) => {\n virtualListHelpers.scrollToIndex(\n correctOptions.findIndex((opt) => opt.dsId === dsId),\n opts,\n );\n },\n [correctOptions, virtualListHelpers],\n );\n\n // ===========================================================================\n // Init focused option when opening the menu list\n // ===========================================================================\n\n const [focusOptionIdx, setFocusOptionIdx] = useState<string>('');\n\n useEffect(() => {\n // this code calculate the option to be focused when opening the menu\n // when losing focus we remove the focused one\n // when focus adquired again getFirstOption calculate the correct one\n if (!hasFocus) setFocusOptionIdx('');\n if (hasFocus && (!focusOptionIdx || showSelectedOptions)) {\n const focusedValue = getFirstOption(correctOptions, selectedValues);\n setFocusOptionIdx(focusedValue);\n scrollOptionIntoView(focusedValue, { align: 'center' });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [showPopover, hasFocus, correctOptions, selectedValues]);\n\n const correctOptionsRef = useMakeMutable(correctOptions);\n\n // focus first option when typing\n useEffect(() => {\n setFocusOptionIdx(correctOptionsRef.current?.[0]?.dsId ?? '');\n }, [correctOptionsRef, inputValue]);\n\n useEffect(() => {\n if (!showPopover) {\n setFocusOptionIdx('');\n setShowSelectedOptions(false);\n }\n }, [showPopover]);\n\n const ctx = useMemo(\n () => ({\n props: { ...propsWithDefaults },\n virtualListHelpers,\n menuState,\n referenceElement,\n listRef,\n focusOptionIdx,\n selectedOptionsRef,\n controlsWrapperRef,\n selectAllCheckboxRef,\n inputValue,\n setInputValue,\n setMenuState,\n hasFocus,\n toggleSelectionButtonRef,\n pillGroupRef,\n showSelectedOptions,\n wrapperListRef,\n setShowSelectedOptions,\n setHasFocus,\n setFocusOptionIdx,\n scrollOptionIntoView,\n setReferenceElement,\n setShowPopover,\n internalRef,\n correctOptions,\n instanceUid,\n }),\n [\n scrollOptionIntoView,\n setMenuState,\n correctOptions,\n hasFocus,\n propsWithDefaults,\n virtualListHelpers,\n inputValue,\n focusOptionIdx,\n wrapperListRef,\n showSelectedOptions,\n menuState,\n pillGroupRef,\n referenceElement,\n selectedOptionsRef,\n controlsWrapperRef,\n selectAllCheckboxRef,\n toggleSelectionButtonRef,\n listRef,\n internalRef,\n instanceUid,\n ],\n );\n\n return ctx;\n};\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACIvB,SAAS,SAAS,UAAU,QAAQ,aAAa,iBAAiB;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,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\n/* eslint-disable import/prefer-default-export */\n/* eslint-disable complexity */\n/* eslint-disable max-statements */\nimport { useMemo, useState, useRef, useCallback, useEffect } from 'react';\nimport { uid } from 'uid';\nimport { type DSFastListT } from '@elliemae/ds-fast-list';\n\nimport { useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from '@elliemae/ds-props-helpers';\nimport { defaultProps } from '../ComboBoxCTX.js';\nimport type { DSComboboxT } from '../react-desc-prop-types.js';\nimport { ComboboxPropTypes } from '../react-desc-prop-types.js';\nimport type { DSComboboxInternalsT } from '../sharedTypes.js';\nimport { DSComboBoxName } from '../theming.js';\nimport { getFirstOption, isSelectedValueEmpty } from '../utils/listHelper.js';\nimport { useCorrectOptions } from './useCorrectOptions.js';\nimport { useOptionsPerSection } from './useOptionsPerSection.js';\n\nexport const useComboBox = (props: DSComboboxT.Props): DSComboboxInternalsT.ComboBoxContextT => {\n const propsWithDefaults = useMemoMergePropsWithDefault<DSComboboxT.InternalProps>(props, defaultProps);\n useValidateTypescriptPropTypes(propsWithDefaults, ComboboxPropTypes, DSComboBoxName);\n const [showPopover, setShowPopover] = useState<boolean>(false);\n const [referenceElement, setReferenceElement] = useState<HTMLElement | null>(null);\n\n const [inputValue, setInputValue] = useState<string>('');\n const [hasFocus, setHasFocus] = useState<boolean>(false);\n\n const internalRef = useRef<HTMLInputElement>(null);\n const wrapperListRef = useRef<HTMLDivElement>(null);\n\n const selectedOptionsRef = useRef<HTMLDivElement>(null);\n const controlsWrapperRef = useRef<HTMLDivElement>(null);\n const pillGroupRef = useRef<HTMLDivElement>(null);\n\n const { id, selectedValues, isMenuOpen, onMenuChange, applyAriaDisabled } = propsWithDefaults;\n\n const instanceUid = useMemo(() => id || uid(5), [id]);\n\n const menuState = useMemo(() => {\n if (isMenuOpen !== undefined) return isMenuOpen;\n return showPopover;\n }, [showPopover, isMenuOpen]);\n\n // ---------------------------------------------------------------------------\n // Options with creatable option + filtered by selected\n // ---------------------------------------------------------------------------\n\n const correctOptions = useCorrectOptions(propsWithDefaults, inputValue);\n\n const optionsPerSection = useOptionsPerSection(correctOptions);\n\n const actionRef: DSComboboxT.ActionRefVirtualized = {\n scrollTo: () => {},\n };\n\n const listRef = useRef<DSComboboxT.ActionRefVirtualized>(actionRef);\n\n // ===========================================================================\n // Scroll into view function\n // ===========================================================================\n const scrollOptionIntoView = useCallback(\n (dsId: string, opts: DSFastListT.ScrollToOptions = { align: 'center' } as DSFastListT.ScrollToOptions) => {\n listRef.current.scrollTo(\n correctOptions.findIndex((opt) => opt.dsId === dsId),\n opts,\n );\n requestAnimationFrame(() => {\n listRef.current.scrollTo(\n correctOptions.findIndex((opt) => opt.dsId === dsId),\n opts,\n );\n });\n },\n [correctOptions],\n );\n\n // ===========================================================================\n // Init focused option when opening the menu list\n // ===========================================================================\n\n const [focusOptionIdx, setFocusOptionIdx] = useState<string>('');\n\n const setMenuState = useCallback(\n (\n newState: boolean,\n reason: string,\n e?: React.KeyboardEvent | React.MouseEvent | React.ChangeEvent<HTMLInputElement>,\n ) => {\n if (applyAriaDisabled) return;\n if (onMenuChange !== undefined) onMenuChange(newState, reason, e);\n setShowPopover(newState);\n\n if (!inputValue && newState && !focusOptionIdx && !isSelectedValueEmpty(selectedValues)) {\n const focusedValue = getFirstOption(correctOptions, selectedValues);\n setFocusOptionIdx(focusedValue);\n scrollOptionIntoView(focusedValue, { align: 'center' });\n } else {\n setFocusOptionIdx('');\n }\n },\n [applyAriaDisabled, onMenuChange, inputValue, focusOptionIdx, selectedValues, correctOptions, scrollOptionIntoView],\n );\n\n // We need to force the auto focus for the inline since we dont control the floating wrapper.\n useEffect(() => {\n if (propsWithDefaults.inline) {\n setMenuState(true, 'inline');\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const ctx = useMemo(\n () => ({\n props: { ...propsWithDefaults },\n menuState,\n referenceElement,\n listRef,\n focusOptionIdx,\n selectedOptionsRef,\n controlsWrapperRef,\n inputValue,\n setInputValue,\n setMenuState,\n hasFocus,\n pillGroupRef,\n wrapperListRef,\n setHasFocus,\n setFocusOptionIdx,\n scrollOptionIntoView,\n setReferenceElement,\n setShowPopover,\n internalRef,\n correctOptions,\n instanceUid,\n optionsPerSection,\n }),\n [\n scrollOptionIntoView,\n setMenuState,\n correctOptions,\n hasFocus,\n propsWithDefaults,\n inputValue,\n focusOptionIdx,\n wrapperListRef,\n menuState,\n pillGroupRef,\n referenceElement,\n selectedOptionsRef,\n controlsWrapperRef,\n listRef,\n internalRef,\n instanceUid,\n optionsPerSection,\n ],\n );\n\n return ctx;\n};\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACIvB,SAAS,SAAS,UAAU,QAAQ,aAAa,iBAAiB;AAClE,SAAS,WAAW;AAGpB,SAAS,8BAA8B,sCAAsC;AAC7E,SAAS,oBAAoB;AAE7B,SAAS,yBAAyB;AAElC,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB,4BAA4B;AACrD,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AAE9B,MAAM,cAAc,CAAC,UAAoE;AAC9F,QAAM,oBAAoB,6BAAwD,OAAO,YAAY;AACrG,iCAA+B,mBAAmB,mBAAmB,cAAc;AACnF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A,IACnB,CACE,UACA,QACA,MACG;AACH,UAAI,kBAAmB;AACvB,UAAI,iBAAiB,OAAW,cAAa,UAAU,QAAQ,CAAC;AAChE,qBAAe,QAAQ;AAEvB,UAAI,CAAC,cAAc,YAAY,CAAC,kBAAkB,CAAC,qBAAqB,cAAc,GAAG;AACvF,cAAM,eAAe,eAAe,gBAAgB,cAAc;AAClE,0BAAkB,YAAY;AAC9B,6BAAqB,cAAc,EAAE,OAAO,SAAS,CAAC;AAAA,MACxD,OAAO;AACL,0BAAkB,EAAE;AAAA,MACtB;AAAA,IACF;AAAA,IACA,CAAC,mBAAmB,cAAc,YAAY,gBAAgB,gBAAgB,gBAAgB,oBAAoB;AAAA,EACpH;AAGA,YAAU,MAAM;AACd,QAAI,kBAAkB,QAAQ;AAC5B,mBAAa,MAAM,QAAQ;AAAA,IAC7B;AAAA,EAEF,GAAG,CAAC,CAAC;AAEL,QAAM,MAAM;AAAA,IACV,OAAO;AAAA,MACL,OAAO,EAAE,GAAG,kBAAkB;AAAA,MAC9B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -2,9 +2,9 @@ import * as React from "react";
2
2
  import { useMemo } from "react";
3
3
  import { uid } from "uid";
4
4
  import { MENU_OPTION_TYPES } from "../constants.js";
5
- import { selectedValuesWithSections, filterOptions } from "../utils/listHelper.js";
6
- const useCorrectOptions = (propsWithDefaults, inputValue, showSelectedOptions) => {
7
- const { filteredOptions, allOptions, selectedValues, onCreate } = propsWithDefaults;
5
+ import { filterOptions } from "../utils/listHelper.js";
6
+ const useCorrectOptions = (propsWithDefaults, inputValue) => {
7
+ const { filteredOptions, allOptions, onCreate } = propsWithDefaults;
8
8
  return useMemo(() => {
9
9
  let correctAllOptions = allOptions;
10
10
  if (allOptions?.every((option) => typeof option === "string")) {
@@ -16,9 +16,6 @@ const useCorrectOptions = (propsWithDefaults, inputValue, showSelectedOptions) =
16
16
  }));
17
17
  }
18
18
  const correctFilterOptions = filteredOptions ?? filterOptions(inputValue, correctAllOptions);
19
- if (showSelectedOptions && Array.isArray(selectedValues) && selectedValues.length > 0) {
20
- return selectedValuesWithSections(correctFilterOptions, selectedValues);
21
- }
22
19
  if (onCreate && inputValue && correctFilterOptions.findIndex(
23
20
  (option) => option.type === MENU_OPTION_TYPES.OPTION && option.label === inputValue
24
21
  ) === -1) {
@@ -32,7 +29,7 @@ const useCorrectOptions = (propsWithDefaults, inputValue, showSelectedOptions) =
32
29
  return [creatableItem, ...correctFilterOptions];
33
30
  }
34
31
  return correctFilterOptions;
35
- }, [filteredOptions, allOptions, showSelectedOptions, selectedValues, onCreate, inputValue]);
32
+ }, [filteredOptions, allOptions, onCreate, inputValue]);
36
33
  };
37
34
  export {
38
35
  useCorrectOptions
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/config/useCorrectOptions.tsx"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\nimport { useMemo } from 'react';\nimport { uid } from 'uid';\nimport type { DSComboboxT } from '../react-desc-prop-types.js';\nimport { MENU_OPTION_TYPES } from '../constants.js';\nimport { selectedValuesWithSections, filterOptions } from '../utils/listHelper.js';\nconst useCorrectOptions = (propsWithDefaults: DSComboboxT.Props, inputValue: string, showSelectedOptions: boolean) => {\n const { filteredOptions, allOptions, selectedValues, onCreate } = propsWithDefaults;\n\n return useMemo(() => {\n let correctAllOptions = allOptions;\n if (allOptions?.every((option) => typeof option === 'string')) {\n correctAllOptions = allOptions.map((option, index) => ({\n dsId: index.toString(),\n label: option as unknown as string,\n type: MENU_OPTION_TYPES.OPTION,\n value: option as unknown as string,\n }));\n }\n const correctFilterOptions = filteredOptions ?? filterOptions(inputValue, correctAllOptions);\n // when show selected toggle is on we return the selected value only as filteredOptions prop\n if (showSelectedOptions && Array.isArray(selectedValues) && selectedValues.length > 0) {\n return selectedValuesWithSections(correctFilterOptions, selectedValues);\n }\n\n // whether oncreate is passed we add as first option the creatable action based on input value string\n if (\n onCreate &&\n inputValue &&\n correctFilterOptions.findIndex(\n (option) => option.type === MENU_OPTION_TYPES.OPTION && option.label === inputValue,\n ) === -1\n ) {\n const creatableUuid = uid();\n const creatableItem: DSComboboxT.ItemCreatableOption = {\n dsId: `creatable-${creatableUuid}`,\n label: inputValue,\n type: 'creatable',\n 'aria-describedby': `aria-creatable`,\n };\n\n return [creatableItem, ...correctFilterOptions];\n }\n\n return correctFilterOptions;\n }, [filteredOptions, allOptions, showSelectedOptions, selectedValues, onCreate, inputValue]);\n};\n\nexport { useCorrectOptions };\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACCvB,SAAS,eAAe;AACxB,SAAS,WAAW;AAEpB,SAAS,yBAAyB;AAClC,SAAS,4BAA4B,qBAAqB;AAC1D,MAAM,oBAAoB,CAAC,mBAAsC,YAAoB,wBAAiC;AACpH,QAAM,EAAE,iBAAiB,YAAY,gBAAgB,SAAS,IAAI;AAElE,SAAO,QAAQ,MAAM;AACnB,QAAI,oBAAoB;AACxB,QAAI,YAAY,MAAM,CAAC,WAAW,OAAO,WAAW,QAAQ,GAAG;AAC7D,0BAAoB,WAAW,IAAI,CAAC,QAAQ,WAAW;AAAA,QACrD,MAAM,MAAM,SAAS;AAAA,QACrB,OAAO;AAAA,QACP,MAAM,kBAAkB;AAAA,QACxB,OAAO;AAAA,MACT,EAAE;AAAA,IACJ;AACA,UAAM,uBAAuB,mBAAmB,cAAc,YAAY,iBAAiB;AAE3F,QAAI,uBAAuB,MAAM,QAAQ,cAAc,KAAK,eAAe,SAAS,GAAG;AACrF,aAAO,2BAA2B,sBAAsB,cAAc;AAAA,IACxE;AAGA,QACE,YACA,cACA,qBAAqB;AAAA,MACnB,CAAC,WAAW,OAAO,SAAS,kBAAkB,UAAU,OAAO,UAAU;AAAA,IAC3E,MAAM,IACN;AACA,YAAM,gBAAgB,IAAI;AAC1B,YAAM,gBAAiD;AAAA,QACrD,MAAM,aAAa,aAAa;AAAA,QAChC,OAAO;AAAA,QACP,MAAM;AAAA,QACN,oBAAoB;AAAA,MACtB;AAEA,aAAO,CAAC,eAAe,GAAG,oBAAoB;AAAA,IAChD;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,iBAAiB,YAAY,qBAAqB,gBAAgB,UAAU,UAAU,CAAC;AAC7F;",
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\nimport { useMemo } from 'react';\nimport { uid } from 'uid';\nimport type { DSComboboxT } from '../react-desc-prop-types.js';\nimport { MENU_OPTION_TYPES } from '../constants.js';\nimport { filterOptions } from '../utils/listHelper.js';\nconst useCorrectOptions = (propsWithDefaults: DSComboboxT.Props, inputValue: string) => {\n const { filteredOptions, allOptions, onCreate } = propsWithDefaults;\n\n return useMemo(() => {\n let correctAllOptions = allOptions;\n if (allOptions?.every((option) => typeof option === 'string')) {\n correctAllOptions = allOptions.map((option, index) => ({\n dsId: index.toString(),\n label: option as unknown as string,\n type: MENU_OPTION_TYPES.OPTION,\n value: option as unknown as string,\n }));\n }\n const correctFilterOptions = filteredOptions ?? filterOptions(inputValue, correctAllOptions);\n\n // whether oncreate is passed we add as first option the creatable action based on input value string\n if (\n onCreate &&\n inputValue &&\n correctFilterOptions.findIndex(\n (option) => option.type === MENU_OPTION_TYPES.OPTION && option.label === inputValue,\n ) === -1\n ) {\n const creatableUuid = uid();\n const creatableItem: DSComboboxT.ItemCreatableOption = {\n dsId: `creatable-${creatableUuid}`,\n label: inputValue,\n type: 'creatable',\n 'aria-describedby': `aria-creatable`,\n };\n\n return [creatableItem, ...correctFilterOptions];\n }\n\n return correctFilterOptions;\n }, [filteredOptions, allOptions, onCreate, inputValue]);\n};\n\nexport { useCorrectOptions };\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACCvB,SAAS,eAAe;AACxB,SAAS,WAAW;AAEpB,SAAS,yBAAyB;AAClC,SAAS,qBAAqB;AAC9B,MAAM,oBAAoB,CAAC,mBAAsC,eAAuB;AACtF,QAAM,EAAE,iBAAiB,YAAY,SAAS,IAAI;AAElD,SAAO,QAAQ,MAAM;AACnB,QAAI,oBAAoB;AACxB,QAAI,YAAY,MAAM,CAAC,WAAW,OAAO,WAAW,QAAQ,GAAG;AAC7D,0BAAoB,WAAW,IAAI,CAAC,QAAQ,WAAW;AAAA,QACrD,MAAM,MAAM,SAAS;AAAA,QACrB,OAAO;AAAA,QACP,MAAM,kBAAkB;AAAA,QACxB,OAAO;AAAA,MACT,EAAE;AAAA,IACJ;AACA,UAAM,uBAAuB,mBAAmB,cAAc,YAAY,iBAAiB;AAG3F,QACE,YACA,cACA,qBAAqB;AAAA,MACnB,CAAC,WAAW,OAAO,SAAS,kBAAkB,UAAU,OAAO,UAAU;AAAA,IAC3E,MAAM,IACN;AACA,YAAM,gBAAgB,IAAI;AAC1B,YAAM,gBAAiD;AAAA,QACrD,MAAM,aAAa,aAAa;AAAA,QAChC,OAAO;AAAA,QACP,MAAM;AAAA,QACN,oBAAoB;AAAA,MACtB;AAEA,aAAO,CAAC,eAAe,GAAG,oBAAoB;AAAA,IAChD;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,iBAAiB,YAAY,UAAU,UAAU,CAAC;AACxD;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,26 @@
1
+ import * as React from "react";
2
+ import { useMemo } from "react";
3
+ const useOptionsPerSection = (correctOptions) => useMemo(() => {
4
+ const result = [];
5
+ let currentSection = null;
6
+ correctOptions.forEach((item) => {
7
+ if (item.type === "section") {
8
+ currentSection = {
9
+ dsId: item.dsId,
10
+ type: item.type,
11
+ label: item.label,
12
+ options: []
13
+ };
14
+ result.push(currentSection);
15
+ } else if ((item.type === "option" || item.type === "separator") && currentSection) {
16
+ currentSection.options.push(item);
17
+ } else if (item.type === "option" || item.type === "creatable" || item.type === "separator") {
18
+ result.push(item);
19
+ }
20
+ });
21
+ return result;
22
+ }, [correctOptions]);
23
+ export {
24
+ useOptionsPerSection
25
+ };
26
+ //# sourceMappingURL=useOptionsPerSection.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/config/useOptionsPerSection.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useMemo } from 'react';\nimport type { DSComboboxT } from '../react-desc-prop-types.js';\n\nexport const useOptionsPerSection = (correctOptions: DSComboboxT.OptionTypes[]) =>\n useMemo(() => {\n const result: DSComboboxT.OptionTypes[] = [];\n let currentSection: DSComboboxT.ItemSectionOptions | null = null;\n\n correctOptions.forEach((item) => {\n if (item.type === 'section') {\n // Start a new section\n currentSection = {\n dsId: item.dsId,\n type: item.type,\n label: item.label,\n options: [],\n };\n result.push(currentSection);\n } else if ((item.type === 'option' || item.type === 'separator') && currentSection) {\n // Add option to the current section's options array\n currentSection.options.push(item);\n } else if (item.type === 'option' || item.type === 'creatable' || item.type === 'separator') {\n // If we encounter an option without a section, push it to the result array\n result.push(item);\n }\n });\n return result;\n }, [correctOptions]);\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,eAAe;AAGjB,MAAM,uBAAuB,CAAC,mBACnC,QAAQ,MAAM;AACZ,QAAM,SAAoC,CAAC;AAC3C,MAAI,iBAAwD;AAE5D,iBAAe,QAAQ,CAAC,SAAS;AAC/B,QAAI,KAAK,SAAS,WAAW;AAE3B,uBAAiB;AAAA,QACf,MAAM,KAAK;AAAA,QACX,MAAM,KAAK;AAAA,QACX,OAAO,KAAK;AAAA,QACZ,SAAS,CAAC;AAAA,MACZ;AACA,aAAO,KAAK,cAAc;AAAA,IAC5B,YAAY,KAAK,SAAS,YAAY,KAAK,SAAS,gBAAgB,gBAAgB;AAElF,qBAAe,QAAQ,KAAK,IAAI;AAAA,IAClC,WAAW,KAAK,SAAS,YAAY,KAAK,SAAS,eAAe,KAAK,SAAS,aAAa;AAE3F,aAAO,KAAK,IAAI;AAAA,IAClB;AAAA,EACF,CAAC;AACD,SAAO;AACT,GAAG,CAAC,cAAc,CAAC;",
6
+ "names": []
7
+ }
@@ -15,14 +15,14 @@ const StyledDropDownButton = styled(DSButtonV2)`
15
15
  }
16
16
 
17
17
  & svg {
18
- fill: ${({ theme, disabled }) => disabled ? theme.colors.neutral["400"] : theme.colors.brand["700"]};
18
+ fill: ${({ theme, disabled, readOnly, applyAriaDisabled }) => disabled || readOnly || applyAriaDisabled ? theme.colors.neutral["400"] : theme.colors.brand["700"]};
19
19
  }
20
20
 
21
21
  ${({ applyAriaDisabled }) => applyAriaDisabled && `cursor: not-allowed`}
22
22
  `;
23
23
  const DropdownIndicator = () => {
24
24
  const {
25
- props: { disabled, applyAriaDisabled },
25
+ props: { disabled, applyAriaDisabled, readOnly },
26
26
  menuState,
27
27
  instanceUid
28
28
  } = useContext(ComboBoxContext);
@@ -37,6 +37,7 @@ const DropdownIndicator = () => {
37
37
  "aria-controls": `combo-listbox-${instanceUid}`,
38
38
  "aria-labelledby": "combo-label",
39
39
  disabled,
40
+ readOnly,
40
41
  "aria-expanded": menuState,
41
42
  "aria-haspopup": "listbox",
42
43
  "aria-hidden": true,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/parts/DropdownIndicator.tsx"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable react/prop-types */\n/* eslint-disable import/no-cycle */\nimport React, { useCallback, useContext } from 'react';\nimport { styled } from '@elliemae/ds-system';\nimport { DSButtonV2 } from '@elliemae/ds-button-v2';\nimport { ChevronSmallDown } from '@elliemae/ds-icons';\nimport ComboBoxContext from '../ComboBoxCTX.js';\nimport { ComboboxDataTestid } from '../ComboboxDataTestids.js';\n\nconst StyledDropDownButton = styled(DSButtonV2)<{ applyAriaDisabled: boolean }>`\n &:focus::after {\n border: none;\n }\n &:hover:not(:disabled) {\n background-color: transparent;\n }\n\n & svg {\n fill: ${({ theme, disabled }) => (disabled ? theme.colors.neutral['400'] : theme.colors.brand['700'])};\n }\n\n ${({ applyAriaDisabled }) => applyAriaDisabled && `cursor: not-allowed`}\n`;\n\nexport const DropdownIndicator = (): JSX.Element => {\n const {\n props: { disabled, applyAriaDisabled },\n menuState,\n instanceUid,\n } = useContext(ComboBoxContext);\n\n const handleOnClick: (e: React.MouseEvent<HTMLButtonElement> | React.KeyboardEvent<HTMLButtonElement>) => void =\n useCallback((e) => {\n e.preventDefault();\n }, []);\n\n return (\n <StyledDropDownButton\n onClick={handleOnClick}\n data-testid={ComboboxDataTestid.DROPDOWN}\n aria-controls={`combo-listbox-${instanceUid}`}\n aria-labelledby=\"combo-label\"\n disabled={disabled}\n aria-expanded={menuState}\n aria-haspopup=\"listbox\"\n aria-hidden\n buttonType=\"icon\"\n tabIndex={-1}\n size=\"s\"\n applyAriaDisabled={applyAriaDisabled}\n >\n <ChevronSmallDown size=\"s\" />\n </StyledDropDownButton>\n );\n};\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACmDjB;AAjDN,SAAgB,aAAa,kBAAkB;AAC/C,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,wBAAwB;AACjC,OAAO,qBAAqB;AAC5B,SAAS,0BAA0B;AAEnC,MAAM,uBAAuB,OAAO,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YASlC,CAAC,EAAE,OAAO,SAAS,MAAO,WAAW,MAAM,OAAO,QAAQ,KAAK,IAAI,MAAM,OAAO,MAAM,KAAK,CAAE;AAAA;AAAA;AAAA,IAGrG,CAAC,EAAE,kBAAkB,MAAM,qBAAqB,qBAAqB;AAAA;AAGlE,MAAM,oBAAoB,MAAmB;AAClD,QAAM;AAAA,IACJ,OAAO,EAAE,UAAU,kBAAkB;AAAA,IACrC;AAAA,IACA;AAAA,EACF,IAAI,WAAW,eAAe;AAE9B,QAAM,gBACJ,YAAY,CAAC,MAAM;AACjB,MAAE,eAAe;AAAA,EACnB,GAAG,CAAC,CAAC;AAEP,SACE;AAAA,IAAC;AAAA;AAAA,MACC,SAAS;AAAA,MACT,eAAa,mBAAmB;AAAA,MAChC,iBAAe,iBAAiB,WAAW;AAAA,MAC3C,mBAAgB;AAAA,MAChB;AAAA,MACA,iBAAe;AAAA,MACf,iBAAc;AAAA,MACd,eAAW;AAAA,MACX,YAAW;AAAA,MACX,UAAU;AAAA,MACV,MAAK;AAAA,MACL;AAAA,MAEA,8BAAC,oBAAiB,MAAK,KAAI;AAAA;AAAA,EAC7B;AAEJ;",
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable react/prop-types */\n/* eslint-disable import/no-cycle */\nimport React, { useCallback, useContext } from 'react';\nimport { styled } from '@elliemae/ds-system';\nimport { DSButtonV2 } from '@elliemae/ds-button-v2';\nimport { ChevronSmallDown } from '@elliemae/ds-icons';\nimport ComboBoxContext from '../ComboBoxCTX.js';\nimport { ComboboxDataTestid } from '../ComboboxDataTestids.js';\n\nconst StyledDropDownButton = styled(DSButtonV2)<{ applyAriaDisabled: boolean }>`\n &:focus::after {\n border: none;\n }\n &:hover:not(:disabled) {\n background-color: transparent;\n }\n\n & svg {\n fill: ${({ theme, disabled, readOnly, applyAriaDisabled }) =>\n disabled || readOnly || applyAriaDisabled ? theme.colors.neutral['400'] : theme.colors.brand['700']};\n }\n\n ${({ applyAriaDisabled }) => applyAriaDisabled && `cursor: not-allowed`}\n`;\n\nexport const DropdownIndicator = (): JSX.Element => {\n const {\n props: { disabled, applyAriaDisabled, readOnly },\n menuState,\n instanceUid,\n } = useContext(ComboBoxContext);\n\n const handleOnClick: (e: React.MouseEvent<HTMLButtonElement> | React.KeyboardEvent<HTMLButtonElement>) => void =\n useCallback((e) => {\n e.preventDefault();\n }, []);\n\n return (\n <StyledDropDownButton\n onClick={handleOnClick}\n data-testid={ComboboxDataTestid.DROPDOWN}\n aria-controls={`combo-listbox-${instanceUid}`}\n aria-labelledby=\"combo-label\"\n disabled={disabled}\n readOnly={readOnly}\n aria-expanded={menuState}\n aria-haspopup=\"listbox\"\n aria-hidden\n buttonType=\"icon\"\n tabIndex={-1}\n size=\"s\"\n applyAriaDisabled={applyAriaDisabled}\n >\n <ChevronSmallDown size=\"s\" />\n </StyledDropDownButton>\n );\n};\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACqDjB;AAnDN,SAAgB,aAAa,kBAAkB;AAC/C,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,wBAAwB;AACjC,OAAO,qBAAqB;AAC5B,SAAS,0BAA0B;AAEnC,MAAM,uBAAuB,OAAO,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YASlC,CAAC,EAAE,OAAO,UAAU,UAAU,kBAAkB,MACtD,YAAY,YAAY,oBAAoB,MAAM,OAAO,QAAQ,KAAK,IAAI,MAAM,OAAO,MAAM,KAAK,CAAC;AAAA;AAAA;AAAA,IAGrG,CAAC,EAAE,kBAAkB,MAAM,qBAAqB,qBAAqB;AAAA;AAGlE,MAAM,oBAAoB,MAAmB;AAClD,QAAM;AAAA,IACJ,OAAO,EAAE,UAAU,mBAAmB,SAAS;AAAA,IAC/C;AAAA,IACA;AAAA,EACF,IAAI,WAAW,eAAe;AAE9B,QAAM,gBACJ,YAAY,CAAC,MAAM;AACjB,MAAE,eAAe;AAAA,EACnB,GAAG,CAAC,CAAC;AAEP,SACE;AAAA,IAAC;AAAA;AAAA,MACC,SAAS;AAAA,MACT,eAAa,mBAAmB;AAAA,MAChC,iBAAe,iBAAiB,WAAW;AAAA,MAC3C,mBAAgB;AAAA,MAChB;AAAA,MACA;AAAA,MACA,iBAAe;AAAA,MACf,iBAAc;AAAA,MACd,eAAW;AAAA,MACX,YAAW;AAAA,MACX,UAAU;AAAA,MACV,MAAK;AAAA,MACL;AAAA,MAEA,8BAAC,oBAAiB,MAAK,KAAI;AAAA;AAAA,EAC7B;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,62 @@
1
+ import * as React from "react";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { createElement } from "react";
4
+ import React2 from "react";
5
+ import { styled } from "@elliemae/ds-system";
6
+ import { SingleMenuItem, MultiMenuItem, Separator } from "@elliemae/ds-menu-items";
7
+ import { MENU_OPTION_TYPES } from "../constants.js";
8
+ import { ComboboxDataTestid } from "../ComboboxDataTestids.js";
9
+ import { isSelected } from "../utils/listHelper.js";
10
+ const StyledSectionWrapper = styled("section")`
11
+ list-style: none;
12
+ min-height: 24px;
13
+ display: grid;
14
+ align-items: center;
15
+ `;
16
+ const StyledSectionLabel = styled("header")`
17
+ display: flex;
18
+ align-items: center;
19
+ padding: 0px 16px;
20
+ min-height: 24px;
21
+ font-size: 1rem;
22
+ color: neutral-500;
23
+ `;
24
+ const Section = React2.memo((props) => {
25
+ const { label, wrapperStyles, focusOptionIdx, selectedValues, innerRef, handleOnMouseDown, options, handleClick } = props;
26
+ const id = `${label.replace(/ /g, "")}-section`;
27
+ const CBItem = Array.isArray(selectedValues) ? MultiMenuItem : SingleMenuItem;
28
+ return /* @__PURE__ */ jsxs(StyledSectionWrapper, { role: "group", "aria-labelledby": id, style: wrapperStyles, innerRef, children: [
29
+ /* @__PURE__ */ jsx(StyledSectionLabel, { id, role: "presentation", children: label }),
30
+ options?.map((option) => {
31
+ const { dsId, type, value, label: optionLabel, readOnly, disabled, applyAriaDisabled, ...rest } = option;
32
+ if (type === MENU_OPTION_TYPES.SEPARATOR) {
33
+ return /* @__PURE__ */ jsx(Separator, {}, dsId);
34
+ }
35
+ return /* @__PURE__ */ createElement(
36
+ CBItem,
37
+ {
38
+ value,
39
+ label: optionLabel,
40
+ dataTestid: ComboboxDataTestid.OPTION,
41
+ disabled,
42
+ applyAriaDisabled: applyAriaDisabled || readOnly,
43
+ onClick: (e) => {
44
+ if (applyAriaDisabled) return;
45
+ handleClick(option, e);
46
+ },
47
+ onMouseDown: handleOnMouseDown,
48
+ isActive: dsId === focusOptionIdx,
49
+ isSelected: isSelected(selectedValues, option),
50
+ tabIndex: -1,
51
+ ...rest,
52
+ key: option.dsId,
53
+ dsId: option.dsId
54
+ }
55
+ );
56
+ })
57
+ ] });
58
+ });
59
+ export {
60
+ Section
61
+ };
62
+ //# sourceMappingURL=Section.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/parts/Section.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\nimport { styled } from '@elliemae/ds-system';\nimport { SingleMenuItem, MultiMenuItem, Separator } from '@elliemae/ds-menu-items';\nimport { MENU_OPTION_TYPES } from '../constants.js';\n\nimport { ComboboxDataTestid } from '../ComboboxDataTestids.js';\nimport type { DSComboboxT } from '../react-desc-prop-types.js';\nimport { isSelected } from '../utils/listHelper.js';\n\ninterface SectionProps {\n label: string;\n wrapperStyles: React.CSSProperties;\n innerRef: (instance: HTMLDivElement | null) => void;\n options: DSComboboxT.ItemOption[] | DSComboboxT.ItemSeparatorOptions[];\n handleClick: (option: DSComboboxT.ItemOption, e: React.MouseEvent<HTMLInputElement>) => void;\n handleOnMouseDown: (e: React.MouseEvent<HTMLLIElement>) => void;\n focusOptionIdx: string;\n selectedValues: DSComboboxT.SelectedOptionsT;\n}\n\nconst StyledSectionWrapper = styled('section')`\n list-style: none;\n min-height: 24px;\n display: grid;\n align-items: center;\n`;\n\nconst StyledSectionLabel = styled('header')`\n display: flex;\n align-items: center;\n padding: 0px 16px;\n min-height: 24px;\n font-size: 1rem;\n color: neutral-500;\n`;\n\nexport const Section = React.memo((props: SectionProps) => {\n const { label, wrapperStyles, focusOptionIdx, selectedValues, innerRef, handleOnMouseDown, options, handleClick } =\n props;\n const id = `${label.replace(/ /g, '')}-section`;\n\n const CBItem = Array.isArray(selectedValues) ? MultiMenuItem : SingleMenuItem;\n\n return (\n <StyledSectionWrapper role=\"group\" aria-labelledby={id} style={wrapperStyles} innerRef={innerRef}>\n <StyledSectionLabel id={id} role=\"presentation\">\n {label}\n </StyledSectionLabel>\n {options?.map((option) => {\n const { dsId, type, value, label: optionLabel, readOnly, disabled, applyAriaDisabled, ...rest } = option;\n\n if (type === MENU_OPTION_TYPES.SEPARATOR) {\n return <Separator key={dsId} />;\n }\n\n return (\n <CBItem\n value={value}\n label={optionLabel}\n dataTestid={ComboboxDataTestid.OPTION}\n disabled={disabled}\n applyAriaDisabled={applyAriaDisabled || readOnly}\n onClick={(e: React.MouseEvent<HTMLInputElement>) => {\n if (applyAriaDisabled) return;\n handleClick(option, e);\n }}\n onMouseDown={handleOnMouseDown}\n isActive={dsId === focusOptionIdx}\n isSelected={isSelected(selectedValues, option)}\n tabIndex={-1}\n {...rest}\n key={option.dsId}\n dsId={option.dsId}\n />\n );\n })}\n </StyledSectionWrapper>\n );\n});\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;AC4CnB,SACE,KADF;AAYM;AAxDV,OAAOA,YAAW;AAClB,SAAS,cAAc;AACvB,SAAS,gBAAgB,eAAe,iBAAiB;AACzD,SAAS,yBAAyB;AAElC,SAAS,0BAA0B;AAEnC,SAAS,kBAAkB;AAa3B,MAAM,uBAAuB,OAAO,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAO7C,MAAM,qBAAqB,OAAO,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASnC,MAAM,UAAUA,OAAM,KAAK,CAAC,UAAwB;AACzD,QAAM,EAAE,OAAO,eAAe,gBAAgB,gBAAgB,UAAU,mBAAmB,SAAS,YAAY,IAC9G;AACF,QAAM,KAAK,GAAG,MAAM,QAAQ,MAAM,EAAE,CAAC;AAErC,QAAM,SAAS,MAAM,QAAQ,cAAc,IAAI,gBAAgB;AAE/D,SACE,qBAAC,wBAAqB,MAAK,SAAQ,mBAAiB,IAAI,OAAO,eAAe,UAC5E;AAAA,wBAAC,sBAAmB,IAAQ,MAAK,gBAC9B,iBACH;AAAA,IACC,SAAS,IAAI,CAAC,WAAW;AACxB,YAAM,EAAE,MAAM,MAAM,OAAO,OAAO,aAAa,UAAU,UAAU,mBAAmB,GAAG,KAAK,IAAI;AAElG,UAAI,SAAS,kBAAkB,WAAW;AACxC,eAAO,oBAAC,eAAe,IAAM;AAAA,MAC/B;AAEA,aACE;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA,OAAO;AAAA,UACP,YAAY,mBAAmB;AAAA,UAC/B;AAAA,UACA,mBAAmB,qBAAqB;AAAA,UACxC,SAAS,CAAC,MAA0C;AAClD,gBAAI,kBAAmB;AACvB,wBAAY,QAAQ,CAAC;AAAA,UACvB;AAAA,UACA,aAAa;AAAA,UACb,UAAU,SAAS;AAAA,UACnB,YAAY,WAAW,gBAAgB,MAAM;AAAA,UAC7C,UAAU;AAAA,UACT,GAAG;AAAA,UACJ,KAAK,OAAO;AAAA,UACZ,MAAM,OAAO;AAAA;AAAA,MACf;AAAA,IAEJ,CAAC;AAAA,KACH;AAEJ,CAAC;",
6
+ "names": ["React"]
7
+ }
@@ -1,17 +1,20 @@
1
1
  import * as React from "react";
2
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
- import { useCallback, useEffect, useContext } from "react";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import React2, { useCallback, useMemo, useEffect, useContext } from "react";
4
4
  import { useGetGlobalAttributes, useGetXstyledProps } from "@elliemae/ds-props-helpers";
5
- import { DSPopperJS } from "@elliemae/ds-popperjs";
5
+ import { mergeRefs } from "@elliemae/ds-system";
6
+ import { useFloatingContext, FloatingWrapper } from "@elliemae/ds-floating-context";
6
7
  import ComboBoxContext from "../../ComboBoxCTX.js";
7
8
  import { StyledContainer, StyledPopperWrapper } from "./styled.js";
8
9
  import { Controls } from "../controls/index.js";
9
10
  import { MenuList } from "../menu-list/index.js";
10
11
  import { ComboboxDataTestid } from "../../ComboboxDataTestids.js";
11
12
  import { LiveRegion } from "../LiveRegion.js";
13
+ import { useOnClickOutside } from "../../config/useClickOutside.js";
12
14
  const Container = () => {
13
- const { props, internalRef, setMenuState, menuState, setReferenceElement, referenceElement } = useContext(ComboBoxContext);
14
- const { inline, startPlacementPreference, placementOrderPreference, withoutPortal, applyAriaDisabled } = props;
15
+ const [referenceElement, setReferenceElement] = React2.useState(null);
16
+ const { props, internalRef, setMenuState, menuState } = useContext(ComboBoxContext);
17
+ const { inline, startPlacementPreference, placementOrderPreference, applyAriaDisabled } = props;
15
18
  const globalAttributes = useGetGlobalAttributes(props);
16
19
  const { zIndex, ...xStyledProps } = useGetXstyledProps(props);
17
20
  const correctZIndex = zIndex ? parseInt(zIndex, 10) : void 0;
@@ -32,43 +35,51 @@ const Container = () => {
32
35
  window.removeEventListener("blur", closeMenuOnWindowBlur);
33
36
  };
34
37
  }, [menuState, setMenuState]);
35
- return (
36
- // eslint-disable-next-line react/jsx-no-useless-fragment
37
- /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(
38
- StyledContainer,
39
- {
40
- "data-testid": dataTestId ?? ComboboxDataTestid.CONTAINER,
41
- innerRef: setReferenceElement,
42
- className,
43
- applyAriaDisabled,
44
- ...xStyledProps,
45
- children: [
46
- /* @__PURE__ */ jsx(LiveRegion, {}),
47
- inline ? /* @__PURE__ */ jsxs(Fragment, { children: [
48
- /* @__PURE__ */ jsx(Controls, {}),
49
- /* @__PURE__ */ jsx(MenuList, {})
50
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
51
- /* @__PURE__ */ jsx(Controls, {}),
52
- referenceElement ? /* @__PURE__ */ jsx(
53
- DSPopperJS,
54
- {
55
- customOffset: [0, 5],
56
- referenceElement,
57
- showPopover: menuState,
58
- closeContextMenu: handleCloseMenu,
59
- startPlacementPreference,
60
- placementOrderPreference,
61
- withoutPortal,
62
- withoutArrow: true,
63
- withoutAnimation: true,
64
- zIndex: correctZIndex,
65
- children: /* @__PURE__ */ jsx(StyledPopperWrapper, { tabIndex: -1, onMouseDown: handleMouseDown, applyAriaDisabled, children: /* @__PURE__ */ jsx(MenuList, {}) })
66
- }
67
- ) : null
68
- ] })
69
- ]
70
- }
71
- ) })
38
+ const config = useMemo(
39
+ () => ({
40
+ placement: "bottom",
41
+ withoutAnimation: true,
42
+ startPlacementPreference,
43
+ placementOrderPreference,
44
+ zIndex: correctZIndex,
45
+ customOffset: [0, 5],
46
+ handleCloseMenu,
47
+ portalDOMContainer: document.body,
48
+ externallyControlledIsOpen: menuState
49
+ }),
50
+ [startPlacementPreference, placementOrderPreference, correctZIndex, handleCloseMenu, menuState]
51
+ );
52
+ const { refs, floatingStyles, context } = useFloatingContext(config);
53
+ const comboboxRef = mergeRefs(setReferenceElement, refs.setReference);
54
+ const hideTooltip = useCallback(() => {
55
+ setMenuState(false, "blur");
56
+ }, [setMenuState]);
57
+ useOnClickOutside(referenceElement, hideTooltip, refs.floating);
58
+ return /* @__PURE__ */ jsxs(
59
+ StyledContainer,
60
+ {
61
+ "data-testid": dataTestId ?? ComboboxDataTestid.CONTAINER,
62
+ innerRef: comboboxRef,
63
+ className,
64
+ applyAriaDisabled,
65
+ ...xStyledProps,
66
+ children: [
67
+ /* @__PURE__ */ jsx(LiveRegion, {}),
68
+ /* @__PURE__ */ jsx(Controls, {}),
69
+ menuState && inline ? /* @__PURE__ */ jsx(MenuList, {}) : null,
70
+ menuState && !inline && referenceElement ? /* @__PURE__ */ jsx(
71
+ FloatingWrapper,
72
+ {
73
+ innerRef: refs.setFloating,
74
+ floatingStyles,
75
+ isOpen: menuState,
76
+ context,
77
+ ...props.popperProps,
78
+ children: /* @__PURE__ */ jsx(StyledPopperWrapper, { tabIndex: -1, onMouseDown: handleMouseDown, applyAriaDisabled, children: /* @__PURE__ */ jsx(MenuList, {}) })
79
+ }
80
+ ) : null
81
+ ]
82
+ }
72
83
  );
73
84
  };
74
85
  export {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/container/Container.tsx"],
4
- "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\nimport React, { useCallback, useEffect, useContext } from 'react';\nimport { useGetGlobalAttributes, useGetXstyledProps } from '@elliemae/ds-props-helpers';\nimport { DSPopperJS } from '@elliemae/ds-popperjs';\nimport ComboBoxContext from '../../ComboBoxCTX.js';\nimport { StyledContainer, StyledPopperWrapper } from './styled.js';\nimport { Controls } from '../controls/index.js';\nimport { MenuList } from '../menu-list/index.js';\nimport { ComboboxDataTestid } from '../../ComboboxDataTestids.js';\nimport { LiveRegion } from '../LiveRegion.js';\n\nexport const Container = (): JSX.Element => {\n const { props, internalRef, setMenuState, menuState, setReferenceElement, referenceElement } =\n useContext(ComboBoxContext);\n\n const { inline, startPlacementPreference, placementOrderPreference, withoutPortal, applyAriaDisabled } = props;\n const globalAttributes = useGetGlobalAttributes(props) as ReturnType<typeof useGetGlobalAttributes> & {\n 'data-testid'?: string;\n };\n const { zIndex, ...xStyledProps } = useGetXstyledProps(props);\n\n const correctZIndex = zIndex ? parseInt(zIndex as string, 10) : undefined;\n // Removing possible collisionable props\n const { className, 'data-testid': dataTestId } = globalAttributes;\n const handleMouseDown = useCallback((e: React.MouseEvent) => {\n e.preventDefault();\n }, []);\n\n const handleCloseMenu = useCallback(() => {\n setMenuState(false, 'blur');\n if (internalRef?.current) internalRef.current.blur();\n }, [internalRef, setMenuState]);\n\n useEffect(() => {\n const closeMenuOnWindowBlur = () => {\n if (menuState) setMenuState(false, 'blur');\n };\n\n window.addEventListener('blur', closeMenuOnWindowBlur);\n\n return () => {\n window.removeEventListener('blur', closeMenuOnWindowBlur);\n };\n }, [menuState, setMenuState]);\n\n return (\n // eslint-disable-next-line react/jsx-no-useless-fragment\n <>\n <StyledContainer\n data-testid={dataTestId ?? ComboboxDataTestid.CONTAINER}\n innerRef={setReferenceElement}\n className={className}\n applyAriaDisabled={applyAriaDisabled}\n {...xStyledProps}\n >\n <LiveRegion />\n\n {inline ? (\n <>\n <Controls />\n <MenuList />\n </>\n ) : (\n <>\n <Controls />\n {referenceElement ? (\n <DSPopperJS\n customOffset={[0, 5]}\n referenceElement={referenceElement}\n showPopover={menuState}\n closeContextMenu={handleCloseMenu}\n startPlacementPreference={startPlacementPreference}\n placementOrderPreference={placementOrderPreference}\n withoutPortal={withoutPortal}\n withoutArrow\n withoutAnimation\n zIndex={correctZIndex}\n >\n <StyledPopperWrapper tabIndex={-1} onMouseDown={handleMouseDown} applyAriaDisabled={applyAriaDisabled}>\n <MenuList />\n </StyledPopperWrapper>\n </DSPopperJS>\n ) : null}\n </>\n )}\n </StyledContainer>\n </>\n );\n};\n"],
5
- "mappings": "AAAA,YAAY,WAAW;ACuDf,SAGE,UAHF,KAGE,YAHF;AAtDR,SAAgB,aAAa,WAAW,kBAAkB;AAC1D,SAAS,wBAAwB,0BAA0B;AAC3D,SAAS,kBAAkB;AAC3B,OAAO,qBAAqB;AAC5B,SAAS,iBAAiB,2BAA2B;AACrD,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,0BAA0B;AACnC,SAAS,kBAAkB;AAEpB,MAAM,YAAY,MAAmB;AAC1C,QAAM,EAAE,OAAO,aAAa,cAAc,WAAW,qBAAqB,iBAAiB,IACzF,WAAW,eAAe;AAE5B,QAAM,EAAE,QA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AAU,IAAI,aAAa,iBAAiB,mBAC/D,8BAAC,YAAS,GACZ;AAAA;AAAA,YACF,IACE;AAAA,aACN;AAAA;AAAA;AAAA,IAEJ,GACF;AAAA;AAEJ;",
6
- "names": []
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\nimport React, { useCallback, useMemo, useEffect, useContext } from 'react';\nimport { useGetGlobalAttributes, useGetXstyledProps } from '@elliemae/ds-props-helpers';\nimport { mergeRefs } from '@elliemae/ds-system';\nimport { useFloatingContext, FloatingWrapper, type DSHookFloatingContextT } from '@elliemae/ds-floating-context';\nimport ComboBoxContext from '../../ComboBoxCTX.js';\nimport { StyledContainer, StyledPopperWrapper } from './styled.js';\nimport { Controls } from '../controls/index.js';\nimport { MenuList } from '../menu-list/index.js';\nimport { ComboboxDataTestid } from '../../ComboboxDataTestids.js';\nimport { LiveRegion } from '../LiveRegion.js';\nimport { useOnClickOutside } from '../../config/useClickOutside.js';\n\nexport const Container = (): JSX.Element => {\n const [referenceElement, setReferenceElement] = React.useState<HTMLElement | null>(null);\n const { props, internalRef, setMenuState, menuState } = useContext(ComboBoxContext);\n\n const { inline, startPlacementPreference, placementOrderPreference, applyAriaDisabled } = props;\n const globalAttributes = useGetGlobalAttributes(props) as ReturnType<typeof useGetGlobalAttributes> & {\n 'data-testid'?: string;\n };\n const { zIndex, ...xStyledProps } = useGetXstyledProps(props);\n\n const correctZIndex = zIndex ? parseInt(zIndex as string, 10) : undefined;\n // Removing possible collisionable props\n const { className, 'data-testid': dataTestId } = globalAttributes;\n const handleMouseDown = useCallback((e: React.MouseEvent) => {\n e.preventDefault();\n }, []);\n\n const handleCloseMenu = useCallback(() => {\n setMenuState(false, 'blur');\n if (internalRef?.current) internalRef.current.blur();\n }, [internalRef, setMenuState]);\n\n useEffect(() => {\n const closeMenuOnWindowBlur = () => {\n if (menuState) setMenuState(false, 'blur');\n };\n\n window.addEventListener('blur', closeMenuOnWindowBlur);\n\n return () => {\n window.removeEventListener('blur', closeMenuOnWindowBlur);\n };\n }, [menuState, setMenuState]);\n\n const config = useMemo(\n () => ({\n placement: 'bottom' as DSHookFloatingContextT.PopperPlacementsT,\n withoutAnimation: true,\n startPlacementPreference,\n placementOrderPreference,\n zIndex: correctZIndex,\n customOffset: [0, 5] as [number, number],\n handleCloseMenu,\n portalDOMContainer: document.body,\n externallyControlledIsOpen: menuState,\n }),\n [startPlacementPreference, placementOrderPreference, correctZIndex, handleCloseMenu, menuState],\n );\n\n const { refs, floatingStyles, context } = useFloatingContext(config);\n\n const comboboxRef = mergeRefs(setReferenceElement, refs.setReference);\n\n const hideTooltip = useCallback(() => {\n setMenuState(false, 'blur');\n }, [setMenuState]);\n\n useOnClickOutside(referenceElement, hideTooltip, refs.floating);\n\n return (\n <StyledContainer\n data-testid={dataTestId ?? ComboboxDataTestid.CONTAINER}\n innerRef={comboboxRef}\n className={className}\n applyAriaDisabled={applyAriaDisabled}\n {...xStyledProps}\n >\n <LiveRegion />\n <Controls />\n\n {menuState && inline ? <MenuList /> : null}\n {menuState && !inline && referenceElement ? (\n <FloatingWrapper\n innerRef={refs.setFloating}\n floatingStyles={floatingStyles}\n isOpen={menuState}\n context={context}\n {...props.popperProps}\n >\n <StyledPopperWrapper tabIndex={-1} onMouseDown={handleMouseDown} applyAriaDisabled={applyAriaDisabled}>\n <MenuList />\n </StyledPopperWrapper>\n </FloatingWrapper>\n ) : null}\n </StyledContainer>\n );\n};\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACyEnB,SAOE,KAPF;AAxEJ,OAAOA,UAAS,aAAa,SAAS,WAAW,kBAAkB;AACnE,SAAS,wBAAwB,0BAA0B;AAC3D,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB,uBAAoD;AACjF,OAAO,qBAAqB;AAC5B,SAAS,iBAAiB,2BAA2B;AACrD,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,0BAA0B;AACnC,SAAS,kBAAkB;AAC3B,SAAS,yBAAy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