@eightshift/ui-components 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/dist/Checkbox-BLcVbhiO.js +178 -0
- package/dist/ColorSwatch-Cmlex_kT.js +66 -0
- package/dist/FieldError-wtMA4667.js +42 -0
- package/dist/FocusScope-1u9yyfIN.js +725 -0
- package/dist/Form-Cq3fu75_.js +5 -0
- package/dist/GridList-BZPXp3_O.js +1256 -0
- package/dist/Group-DyqpTRPe.js +49 -0
- package/dist/Input-jsbb4ugq.js +130 -0
- package/dist/Label-BPzS-sR7.js +17 -0
- package/dist/ListBox-w9gDaJkV.js +4423 -0
- package/dist/LiveAnnouncer-IsokfWQ5.js +73 -0
- package/dist/NumberFormatter-LzoKy975.js +160 -0
- package/dist/RSPContexts-CrNYmadY.js +14 -0
- package/dist/Select-49a62830.esm-C-RFtLiD.js +2541 -0
- package/dist/SelectionManager-mefd0ThJ.js +2155 -0
- package/dist/Separator-DHn0CwdK.js +325 -0
- package/dist/Slider-Pyh2V4bY.js +885 -0
- package/dist/Text-BM136LvS.js +17 -0
- package/dist/VisuallyHidden-BYRI1Lfo.js +51 -0
- package/dist/_commonjsHelpers-CUmg6egw.js +6 -0
- package/dist/ariaHideOutside-ByKBPHmX.js +113 -0
- package/dist/assets/style.css +1 -0
- package/dist/button-BkkdyHfJ.js +307 -0
- package/dist/components/animated-visibility/animated-visibility.js +7165 -0
- package/dist/components/base-control/base-control.js +97 -0
- package/dist/components/breakpoint-preview/breakpoint-preview.js +218 -0
- package/dist/components/button/button.js +10 -0
- package/dist/components/checkbox/checkbox.js +119 -0
- package/dist/components/color-pickers/color-picker.js +242 -0
- package/dist/components/color-pickers/color-swatch.js +62 -0
- package/dist/components/color-pickers/gradient-editor.js +516 -0
- package/dist/components/color-pickers/solid-color-picker.js +1633 -0
- package/dist/components/component-toggle/component-toggle.js +71 -0
- package/dist/components/container-panel/container-panel.js +39 -0
- package/dist/components/expandable/expandable.js +144 -0
- package/dist/components/input-field/input-field.js +224 -0
- package/dist/components/link-input/link-input.js +937 -0
- package/dist/components/list-box/list-box.js +152 -0
- package/dist/components/matrix-align/matrix-align.js +185 -0
- package/dist/components/menu/menu.js +1608 -0
- package/dist/components/notice/notice.js +119 -0
- package/dist/components/number-picker/number-picker.js +277 -0
- package/dist/components/popover/popover.js +9 -0
- package/dist/components/radio/radio.js +552 -0
- package/dist/components/repeater/repeater-item.js +127 -0
- package/dist/components/repeater/repeater.js +248 -0
- package/dist/components/responsive/responsive-legacy.js +326 -0
- package/dist/components/responsive/responsive.js +499 -0
- package/dist/components/responsive-preview/responsive-preview.js +119 -0
- package/dist/components/rich-label/rich-label.js +56 -0
- package/dist/components/select/async-multi-select.js +144 -0
- package/dist/components/select/async-single-select.js +126 -0
- package/dist/components/select/custom-select-default-components.js +38 -0
- package/dist/components/select/multi-select-components.js +8 -0
- package/dist/components/select/multi-select.js +134 -0
- package/dist/components/select/react-select-component-wrappers.js +90 -0
- package/dist/components/select/shared.js +45 -0
- package/dist/components/select/single-select.js +116 -0
- package/dist/components/select/styles.js +55 -0
- package/dist/components/slider/column-config-slider.js +225 -0
- package/dist/components/slider/slider.js +362 -0
- package/dist/components/slider/utils.js +45 -0
- package/dist/components/spacer/spacer.js +93 -0
- package/dist/components/tabs/tabs.js +626 -0
- package/dist/components/toggle/switch.js +140 -0
- package/dist/components/toggle/toggle.js +58 -0
- package/dist/components/toggle-button/toggle-button.js +206 -0
- package/dist/components/tooltip/tooltip.js +10 -0
- package/dist/context-jMy6xdVq.js +98 -0
- package/dist/default-i18n-BhE-OUmt.js +873 -0
- package/dist/filterDOMProps-DG2RfOUr.js +30 -0
- package/dist/focusSafely-C3K8zAKj.js +743 -0
- package/dist/hooks/use-cell-edit-mode.js +35 -0
- package/dist/icons/block-icon.js +42 -0
- package/dist/icons/generic-color-swatch.js +21 -0
- package/dist/icons/icons.js +3636 -0
- package/dist/index-Bfb9bWcb.js +28844 -0
- package/dist/index-a301f526.esm-Bioi4cGX.js +3576 -0
- package/dist/index.js +109 -0
- package/dist/intlStrings-CUhoK9EN.js +2484 -0
- package/dist/isScrollable-PcyglExV.js +10 -0
- package/dist/modifiers.esm-BuJQPI1X.js +31 -0
- package/dist/multi-select-components-CjVpCNko.js +3677 -0
- package/dist/number-rWqELA8W.js +39 -0
- package/dist/popover-Dx3vKXUX.js +1061 -0
- package/dist/react-select-async.esm-TFb_ZX6C.js +111 -0
- package/dist/react-select.esm-BjRWqf0E.js +15 -0
- package/dist/style.js +1 -0
- package/dist/textSelection-BosCCRVE.js +89 -0
- package/dist/tooltip-CkCndvTI.js +1094 -0
- package/dist/useButton-CuG5UzUw.js +74 -0
- package/dist/useEvent-DHv-yhOH.js +24 -0
- package/dist/useFocusRing-Cc-4eouh.js +41 -0
- package/dist/useFocusable-5q1Gek1J.js +81 -0
- package/dist/useFormReset-Buc9YJcv.js +23 -0
- package/dist/useFormValidationState-BAPPNXic.js +238 -0
- package/dist/useHasTabbableChild-D3uUNhJ0.js +37 -0
- package/dist/useLabel-CGlkoFG0.js +28 -0
- package/dist/useLabels-Dg62M_3P.js +25 -0
- package/dist/useListData-BelKu4kx.js +211 -0
- package/dist/useListState-Domq0blV.js +137 -0
- package/dist/useLocalizedStringFormatter-Prmz0h0A.js +130 -0
- package/dist/useNumberFieldState-BLU3uhSR.js +1253 -0
- package/dist/useNumberFormatter-BLc2xjZn.js +13 -0
- package/dist/usePress-BQgVor4T.js +698 -0
- package/dist/useToggle-C9ETOBaZ.js +58 -0
- package/dist/useToggleState-DJ_z5E2S.js +21 -0
- package/dist/utilities/classnames.js +16 -0
- package/dist/utilities/text-helpers.js +79 -0
- package/dist/utils-BsiH7-5Y.js +488 -0
- package/package.json +71 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { A as AsyncSelect$1 } from "../../react-select-async.esm-TFb_ZX6C.js";
|
|
3
|
+
import { D as DndContext, g as getDragEndHandler, S as SortableContext, a as getMultiValue, b as getMultiValueRemove } from "../../multi-select-components-CjVpCNko.js";
|
|
4
|
+
import { r as restrictToParentElement } from "../../modifiers.esm-BuJQPI1X.js";
|
|
5
|
+
import { CustomSelectDefaultMultiValueRemove, CustomSelectDefaultDropdownIndicator, CustomSelectDefaultClearIndicator } from "./custom-select-default-components.js";
|
|
6
|
+
import { BaseControl } from "../base-control/base-control.js";
|
|
7
|
+
import { eightshiftSelectClasses } from "./styles.js";
|
|
8
|
+
import { c as components } from "../../index-a301f526.esm-Bioi4cGX.js";
|
|
9
|
+
/**
|
|
10
|
+
* Multi-select menu with async loading and re-ordering.
|
|
11
|
+
*
|
|
12
|
+
* @component
|
|
13
|
+
* @param {Object} props - Component props.
|
|
14
|
+
* @param {string} [props.label] - Label of the component.
|
|
15
|
+
* @param {string} [props.help] - Help text of the component.
|
|
16
|
+
* @param {string} [props.icon] - Icon of the component.
|
|
17
|
+
* @param {string} [props.subtitle] - Subtitle of the component.
|
|
18
|
+
* @param {JSX.Element|JSX.Element[]} [props.actions] - Actions to show to the right of the label.
|
|
19
|
+
* @param {boolean} [props.inline] - Whether the Select menu is displayed inline with the label, to the right.
|
|
20
|
+
* @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.
|
|
21
|
+
* @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}[]>`.
|
|
22
|
+
* @param {{label: string, value: string, metadata: Object<string, any>?}[]} props.value - Current value of the select.
|
|
23
|
+
* @param {Function} props.onChange - Function to call when the value changes.
|
|
24
|
+
* @param {boolean} [props.clearable] - Whether the select is clearable.
|
|
25
|
+
* @param {boolean} [props.noSearch] - Whether the search is disabled.
|
|
26
|
+
* @param {boolean} [props.disabled] - Whether the select is disabled.
|
|
27
|
+
* @param {boolean} [props.keepMenuOpenAfterSelect] - Whether the menu stays open after an select.
|
|
28
|
+
* @param {string} [props.placeholder] - Placeholder text to show when no value is selected.
|
|
29
|
+
* @param {JSX.Element} [props.customClearIndicator] - If provided, replaces the default 'Clear all' button.
|
|
30
|
+
* @param {JSX.Element} [props.customDropdownArrow] - If provided, replaces the default dropdown arrow indicator.
|
|
31
|
+
* @param {JSX.Element} [props.customMenuOption] - If provided, replaces the default item in the dropdown menu (react-select's `components.Option`).
|
|
32
|
+
* @param {JSX.Element} [props.customValueDisplay] - If provided, replaces the default current value display of each selected item (react-select's `components.MultiValue`).
|
|
33
|
+
* @param {JSX.Element} [props.customValueRemove] - If provided, replaces the default item remove button (react-select's `components.MultiValueRemove`.
|
|
34
|
+
* @param {JSX.Element} [props.customValueContainer] - If provided, replaces the default items container component (react-select's `components.MultiValueContainer`).
|
|
35
|
+
* @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.
|
|
36
|
+
* @param {string} [props.className] - Classes to pass to the select menu.
|
|
37
|
+
*
|
|
38
|
+
* @returns {JSX.Element} The AsyncMultiSelect component.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* const [value, setValue] = useState([]);
|
|
42
|
+
*
|
|
43
|
+
* const loadOptions = async (searchText) => {
|
|
44
|
+
* const response = await fetch(`https://api.example.com/items?q=${searchText}`);
|
|
45
|
+
* const data = await response.json();
|
|
46
|
+
*
|
|
47
|
+
* return data.items.map((item) => ({
|
|
48
|
+
* label: item.name,
|
|
49
|
+
* value: item.id,
|
|
50
|
+
* }));
|
|
51
|
+
* };
|
|
52
|
+
*
|
|
53
|
+
* <AsyncMultiSelect
|
|
54
|
+
* label='Select items'
|
|
55
|
+
* loadOptions={loadOptions}
|
|
56
|
+
* value={value}
|
|
57
|
+
* onChange={setValue}
|
|
58
|
+
* />
|
|
59
|
+
*
|
|
60
|
+
* @preserve
|
|
61
|
+
*/
|
|
62
|
+
const AsyncMultiSelect = (props) => {
|
|
63
|
+
const {
|
|
64
|
+
label,
|
|
65
|
+
help,
|
|
66
|
+
icon,
|
|
67
|
+
subtitle,
|
|
68
|
+
actions,
|
|
69
|
+
inline,
|
|
70
|
+
loadOptions,
|
|
71
|
+
preloadOptions = true,
|
|
72
|
+
value,
|
|
73
|
+
onChange,
|
|
74
|
+
disabled = false,
|
|
75
|
+
noSearch = false,
|
|
76
|
+
clearable = false,
|
|
77
|
+
keepMenuOpenAfterSelect = false,
|
|
78
|
+
className,
|
|
79
|
+
placeholder,
|
|
80
|
+
customMenuOption,
|
|
81
|
+
customValueRemove,
|
|
82
|
+
customValueDisplay,
|
|
83
|
+
customDropdownArrow,
|
|
84
|
+
customValueContainer,
|
|
85
|
+
customClearIndicator,
|
|
86
|
+
processLoadedOptions = (options) => options,
|
|
87
|
+
...additionalProps
|
|
88
|
+
} = props;
|
|
89
|
+
const customLoadOptions = async (searchText) => {
|
|
90
|
+
const results = await loadOptions(searchText);
|
|
91
|
+
return processLoadedOptions((results == null ? void 0 : results.map((item) => ({ id: item.value, ...item }))) ?? []);
|
|
92
|
+
};
|
|
93
|
+
return /* @__PURE__ */ jsx(
|
|
94
|
+
BaseControl,
|
|
95
|
+
{
|
|
96
|
+
label,
|
|
97
|
+
icon,
|
|
98
|
+
subtitle,
|
|
99
|
+
actions,
|
|
100
|
+
help,
|
|
101
|
+
inline,
|
|
102
|
+
children: /* @__PURE__ */ jsx(
|
|
103
|
+
DndContext,
|
|
104
|
+
{
|
|
105
|
+
modifiers: [restrictToParentElement],
|
|
106
|
+
onDragEnd: getDragEndHandler(onChange, value),
|
|
107
|
+
children: /* @__PURE__ */ jsx(SortableContext, { items: value.map(({ id }) => id), children: /* @__PURE__ */ jsx(
|
|
108
|
+
AsyncSelect$1,
|
|
109
|
+
{
|
|
110
|
+
isMulti: true,
|
|
111
|
+
unstyled: true,
|
|
112
|
+
loadOptions: customLoadOptions,
|
|
113
|
+
defaultOptions: preloadOptions,
|
|
114
|
+
value,
|
|
115
|
+
onChange,
|
|
116
|
+
closeMenuOnSelect: !keepMenuOpenAfterSelect,
|
|
117
|
+
isClearable: clearable,
|
|
118
|
+
isSearchable: !noSearch,
|
|
119
|
+
isDisabled: disabled,
|
|
120
|
+
className,
|
|
121
|
+
placeholder,
|
|
122
|
+
classNames: eightshiftSelectClasses,
|
|
123
|
+
components: {
|
|
124
|
+
MultiValue: getMultiValue(customValueDisplay ?? components.MultiValue),
|
|
125
|
+
MultiValueContainer: customValueContainer ?? components.MultiValueContainer,
|
|
126
|
+
MultiValueRemove: getMultiValueRemove(
|
|
127
|
+
customValueRemove ?? CustomSelectDefaultMultiValueRemove
|
|
128
|
+
),
|
|
129
|
+
Option: customMenuOption ?? components.Option,
|
|
130
|
+
IndicatorSeparator: null,
|
|
131
|
+
DropdownIndicator: customDropdownArrow ?? CustomSelectDefaultDropdownIndicator,
|
|
132
|
+
ClearIndicator: customClearIndicator ?? CustomSelectDefaultClearIndicator
|
|
133
|
+
},
|
|
134
|
+
...additionalProps
|
|
135
|
+
}
|
|
136
|
+
) })
|
|
137
|
+
}
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
};
|
|
142
|
+
export {
|
|
143
|
+
AsyncMultiSelect
|
|
144
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { A as AsyncSelect$1 } from "../../react-select-async.esm-TFb_ZX6C.js";
|
|
3
|
+
import { CustomSelectDefaultDropdownIndicator, CustomSelectDefaultClearIndicator } 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-a301f526.esm-Bioi4cGX.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<Promise>} 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
|
+
*
|
|
34
|
+
* @returns {JSX.Element} The AsyncSelect component.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const [value, setValue] = useState(null);
|
|
38
|
+
*
|
|
39
|
+
* const loadOptions = async (searchText) => {
|
|
40
|
+
* const response = await fetch(`https://api.example.com/items?q=${searchText}`);
|
|
41
|
+
* const data = await response.json();
|
|
42
|
+
*
|
|
43
|
+
* return data.items.map((item) => ({
|
|
44
|
+
* label: item.name,
|
|
45
|
+
* value: item.id,
|
|
46
|
+
* }));
|
|
47
|
+
* };
|
|
48
|
+
*
|
|
49
|
+
* <AsyncMultiSelect
|
|
50
|
+
* label='Select items'
|
|
51
|
+
* loadOptions={loadOptions}
|
|
52
|
+
* value={value}
|
|
53
|
+
* onChange={setValue}
|
|
54
|
+
* />
|
|
55
|
+
*
|
|
56
|
+
* @preserve
|
|
57
|
+
*/
|
|
58
|
+
const AsyncSelect = (props) => {
|
|
59
|
+
const {
|
|
60
|
+
label,
|
|
61
|
+
help,
|
|
62
|
+
icon,
|
|
63
|
+
subtitle,
|
|
64
|
+
actions,
|
|
65
|
+
inline,
|
|
66
|
+
loadOptions,
|
|
67
|
+
preloadOptions = true,
|
|
68
|
+
value,
|
|
69
|
+
onChange,
|
|
70
|
+
noSearch = false,
|
|
71
|
+
disabled = false,
|
|
72
|
+
clearable = false,
|
|
73
|
+
keepMenuOpenAfterSelect = false,
|
|
74
|
+
className,
|
|
75
|
+
placeholder,
|
|
76
|
+
customMenuOption,
|
|
77
|
+
customValueDisplay,
|
|
78
|
+
customDropdownArrow,
|
|
79
|
+
customClearIndicator,
|
|
80
|
+
processLoadedOptions = (options) => options,
|
|
81
|
+
...additionalProps
|
|
82
|
+
} = props;
|
|
83
|
+
const customLoadOptions = async (searchText) => {
|
|
84
|
+
const results = await loadOptions(searchText);
|
|
85
|
+
return processLoadedOptions((results == null ? void 0 : results.map((item) => ({ id: item.value, ...item }))) ?? []);
|
|
86
|
+
};
|
|
87
|
+
return /* @__PURE__ */ jsx(
|
|
88
|
+
BaseControl,
|
|
89
|
+
{
|
|
90
|
+
label,
|
|
91
|
+
icon,
|
|
92
|
+
subtitle,
|
|
93
|
+
actions,
|
|
94
|
+
help,
|
|
95
|
+
inline,
|
|
96
|
+
children: /* @__PURE__ */ jsx(
|
|
97
|
+
AsyncSelect$1,
|
|
98
|
+
{
|
|
99
|
+
unstyled: true,
|
|
100
|
+
loadOptions: customLoadOptions,
|
|
101
|
+
defaultOptions: preloadOptions,
|
|
102
|
+
value,
|
|
103
|
+
onChange,
|
|
104
|
+
closeMenuOnSelect: !keepMenuOpenAfterSelect,
|
|
105
|
+
isClearable: clearable,
|
|
106
|
+
isSearchable: !noSearch,
|
|
107
|
+
isDisabled: disabled,
|
|
108
|
+
className,
|
|
109
|
+
placeholder,
|
|
110
|
+
classNames: eightshiftSelectClasses,
|
|
111
|
+
components: {
|
|
112
|
+
Option: customMenuOption ?? components.Option,
|
|
113
|
+
SingleValue: customValueDisplay ?? components.SingleValue,
|
|
114
|
+
IndicatorSeparator: null,
|
|
115
|
+
DropdownIndicator: customDropdownArrow ?? CustomSelectDefaultDropdownIndicator,
|
|
116
|
+
ClearIndicator: customClearIndicator ?? CustomSelectDefaultClearIndicator
|
|
117
|
+
},
|
|
118
|
+
...additionalProps
|
|
119
|
+
}
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
export {
|
|
125
|
+
AsyncSelect
|
|
126
|
+
};
|
|
@@ -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 { classnames } from "../../utilities/classnames.js";
|
|
5
|
+
import { c as components } from "../../index-a301f526.esm-Bioi4cGX.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: classnames(props.selectProps.menuIsOpen && "-es-uic-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-uic-size-4" }) });
|
|
34
|
+
export {
|
|
35
|
+
CustomSelectDefaultClearIndicator,
|
|
36
|
+
CustomSelectDefaultDropdownIndicator,
|
|
37
|
+
CustomSelectDefaultMultiValueRemove
|
|
38
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { S as StateManagedSelect$1 } from "../../react-select.esm-BjRWqf0E.js";
|
|
3
|
+
import { D as DndContext, g as getDragEndHandler, S as SortableContext, a as getMultiValue, b as getMultiValueRemove } from "../../multi-select-components-CjVpCNko.js";
|
|
4
|
+
import { r as restrictToParentElement } from "../../modifiers.esm-BuJQPI1X.js";
|
|
5
|
+
import { CustomSelectDefaultMultiValueRemove, CustomSelectDefaultDropdownIndicator, CustomSelectDefaultClearIndicator } from "./custom-select-default-components.js";
|
|
6
|
+
import { getValue, customOnChange } from "./shared.js";
|
|
7
|
+
import { BaseControl } from "../base-control/base-control.js";
|
|
8
|
+
import { eightshiftSelectClasses } from "./styles.js";
|
|
9
|
+
import { c as components } from "../../index-a301f526.esm-Bioi4cGX.js";
|
|
10
|
+
/**
|
|
11
|
+
* Multi-select menu with re-orderable items.
|
|
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 {{label: string, value: string, metadata: Object<string, any>?}[]} props.options - Options to display in the select. `[{ label: string, value: string }]`.
|
|
22
|
+
* @param {{label: string, value: string, metadata: Object<string, any>?}[]} props.value - Current value of the select.
|
|
23
|
+
* @param {Function} props.onChange - Function to call when the value changes.
|
|
24
|
+
* @param {boolean} [props.simpleValue=false] - If `true`, instead of using a `{label: '', value: ''}` value type, a string is used (just the value).
|
|
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 {string} [props.className] - Classes to pass to the select menu.
|
|
37
|
+
*
|
|
38
|
+
* @returns {JSX.Element} The MultiSelect component.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* const [value, setValue] = useState([]);
|
|
42
|
+
*
|
|
43
|
+
* const options = [
|
|
44
|
+
* { label: 'Option 1', value: 'option-1' },
|
|
45
|
+
* { label: 'Option 2', value: 'option-2' },
|
|
46
|
+
* { label: 'Option 3', value: 'option-3' },
|
|
47
|
+
* ];
|
|
48
|
+
*
|
|
49
|
+
* <MultiSelect
|
|
50
|
+
* label='Select items'
|
|
51
|
+
* options={loadOptions}
|
|
52
|
+
* value={value}
|
|
53
|
+
* onChange={setValue}
|
|
54
|
+
* />
|
|
55
|
+
*
|
|
56
|
+
* @preserve
|
|
57
|
+
*/
|
|
58
|
+
const MultiSelect = (props) => {
|
|
59
|
+
const {
|
|
60
|
+
label,
|
|
61
|
+
help,
|
|
62
|
+
icon,
|
|
63
|
+
subtitle,
|
|
64
|
+
actions,
|
|
65
|
+
inline,
|
|
66
|
+
value,
|
|
67
|
+
onChange,
|
|
68
|
+
options,
|
|
69
|
+
simpleValue = false,
|
|
70
|
+
disabled = false,
|
|
71
|
+
noSearch = false,
|
|
72
|
+
clearable = false,
|
|
73
|
+
keepMenuOpenAfterSelect = false,
|
|
74
|
+
placeholder,
|
|
75
|
+
customClearIndicator,
|
|
76
|
+
customDropdownArrow,
|
|
77
|
+
customMenuOption,
|
|
78
|
+
customValueDisplay,
|
|
79
|
+
customValueRemove,
|
|
80
|
+
customValueContainer,
|
|
81
|
+
className,
|
|
82
|
+
...additionalProps
|
|
83
|
+
} = props;
|
|
84
|
+
return /* @__PURE__ */ jsx(
|
|
85
|
+
BaseControl,
|
|
86
|
+
{
|
|
87
|
+
label,
|
|
88
|
+
icon,
|
|
89
|
+
subtitle,
|
|
90
|
+
actions,
|
|
91
|
+
help,
|
|
92
|
+
inline,
|
|
93
|
+
children: /* @__PURE__ */ jsx(
|
|
94
|
+
DndContext,
|
|
95
|
+
{
|
|
96
|
+
modifiers: [restrictToParentElement],
|
|
97
|
+
onDragEnd: getDragEndHandler(onChange, value),
|
|
98
|
+
children: /* @__PURE__ */ jsx(SortableContext, { items: value.map(({ id }) => id), children: /* @__PURE__ */ jsx(
|
|
99
|
+
StateManagedSelect$1,
|
|
100
|
+
{
|
|
101
|
+
isMulti: true,
|
|
102
|
+
unstyled: true,
|
|
103
|
+
options: options.map((item) => ({ id: item.value, ...item })),
|
|
104
|
+
value: getValue(simpleValue, value, options),
|
|
105
|
+
onChange: (v) => customOnChange(simpleValue, v, onChange),
|
|
106
|
+
closeMenuOnSelect: !keepMenuOpenAfterSelect,
|
|
107
|
+
isClearable: clearable,
|
|
108
|
+
isSearchable: !noSearch,
|
|
109
|
+
isDisabled: disabled,
|
|
110
|
+
className,
|
|
111
|
+
placeholder,
|
|
112
|
+
classNames: eightshiftSelectClasses,
|
|
113
|
+
components: {
|
|
114
|
+
MultiValue: getMultiValue(customValueDisplay ?? components.MultiValue),
|
|
115
|
+
MultiValueContainer: customValueContainer ?? components.MultiValueContainer,
|
|
116
|
+
MultiValueRemove: getMultiValueRemove(
|
|
117
|
+
customValueRemove ?? CustomSelectDefaultMultiValueRemove
|
|
118
|
+
),
|
|
119
|
+
Option: customMenuOption ?? components.Option,
|
|
120
|
+
IndicatorSeparator: null,
|
|
121
|
+
DropdownIndicator: customDropdownArrow ?? CustomSelectDefaultDropdownIndicator,
|
|
122
|
+
ClearIndicator: customClearIndicator ?? CustomSelectDefaultClearIndicator
|
|
123
|
+
},
|
|
124
|
+
...additionalProps
|
|
125
|
+
}
|
|
126
|
+
) })
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
export {
|
|
133
|
+
MultiSelect
|
|
134
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { c as components } from "../../index-a301f526.esm-Bioi4cGX.js";
|
|
3
|
+
/**
|
|
4
|
+
* Custom dropdown indicator for CustomSelect.
|
|
5
|
+
*
|
|
6
|
+
* (a wrapper for `components.DropdownIndicator` from `react-select`)
|
|
7
|
+
*
|
|
8
|
+
* @param {import('react-select').DropdownIndicatorProps} props - components.DropdownIndicator props.
|
|
9
|
+
*
|
|
10
|
+
* @preserve
|
|
11
|
+
*/
|
|
12
|
+
const RSDropdownIndicator = (props) => /* @__PURE__ */ jsx(components.DropdownIndicator, { ...props });
|
|
13
|
+
/**
|
|
14
|
+
* Custom value display for CustomSelect.
|
|
15
|
+
*
|
|
16
|
+
* (a wrapper for `components.SingleValue` from `react-select`)
|
|
17
|
+
*
|
|
18
|
+
* @param {import('react-select').SingleValueProps} props - components.SingleValue props.
|
|
19
|
+
*
|
|
20
|
+
* @preserve
|
|
21
|
+
*/
|
|
22
|
+
const RSSingleValue = (props) => /* @__PURE__ */ jsx(components.SingleValue, { ...props });
|
|
23
|
+
/**
|
|
24
|
+
* Custom value display for multi item select.
|
|
25
|
+
*
|
|
26
|
+
* (a wrapper for `components.MultiValue` from `react-select`)
|
|
27
|
+
*
|
|
28
|
+
* @param {import('react-select').MultiValueProps} props - components.SingleValue props.
|
|
29
|
+
*
|
|
30
|
+
* @preserve
|
|
31
|
+
*/
|
|
32
|
+
const RSMultiValue = (props) => /* @__PURE__ */ jsx(components.MultiValue, { ...props });
|
|
33
|
+
/**
|
|
34
|
+
* Custom option for CustomSelect.
|
|
35
|
+
*
|
|
36
|
+
* (a wrapper for `components.Option` from `react-select`)
|
|
37
|
+
*
|
|
38
|
+
* @param {import('react-select').OptionProps} props - components.Option props.
|
|
39
|
+
*
|
|
40
|
+
* @preserve
|
|
41
|
+
*/
|
|
42
|
+
const RSOption = (props) => /* @__PURE__ */ jsx(components.Option, { ...props });
|
|
43
|
+
/**
|
|
44
|
+
* Custom multiple value remove button for CustomSelect.
|
|
45
|
+
*
|
|
46
|
+
* (a wrapper for `components.MultiValueRemove` from `react-select`)
|
|
47
|
+
*
|
|
48
|
+
* @param {import('react-select').MultiValueRemoveProps} props - components.MultiValueRemove props.
|
|
49
|
+
*
|
|
50
|
+
* @preserve
|
|
51
|
+
*/
|
|
52
|
+
const RSMultiValueRemove = (props) => /* @__PURE__ */ jsx(components.MultiValueRemove, { ...props });
|
|
53
|
+
/**
|
|
54
|
+
* Custom multiple value display container for CustomSelect.
|
|
55
|
+
*
|
|
56
|
+
* (a wrapper for `components.MultiValueContainer` from `react-select`)
|
|
57
|
+
*
|
|
58
|
+
* @param {import('react-select').MultiValueGenericProps} props - components.MultiValueContainer props.
|
|
59
|
+
*
|
|
60
|
+
* @preserve
|
|
61
|
+
*/
|
|
62
|
+
const RSMultiValueContainer = (props) => /* @__PURE__ */ jsx(components.MultiValueContainer, { ...props });
|
|
63
|
+
/**
|
|
64
|
+
* Custom multiple value display for CustomSelect.
|
|
65
|
+
*
|
|
66
|
+
* (a wrapper for `components.MultiValueLabel` from `react-select`)
|
|
67
|
+
*
|
|
68
|
+
* @param {import('react-select').MultiValueGenericProps} props - components.MultiValueLabel props.
|
|
69
|
+
*
|
|
70
|
+
* @preserve
|
|
71
|
+
*/
|
|
72
|
+
const RSMultiValueLabel = (props) => /* @__PURE__ */ jsx(components.MultiValueLabel, { ...props });
|
|
73
|
+
/**
|
|
74
|
+
* Default clear indicator for CustomSelect.
|
|
75
|
+
*
|
|
76
|
+
* @param {import('react-select').ClearIndicatorProps} props - components.ClearIndicator props.
|
|
77
|
+
*
|
|
78
|
+
* @preserve
|
|
79
|
+
*/
|
|
80
|
+
const RSClearIndicator = (props) => /* @__PURE__ */ jsx(components.ClearIndicator, { ...props });
|
|
81
|
+
export {
|
|
82
|
+
RSClearIndicator,
|
|
83
|
+
RSDropdownIndicator,
|
|
84
|
+
RSMultiValue,
|
|
85
|
+
RSMultiValueContainer,
|
|
86
|
+
RSMultiValueLabel,
|
|
87
|
+
RSMultiValueRemove,
|
|
88
|
+
RSOption,
|
|
89
|
+
RSSingleValue
|
|
90
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles getting the current value.
|
|
3
|
+
*
|
|
4
|
+
* @param {boolean} simpleValue - Whether `simpleValue` is set.
|
|
5
|
+
* @param {string|{label: string, value: string, metadata: Object<string, any>[]}} value - Current value.
|
|
6
|
+
* @param {{label: string, value: string}[]} options - Options passed to the component.
|
|
7
|
+
*
|
|
8
|
+
* @returns Appropriate output for the given input combination.
|
|
9
|
+
*
|
|
10
|
+
* @preserve
|
|
11
|
+
*/
|
|
12
|
+
const getValue = (simpleValue, value, options) => {
|
|
13
|
+
if (!simpleValue) {
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
return value.map((value2) => options == null ? void 0 : options.find(({ value: itemValue }) => itemValue === value2));
|
|
18
|
+
}
|
|
19
|
+
return options == null ? void 0 : options.find(({ value: itemValue }) => itemValue === value);
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Handles the `onChange` callback.
|
|
23
|
+
*
|
|
24
|
+
* @param {boolean} simpleValue - Whether `simpleValue` is set.
|
|
25
|
+
* @param {string|{label: string, value: string, metadata: Object<string, any>[]}} newValue - The new value to be set.
|
|
26
|
+
* @param {Function} - onChange The `onChange` callback passed to the component.
|
|
27
|
+
* @returns {void}
|
|
28
|
+
*
|
|
29
|
+
* @preserve
|
|
30
|
+
*/
|
|
31
|
+
const customOnChange = (simpleValue, newValue, onChange) => {
|
|
32
|
+
if (!simpleValue) {
|
|
33
|
+
onChange(newValue);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (Array.isArray(newValue)) {
|
|
37
|
+
onChange(newValue.map((item) => item == null ? void 0 : item.value));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
onChange(newValue == null ? void 0 : newValue.value);
|
|
41
|
+
};
|
|
42
|
+
export {
|
|
43
|
+
customOnChange,
|
|
44
|
+
getValue
|
|
45
|
+
};
|