@wordpress/components 26.0.2 → 27.0.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 (223) hide show
  1. package/.stylelintrc.js +2 -2
  2. package/CHANGELOG.md +23 -0
  3. package/CONTRIBUTING.md +72 -0
  4. package/build/autocomplete/index.js +3 -8
  5. package/build/autocomplete/index.js.map +1 -1
  6. package/build/color-picker/component.js +10 -1
  7. package/build/color-picker/component.js.map +1 -1
  8. package/build/color-picker/styles.js +8 -9
  9. package/build/color-picker/styles.js.map +1 -1
  10. package/build/combobox-control/index.js +4 -9
  11. package/build/combobox-control/index.js.map +1 -1
  12. package/build/custom-select-control/index.js +2 -15
  13. package/build/custom-select-control/index.js.map +1 -1
  14. package/build/custom-select-control-v2/custom-select-item.js +32 -0
  15. package/build/custom-select-control-v2/custom-select-item.js.map +1 -0
  16. package/build/custom-select-control-v2/custom-select.js +91 -0
  17. package/build/custom-select-control-v2/custom-select.js.map +1 -0
  18. package/build/custom-select-control-v2/default-component/index.js +41 -0
  19. package/build/custom-select-control-v2/default-component/index.js.map +1 -0
  20. package/build/custom-select-control-v2/index.js +13 -82
  21. package/build/custom-select-control-v2/index.js.map +1 -1
  22. package/build/custom-select-control-v2/legacy-adapter.js +29 -0
  23. package/build/custom-select-control-v2/legacy-adapter.js.map +1 -0
  24. package/build/custom-select-control-v2/legacy-component/index.js +123 -0
  25. package/build/custom-select-control-v2/legacy-component/index.js.map +1 -0
  26. package/build/custom-select-control-v2/styles.js +73 -50
  27. package/build/custom-select-control-v2/styles.js.map +1 -1
  28. package/build/custom-select-control-v2/types.js.map +1 -1
  29. package/build/font-size-picker/font-size-picker-select.js +0 -1
  30. package/build/font-size-picker/font-size-picker-select.js.map +1 -1
  31. package/build/form-token-field/index.js +3 -8
  32. package/build/form-token-field/index.js.map +1 -1
  33. package/build/form-token-field/suggestions-list.js +5 -12
  34. package/build/form-token-field/suggestions-list.js.map +1 -1
  35. package/build/mobile/keyboard-aware-flat-list/use-scroll-to-section.native.js +1 -1
  36. package/build/mobile/keyboard-aware-flat-list/use-scroll-to-section.native.js.map +1 -1
  37. package/build/modal/index.js +2 -10
  38. package/build/modal/index.js.map +1 -1
  39. package/build/progress-bar/styles.js +5 -5
  40. package/build/progress-bar/styles.js.map +1 -1
  41. package/build/utils/with-ignore-ime-events.js +34 -0
  42. package/build/utils/with-ignore-ime-events.js.map +1 -0
  43. package/build-module/autocomplete/index.js +3 -8
  44. package/build-module/autocomplete/index.js.map +1 -1
  45. package/build-module/color-picker/component.js +11 -2
  46. package/build-module/color-picker/component.js.map +1 -1
  47. package/build-module/color-picker/styles.js +8 -9
  48. package/build-module/color-picker/styles.js.map +1 -1
  49. package/build-module/combobox-control/index.js +4 -9
  50. package/build-module/combobox-control/index.js.map +1 -1
  51. package/build-module/custom-select-control/index.js +2 -15
  52. package/build-module/custom-select-control/index.js.map +1 -1
  53. package/build-module/custom-select-control-v2/custom-select-item.js +26 -0
  54. package/build-module/custom-select-control-v2/custom-select-item.js.map +1 -0
  55. package/build-module/custom-select-control-v2/custom-select.js +82 -0
  56. package/build-module/custom-select-control-v2/custom-select.js.map +1 -0
  57. package/build-module/custom-select-control-v2/default-component/index.js +30 -0
  58. package/build-module/custom-select-control-v2/default-component/index.js.map +1 -0
  59. package/build-module/custom-select-control-v2/index.js +2 -74
  60. package/build-module/custom-select-control-v2/index.js.map +1 -1
  61. package/build-module/custom-select-control-v2/legacy-adapter.js +21 -0
  62. package/build-module/custom-select-control-v2/legacy-adapter.js.map +1 -0
  63. package/build-module/custom-select-control-v2/legacy-component/index.js +111 -0
  64. package/build-module/custom-select-control-v2/legacy-component/index.js.map +1 -0
  65. package/build-module/custom-select-control-v2/styles.js +73 -42
  66. package/build-module/custom-select-control-v2/styles.js.map +1 -1
  67. package/build-module/custom-select-control-v2/types.js.map +1 -1
  68. package/build-module/font-size-picker/font-size-picker-select.js +0 -1
  69. package/build-module/font-size-picker/font-size-picker-select.js.map +1 -1
  70. package/build-module/form-token-field/index.js +3 -8
  71. package/build-module/form-token-field/index.js.map +1 -1
  72. package/build-module/form-token-field/suggestions-list.js +5 -12
  73. package/build-module/form-token-field/suggestions-list.js.map +1 -1
  74. package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-section.native.js +1 -1
  75. package/build-module/mobile/keyboard-aware-flat-list/use-scroll-to-section.native.js.map +1 -1
  76. package/build-module/modal/index.js +3 -10
  77. package/build-module/modal/index.js.map +1 -1
  78. package/build-module/progress-bar/styles.js +5 -5
  79. package/build-module/progress-bar/styles.js.map +1 -1
  80. package/build-module/utils/with-ignore-ime-events.js +28 -0
  81. package/build-module/utils/with-ignore-ime-events.js.map +1 -0
  82. package/build-style/style-rtl.css +8 -1
  83. package/build-style/style.css +8 -1
  84. package/build-types/alignment-matrix-control/stories/index.story.d.ts +1 -1
  85. package/build-types/angle-picker-control/stories/index.story.d.ts +1 -1
  86. package/build-types/animate/stories/index.story.d.ts +7 -7
  87. package/build-types/autocomplete/index.d.ts.map +1 -1
  88. package/build-types/base-control/stories/index.story.d.ts +1 -1
  89. package/build-types/border-box-control/stories/index.story.d.ts +1 -1
  90. package/build-types/border-control/stories/index.story.d.ts +6 -6
  91. package/build-types/box-control/stories/index.story.d.ts +6 -6
  92. package/build-types/button/stories/e2e/index.story.d.ts +1 -1
  93. package/build-types/button/stories/index.story.d.ts +7 -7
  94. package/build-types/card/stories/index.story.d.ts +2 -2
  95. package/build-types/circular-option-picker/stories/index.story.d.ts +5 -5
  96. package/build-types/color-palette/stories/index.story.d.ts +3 -3
  97. package/build-types/color-picker/component.d.ts.map +1 -1
  98. package/build-types/color-picker/stories/index.story.d.ts +1 -1
  99. package/build-types/color-picker/styles.d.ts.map +1 -1
  100. package/build-types/combobox-control/index.d.ts.map +1 -1
  101. package/build-types/combobox-control/stories/index.story.d.ts +2 -2
  102. package/build-types/confirm-dialog/stories/index.story.d.ts +2 -2
  103. package/build-types/custom-gradient-picker/stories/index.story.d.ts +1 -1
  104. package/build-types/custom-select-control/index.d.ts.map +1 -1
  105. package/build-types/custom-select-control-v2/custom-select-item.d.ts +9 -0
  106. package/build-types/custom-select-control-v2/custom-select-item.d.ts.map +1 -0
  107. package/build-types/custom-select-control-v2/custom-select.d.ts +6 -0
  108. package/build-types/custom-select-control-v2/custom-select.d.ts.map +1 -0
  109. package/build-types/custom-select-control-v2/default-component/index.d.ts +5 -0
  110. package/build-types/custom-select-control-v2/default-component/index.d.ts.map +1 -0
  111. package/build-types/custom-select-control-v2/index.d.ts +5 -6
  112. package/build-types/custom-select-control-v2/index.d.ts.map +1 -1
  113. package/build-types/custom-select-control-v2/legacy-adapter.d.ts +6 -0
  114. package/build-types/custom-select-control-v2/legacy-adapter.d.ts.map +1 -0
  115. package/build-types/custom-select-control-v2/legacy-component/index.d.ts +5 -0
  116. package/build-types/custom-select-control-v2/legacy-component/index.d.ts.map +1 -0
  117. package/build-types/custom-select-control-v2/stories/default.story.d.ts +29 -0
  118. package/build-types/custom-select-control-v2/stories/default.story.d.ts.map +1 -0
  119. package/build-types/custom-select-control-v2/stories/legacy.story.d.ts +12 -0
  120. package/build-types/custom-select-control-v2/stories/legacy.story.d.ts.map +1 -0
  121. package/build-types/custom-select-control-v2/styles.d.ts +31 -6
  122. package/build-types/custom-select-control-v2/styles.d.ts.map +1 -1
  123. package/build-types/custom-select-control-v2/types.d.ts +137 -14
  124. package/build-types/custom-select-control-v2/types.d.ts.map +1 -1
  125. package/build-types/dimension-control/stories/index.story.d.ts +2 -2
  126. package/build-types/drop-zone/stories/index.story.d.ts +1 -1
  127. package/build-types/dropdown/stories/index.story.d.ts +3 -3
  128. package/build-types/dropdown-menu/stories/index.story.d.ts +2 -2
  129. package/build-types/dropdown-menu-v2/stories/index.story.d.ts.map +1 -1
  130. package/build-types/duotone-picker/stories/duotone-picker.story.d.ts +1 -1
  131. package/build-types/duotone-picker/stories/duotone-swatch.story.d.ts +3 -3
  132. package/build-types/focal-point-picker/stories/index.story.d.ts +4 -4
  133. package/build-types/font-size-picker/font-size-picker-select.d.ts.map +1 -1
  134. package/build-types/form-file-upload/stories/index.story.d.ts +5 -5
  135. package/build-types/form-token-field/index.d.ts.map +1 -1
  136. package/build-types/form-token-field/suggestions-list.d.ts.map +1 -1
  137. package/build-types/gradient-picker/stories/index.story.d.ts +3 -3
  138. package/build-types/guide/stories/index.story.d.ts +1 -1
  139. package/build-types/icon/stories/index.story.d.ts +4 -4
  140. package/build-types/input-control/stories/index.story.d.ts +6 -6
  141. package/build-types/keyboard-shortcuts/stories/index.story.d.ts +1 -1
  142. package/build-types/menu-group/stories/index.story.d.ts +1 -1
  143. package/build-types/menu-item/stories/index.story.d.ts +4 -4
  144. package/build-types/modal/index.d.ts.map +1 -1
  145. package/build-types/navigation/stories/index.story.d.ts +6 -6
  146. package/build-types/notice/stories/index.story.d.ts +4 -4
  147. package/build-types/number-control/stories/index.story.d.ts +1 -1
  148. package/build-types/palette-edit/stories/index.story.d.ts +2 -2
  149. package/build-types/progress-bar/stories/index.story.d.ts.map +1 -1
  150. package/build-types/query-controls/stories/index.story.d.ts +1 -1
  151. package/build-types/resizable-box/stories/index.story.d.ts +2 -2
  152. package/build-types/responsive-wrapper/stories/index.story.d.ts +1 -1
  153. package/build-types/sandbox/stories/index.story.d.ts +1 -1
  154. package/build-types/search-control/stories/index.story.d.ts +2 -2
  155. package/build-types/select-control/stories/index.story.d.ts +2 -2
  156. package/build-types/shortcut/stories/index.story.d.ts +1 -1
  157. package/build-types/tab-panel/stories/index.story.d.ts +4 -4
  158. package/build-types/tabs/stories/index.story.d.ts +9 -9
  159. package/build-types/tabs/stories/index.story.d.ts.map +1 -1
  160. package/build-types/text/stories/index.story.d.ts +3 -3
  161. package/build-types/theme/stories/index.story.d.ts +1 -1
  162. package/build-types/theme/stories/index.story.d.ts.map +1 -1
  163. package/build-types/toggle-control/stories/index.story.d.ts +2 -2
  164. package/build-types/toolbar/stories/index.story.d.ts +3 -3
  165. package/build-types/tooltip/stories/index.story.d.ts +1 -1
  166. package/build-types/tree-grid/stories/index.story.d.ts +1 -1
  167. package/build-types/tree-select/stories/index.story.d.ts +1 -1
  168. package/build-types/utils/with-ignore-ime-events.d.ts +15 -0
  169. package/build-types/utils/with-ignore-ime-events.d.ts.map +1 -0
  170. package/build-types/v-stack/stories/index.story.d.ts +1 -1
  171. package/package.json +19 -20
  172. package/src/alignment-matrix-control/test/index.tsx +3 -1
  173. package/src/autocomplete/index.tsx +3 -10
  174. package/src/circular-option-picker/test/index.tsx +4 -1
  175. package/src/color-picker/component.tsx +22 -11
  176. package/src/color-picker/styles.ts +1 -15
  177. package/src/combobox-control/index.tsx +33 -41
  178. package/src/composite/legacy/test/index.tsx +18 -2
  179. package/src/custom-select-control/README.md +0 -10
  180. package/src/custom-select-control/index.js +3 -22
  181. package/src/custom-select-control/stories/index.story.js +0 -1
  182. package/src/custom-select-control/test/index.js +17 -17
  183. package/src/custom-select-control-v2/README.md +97 -7
  184. package/src/custom-select-control-v2/custom-select-item.tsx +29 -0
  185. package/src/custom-select-control-v2/custom-select.tsx +122 -0
  186. package/src/custom-select-control-v2/default-component/index.tsx +24 -0
  187. package/src/custom-select-control-v2/index.tsx +2 -102
  188. package/src/custom-select-control-v2/legacy-adapter.tsx +25 -0
  189. package/src/custom-select-control-v2/legacy-component/index.tsx +133 -0
  190. package/src/custom-select-control-v2/stories/{index.story.tsx → default.story.tsx} +27 -33
  191. package/src/custom-select-control-v2/stories/legacy.story.tsx +88 -0
  192. package/src/custom-select-control-v2/styles.ts +82 -38
  193. package/src/custom-select-control-v2/test/index.tsx +808 -148
  194. package/src/custom-select-control-v2/types.ts +148 -20
  195. package/src/dropdown-menu-v2/stories/index.story.tsx +1 -0
  196. package/src/dropdown-menu-v2/test/index.tsx +4 -1
  197. package/src/font-size-picker/font-size-picker-select.tsx +0 -1
  198. package/src/form-token-field/index.tsx +3 -10
  199. package/src/form-token-field/suggestions-list.tsx +5 -17
  200. package/src/mobile/keyboard-aware-flat-list/use-scroll-to-section.native.js +1 -1
  201. package/src/modal/index.tsx +2 -12
  202. package/src/modal/style.scss +1 -0
  203. package/src/progress-bar/stories/index.story.tsx +1 -0
  204. package/src/progress-bar/styles.ts +2 -2
  205. package/src/tab-panel/test/index.tsx +8 -1
  206. package/src/tabs/stories/index.story.tsx +1 -0
  207. package/src/tabs/test/index.tsx +36 -6
  208. package/src/theme/stories/index.story.tsx +1 -0
  209. package/src/toggle-group-control/test/index.tsx +4 -0
  210. package/src/toolbar/toolbar-group/style.scss +1 -0
  211. package/src/tooltip/test/index.tsx +5 -0
  212. package/src/utils/with-ignore-ime-events.ts +32 -0
  213. package/tsconfig.json +0 -1
  214. package/tsconfig.tsbuildinfo +1 -1
  215. package/build/custom-select-control/styles.js +0 -27
  216. package/build/custom-select-control/styles.js.map +0 -1
  217. package/build-module/custom-select-control/styles.js +0 -18
  218. package/build-module/custom-select-control/styles.js.map +0 -1
  219. package/build-types/custom-select-control/styles.d.ts +0 -11
  220. package/build-types/custom-select-control/styles.d.ts.map +0 -1
  221. package/build-types/custom-select-control-v2/stories/index.story.d.ts +0 -20
  222. package/build-types/custom-select-control-v2/stories/index.story.d.ts.map +0 -1
  223. package/src/custom-select-control/styles.ts +0 -28
@@ -0,0 +1,82 @@
1
+ import { createElement, Fragment } from "react";
2
+ /**
3
+ * WordPress dependencies
4
+ */
5
+ import { createContext, useMemo } from '@wordpress/element';
6
+ import { __, sprintf } from '@wordpress/i18n';
7
+ import { Icon, chevronDown } from '@wordpress/icons';
8
+
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+ import { VisuallyHidden } from '..';
13
+ import * as Styled from './styles';
14
+ import { contextConnectWithoutRef, useContextSystem } from '../context';
15
+ export const CustomSelectContext = createContext(undefined);
16
+ function defaultRenderSelectedValue(value) {
17
+ const isValueEmpty = Array.isArray(value) ? value.length === 0 : value === undefined || value === null;
18
+ if (isValueEmpty) {
19
+ return __('Select an item');
20
+ }
21
+ if (Array.isArray(value)) {
22
+ return value.length === 1 ? value[0] :
23
+ // translators: %s: number of items selected (it will always be 2 or more items)
24
+ sprintf(__('%s items selected'), value.length);
25
+ }
26
+ return value;
27
+ }
28
+ const UnconnectedCustomSelectButton = props => {
29
+ const {
30
+ renderSelectedValue,
31
+ size = 'default',
32
+ store,
33
+ ...restProps
34
+ } = useContextSystem(props, 'CustomSelectControlButton');
35
+ const {
36
+ value: currentValue
37
+ } = store.useState();
38
+ const computedRenderSelectedValue = useMemo(() => renderSelectedValue !== null && renderSelectedValue !== void 0 ? renderSelectedValue : defaultRenderSelectedValue, [renderSelectedValue]);
39
+ return createElement(Styled.Select, {
40
+ ...restProps,
41
+ size: size,
42
+ hasCustomRenderProp: !!renderSelectedValue,
43
+ store: store
44
+ // to match legacy behavior where using arrow keys
45
+ // move selection rather than open the popover
46
+ ,
47
+ showOnKeyDown: false
48
+ }, createElement("div", null, computedRenderSelectedValue(currentValue)), createElement(Icon, {
49
+ icon: chevronDown,
50
+ size: 18
51
+ }));
52
+ };
53
+ const CustomSelectButton = contextConnectWithoutRef(UnconnectedCustomSelectButton, 'CustomSelectControlButton');
54
+ function _CustomSelect(props) {
55
+ const {
56
+ children,
57
+ hideLabelFromVision = false,
58
+ label,
59
+ store,
60
+ ...restProps
61
+ } = props;
62
+ return createElement(Fragment, null, hideLabelFromVision ?
63
+ // TODO: Replace with BaseControl
64
+ createElement(VisuallyHidden, {
65
+ as: "label"
66
+ }, label) : createElement(Styled.SelectLabel, {
67
+ store: store
68
+ }, label), createElement(CustomSelectButton, {
69
+ ...restProps,
70
+ store: store
71
+ }), createElement(Styled.SelectPopover, {
72
+ gutter: 12,
73
+ store: store,
74
+ sameWidth: true
75
+ }, createElement(CustomSelectContext.Provider, {
76
+ value: {
77
+ store
78
+ }
79
+ }, children)));
80
+ }
81
+ export default _CustomSelect;
82
+ //# sourceMappingURL=custom-select.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createContext","useMemo","__","sprintf","Icon","chevronDown","VisuallyHidden","Styled","contextConnectWithoutRef","useContextSystem","CustomSelectContext","undefined","defaultRenderSelectedValue","value","isValueEmpty","Array","isArray","length","UnconnectedCustomSelectButton","props","renderSelectedValue","size","store","restProps","currentValue","useState","computedRenderSelectedValue","createElement","Select","hasCustomRenderProp","showOnKeyDown","icon","CustomSelectButton","_CustomSelect","children","hideLabelFromVision","label","Fragment","as","SelectLabel","SelectPopover","gutter","sameWidth","Provider"],"sources":["@wordpress/components/src/custom-select-control-v2/custom-select.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext, useMemo } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Icon, chevronDown } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { VisuallyHidden } from '..';\nimport * as Styled from './styles';\nimport type {\n\tCustomSelectContext as CustomSelectContextType,\n\tCustomSelectStore,\n\tCustomSelectButtonProps,\n\t_CustomSelectProps,\n} from './types';\nimport {\n\tcontextConnectWithoutRef,\n\tuseContextSystem,\n\ttype WordPressComponentProps,\n} from '../context';\n\nexport const CustomSelectContext =\n\tcreateContext< CustomSelectContextType >( undefined );\n\nfunction defaultRenderSelectedValue(\n\tvalue: CustomSelectButtonProps[ 'value' ]\n) {\n\tconst isValueEmpty = Array.isArray( value )\n\t\t? value.length === 0\n\t\t: value === undefined || value === null;\n\n\tif ( isValueEmpty ) {\n\t\treturn __( 'Select an item' );\n\t}\n\n\tif ( Array.isArray( value ) ) {\n\t\treturn value.length === 1\n\t\t\t? value[ 0 ]\n\t\t\t: // translators: %s: number of items selected (it will always be 2 or more items)\n\t\t\t sprintf( __( '%s items selected' ), value.length );\n\t}\n\n\treturn value;\n}\n\nconst UnconnectedCustomSelectButton = (\n\tprops: Omit<\n\t\tWordPressComponentProps<\n\t\t\tCustomSelectButtonProps & CustomSelectStore,\n\t\t\t'button',\n\t\t\tfalse\n\t\t>,\n\t\t'onChange'\n\t>\n) => {\n\tconst {\n\t\trenderSelectedValue,\n\t\tsize = 'default',\n\t\tstore,\n\t\t...restProps\n\t} = useContextSystem( props, 'CustomSelectControlButton' );\n\n\tconst { value: currentValue } = store.useState();\n\n\tconst computedRenderSelectedValue = useMemo(\n\t\t() => renderSelectedValue ?? defaultRenderSelectedValue,\n\t\t[ renderSelectedValue ]\n\t);\n\n\treturn (\n\t\t<Styled.Select\n\t\t\t{ ...restProps }\n\t\t\tsize={ size }\n\t\t\thasCustomRenderProp={ !! renderSelectedValue }\n\t\t\tstore={ store }\n\t\t\t// to match legacy behavior where using arrow keys\n\t\t\t// move selection rather than open the popover\n\t\t\tshowOnKeyDown={ false }\n\t\t>\n\t\t\t<div>{ computedRenderSelectedValue( currentValue ) }</div>\n\t\t\t<Icon icon={ chevronDown } size={ 18 } />\n\t\t</Styled.Select>\n\t);\n};\n\nconst CustomSelectButton = contextConnectWithoutRef(\n\tUnconnectedCustomSelectButton,\n\t'CustomSelectControlButton'\n);\n\nfunction _CustomSelect( props: _CustomSelectProps & CustomSelectStore ) {\n\tconst {\n\t\tchildren,\n\t\thideLabelFromVision = false,\n\t\tlabel,\n\t\tstore,\n\t\t...restProps\n\t} = props;\n\n\treturn (\n\t\t<>\n\t\t\t{ hideLabelFromVision ? ( // TODO: Replace with BaseControl\n\t\t\t\t<VisuallyHidden as=\"label\">{ label }</VisuallyHidden>\n\t\t\t) : (\n\t\t\t\t<Styled.SelectLabel store={ store }>\n\t\t\t\t\t{ label }\n\t\t\t\t</Styled.SelectLabel>\n\t\t\t) }\n\t\t\t<CustomSelectButton { ...restProps } store={ store } />\n\t\t\t<Styled.SelectPopover gutter={ 12 } store={ store } sameWidth>\n\t\t\t\t<CustomSelectContext.Provider value={ { store } }>\n\t\t\t\t\t{ children }\n\t\t\t\t</CustomSelectContext.Provider>\n\t\t\t</Styled.SelectPopover>\n\t\t</>\n\t);\n}\n\nexport default _CustomSelect;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,aAAa,EAAEC,OAAO,QAAQ,oBAAoB;AAC3D,SAASC,EAAE,EAAEC,OAAO,QAA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ACRL,SAAS;IACdF,IAAI,EAAGA,IAAM;IACbQ,mBAAmB,EAAG,CAAC,CAAET,mBAAqB;IAC9CE,KAAK,EAAGA;IACR;IACA;IAAA;IACAQ,aAAa,EAAG;EAAO,GAEvBH,aAAA,cAAOD,2BAA2B,CAAEF,YAAa,CAAQ,CAAC,EAC1DG,aAAA,CAACvB,IAAI;IAAC2B,IAAI,EAAG1B,WAAa;IAACgB,IAAI,EAAG;EAAI,CAAE,CAC1B,CAAC;AAElB,CAAC;AAED,MAAMW,kBAAkB,GAAGxB,wBAAwB,CAClDU,6BAA6B,EAC7B,2BACD,CAAC;AAED,SAASe,aAAaA,CAAEd,KAA6C,EAAG;EACvE,MAAM;IACLe,QAAQ;IACRC,mBAAmB,GAAG,KAAK;IAC3BC,KAAK;IACLd,KAAK;IACL,GAAGC;EACJ,CAAC,GAAGJ,KAAK;EAET,OACCQ,aAAA,CAAAU,QAAA,QACGF,mBAAmB;EAAK;EACzBR,aAAA,CAACrB,cAAc;IAACgC,EAAE,EAAC;EAAO,GAAGF,KAAuB,CAAC,GAErDT,aAAA,CAACpB,MAAM,CAACgC,WAAW;IAACjB,KAAK,EAAGA;EAAO,GAChCc,KACiB,CACpB,EACDT,aAAA,CAACK,kBAAkB;IAAA,GAAMT,SAAS;IAAGD,KAAK,EAAGA;EAAO,CAAE,CAAC,EACvDK,aAAA,CAACpB,MAAM,CAACiC,aAAa;IAACC,MAAM,EAAG,EAAI;IAACnB,KAAK,EAAGA,KAAO;IAACoB,SAAS;EAAA,GAC5Df,aAAA,CAACjB,mBAAmB,CAACiC,QAAQ;IAAC9B,KAAK,EAAG;MAAES;IAAM;EAAG,GAC9CY,QAC2B,CACT,CACrB,CAAC;AAEL;AAEA,eAAeD,aAAa"}
@@ -0,0 +1,30 @@
1
+ import { createElement } from "react";
2
+ /**
3
+ * External dependencies
4
+ */
5
+ // eslint-disable-next-line no-restricted-imports
6
+ import * as Ariakit from '@ariakit/react';
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import _CustomSelect from '../custom-select';
11
+ function CustomSelect(props) {
12
+ const {
13
+ defaultValue,
14
+ onChange,
15
+ value,
16
+ ...restProps
17
+ } = props;
18
+ // Forward props + store from v2 implementation
19
+ const store = Ariakit.useSelectStore({
20
+ setValue: nextValue => onChange?.(nextValue),
21
+ defaultValue,
22
+ value
23
+ });
24
+ return createElement(_CustomSelect, {
25
+ ...restProps,
26
+ store: store
27
+ });
28
+ }
29
+ export default CustomSelect;
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Ariakit","_CustomSelect","CustomSelect","props","defaultValue","onChange","value","restProps","store","useSelectStore","setValue","nextValue","createElement"],"sources":["@wordpress/components/src/custom-select-control-v2/default-component/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\n// eslint-disable-next-line no-restricted-imports\nimport * as Ariakit from '@ariakit/react';\n/**\n * Internal dependencies\n */\nimport _CustomSelect from '../custom-select';\nimport type { CustomSelectProps } from '../types';\n\nfunction CustomSelect( props: CustomSelectProps ) {\n\tconst { defaultValue, onChange, value, ...restProps } = props;\n\t// Forward props + store from v2 implementation\n\tconst store = Ariakit.useSelectStore( {\n\t\tsetValue: ( nextValue ) => onChange?.( nextValue ),\n\t\tdefaultValue,\n\t\tvalue,\n\t} );\n\n\treturn <_CustomSelect { ...restProps } store={ store } />;\n}\n\nexport default CustomSelect;\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC;AACA;AACA;AACA,OAAOC,aAAa,MAAM,kBAAkB;AAG5C,SAASC,YAAYA,CAAEC,KAAwB,EAAG;EACjD,MAAM;IAAEC,YAAY;IAAEC,QAAQ;IAAEC,KAAK;IAAE,GAAGC;EAAU,CAAC,GAAGJ,KAAK;EAC7D;EACA,MAAMK,KAAK,GAAGR,OAAO,CAACS,cAAc,CAAE;IACrCC,QAAQ,EAAIC,SAAS,IAAMN,QAAQ,GAAIM,SAAU,CAAC;IAClDP,YAAY;IACZE;EACD,CAAE,CAAC;EAEH,OAAOM,aAAA,CAACX,aAAa;IAAA,GAAMM,SAAS;IAAGC,KAAK,EAAGA;EAAO,CAAE,CAAC;AAC1D;AAEA,eAAeN,YAAY"}
@@ -1,78 +1,6 @@
1
- import { createElement, Fragment } from "react";
2
- /**
3
- * External dependencies
4
- */
5
- // eslint-disable-next-line no-restricted-imports
6
- import * as Ariakit from '@ariakit/react';
7
- /**
8
- * WordPress dependencies
9
- */
10
- import { createContext, useContext } from '@wordpress/element';
11
- import { __, sprintf } from '@wordpress/i18n';
12
-
13
1
  /**
14
2
  * Internal dependencies
15
3
  */
16
- import * as Styled from './styles';
17
- export const CustomSelectContext = createContext(undefined);
18
- function defaultRenderSelectedValue(value) {
19
- const isValueEmpty = Array.isArray(value) ? value.length === 0 : value === undefined || value === null;
20
- if (isValueEmpty) {
21
- return __('Select an item');
22
- }
23
- if (Array.isArray(value)) {
24
- return value.length === 1 ? value[0] :
25
- // translators: %s: number of items selected (it will always be 2 or more items)
26
- sprintf(__('%s items selected'), value.length);
27
- }
28
- return value;
29
- }
30
- export function CustomSelect({
31
- children,
32
- defaultValue,
33
- label,
34
- onChange,
35
- size = 'default',
36
- value,
37
- renderSelectedValue,
38
- ...props
39
- }) {
40
- const store = Ariakit.useSelectStore({
41
- setValue: nextValue => onChange?.(nextValue),
42
- defaultValue,
43
- value,
44
- // fix for Safari bug: https://github.com/WordPress/gutenberg/issues/55023#issuecomment-1834035917
45
- virtualFocus: false
46
- });
47
- const {
48
- value: currentValue
49
- } = store.useState();
50
- const computedRenderSelectedValue = renderSelectedValue !== null && renderSelectedValue !== void 0 ? renderSelectedValue : defaultRenderSelectedValue;
51
- return createElement(Fragment, null, createElement(Styled.CustomSelectLabel, {
52
- store: store
53
- }, label), createElement(Styled.CustomSelectButton, {
54
- ...props,
55
- size: size,
56
- hasCustomRenderProp: !!renderSelectedValue,
57
- store: store
58
- }, computedRenderSelectedValue(currentValue), createElement(Ariakit.SelectArrow, null)), createElement(Styled.CustomSelectPopover, {
59
- gutter: 12,
60
- store: store,
61
- sameWidth: true
62
- }, createElement(CustomSelectContext.Provider, {
63
- value: {
64
- store
65
- }
66
- }, children)));
67
- }
68
- export function CustomSelectItem({
69
- children,
70
- ...props
71
- }) {
72
- const customSelectContext = useContext(CustomSelectContext);
73
- return createElement(Styled.CustomSelectItem, {
74
- store: customSelectContext?.store,
75
- ...props
76
- }, children !== null && children !== void 0 ? children : props.value, createElement(Ariakit.SelectItemCheck, null));
77
- }
4
+ export { default as CustomSelect } from './legacy-adapter';
5
+ export { default as CustomSelectItem } from './custom-select-item';
78
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Ariakit","createContext","useContext","__","sprintf","Styled","CustomSelectContext","undefined","defaultRenderSelectedValue","value","isValueEmpty","Array","isArray","length","CustomSelect","children","defaultValue","label","onChange","size","renderSelectedValue","props","store","useSelectStore","setValue","nextValue","virtualFocus","currentValue","useState","computedRenderSelectedValue","createElement","Fragment","CustomSelectLabel","CustomSelectButton","hasCustomRenderProp","SelectArrow","CustomSelectPopover","gutter","sameWidth","Provider","CustomSelectItem","customSelectContext","SelectItemCheck"],"sources":["@wordpress/components/src/custom-select-control-v2/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\n// eslint-disable-next-line no-restricted-imports\nimport * as Ariakit from '@ariakit/react';\n/**\n * WordPress dependencies\n */\nimport { createContext, useContext } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport * as Styled from './styles';\nimport type {\n\tCustomSelectProps,\n\tCustomSelectItemProps,\n\tCustomSelectContext as CustomSelectContextType,\n} from './types';\nimport type { WordPressComponentProps } from '../context';\n\nexport const CustomSelectContext =\n\tcreateContext< CustomSelectContextType >( undefined );\n\nfunction defaultRenderSelectedValue( value: CustomSelectProps[ 'value' ] ) {\n\tconst isValueEmpty = Array.isArray( value )\n\t\t? value.length === 0\n\t\t: value === undefined || value === null;\n\n\tif ( isValueEmpty ) {\n\t\treturn __( 'Select an item' );\n\t}\n\n\tif ( Array.isArray( value ) ) {\n\t\treturn value.length === 1\n\t\t\t? value[ 0 ]\n\t\t\t: // translators: %s: number of items selected (it will always be 2 or more items)\n\t\t\t sprintf( __( '%s items selected' ), value.length );\n\t}\n\n\treturn value;\n}\n\nexport function CustomSelect( {\n\tchildren,\n\tdefaultValue,\n\tlabel,\n\tonChange,\n\tsize = 'default',\n\tvalue,\n\trenderSelectedValue,\n\t...props\n}: WordPressComponentProps< CustomSelectProps, 'button', false > ) {\n\tconst store = Ariakit.useSelectStore( {\n\t\tsetValue: ( nextValue ) => onChange?.( nextValue ),\n\t\tdefaultValue,\n\t\tvalue,\n\t\t// fix for Safari bug: https://github.com/WordPress/gutenberg/issues/55023#issuecomment-1834035917\n\t\tvirtualFocus: false,\n\t} );\n\n\tconst { value: currentValue } = store.useState();\n\n\tconst computedRenderSelectedValue =\n\t\trenderSelectedValue ?? defaultRenderSelectedValue;\n\n\treturn (\n\t\t<>\n\t\t\t<Styled.CustomSelectLabel store={ store }>\n\t\t\t\t{ label }\n\t\t\t</Styled.CustomSelectLabel>\n\t\t\t<Styled.CustomSelectButton\n\t\t\t\t{ ...props }\n\t\t\t\tsize={ size }\n\t\t\t\thasCustomRenderProp={ !! renderSelectedValue }\n\t\t\t\tstore={ store }\n\t\t\t>\n\t\t\t\t{ computedRenderSelectedValue( currentValue ) }\n\t\t\t\t<Ariakit.SelectArrow />\n\t\t\t</Styled.CustomSelectButton>\n\t\t\t<Styled.CustomSelectPopover gutter={ 12 } store={ store } sameWidth>\n\t\t\t\t<CustomSelectContext.Provider value={ { store } }>\n\t\t\t\t\t{ children }\n\t\t\t\t</CustomSelectContext.Provider>\n\t\t\t</Styled.CustomSelectPopover>\n\t\t</>\n\t);\n}\n\nexport function CustomSelectItem( {\n\tchildren,\n\t...props\n}: WordPressComponentProps< CustomSelectItemProps, 'div', false > ) {\n\tconst customSelectContext = useContext( CustomSelectContext );\n\treturn (\n\t\t<Styled.CustomSelectItem\n\t\t\tstore={ customSelectContext?.store }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ children ?? props.value }\n\t\t\t<Ariakit.SelectItemCheck />\n\t\t</Styled.CustomSelectItem>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC;AACA;AACA;AACA,SAASC,aAAa,EAAEC,UAAU,QAAQ,oBAAoB;AAC9D,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;;AAE7C;AACA;AACA;AACA,OAAO,KAAKC,MAAM,MAAM,UAAU;AAQlC,OAAO,MAAMC,mBAAmB,GAC/BL,aAAa,CAA6BM,SAAU,CAAC;AAEtD,SAASC,0BAA0BA,CAAEC,KAAmC,EAAG;EAC1E,MAAMC,YAAY,GAAGC,KAAK,CAACC,OAAO,CAAEH,KAAM,CAAC,GACxCA,KAAK,CAACI,MAAM,KAAK,CAAC,GAClBJ,KAAK,KAAKF,SAAS,IAAIE,KAAK,KAAK,IAAI;EAExC,IAAKC,YAAY,EAAG;IACnB,OAAOP,EAAE,CAAE,gBAAiB,CAAC;EAC9B;EAEA,IAAKQ,KAAK,CAACC,OAAO,CAAEH,KAAM,CAAC,EAAG;IAC7B,OAAOA,KAAK,CAACI,MAAM,KAAK,CAAC,GACtBJ,KAAK,CAAE,CAAC,CAAE;IACV;IACAL,OAAO,CAAED,EAAE,CAAE,mBAAoB,CAAC,EAAEM,KAAK,CAACI,MAAO,CAAC;EACtD;EAEA,OAAOJ,KAAK;AACb;AAEA,OAAO,SAASK,YAAYA,CAAE;EAC7BC,QAAQ;EACRC,YAAY;EACZC,KAAK;EACLC,QAAQ;EACRC,IAAI,GAAG,SAAS;EAChBV,KAAK;EACLW,mBAAmB;EACnB,GAAGC;AAC2D,CAAC,EAAG;EAClE,MAAMC,KAAK,GAAGtB,OAAO,CAACuB,cAAc,CAAE;IACrCC,QAAQ,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,CAAC9B,OAAO,CAAC0C,eAAe,MAAE,CACF,CAAC;AAE5B"}
1
+ {"version":3,"names":["default","CustomSelect","CustomSelectItem"],"sources":["@wordpress/components/src/custom-select-control-v2/index.tsx"],"sourcesContent":["/**\n * Internal dependencies\n */\nexport { default as CustomSelect } from './legacy-adapter';\nexport { default as CustomSelectItem } from './custom-select-item';\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,IAAIC,YAAY,QAAQ,kBAAkB;AAC1D,SAASD,OAAO,IAAIE,gBAAgB,QAAQ,sBAAsB"}
@@ -0,0 +1,21 @@
1
+ import { createElement } from "react";
2
+ /**
3
+ * Internal dependencies
4
+ */
5
+ import _LegacyCustomSelect from './legacy-component';
6
+ import _NewCustomSelect from './default-component';
7
+ function isLegacy(props) {
8
+ return typeof props.options !== 'undefined';
9
+ }
10
+ function CustomSelect(props) {
11
+ if (isLegacy(props)) {
12
+ return createElement(_LegacyCustomSelect, {
13
+ ...props
14
+ });
15
+ }
16
+ return createElement(_NewCustomSelect, {
17
+ ...props
18
+ });
19
+ }
20
+ export default CustomSelect;
21
+ //# sourceMappingURL=legacy-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_LegacyCustomSelect","_NewCustomSelect","isLegacy","props","options","CustomSelect","createElement"],"sources":["@wordpress/components/src/custom-select-control-v2/legacy-adapter.tsx"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport _LegacyCustomSelect from './legacy-component';\nimport _NewCustomSelect from './default-component';\nimport type { CustomSelectProps, LegacyCustomSelectProps } from './types';\nimport type { WordPressComponentProps } from '../context';\n\nfunction isLegacy( props: any ): props is LegacyCustomSelectProps {\n\treturn typeof props.options !== 'undefined';\n}\n\nfunction CustomSelect(\n\tprops:\n\t\t| LegacyCustomSelectProps\n\t\t| WordPressComponentProps< CustomSelectProps, 'button', false >\n) {\n\tif ( isLegacy( props ) ) {\n\t\treturn <_LegacyCustomSelect { ...props } />;\n\t}\n\n\treturn <_NewCustomSelect { ...props } />;\n}\n\nexport default CustomSelect;\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,mBAAmB,MAAM,oBAAoB;AACpD,OAAOC,gBAAgB,MAAM,qBAAqB;AAIlD,SAASC,QAAQA,CAAEC,KAAU,EAAqC;EACjE,OAAO,OAAOA,KAAK,CAACC,OAAO,KAAK,WAAW;AAC5C;AAEA,SAASC,YAAYA,CACpBF,KAEgE,EAC/D;EACD,IAAKD,QAAQ,CAAEC,KAAM,CAAC,EAAG;IACxB,OAAOG,aAAA,CAACN,mBAAmB;MAAA,GAAMG;IAAK,CAAI,CAAC;EAC5C;EAEA,OAAOG,aAAA,CAACL,gBAAgB;IAAA,GAAME;EAAK,CAAI,CAAC;AACzC;AAEA,eAAeE,YAAY"}
@@ -0,0 +1,111 @@
1
+ import { createElement, Fragment } from "react";
2
+ /**
3
+ * External dependencies
4
+ */
5
+ // eslint-disable-next-line no-restricted-imports
6
+ import * as Ariakit from '@ariakit/react';
7
+ /**
8
+ * WordPress dependencies
9
+ */
10
+ import { useMemo } from '@wordpress/element';
11
+ /**
12
+ * Internal dependencies
13
+ */
14
+ import _CustomSelect from '../custom-select';
15
+ import { CustomSelectItem } from '..';
16
+ import * as Styled from '../styles';
17
+ import { ContextSystemProvider } from '../../context';
18
+ function CustomSelect(props) {
19
+ const {
20
+ __experimentalShowSelectedHint,
21
+ __next40pxDefaultSize = false,
22
+ options,
23
+ onChange,
24
+ size = 'default',
25
+ value,
26
+ ...restProps
27
+ } = props;
28
+
29
+ // Forward props + store from v2 implementation
30
+ const store = Ariakit.useSelectStore({
31
+ async setValue(nextValue) {
32
+ if (!onChange) return;
33
+
34
+ // Executes the logic in a microtask after the popup is closed.
35
+ // This is simply to ensure the isOpen state matches that in Downshift.
36
+ await Promise.resolve();
37
+ const state = store.getState();
38
+ const changeObject = {
39
+ highlightedIndex: state.renderedItems.findIndex(item => item.value === nextValue),
40
+ inputValue: '',
41
+ isOpen: state.open,
42
+ selectedItem: {
43
+ name: nextValue,
44
+ key: nextValue
45
+ },
46
+ type: ''
47
+ };
48
+ onChange(changeObject);
49
+ }
50
+ });
51
+ const children = options.map(({
52
+ name,
53
+ key,
54
+ __experimentalHint,
55
+ ...rest
56
+ }) => {
57
+ const withHint = createElement(Styled.WithHintWrapper, null, createElement("span", null, name), createElement(Styled.ExperimentalHintItem, {
58
+ className: "components-custom-select-control__item-hint"
59
+ }, __experimentalHint));
60
+ return createElement(CustomSelectItem, {
61
+ key: key,
62
+ value: name,
63
+ children: __experimentalShowSelectedHint ? withHint : name,
64
+ ...rest
65
+ });
66
+ });
67
+ const renderSelectedValueHint = () => {
68
+ const {
69
+ value: currentValue
70
+ } = store.getState();
71
+ const currentHint = options?.find(({
72
+ name
73
+ }) => currentValue === name);
74
+ return createElement(Fragment, null, currentValue, createElement(Styled.SelectedExperimentalHintItem, {
75
+ className: "components-custom-select-control__hint"
76
+ }, currentHint?.__experimentalHint));
77
+ };
78
+
79
+ // translate legacy button sizing
80
+ const contextSystemValue = useMemo(() => {
81
+ let selectedSize;
82
+ if (__next40pxDefaultSize && size === 'default' || size === '__unstable-large') {
83
+ selectedSize = 'default';
84
+ } else if (!__next40pxDefaultSize && size === 'default') {
85
+ selectedSize = 'compact';
86
+ } else {
87
+ selectedSize = size;
88
+ }
89
+ return {
90
+ CustomSelectControlButton: {
91
+ _overrides: {
92
+ size: selectedSize
93
+ }
94
+ }
95
+ };
96
+ }, [__next40pxDefaultSize, size]);
97
+ const translatedProps = {
98
+ 'aria-describedby': props.describedBy,
99
+ children,
100
+ renderSelectedValue: __experimentalShowSelectedHint ? renderSelectedValueHint : undefined,
101
+ ...restProps
102
+ };
103
+ return createElement(ContextSystemProvider, {
104
+ value: contextSystemValue
105
+ }, createElement(_CustomSelect, {
106
+ ...translatedProps,
107
+ store: store
108
+ }));
109
+ }
110
+ export default CustomSelect;
111
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Ariakit","useMemo","_CustomSelect","CustomSelectItem","Styled","ContextSystemProvider","CustomSelect","props","__experimentalShowSelectedHint","__next40pxDefaultSize","options","onChange","size","value","restProps","store","useSelectStore","setValue","nextValue","Promise","resolve","state","getState","changeObject","highlightedIndex","renderedItems","findIndex","item","inputValue","isOpen","open","selectedItem","name","key","type","children","map","__experimentalHint","rest","withHint","createElement","WithHintWrapper","ExperimentalHintItem","className","renderSelectedValueHint","currentValue","currentHint","find","Fragment","SelectedExperimentalHintItem","contextSystemValue","selectedSize","CustomSelectControlButton","_overrides","translatedProps","describedBy","renderSelectedValue","undefined"],"sources":["@wordpress/components/src/custom-select-control-v2/legacy-component/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\n// eslint-disable-next-line no-restricted-imports\nimport * as Ariakit from '@ariakit/react';\n/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n/**\n * Internal dependencies\n */\nimport _CustomSelect from '../custom-select';\nimport type { LegacyCustomSelectProps } from '../types';\nimport { CustomSelectItem } from '..';\nimport * as Styled from '../styles';\nimport { ContextSystemProvider } from '../../context';\n\nfunction CustomSelect( props: LegacyCustomSelectProps ) {\n\tconst {\n\t\t__experimentalShowSelectedHint,\n\t\t__next40pxDefaultSize = false,\n\t\toptions,\n\t\tonChange,\n\t\tsize = 'default',\n\t\tvalue,\n\t\t...restProps\n\t} = props;\n\n\t// Forward props + store from v2 implementation\n\tconst store = Ariakit.useSelectStore( {\n\t\tasync setValue( nextValue ) {\n\t\t\tif ( ! onChange ) return;\n\n\t\t\t// Executes the logic in a microtask after the popup is closed.\n\t\t\t// This is simply to ensure the isOpen state matches that in Downshift.\n\t\t\tawait Promise.resolve();\n\t\t\tconst state = store.getState();\n\n\t\t\tconst changeObject = {\n\t\t\t\thighlightedIndex: state.renderedItems.findIndex(\n\t\t\t\t\t( item ) => item.value === nextValue\n\t\t\t\t),\n\t\t\t\tinputValue: '',\n\t\t\t\tisOpen: state.open,\n\t\t\t\tselectedItem: {\n\t\t\t\t\tname: nextValue as string,\n\t\t\t\t\tkey: nextValue as string,\n\t\t\t\t},\n\t\t\t\ttype: '',\n\t\t\t};\n\t\t\tonChange( changeObject );\n\t\t},\n\t} );\n\n\tconst children = options.map(\n\t\t( { name, key, __experimentalHint, ...rest } ) => {\n\t\t\tconst withHint = (\n\t\t\t\t<Styled.WithHintWrapper>\n\t\t\t\t\t<span>{ name }</span>\n\t\t\t\t\t<Styled.ExperimentalHintItem className=\"components-custom-select-control__item-hint\">\n\t\t\t\t\t\t{ __experimentalHint }\n\t\t\t\t\t</Styled.ExperimentalHintItem>\n\t\t\t\t</Styled.WithHintWrapper>\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t<CustomSelectItem\n\t\t\t\t\tkey={ key }\n\t\t\t\t\tvalue={ name }\n\t\t\t\t\tchildren={\n\t\t\t\t\t\t__experimentalShowSelectedHint ? withHint : name\n\t\t\t\t\t}\n\t\t\t\t\t{ ...rest }\n\t\t\t\t/>\n\t\t\t);\n\t\t}\n\t);\n\n\tconst renderSelectedValueHint = () => {\n\t\tconst { value: currentValue } = store.getState();\n\n\t\tconst currentHint = options?.find(\n\t\t\t( { name } ) => currentValue === name\n\t\t);\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{ currentValue }\n\t\t\t\t<Styled.SelectedExperimentalHintItem className=\"components-custom-select-control__hint\">\n\t\t\t\t\t{ currentHint?.__experimentalHint }\n\t\t\t\t</Styled.SelectedExperimentalHintItem>\n\t\t\t</>\n\t\t);\n\t};\n\n\t// translate legacy button sizing\n\tconst contextSystemValue = useMemo( () => {\n\t\tlet selectedSize;\n\n\t\tif (\n\t\t\t( __next40pxDefaultSize && size === 'default' ) ||\n\t\t\tsize === '__unstable-large'\n\t\t) {\n\t\t\tselectedSize = 'default';\n\t\t} else if ( ! __next40pxDefaultSize && size === 'default' ) {\n\t\t\tselectedSize = 'compact';\n\t\t} else {\n\t\t\tselectedSize = size;\n\t\t}\n\n\t\treturn {\n\t\t\tCustomSelectControlButton: { _overrides: { size: selectedSize } },\n\t\t};\n\t}, [ __next40pxDefaultSize, size ] );\n\n\tconst translatedProps = {\n\t\t'aria-describedby': props.describedBy,\n\t\tchildren,\n\t\trenderSelectedValue: __experimentalShowSelectedHint\n\t\t\t? renderSelectedValueHint\n\t\t\t: undefined,\n\t\t...restProps,\n\t};\n\n\treturn (\n\t\t<ContextSystemProvider value={ contextSystemValue }>\n\t\t\t<_CustomSelect { ...translatedProps } store={ store } />\n\t\t</ContextSystemProvider>\n\t);\n}\n\nexport default CustomSelect;\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA,OAAO,KAAKA,OAAO,MAAM,gBAAgB;AACzC;AACA;AACA;AACA,SAASC,OAAO,QAAQ,oBAAoB;AAC5C;AACA;AACA;AACA,OAAOC,aAAa,MAAM,kBAAkB;AAE5C,SAASC,gBAAgB,QAAQ,IAAI;AACrC,OAAO,KAAKC,MAAM,MAAM,WAAW;AACnC,SAASC,qBAAqB,QAAQ,eAAe;AAErD,SAASC,YAAYA,CAAEC,KAA8B,EAAG;EACvD,MAAM;IACLC,8BAA8B;IAC9BC,qBAAqB,GAAG,KAAK;IAC7BC,OAAO;IACPC,QAAQ;IACRC,IAAI,GAAG,SAAS;IAChBC,KAAK;IACL,GAAGC;EACJ,CAAC,GAAGP,KAAK;;EAET;EACA,MAAMQ,KAAK,GAAGf,OAAO,CAACgB,cAAc,CAAE;IACrC,MAAMC,QAAQA,CAAEC,SAAS,EAAG;MAC3B,IAAK,CAAEP,QAAQ,EAAG;;MAElB;MACA;MACA,MAAMQ,OAAO,CAACC,OAAO,CAAC,CAAC;MACvB,MAAMC,KAAK,GAAGN,KAAK,CAACO,QAAQ,CAAC,CAAC;MAE9B,MAAMC,YAAY,GAAG;QACpBC,gBAAgB,EAAEH,KAAK,CAACI,aAAa,CAACC,SAAS,CAC5CC,IAAI,IAAMA,IAAI,CAACd,KAAK,KAAKK,SAC5B,CAAC;QACDU,UAAU,EAAE,EAAE;QACdC,MAAM,EAAER,KAAK,CAACS,IAAI;QACl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