@eightshift/ui-components 5.0.0 → 5.0.2

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 (144) hide show
  1. package/dist/Button-BpwTmkAe.js +185 -0
  2. package/dist/Collection-n5d0zIgb.js +2398 -0
  3. package/dist/Color-lVhk8V_G.js +2452 -0
  4. package/dist/ColorSwatch-DntWEAC3.js +64 -0
  5. package/dist/ComboBox-BJpTEATT.js +1915 -0
  6. package/dist/Dialog-O9uw63D7.js +2317 -0
  7. package/dist/FieldError-DHrSdE_Q.js +42 -0
  8. package/dist/FocusScope-BEPI2m7u.js +831 -0
  9. package/dist/Form-Cq3fu75_.js +5 -0
  10. package/dist/Group-DDPhPPTQ.js +48 -0
  11. package/dist/Heading-ba38ScjJ.js +16 -0
  12. package/dist/Hidden-rE6uR-lr.js +41 -0
  13. package/dist/Input-BmDS8Juy.js +133 -0
  14. package/dist/Label-JS_ob-kh.js +17 -0
  15. package/dist/List-CZMUbkFU.js +593 -0
  16. package/dist/ListBox-BTxlCGcc.js +664 -0
  17. package/dist/NumberFormatter-DA8u1Ot7.js +140 -0
  18. package/dist/OverlayArrow-5aDgmImj.js +637 -0
  19. package/dist/RSPContexts-2lR5GG9p.js +14 -0
  20. package/dist/Select-aab027f3.esm-BKIJGje-.js +2469 -0
  21. package/dist/Separator-CaTBkETC.js +332 -0
  22. package/dist/Slider-C-S1oEH9.js +853 -0
  23. package/dist/Text-BuJgePCv.js +16 -0
  24. package/dist/VisuallyHidden-BYi0pekx.js +48 -0
  25. package/dist/_commonjsHelpers-CUmg6egw.js +6 -0
  26. package/dist/assets/index.css +57 -0
  27. package/dist/assets/style-admin.css +5908 -0
  28. package/dist/assets/style-editor.css +5908 -0
  29. package/dist/assets/style.css +5914 -0
  30. package/dist/assets/wp-font-enhancements.css +8 -0
  31. package/dist/assets/wp-ui-enhancements.css +396 -0
  32. package/dist/components/animated-visibility/animated-visibility.js +105 -0
  33. package/dist/components/base-control/base-control.js +86 -0
  34. package/dist/components/breakpoint-preview/breakpoint-preview.js +161 -0
  35. package/dist/components/button/button.js +387 -0
  36. package/dist/components/checkbox/checkbox.js +323 -0
  37. package/dist/components/color-pickers/color-picker.js +272 -0
  38. package/dist/components/color-pickers/color-swatch.js +59 -0
  39. package/dist/components/color-pickers/gradient-editor.js +534 -0
  40. package/dist/components/color-pickers/solid-color-picker.js +1567 -0
  41. package/dist/components/component-toggle/component-toggle.js +161 -0
  42. package/dist/components/container-panel/container-panel.js +131 -0
  43. package/dist/components/draggable/draggable-context.js +5 -0
  44. package/dist/components/draggable/draggable-handle.js +46 -0
  45. package/dist/components/draggable/draggable.js +7320 -0
  46. package/dist/components/draggable-list/draggable-list-context.js +5 -0
  47. package/dist/components/draggable-list/draggable-list-item.js +77 -0
  48. package/dist/components/draggable-list/draggable-list.js +151 -0
  49. package/dist/components/expandable/expandable.js +342 -0
  50. package/dist/components/index.js +137 -0
  51. package/dist/components/input-field/input-field.js +231 -0
  52. package/dist/components/item-collection/item-collection.js +59 -0
  53. package/dist/components/layout/hstack.js +30 -0
  54. package/dist/components/layout/vstack.js +30 -0
  55. package/dist/components/link-input/link-input.js +284 -0
  56. package/dist/components/matrix-align/matrix-align.js +134 -0
  57. package/dist/components/menu/menu.js +285 -0
  58. package/dist/components/modal/modal.js +305 -0
  59. package/dist/components/notice/notice.js +123 -0
  60. package/dist/components/number-picker/number-picker.js +292 -0
  61. package/dist/components/option-select/option-select.js +264 -0
  62. package/dist/components/options-panel/options-panel.js +158 -0
  63. package/dist/components/placeholders/file-placeholder.js +42 -0
  64. package/dist/components/placeholders/image-placeholder.js +88 -0
  65. package/dist/components/placeholders/media-placeholder.js +63 -0
  66. package/dist/components/popover/popover.js +207 -0
  67. package/dist/components/radio/radio.js +582 -0
  68. package/dist/components/repeater/repeater-context.js +5 -0
  69. package/dist/components/repeater/repeater-item.js +119 -0
  70. package/dist/components/repeater/repeater.js +280 -0
  71. package/dist/components/responsive/mini-responsive.js +498 -0
  72. package/dist/components/responsive/responsive-legacy.js +343 -0
  73. package/dist/components/responsive/responsive.js +583 -0
  74. package/dist/components/responsive-preview/responsive-preview.js +123 -0
  75. package/dist/components/rich-label/rich-label.js +66 -0
  76. package/dist/components/select/async-multi-select.js +157 -0
  77. package/dist/components/select/async-single-select.js +137 -0
  78. package/dist/components/select/custom-select-default-components.js +38 -0
  79. package/dist/components/select/multi-select-components.js +8 -0
  80. package/dist/components/select/multi-select.js +151 -0
  81. package/dist/components/select/react-select-component-wrappers.js +90 -0
  82. package/dist/components/select/shared.js +26 -0
  83. package/dist/components/select/single-select.js +131 -0
  84. package/dist/components/select/styles.js +49 -0
  85. package/dist/components/select/v2/async-select.js +297 -0
  86. package/dist/components/select/v2/shared.js +24 -0
  87. package/dist/components/select/v2/single-select.js +1004 -0
  88. package/dist/components/slider/column-config-slider.js +210 -0
  89. package/dist/components/slider/slider.js +345 -0
  90. package/dist/components/slider/utils.js +94 -0
  91. package/dist/components/spacer/spacer.js +97 -0
  92. package/dist/components/tabs/tabs.js +703 -0
  93. package/dist/components/toggle/switch.js +156 -0
  94. package/dist/components/toggle/toggle.js +64 -0
  95. package/dist/components/toggle-button/toggle-button.js +343 -0
  96. package/dist/components/tooltip/tooltip.js +527 -0
  97. package/dist/context-BbYZoHvX.js +92 -0
  98. package/dist/default-i18n-CT_oS1Fy.js +922 -0
  99. package/dist/filterDOMProps-EDDcM64A.js +28 -0
  100. package/dist/icons/block-icon.js +42 -0
  101. package/dist/icons/generic-color-swatch.js +113 -0
  102. package/dist/icons/icons.js +30495 -0
  103. package/dist/icons/index.js +11 -0
  104. package/dist/icons/jsx-svg.js +50 -0
  105. package/dist/index-641ee5b8.esm-BPU8rMZr.js +3137 -0
  106. package/dist/index-BljRBEr_.js +44 -0
  107. package/dist/index-CFozsmNS.js +28321 -0
  108. package/dist/index.js +139 -0
  109. package/dist/lite-DVmmD_-j.js +7 -0
  110. package/dist/modifiers.esm-BuJQPI1X.js +31 -0
  111. package/dist/multi-select-components-Sp-JEFEX.js +3744 -0
  112. package/dist/number-GajL10e1.js +36 -0
  113. package/dist/react-jsx-parser.min-DZCiis5V.js +11753 -0
  114. package/dist/react-select-async.esm-D937XTWW.js +107 -0
  115. package/dist/react-select.esm-Ciai3aKf.js +15 -0
  116. package/dist/style-admin.js +1 -0
  117. package/dist/style-editor.js +1 -0
  118. package/dist/style.js +1 -0
  119. package/dist/textSelection-8DpK8fJl.js +46 -0
  120. package/dist/useButton-Bt3BffJm.js +50 -0
  121. package/dist/useEvent-ICdlokG-.js +23 -0
  122. package/dist/useFocusRing-Bv0UJQl8.js +107 -0
  123. package/dist/useFormReset-D2YaWRIA.js +22 -0
  124. package/dist/useFormValidation-Dy0PXJg5.js +224 -0
  125. package/dist/useHover-C2SkI1Fn.js +895 -0
  126. package/dist/useLabel-BPCd5c7-.js +27 -0
  127. package/dist/useLabels-B7-lUnAF.js +23 -0
  128. package/dist/useListState-DkyH7elT.js +168 -0
  129. package/dist/useLocalizedStringFormatter-C9GO0IDB.js +121 -0
  130. package/dist/useNumberField-CU1_u8ze.js +1215 -0
  131. package/dist/useNumberFormatter-CZ9QUnRt.js +13 -0
  132. package/dist/usePress-BrJylgPR.js +688 -0
  133. package/dist/useSingleSelectListState-C4sorv2p.js +38 -0
  134. package/dist/useToggle-CDa3YAZI.js +59 -0
  135. package/dist/useToggleState-ibcBUHnB.js +19 -0
  136. package/dist/utilities/array-helpers.js +56 -0
  137. package/dist/utilities/debounce-throttle.js +123 -0
  138. package/dist/utilities/es-dash.js +382 -0
  139. package/dist/utilities/index.js +27 -0
  140. package/dist/utilities/text-helpers.js +136 -0
  141. package/dist/utils-CZt7LCbO.js +403 -0
  142. package/dist/wp/wp-font-enhancements.js +1 -0
  143. package/dist/wp/wp-ui-enhancements.js +1 -0
  144. package/package.json +24 -24
@@ -0,0 +1,123 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { _ as __ } from "../../default-i18n-CT_oS1Fy.js";
3
+ import { upperFirst } from "../../utilities/es-dash.js";
4
+ import { BreakpointPreview } from "../breakpoint-preview/breakpoint-preview.js";
5
+ import { icons } from "../../icons/icons.js";
6
+ import { RichLabel } from "../rich-label/rich-label.js";
7
+ /**
8
+ * A component that displays a preview of the responsive settings.
9
+ *
10
+ * **Note**: Only intended for horizontal groups of buttons that don't wrap.
11
+ *
12
+ * @component
13
+ * @param {Object} props - Component props.
14
+ * @param {Object} props.value - The value object.
15
+ * @param {boolean} props.isDesktopFirst - Whether the desktop-first mode is enabled.
16
+ * @param {string[]} props.breakpoints - Breakpoints to use.
17
+ * @param {string[]} [props.desktopFirstBreakpoints] - Breakpoints to use in desktop-first mode. If not provided, the breakpoints will be used in reverse order.
18
+ * @param {{label: string, value: string}[]} props.options - Options of the attribute the component is linked to. `{ value: string, label: string }[]`.
19
+ * @param {Object} props.breakpointData - Breakpoints to use. `{ [breakpoint: string]: number }`.
20
+ * @param {Object<string, number>} [props.breakpointUiData] - Allows overriding breakpoint names and icons. `{ [breakpoint: string]: { label: string, icon: JSX.Element|string } }`.
21
+ *
22
+ * @returns {JSX.Element} The ResponsivePreview component.
23
+ *
24
+ * @example
25
+ * <ResponsivePreview
26
+ * value={value}
27
+ * isDesktopFirst={isDesktopFirst}
28
+ * breakpoints={breakpoints}
29
+ * options={options}
30
+ * breakpointData={breakpointData} // e.g. from global manifest
31
+ * />
32
+ *
33
+ * @preserve
34
+ */
35
+ const ResponsivePreview = (props) => {
36
+ var _a, _b;
37
+ const {
38
+ value,
39
+ isDesktopFirst: rawIsDesktopFirst,
40
+ breakpoints: rawBreakpoints,
41
+ desktopFirstBreakpoints: rawDesktopFirstBreakpoints,
42
+ options,
43
+ breakpointData,
44
+ breakpointUiData
45
+ } = props;
46
+ const isDesktopFirst = rawIsDesktopFirst ?? (value == null ? void 0 : value["_desktopFirst"]) ?? false;
47
+ const breakpoints = rawBreakpoints;
48
+ const desktopFirstBreakpoints = rawDesktopFirstBreakpoints ?? rawBreakpoints.slice(0, -1);
49
+ const firstMobileFirstOverride = breakpoints.find((breakpoint) => value == null ? void 0 : value[breakpoint]);
50
+ const lastDesktopFirstOverride = desktopFirstBreakpoints.toReversed().find((breakpoint) => value == null ? void 0 : value[breakpoint]);
51
+ let previewItems = [];
52
+ if (firstMobileFirstOverride && !isDesktopFirst) {
53
+ previewItems = [
54
+ ...previewItems,
55
+ {
56
+ breakpoint: __("Default", "eightshift-ui-components"),
57
+ value: ((_a = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value["_default"]))) == null ? void 0 : _a.label) ?? upperFirst(value == null ? void 0 : value["_default"])
58
+ }
59
+ ];
60
+ breakpoints.forEach((breakpoint) => {
61
+ var _a2, _b2;
62
+ if (typeof (value == null ? void 0 : value[breakpoint]) === "undefined") {
63
+ return;
64
+ }
65
+ previewItems = [
66
+ ...previewItems,
67
+ {
68
+ width: breakpointData[breakpoint],
69
+ breakpoint: ((_a2 = breakpointUiData == null ? void 0 : breakpointUiData[breakpoint]) == null ? void 0 : _a2.label) ?? breakpoint,
70
+ value: ((_b2 = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value[breakpoint]))) == null ? void 0 : _b2.label) ?? upperFirst(value == null ? void 0 : value[breakpoint])
71
+ }
72
+ ];
73
+ });
74
+ }
75
+ if (lastDesktopFirstOverride && isDesktopFirst) {
76
+ desktopFirstBreakpoints.forEach((breakpoint) => {
77
+ var _a2, _b2;
78
+ if (typeof (value == null ? void 0 : value[breakpoint]) === "undefined") {
79
+ return;
80
+ }
81
+ previewItems = [
82
+ ...previewItems,
83
+ {
84
+ alignEnd: true,
85
+ widthEnd: breakpointData[breakpoint.replace("max-", "")],
86
+ breakpoint: ((_a2 = breakpointUiData == null ? void 0 : breakpointUiData[breakpoint.replace("max-", "")]) == null ? void 0 : _a2.label) ?? breakpoint.replace("max-", ""),
87
+ value: ((_b2 = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value[breakpoint]))) == null ? void 0 : _b2.label) ?? upperFirst(value == null ? void 0 : value[breakpoint])
88
+ }
89
+ ];
90
+ });
91
+ previewItems = [
92
+ ...previewItems,
93
+ {
94
+ breakpoint: __("Default", "eightshift-ui-components"),
95
+ value: ((_b = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value["_default"]))) == null ? void 0 : _b.label) ?? upperFirst(value == null ? void 0 : value["_default"])
96
+ }
97
+ ];
98
+ }
99
+ return /* @__PURE__ */ jsxs("div", { className: "es:flex es:min-w-72 es:flex-col es:items-start es:gap-4 es:p-2 es:text-sm", children: [
100
+ /* @__PURE__ */ jsxs("div", { className: "es:flex es:w-full es:items-center es:gap-2.5", children: [
101
+ /* @__PURE__ */ jsx(
102
+ RichLabel,
103
+ {
104
+ icon: icons.previewResponsive,
105
+ label: __("Responsive preview", "eightshift-ui-components")
106
+ }
107
+ ),
108
+ /* @__PURE__ */ jsx("span", { className: "es:ml-auto es:select-none es:rounded es:bg-secondary-100 es:px-1 es:py-0.5 es:text-xs es:text-secondary-500", children: isDesktopFirst ? __("Desktop-first", "eightshift-ui-components") : __("Mobile-first", "eightshift-ui-components") })
109
+ ] }),
110
+ previewItems.length === 0 && /* @__PURE__ */ jsx("span", { className: "es:text-sm es:italic es:text-secondary-500", children: __("No overrides applied", "eightshift-ui-components") }),
111
+ /* @__PURE__ */ jsx(
112
+ BreakpointPreview,
113
+ {
114
+ blocks: previewItems,
115
+ dotsStart: true,
116
+ dotsEnd: true
117
+ }
118
+ )
119
+ ] });
120
+ };
121
+ export {
122
+ ResponsivePreview
123
+ };
@@ -0,0 +1,66 @@
1
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
+ import { c as clsx } from "../../lite-DVmmD_-j.js";
3
+ /**
4
+ * Component that displays a label, with an optional icon and subtitle.
5
+ *
6
+ * @component
7
+ * @param {Object} props - Component props.
8
+ * @param {JSX.Element} [props.icon] - Icon to display.
9
+ * @param {string} [props.label] - Label to display.
10
+ * @param {string} [props.subtitle] - Subtitle to display.
11
+ * @param {JSX.Element} [props.as] - Element to render the label as. Not compatible with `contentsOnly`.
12
+ * @param {string} [props.className] - Classes to pass to the label.
13
+ * @param {string} [props.iconClassName] - Classes to pass to the icon.
14
+ * @param {boolean} [props.fullWidth=false] - If `true`, the component will take up as much space as it can.
15
+ * @param {boolean} [props.contentsOnly] - If `true`, only the label (/icon/subtitle) will be rendered, without any wrapping elements. Useful if you want to provide your own layout.
16
+ * @param {boolean} [props.hidden] - If `true`, the component is not rendered.
17
+ * @param {boolean} [props.noColor] - If `true`, colors on text won't be set, opacity will be used instead.
18
+ * @param {boolean} [props.fullSizeSubtitle] - If `true`, the subtitle is the same size as the label.
19
+ * @param {boolean} [props.inlineSubtitle] - If `true`, the subtitle is shown after the label instead of below it.
20
+ *
21
+ * @returns {JSX.Element} The RichLabel component.
22
+ *
23
+ * @example
24
+ * <RichLabel
25
+ * icon={icons.myIcon}
26
+ * label='My label'
27
+ * />
28
+ *
29
+ * @preserve
30
+ */
31
+ const RichLabel = (props) => {
32
+ const { icon, label, subtitle, as, className, iconClassName, fullWidth = false, contentsOnly, hidden, noColor, fullSizeSubtitle, inlineSubtitle } = props;
33
+ if (hidden) {
34
+ return null;
35
+ }
36
+ const ComponentToRender = as ?? "div";
37
+ if (contentsOnly) {
38
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
39
+ icon && /* @__PURE__ */ jsx("span", { className: clsx("es:icon:size-5.5", !noColor && "es:text-slate-500"), children: icon }),
40
+ label && /* @__PURE__ */ jsx("span", { className: clsx("es:text-balance", !noColor && "es:text-secondary-800"), children: label }),
41
+ subtitle && /* @__PURE__ */ jsx("span", { className: clsx("es:text-balance es:text-xs es:opacity-65", !noColor && "es:text-secondary-800"), children: subtitle })
42
+ ] });
43
+ }
44
+ return /* @__PURE__ */ jsxs(
45
+ ComponentToRender,
46
+ {
47
+ className: clsx(
48
+ "es:flex es:items-center es:gap-1.5 es:text-sm",
49
+ !noColor && "es:text-secondary-800 es:[&>span>svg]:text-slate-500",
50
+ noColor && "es:[&>span>svg]:opacity-80",
51
+ fullWidth && "es:grow",
52
+ className
53
+ ),
54
+ children: [
55
+ icon && /* @__PURE__ */ jsx("span", { className: clsx("es:icon:size-5.5", iconClassName), children: icon }),
56
+ (label || subtitle) && /* @__PURE__ */ jsxs("div", { className: clsx("es:flex es:items-start es:text-balance es:text-start", inlineSubtitle ? "es:gap-1.5" : "es:flex-col"), children: [
57
+ label && /* @__PURE__ */ jsx("span", { children: label }),
58
+ subtitle && /* @__PURE__ */ jsx("span", { className: clsx(!fullSizeSubtitle && "es:text-xs", "es:opacity-65"), children: subtitle })
59
+ ] })
60
+ ]
61
+ }
62
+ );
63
+ };
64
+ export {
65
+ RichLabel
66
+ };
@@ -0,0 +1,157 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useId } from "react";
3
+ import { A as AsyncSelect$1 } from "../../react-select-async.esm-D937XTWW.js";
4
+ import { D as DndContext, g as getDragEndHandler, S as SortableContext, a as getMultiValueRemove, b as getMultiValue } from "../../multi-select-components-Sp-JEFEX.js";
5
+ import { r as restrictToParentElement } from "../../modifiers.esm-BuJQPI1X.js";
6
+ import { CustomSelectDefaultClearIndicator, CustomSelectDefaultDropdownIndicator, CustomSelectDefaultMultiValueRemove } from "./custom-select-default-components.js";
7
+ import { BaseControl } from "../base-control/base-control.js";
8
+ import { eightshiftSelectClasses } from "./styles.js";
9
+ import { c as components } from "../../index-641ee5b8.esm-BPU8rMZr.js";
10
+ /**
11
+ * Multi-select menu with async loading and re-ordering.
12
+ *
13
+ * @component
14
+ * @param {Object} props - Component props.
15
+ * @param {string} [props.label] - Label of the component.
16
+ * @param {string} [props.help] - Help text of the component.
17
+ * @param {string} [props.icon] - Icon of the component.
18
+ * @param {string} [props.subtitle] - Subtitle of the component.
19
+ * @param {JSX.Element|JSX.Element[]} [props.actions] - Actions to show to the right of the label.
20
+ * @param {boolean} [props.inline] - Whether the Select menu is displayed inline with the label, to the right.
21
+ * @param {boolean|{label: string, value: string, metadata: Object<string, any>?}[]} [props.preloadOptions=true] - If `true`, the initial loading is done as soon as the component is loaded. If an array of `{label: '', value: ''}` option is provided, that is loaded immediately, dynamic fetching only happens in search. If `false`, nothing is loaded immediately, fetching only happens when an user types to search.
22
+ * @param {Function<Promise>} props.loadOptions - Async function that returns an array of `{label: '', value: ''}`-formatted items. `loadOptions(searchText: string): Promise<{label: string, value: string, [metadata]: Array}[]>`.
23
+ * @param {{label: string, value: string, metadata: Object<string, any>?}[]} props.value - Current value of the select.
24
+ * @param {Function} props.onChange - Function to call when the value changes.
25
+ * @param {boolean} [props.clearable] - Whether the select is clearable.
26
+ * @param {boolean} [props.noSearch] - Whether the search is disabled.
27
+ * @param {boolean} [props.disabled] - Whether the select is disabled.
28
+ * @param {boolean} [props.keepMenuOpenAfterSelect] - Whether the menu stays open after an select.
29
+ * @param {string} [props.placeholder] - Placeholder text to show when no value is selected.
30
+ * @param {JSX.Element} [props.customClearIndicator] - If provided, replaces the default 'Clear all' button.
31
+ * @param {JSX.Element} [props.customDropdownArrow] - If provided, replaces the default dropdown arrow indicator.
32
+ * @param {JSX.Element} [props.customMenuOption] - If provided, replaces the default item in the dropdown menu (react-select's `components.Option`).
33
+ * @param {JSX.Element} [props.customValueDisplay] - If provided, replaces the default current value display of each selected item (react-select's `components.MultiValue`).
34
+ * @param {JSX.Element} [props.customValueRemove] - If provided, replaces the default item remove button (react-select's `components.MultiValueRemove`.
35
+ * @param {JSX.Element} [props.customValueContainer] - If provided, replaces the default items container component (react-select's `components.MultiValueContainer`).
36
+ * @param {Function} [props.processLoadedOptions] - Allows modifying (filtering, grouping, ...) options output after the items have been dynamically fetched. Must include `label`, `value`, and `id` keys in the output, additional fields can be added as required.
37
+ * @param {string} [props.className] - Classes to pass to the select menu.
38
+ * @param {boolean} [props.hidden] - If `true`, the component is not rendered.
39
+ *
40
+ * @returns {JSX.Element} The AsyncMultiSelect component.
41
+ *
42
+ * @example
43
+ * const [value, setValue] = useState([]);
44
+ *
45
+ * const loadOptions = async (searchText) => {
46
+ * const response = await fetch(`https://api.example.com/items?q=${searchText}`);
47
+ * const data = await response.json();
48
+ *
49
+ * return data.items.map((item) => ({
50
+ * label: item.name,
51
+ * value: item.id,
52
+ * }));
53
+ * };
54
+ *
55
+ * <AsyncMultiSelect
56
+ * label='Select items'
57
+ * loadOptions={loadOptions}
58
+ * value={value}
59
+ * onChange={setValue}
60
+ * />
61
+ *
62
+ * @preserve
63
+ */
64
+ const AsyncMultiSelect = (props) => {
65
+ const {
66
+ label,
67
+ help,
68
+ icon,
69
+ subtitle,
70
+ actions,
71
+ inline,
72
+ loadOptions,
73
+ preloadOptions = true,
74
+ value: rawValue,
75
+ onChange,
76
+ disabled = false,
77
+ noSearch = false,
78
+ clearable = false,
79
+ keepMenuOpenAfterSelect = false,
80
+ className,
81
+ placeholder,
82
+ customMenuOption,
83
+ customValueRemove,
84
+ customValueDisplay,
85
+ customDropdownArrow,
86
+ customValueContainer,
87
+ customClearIndicator,
88
+ processLoadedOptions = (options) => options,
89
+ hidden,
90
+ ...additionalProps
91
+ } = props;
92
+ const idBase = useId();
93
+ const value = rawValue.map((item, index) => ({
94
+ ...item,
95
+ id: (item == null ? void 0 : item.value) ?? `${idBase}-${index}`
96
+ }));
97
+ const modifiedOnChange = (v) => {
98
+ onChange(v == null ? void 0 : v.map((item) => ({ ...item, id: void 0 })));
99
+ };
100
+ if (hidden) {
101
+ return null;
102
+ }
103
+ const customLoadOptions = async (searchText) => {
104
+ const results = await loadOptions(searchText);
105
+ return processLoadedOptions((results == null ? void 0 : results.map((item) => ({ id: item.value, ...item }))) ?? []);
106
+ };
107
+ return /* @__PURE__ */ jsx(
108
+ BaseControl,
109
+ {
110
+ label,
111
+ icon,
112
+ subtitle,
113
+ actions,
114
+ help,
115
+ inline,
116
+ children: /* @__PURE__ */ jsx(
117
+ DndContext,
118
+ {
119
+ modifiers: [restrictToParentElement],
120
+ onDragEnd: getDragEndHandler(modifiedOnChange, value),
121
+ children: /* @__PURE__ */ jsx(SortableContext, { items: value.map(({ id }) => id), children: /* @__PURE__ */ jsx(
122
+ AsyncSelect$1,
123
+ {
124
+ isMulti: true,
125
+ unstyled: true,
126
+ loadOptions: customLoadOptions,
127
+ defaultOptions: preloadOptions,
128
+ value,
129
+ onChange: modifiedOnChange,
130
+ closeMenuOnSelect: !keepMenuOpenAfterSelect,
131
+ isClearable: clearable,
132
+ isSearchable: !noSearch,
133
+ isDisabled: disabled,
134
+ className,
135
+ placeholder,
136
+ classNames: eightshiftSelectClasses,
137
+ components: {
138
+ MultiValue: getMultiValue(customValueDisplay ?? components.MultiValue),
139
+ MultiValueContainer: customValueContainer ?? components.MultiValueContainer,
140
+ MultiValueRemove: getMultiValueRemove(customValueRemove ?? CustomSelectDefaultMultiValueRemove),
141
+ Option: customMenuOption ?? components.Option,
142
+ IndicatorSeparator: null,
143
+ DropdownIndicator: customDropdownArrow ?? CustomSelectDefaultDropdownIndicator,
144
+ ClearIndicator: customClearIndicator ?? CustomSelectDefaultClearIndicator
145
+ },
146
+ menuPortalTarget: document.body,
147
+ ...additionalProps
148
+ }
149
+ ) })
150
+ }
151
+ )
152
+ }
153
+ );
154
+ };
155
+ export {
156
+ AsyncMultiSelect
157
+ };
@@ -0,0 +1,137 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { A as AsyncSelect$1 } from "../../react-select-async.esm-D937XTWW.js";
3
+ import { CustomSelectDefaultClearIndicator, CustomSelectDefaultDropdownIndicator } from "./custom-select-default-components.js";
4
+ import { BaseControl } from "../base-control/base-control.js";
5
+ import { eightshiftSelectClasses } from "./styles.js";
6
+ import { c as components } from "../../index-641ee5b8.esm-BPU8rMZr.js";
7
+ /**
8
+ * Select menu with async loading.
9
+ *
10
+ * @component
11
+ * @param {Object} props - Component props.
12
+ * @param {string} [props.label] - Label of the component.
13
+ * @param {string} [props.help] - Help text of the component.
14
+ * @param {string} [props.icon] - Icon of the component.
15
+ * @param {string} [props.subtitle] - Subtitle of the component.
16
+ * @param {JSX.Element|JSX.Element[]} [props.actions] - Actions to show to the right of the label.
17
+ * @param {boolean} [props.inline] - Whether the Select menu is displayed inline with the label, to the right.
18
+ * @param {boolean|{label: string, value: string, metadata: Object<string, any>?}[]} [props.preloadOptions=true] - If `true`, the initial loading is done as soon as the component is loaded. If an array of `{label: '', value: ''}` option is provided, that is loaded immediately, dynamic fetching only happens in search. If `false`, nothing is loaded immediately, fetching only happens when an user types to search.
19
+ * @param {Function} props.loadOptions - Async function that returns an array of `{label: '', value: ''}`-formatted items. `loadOptions(searchText: string): Promise<{label: string, value: string, metadata: Object<string, any>?}[]>`.
20
+ * @param {{label: string, value: string, metadata: Object<string, any>?}} props.value - Current value of the select.
21
+ * @param {Function} props.onChange - Function to call when the value changes.
22
+ * @param {boolean} [props.clearable=false] - Whether the select is clearable.
23
+ * @param {boolean} [props.noSearch=false] - Whether the search is disabled.
24
+ * @param {boolean} [props.disabled=false] - Whether the select is disabled.
25
+ * @param {boolean} [props.keepMenuOpenAfterSelect=false] - Whether the menu stays open after an select.
26
+ * @param {string} [props.placeholder] - Placeholder text to show when no value is selected.
27
+ * @param {JSX.Element} [props.customDropdownIndicator] - If provided, replaces the default dropdown arrow indicator.
28
+ * @param {JSX.Element} [props.customClearIndicator] - If provided and `noClear` is `false`, replaces the default 'Clear all' button.
29
+ * @param {JSX.Element} [props.customMenuOption] - If provided, replaces the default item in the dropdown menu (react-select's `components.Option`).
30
+ * @param {JSX.Element} [props.customValueDisplay] - If provided, replaces the default current value display of each selected item (react-select's `components.SingleValue`).
31
+ * @param {Function} [props.processLoadedOptions] - Allows modifying (filtering, grouping, ...) options output after the items have been dynamically fetched. Must include `label`, `value`, and `id` keys in the output, additional fields can be added as required.
32
+ * @param {string} props.className - Classes to pass to the select menu.
33
+ * @param {boolean} [props.hidden] - If `true`, the component is not rendered.
34
+ *
35
+ * @returns {JSX.Element} The AsyncSelect component.
36
+ *
37
+ * @example
38
+ * const [value, setValue] = useState(null);
39
+ *
40
+ * const loadOptions = async (searchText) => {
41
+ * const response = await fetch(`https://api.example.com/items?q=${searchText}`);
42
+ * const data = await response.json();
43
+ *
44
+ * return data.items.map((item) => ({
45
+ * label: item.name,
46
+ * value: item.id,
47
+ * }));
48
+ * };
49
+ *
50
+ * <AsyncMultiSelect
51
+ * label='Select items'
52
+ * loadOptions={loadOptions}
53
+ * value={value}
54
+ * onChange={setValue}
55
+ * />
56
+ *
57
+ * @preserve
58
+ */
59
+ const AsyncSelect = (props) => {
60
+ const {
61
+ label,
62
+ help,
63
+ icon,
64
+ subtitle,
65
+ actions,
66
+ inline,
67
+ loadOptions,
68
+ preloadOptions = true,
69
+ value,
70
+ onChange,
71
+ noSearch = false,
72
+ disabled = false,
73
+ clearable = false,
74
+ keepMenuOpenAfterSelect = false,
75
+ className,
76
+ placeholder,
77
+ customMenuOption,
78
+ customValueDisplay,
79
+ customDropdownArrow,
80
+ customClearIndicator,
81
+ processLoadedOptions = (options) => options,
82
+ hidden,
83
+ ...additionalProps
84
+ } = props;
85
+ if (hidden) {
86
+ return null;
87
+ }
88
+ const customLoadOptions = async (searchText) => {
89
+ const results = await loadOptions(searchText);
90
+ return processLoadedOptions((results == null ? void 0 : results.map((item) => ({ id: item.value, ...item }))) ?? []);
91
+ };
92
+ return /* @__PURE__ */ jsx(
93
+ BaseControl,
94
+ {
95
+ label,
96
+ icon,
97
+ subtitle,
98
+ actions,
99
+ help,
100
+ inline,
101
+ children: /* @__PURE__ */ jsx(
102
+ AsyncSelect$1,
103
+ {
104
+ unstyled: true,
105
+ loadOptions: customLoadOptions,
106
+ defaultOptions: preloadOptions,
107
+ value,
108
+ onChange: (value2) => {
109
+ if (value2 && "id" in value2) {
110
+ delete value2.id;
111
+ }
112
+ onChange(value2);
113
+ },
114
+ closeMenuOnSelect: !keepMenuOpenAfterSelect,
115
+ isClearable: clearable,
116
+ isSearchable: !noSearch,
117
+ isDisabled: disabled,
118
+ className,
119
+ placeholder,
120
+ classNames: eightshiftSelectClasses,
121
+ components: {
122
+ Option: customMenuOption ?? components.Option,
123
+ SingleValue: customValueDisplay ?? components.SingleValue,
124
+ IndicatorSeparator: null,
125
+ DropdownIndicator: customDropdownArrow ?? CustomSelectDefaultDropdownIndicator,
126
+ ClearIndicator: customClearIndicator ?? CustomSelectDefaultClearIndicator
127
+ },
128
+ menuPortalTarget: document.body,
129
+ ...additionalProps
130
+ }
131
+ )
132
+ }
133
+ );
134
+ };
135
+ export {
136
+ AsyncSelect
137
+ };
@@ -0,0 +1,38 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import React__default from "react";
3
+ import { icons } from "../../icons/icons.js";
4
+ import { c as clsx } from "../../lite-DVmmD_-j.js";
5
+ import { c as components } from "../../index-641ee5b8.esm-BPU8rMZr.js";
6
+ /**
7
+ * Default dropdown indicator for CustomSelect.
8
+ *
9
+ * @param {import('react-select').DropdownIndicatorProps} props - components.DropdownIndicator props.
10
+ *
11
+ * @preserve
12
+ */
13
+ const CustomSelectDefaultDropdownIndicator = (props) => {
14
+ return /* @__PURE__ */ jsx(components.DropdownIndicator, { ...props, children: React__default.cloneElement(icons.dropdownCaretAlt, {
15
+ className: clsx(props.selectProps.menuIsOpen && "es:-scale-y-100 ")
16
+ }) });
17
+ };
18
+ /**
19
+ * Default clear indicator for CustomSelect.
20
+ *
21
+ * @param {import('react-select').ClearIndicatorProps} props - components.DropdownIndicator props.
22
+ *
23
+ * @preserve
24
+ */
25
+ const CustomSelectDefaultClearIndicator = (props) => /* @__PURE__ */ jsx(components.ClearIndicator, { ...props, children: icons.clear });
26
+ /**
27
+ * Default multiple value remove element for CustomSelect.
28
+ *
29
+ * @param {import('react-select').MultiValueRemoveProps} props - components.MultiValueRemove props.
30
+ *
31
+ * @preserve
32
+ */
33
+ const CustomSelectDefaultMultiValueRemove = (props) => /* @__PURE__ */ jsx(components.MultiValueRemove, { ...props, children: React__default.cloneElement(icons.clear, { className: "es:size-4" }) });
34
+ export {
35
+ CustomSelectDefaultClearIndicator,
36
+ CustomSelectDefaultDropdownIndicator,
37
+ CustomSelectDefaultMultiValueRemove
38
+ };
@@ -0,0 +1,8 @@
1
+ import "react/jsx-runtime";
2
+ import { g, b, a } from "../../multi-select-components-Sp-JEFEX.js";
3
+ import "../../lite-DVmmD_-j.js";
4
+ export {
5
+ g as getDragEndHandler,
6
+ b as getMultiValue,
7
+ a as getMultiValueRemove
8
+ };