@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,248 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { $ as $72e60046c03fbe42$export$54fe942636b6416d, a as $72e60046c03fbe42$export$a7bfbda1311ca015 } from "../../GridList-BZPXp3_O.js";
|
|
3
|
+
import { b as $d8f176866e6dc039$export$2cfc5be7a55829f6, c as $d8f176866e6dc039$export$62ed72bc21f6b8a6 } from "../../ListBox-w9gDaJkV.js";
|
|
4
|
+
import { B as Button, a as ButtonGroup } from "../../button-BkkdyHfJ.js";
|
|
5
|
+
import { icons } from "../../icons/icons.js";
|
|
6
|
+
import { useId, useState, useEffect } from "react";
|
|
7
|
+
import { classnames } from "../../utilities/classnames.js";
|
|
8
|
+
import { _ as __ } from "../../default-i18n-BhE-OUmt.js";
|
|
9
|
+
import { BaseControl } from "../base-control/base-control.js";
|
|
10
|
+
import { AnimatedVisibility } from "../animated-visibility/animated-visibility.js";
|
|
11
|
+
import { ToggleButton } from "../toggle-button/toggle-button.js";
|
|
12
|
+
import { $ as $0d86e9c8f07f9a7b$export$762f73dccccd255d } from "../../useListData-BelKu4kx.js";
|
|
13
|
+
/**
|
|
14
|
+
* A component that allows re-ordering a list of items with additional sub-options.
|
|
15
|
+
*
|
|
16
|
+
* @component
|
|
17
|
+
* @param {Object} props - Component props.
|
|
18
|
+
* @param {JSX.Element} [props.icon] - Icon to display in the label.
|
|
19
|
+
* @param {string} [props.label] - Label to display.
|
|
20
|
+
* @param {string} [props.subtitle] - Subtitle to display.
|
|
21
|
+
* @param {string} [props.help] - Help text to display below the input.
|
|
22
|
+
* @param {JSX.Element|JSX.Element[]} [props.actions] - Actions to display to the right of the label.
|
|
23
|
+
* @param {Object[]<string, any>} props.items - Data to display in the repeater.
|
|
24
|
+
* @param {string} [props.itemLabelProp] - Property of an item to use as the label when re-ordering items.
|
|
25
|
+
* @param {boolean} [props.hideEmptyState] - If `true`, the empty state will not be displayed when there are no items.
|
|
26
|
+
* @param {Object<string, any>} [props.addDefaultItem] - Additional properties to add to a new item.
|
|
27
|
+
* @param {boolean} [props.addDisabled] - If `true`, the add button is disabled.
|
|
28
|
+
* @param {Function} props.onChange - Function to run when the items change.
|
|
29
|
+
* @param {Function} [props.onAfterItemAdd] - Function to run after an item is added.
|
|
30
|
+
* @param {Function} [props.onAfterItemRemove] - Function to run after an item is removed.
|
|
31
|
+
* @param {Number} [props.minItems] - The minimum number of items that must be present. If there are less items than this, deleting items will be disabled.
|
|
32
|
+
*
|
|
33
|
+
* @returns {JSX.Element} The Repeater component.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* <Repeater
|
|
37
|
+
* label='My repeater'
|
|
38
|
+
* items={items}
|
|
39
|
+
* onChange={setItems}
|
|
40
|
+
* >
|
|
41
|
+
* {(item) => {
|
|
42
|
+
* const { title, updateData } = item;
|
|
43
|
+
*
|
|
44
|
+
* return (
|
|
45
|
+
* <RepeaterItem
|
|
46
|
+
* label={title ?? 'New item'}
|
|
47
|
+
* icon={icons.myIcon}
|
|
48
|
+
* >
|
|
49
|
+
* <InputField
|
|
50
|
+
* label='Title'
|
|
51
|
+
* type='text'
|
|
52
|
+
* value={title}
|
|
53
|
+
* onChange={(value) => updateData({ title: value })}
|
|
54
|
+
* />
|
|
55
|
+
* </RepeaterItem>
|
|
56
|
+
* );
|
|
57
|
+
* }}
|
|
58
|
+
* </Repeater>
|
|
59
|
+
*
|
|
60
|
+
* @preserve
|
|
61
|
+
*/
|
|
62
|
+
const Repeater = (props) => {
|
|
63
|
+
const itemIdBase = useId("repeater-item-");
|
|
64
|
+
const {
|
|
65
|
+
children,
|
|
66
|
+
onChange,
|
|
67
|
+
items,
|
|
68
|
+
itemLabelProp,
|
|
69
|
+
"aria-label": ariaLabel,
|
|
70
|
+
icon,
|
|
71
|
+
label,
|
|
72
|
+
subtitle,
|
|
73
|
+
help,
|
|
74
|
+
actions,
|
|
75
|
+
hideEmptyState,
|
|
76
|
+
addDefaultItem = {},
|
|
77
|
+
addDisabled,
|
|
78
|
+
onAfterItemAdd,
|
|
79
|
+
onAfterItemRemove,
|
|
80
|
+
minItems,
|
|
81
|
+
...rest
|
|
82
|
+
} = props;
|
|
83
|
+
const list = $0d86e9c8f07f9a7b$export$762f73dccccd255d({
|
|
84
|
+
initialItems: items == null ? void 0 : items.map((item, i) => ({ id: item.id ?? `${itemIdBase}${i}`, ...item })),
|
|
85
|
+
getKey: ({ id }) => id
|
|
86
|
+
});
|
|
87
|
+
const [selectable, setSelectable] = useState(false);
|
|
88
|
+
const [canDelete, setCanDelete] = useState(false);
|
|
89
|
+
const [canReorder, setCanReorder] = useState(true);
|
|
90
|
+
let { dragAndDropHooks } = $d8f176866e6dc039$export$2cfc5be7a55829f6({
|
|
91
|
+
isDisabled: selectable || !canReorder,
|
|
92
|
+
getItems: (keys) => [...keys].map((key) => ({
|
|
93
|
+
"text/plain": list.getItem(key)[itemLabelProp] ?? __("New item", "eightshift-ui-components")
|
|
94
|
+
})),
|
|
95
|
+
onReorder(e) {
|
|
96
|
+
if (e.target.dropPosition === "before") {
|
|
97
|
+
list.moveBefore(e.target.key, e.keys);
|
|
98
|
+
} else if (e.target.dropPosition === "after") {
|
|
99
|
+
list.moveAfter(e.target.key, e.keys);
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
renderDropIndicator(target) {
|
|
103
|
+
return /* @__PURE__ */ jsx(
|
|
104
|
+
$d8f176866e6dc039$export$62ed72bc21f6b8a6,
|
|
105
|
+
{
|
|
106
|
+
target,
|
|
107
|
+
className: ({ isDropTarget }) => classnames(
|
|
108
|
+
"es-uic-h-10 es-uic-rounded-lg es-uic-border es-uic-border-gray-300 es-uic-transition",
|
|
109
|
+
isDropTarget ? "es-uic-border-teal-500 es-uic-bg-teal-500/5" : "es-uic-border-dashed"
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
},
|
|
114
|
+
renderDragPreview(items2) {
|
|
115
|
+
let label2 = items2[0]["text/plain"];
|
|
116
|
+
if (!label2 || label2 === "") {
|
|
117
|
+
label2 = __("New item", "eightshift-ui-components");
|
|
118
|
+
}
|
|
119
|
+
return /* @__PURE__ */ jsx("div", { className: "es-uic-rounded-md es-uic-bg-teal-500 es-uic-px-1.5 es-uic-py-1 es-uic-text-xs es-uic-text-white es-uic-shadow-lg es-uic-shadow-teal-500/30", children: label2 });
|
|
120
|
+
},
|
|
121
|
+
async onInsert(e) {
|
|
122
|
+
let items2 = await Promise.all(
|
|
123
|
+
e.items.map(async (item) => {
|
|
124
|
+
let name = item.kind === "text" ? await item.getText("text/plain") : item.name;
|
|
125
|
+
return { id: Math.random(), name };
|
|
126
|
+
})
|
|
127
|
+
);
|
|
128
|
+
if (e.target.dropPosition === "before") {
|
|
129
|
+
list.insertBefore(e.target.key, ...items2);
|
|
130
|
+
} else if (e.target.dropPosition === "after") {
|
|
131
|
+
list.insertAfter(e.target.key, ...items2);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
const items2 = list.items.map((item) => {
|
|
137
|
+
const { id, ...rest2 } = item;
|
|
138
|
+
return rest2;
|
|
139
|
+
});
|
|
140
|
+
onChange(items2);
|
|
141
|
+
}, [list.items]);
|
|
142
|
+
return /* @__PURE__ */ jsx(
|
|
143
|
+
BaseControl,
|
|
144
|
+
{
|
|
145
|
+
icon,
|
|
146
|
+
label,
|
|
147
|
+
subtitle,
|
|
148
|
+
help,
|
|
149
|
+
actions: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
150
|
+
actions,
|
|
151
|
+
/* @__PURE__ */ jsx(
|
|
152
|
+
AnimatedVisibility,
|
|
153
|
+
{
|
|
154
|
+
visible: selectable,
|
|
155
|
+
transition: "scaleFade",
|
|
156
|
+
children: /* @__PURE__ */ jsx(
|
|
157
|
+
Button,
|
|
158
|
+
{
|
|
159
|
+
onPress: () => {
|
|
160
|
+
var _a;
|
|
161
|
+
const removedItems = [
|
|
162
|
+
...((_a = list == null ? void 0 : list.selectedKeys.keys()) == null ? void 0 : _a.map((key) => list.getItem(key))) ?? []
|
|
163
|
+
];
|
|
164
|
+
list.removeSelectedItems();
|
|
165
|
+
setSelectable(false);
|
|
166
|
+
setCanDelete(false);
|
|
167
|
+
if (onAfterItemRemove) {
|
|
168
|
+
onAfterItemRemove(removedItems);
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
size: "small",
|
|
172
|
+
icon: icons.trash,
|
|
173
|
+
tooltip: __("Remove selected", "eightshift-ui-components"),
|
|
174
|
+
disabled: !canDelete,
|
|
175
|
+
"aria-label": __("Remove selected", "eightshift-ui-components"),
|
|
176
|
+
type: "danger"
|
|
177
|
+
}
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
),
|
|
181
|
+
/* @__PURE__ */ jsxs(ButtonGroup, { children: [
|
|
182
|
+
/* @__PURE__ */ jsx(
|
|
183
|
+
Button,
|
|
184
|
+
{
|
|
185
|
+
onPress: () => {
|
|
186
|
+
const newItem = { id: `${itemIdBase}${list.items.length + 1}`, ...addDefaultItem };
|
|
187
|
+
list.append(newItem);
|
|
188
|
+
if (onAfterItemAdd) {
|
|
189
|
+
onAfterItemAdd(newItem);
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
size: "small",
|
|
193
|
+
icon: icons.add,
|
|
194
|
+
tooltip: __("Add item", "eightshift-ui-components"),
|
|
195
|
+
disabled: addDisabled || selectable
|
|
196
|
+
}
|
|
197
|
+
),
|
|
198
|
+
/* @__PURE__ */ jsx(
|
|
199
|
+
ToggleButton,
|
|
200
|
+
{
|
|
201
|
+
selected: selectable,
|
|
202
|
+
onChange: () => {
|
|
203
|
+
list.setSelectedKeys([]);
|
|
204
|
+
setSelectable(!selectable);
|
|
205
|
+
},
|
|
206
|
+
size: "small",
|
|
207
|
+
icon: icons.checkSquare,
|
|
208
|
+
tooltip: __("Select items", "eightshift-ui-components"),
|
|
209
|
+
disabled: minItems && items.length <= minItems
|
|
210
|
+
}
|
|
211
|
+
)
|
|
212
|
+
] })
|
|
213
|
+
] }),
|
|
214
|
+
className: "es-uic-w-full",
|
|
215
|
+
children: /* @__PURE__ */ jsx($72e60046c03fbe42$export$54fe942636b6416d.Provider, { value: { setCanReorder }, children: /* @__PURE__ */ jsx(
|
|
216
|
+
$72e60046c03fbe42$export$a7bfbda1311ca015,
|
|
217
|
+
{
|
|
218
|
+
"aria-label": ariaLabel ?? __("Repeater", "eightshift-ui-components"),
|
|
219
|
+
selectionMode: selectable ? "multiple" : "none",
|
|
220
|
+
selectionBehavior: "toggle",
|
|
221
|
+
selectedKeys: list.selectedKeys,
|
|
222
|
+
onSelectionChange: (selected) => {
|
|
223
|
+
list.setSelectedKeys(selected);
|
|
224
|
+
setCanDelete((selected.size ?? 0) > 0);
|
|
225
|
+
},
|
|
226
|
+
items: list.items.map((item, index) => ({
|
|
227
|
+
...item,
|
|
228
|
+
updateData: (newValue) => {
|
|
229
|
+
list.update(item.id, { ...list.getItem(item.id), ...newValue });
|
|
230
|
+
},
|
|
231
|
+
itemIndex: index,
|
|
232
|
+
deleteItem: () => list.remove(item.id),
|
|
233
|
+
canReorder,
|
|
234
|
+
setCanReorder
|
|
235
|
+
})),
|
|
236
|
+
dragAndDropHooks,
|
|
237
|
+
renderEmptyState: () => hideEmptyState ? null : /* @__PURE__ */ jsx("div", { className: "es-uic-rounded-md es-uic-border es-uic-border-dashed es-uic-border-gray-300 es-uic-p-2 es-uic-text-sm es-uic-text-gray-400", children: __("No items", "eightshift-ui-components") }),
|
|
238
|
+
className: "es-uic-space-y-1.5",
|
|
239
|
+
...rest,
|
|
240
|
+
children
|
|
241
|
+
}
|
|
242
|
+
) })
|
|
243
|
+
}
|
|
244
|
+
);
|
|
245
|
+
};
|
|
246
|
+
export {
|
|
247
|
+
Repeater
|
|
248
|
+
};
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { D as DecorativeTooltip } from "../../tooltip-CkCndvTI.js";
|
|
4
|
+
import { classnames } from "../../utilities/classnames.js";
|
|
5
|
+
import { _ as __, s as sprintf } from "../../default-i18n-BhE-OUmt.js";
|
|
6
|
+
import { BreakpointPreview } from "../breakpoint-preview/breakpoint-preview.js";
|
|
7
|
+
import { upperFirst } from "../../utilities/text-helpers.js";
|
|
8
|
+
import { icons } from "../../icons/icons.js";
|
|
9
|
+
import { B as Button } from "../../button-BkkdyHfJ.js";
|
|
10
|
+
import { AnimatedVisibility } from "../animated-visibility/animated-visibility.js";
|
|
11
|
+
import { ToggleButton } from "../toggle-button/toggle-button.js";
|
|
12
|
+
import { BaseControl } from "../base-control/base-control.js";
|
|
13
|
+
/**
|
|
14
|
+
* A component that allows the user to set different values for different breakpoints.
|
|
15
|
+
*
|
|
16
|
+
* Replacement for the `Responsive` component from Eightshift Frontend libs v12 (and older).
|
|
17
|
+
*
|
|
18
|
+
* Meant to be used with a more complex attribute setup, with one attribute per breakpoint,
|
|
19
|
+
* and a single value object that contains all the values.
|
|
20
|
+
*
|
|
21
|
+
* Inner items should be passed as a render function.
|
|
22
|
+
* The following props are passed to the render function:
|
|
23
|
+
* - `breakpoint: string` - Name of the current breakpoint.
|
|
24
|
+
* - `currentValue: any` - Current value.
|
|
25
|
+
* - `handleChange: Function<(attributeName: string, value: any) => void>` - A function to change the value for the breakpoint..
|
|
26
|
+
* - `options: Object<string, any>` - (Optional) Options list passed to the `ResponsiveLegacy` component. (optional)
|
|
27
|
+
* - `isInlineCollapsedView: boolean` - (Optional) `true` if in `inline` mode, and the details are collapsed.
|
|
28
|
+
* - `isInlineExpandedView: boolean` - (Optional) `true` if in `inline` mode, and the details are shown.
|
|
29
|
+
*
|
|
30
|
+
* @component
|
|
31
|
+
* @param {Object} props - Component props.
|
|
32
|
+
* @param {Object} props.value - The current value of the component.
|
|
33
|
+
* @param {Function} props.onChange - Function to run when the value changes. `(newValue: Object) => void`.
|
|
34
|
+
* @param {Object} props.attribute - The attribute the component is linked to. `{ [breakpoint: string]: string }`.
|
|
35
|
+
* @param {JSX.Element} [props.icon] - The icon of the component.
|
|
36
|
+
* @param {string} [props.help] - The help text of the component.
|
|
37
|
+
* @param {string} [props.label] - The label of the component.
|
|
38
|
+
* @param {string} [props.subtitle] - The subtitle of the component.
|
|
39
|
+
* @param {{label: string, value: string}[]} props.options - Options of the attribute the component is linked to. `{ value: string, label: string }[]`.
|
|
40
|
+
* @param {any} [props.inheritValue=''] - Value that will be used as a default for breakpoints that don't have a value set. If `undefined`, needs to be used, use `allowUndefined` instead.
|
|
41
|
+
* @param {boolean?} [props.allowUndefined] - If `true`, `undefined` is used as a default value for breakpoints that don't have a value set. Overrides `inheritValue`.
|
|
42
|
+
* @param {Object} props.globalManifest - The global manifest.
|
|
43
|
+
* @param {boolean} [props.inline] - If `true`, the default breakpoint is shown inline with the label. In the expanded state, all breakpoints are shown below the label.
|
|
44
|
+
* @param {Object<string, number>} [props.breakpointData] - Breakpoints to use. `{ [breakpoint: string]: number }`.
|
|
45
|
+
* @param {string[]} [props.breakpoints] - Breakpoints to use. `{ [breakpoint: string]: number }`.
|
|
46
|
+
*
|
|
47
|
+
* @returns {JSX.Element} The ResponsiveLegacy component.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* // Basic example
|
|
51
|
+
* <ResponsiveLegacy
|
|
52
|
+
* attribute={myResponsiveAttribute} // from 'responsiveAttributes' in manifest
|
|
53
|
+
* value={value} // attributes
|
|
54
|
+
* onChange={(attributeName, value) => setAttributes({
|
|
55
|
+
* [attributeName]: value,
|
|
56
|
+
* })}
|
|
57
|
+
* icon={icons.myIcon}
|
|
58
|
+
* label={__('Label', 'eightshift-ui-components')}
|
|
59
|
+
* options={[
|
|
60
|
+
* { value: 'value1', label: 'Value 1' },
|
|
61
|
+
* { value: 'value2', label: 'Value 2' },
|
|
62
|
+
* { value: 'value3', label: 'Value 3' },
|
|
63
|
+
* ]}
|
|
64
|
+
* breakpointData={breakpoints} // From global manifest
|
|
65
|
+
* >
|
|
66
|
+
* {({ currentValue, options, handleChange }) => (
|
|
67
|
+
* <Select
|
|
68
|
+
* value={currentValue}
|
|
69
|
+
* options={options}
|
|
70
|
+
* onChange={handleChange}
|
|
71
|
+
* />
|
|
72
|
+
* )}
|
|
73
|
+
* </ResponsiveLegacy>
|
|
74
|
+
*
|
|
75
|
+
* @preserve
|
|
76
|
+
*/
|
|
77
|
+
const ResponsiveLegacy = (props) => {
|
|
78
|
+
const {
|
|
79
|
+
value,
|
|
80
|
+
onChange,
|
|
81
|
+
attribute,
|
|
82
|
+
icon,
|
|
83
|
+
help,
|
|
84
|
+
label,
|
|
85
|
+
subtitle,
|
|
86
|
+
options,
|
|
87
|
+
inheritValue: rawInheritValue = "",
|
|
88
|
+
allowUndefined,
|
|
89
|
+
children,
|
|
90
|
+
inline,
|
|
91
|
+
breakpointData,
|
|
92
|
+
breakpoints: rawBreakpoints = Object.keys(breakpointData).toReversed()
|
|
93
|
+
} = props;
|
|
94
|
+
const inheritValue = allowUndefined ? void 0 : rawInheritValue;
|
|
95
|
+
const [detailsVisible, setDetailsVisible] = useState(false);
|
|
96
|
+
const breakpoints = rawBreakpoints.slice(1);
|
|
97
|
+
const globalOverride = breakpoints.find((breakpoint) => (value == null ? void 0 : value[attribute[breakpoint]]) !== inheritValue);
|
|
98
|
+
const defaultBreakpoint = rawBreakpoints[0];
|
|
99
|
+
const DefaultTooltip = () => {
|
|
100
|
+
var _a, _b;
|
|
101
|
+
return /* @__PURE__ */ jsx(
|
|
102
|
+
DecorativeTooltip,
|
|
103
|
+
{
|
|
104
|
+
placement: "left",
|
|
105
|
+
className: "es-uic-p-3",
|
|
106
|
+
theme: "light",
|
|
107
|
+
offset: 7.5,
|
|
108
|
+
arrow: true,
|
|
109
|
+
text: /* @__PURE__ */ jsxs("div", { className: "es-uic-max-w-64 es-uic-p-1", children: [
|
|
110
|
+
/* @__PURE__ */ jsx("span", { className: "es-uic-block es-uic-text-balance es-uic-font-semibold es-uic-tabular-nums", children: __("Default", "eightshift-ui-components") }),
|
|
111
|
+
/* @__PURE__ */ jsxs("span", { className: "es-uic-block es-uic-text-balance es-uic-tabular-nums", children: [
|
|
112
|
+
!globalOverride && __("Always applied, regardless of browser width.", "eightshift-ui-components"),
|
|
113
|
+
globalOverride && sprintf(
|
|
114
|
+
__("Applied when the browser width is %dpx or wider.", "eightshift-ui-components"),
|
|
115
|
+
breakpointData[globalOverride] + 1
|
|
116
|
+
)
|
|
117
|
+
] }),
|
|
118
|
+
globalOverride && /* @__PURE__ */ jsx("div", { className: "es-uic-mx-auto es-uic-mt-2", children: /* @__PURE__ */ jsx(
|
|
119
|
+
BreakpointPreview,
|
|
120
|
+
{
|
|
121
|
+
blocks: [
|
|
122
|
+
{
|
|
123
|
+
breakpoint: globalOverride,
|
|
124
|
+
value: ((_a = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value[attribute[globalOverride]]))) == null ? void 0 : _a.label) ?? upperFirst(value == null ? void 0 : value[globalOverride]),
|
|
125
|
+
dotsStart: true,
|
|
126
|
+
alignEnd: true
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
breakpoint: __("Default", "eightshift-ui-components"),
|
|
130
|
+
value: ((_b = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value[attribute[defaultBreakpoint]]))) == null ? void 0 : _b.label) ?? upperFirst(value == null ? void 0 : value[defaultBreakpoint]),
|
|
131
|
+
width: breakpointData[breakpoints.at(-1)],
|
|
132
|
+
dotsEnd: true,
|
|
133
|
+
active: true
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
) })
|
|
138
|
+
] }),
|
|
139
|
+
children: /* @__PURE__ */ jsx("div", { className: "es-uic-flex es-uic-size-8 es-uic-items-center es-uic-justify-center es-uic-rounded es-uic-bg-gray-200 es-uic-p-0.5 es-uic-text-gray-950 [&>svg]:es-uic-size-4", children: icons[`screen${upperFirst(defaultBreakpoint)}`] ?? icons.play })
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
};
|
|
143
|
+
return /* @__PURE__ */ jsxs(
|
|
144
|
+
BaseControl,
|
|
145
|
+
{
|
|
146
|
+
icon,
|
|
147
|
+
label,
|
|
148
|
+
subtitle,
|
|
149
|
+
help,
|
|
150
|
+
className: "es-uic-w-full",
|
|
151
|
+
actions: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
152
|
+
inline && /* @__PURE__ */ jsx(
|
|
153
|
+
AnimatedVisibility,
|
|
154
|
+
{
|
|
155
|
+
visible: !detailsVisible,
|
|
156
|
+
transition: "scaleFade",
|
|
157
|
+
noInitial: true,
|
|
158
|
+
children: children({
|
|
159
|
+
breakpoint: defaultBreakpoint,
|
|
160
|
+
currentValue: value == null ? void 0 : value[attribute[defaultBreakpoint]],
|
|
161
|
+
options,
|
|
162
|
+
handleChange: (newValue) => onChange(attribute[defaultBreakpoint], newValue),
|
|
163
|
+
isInlineCollapsedView: true
|
|
164
|
+
})
|
|
165
|
+
},
|
|
166
|
+
defaultBreakpoint
|
|
167
|
+
),
|
|
168
|
+
/* @__PURE__ */ jsx(
|
|
169
|
+
ToggleButton,
|
|
170
|
+
{
|
|
171
|
+
icon: icons.responsiveOverridesAlt,
|
|
172
|
+
onChange: () => setDetailsVisible(!detailsVisible),
|
|
173
|
+
selected: detailsVisible,
|
|
174
|
+
tooltip: detailsVisible ? __("Hide responsive overrides", "eightshift-ui-components") : __("Show responsive overrides", "eightshift-ui-components")
|
|
175
|
+
}
|
|
176
|
+
)
|
|
177
|
+
] }),
|
|
178
|
+
children: [
|
|
179
|
+
!inline && /* @__PURE__ */ jsxs(
|
|
180
|
+
"div",
|
|
181
|
+
{
|
|
182
|
+
className: classnames(
|
|
183
|
+
"es-uic-grid es-uic-items-center es-uic-gap-x-2 es-uic-transition-[grid-template-columns,_margin-block-end] es-uic-duration-150",
|
|
184
|
+
detailsVisible ? "es-uic-mb-2 es-uic-grid-cols-[minmax(0,_2rem),_minmax(0,_1fr),_minmax(0,_2.25rem)]" : "es-uic-grid-cols-[minmax(0,_0rem),_minmax(0,_1fr),_minmax(0,_2.25rem)]"
|
|
185
|
+
),
|
|
186
|
+
children: [
|
|
187
|
+
detailsVisible && /* @__PURE__ */ jsx(DefaultTooltip, {}),
|
|
188
|
+
/* @__PURE__ */ jsx("div", { className: classnames(detailsVisible ? "es-uic-col-start-2 es-uic-col-end-2" : "es-uic-col-span-full"), children: children({
|
|
189
|
+
breakpoint: defaultBreakpoint,
|
|
190
|
+
currentValue: value == null ? void 0 : value[attribute[defaultBreakpoint]],
|
|
191
|
+
options,
|
|
192
|
+
handleChange: (newValue) => onChange(attribute[defaultBreakpoint], newValue)
|
|
193
|
+
}) })
|
|
194
|
+
]
|
|
195
|
+
},
|
|
196
|
+
defaultBreakpoint
|
|
197
|
+
),
|
|
198
|
+
inline && /* @__PURE__ */ jsxs(
|
|
199
|
+
AnimatedVisibility,
|
|
200
|
+
{
|
|
201
|
+
className: "es-uic-mb-2 es-uic-grid es-uic-grid-cols-[minmax(0,_auto),_minmax(0,_1fr),_minmax(0,_2.25rem)] es-uic-items-center es-uic-gap-x-2",
|
|
202
|
+
visible: detailsVisible,
|
|
203
|
+
children: [
|
|
204
|
+
/* @__PURE__ */ jsx(DefaultTooltip, {}),
|
|
205
|
+
/* @__PURE__ */ jsx("div", { className: "es-uic-col-start-2 es-uic-col-end-2", children: children({
|
|
206
|
+
breakpoint: defaultBreakpoint,
|
|
207
|
+
currentValue: value == null ? void 0 : value[attribute[defaultBreakpoint]],
|
|
208
|
+
options,
|
|
209
|
+
handleChange: (newValue) => onChange(attribute[defaultBreakpoint], newValue),
|
|
210
|
+
isInlineExpandedView: true
|
|
211
|
+
}) })
|
|
212
|
+
]
|
|
213
|
+
},
|
|
214
|
+
defaultBreakpoint
|
|
215
|
+
),
|
|
216
|
+
/* @__PURE__ */ jsx(
|
|
217
|
+
AnimatedVisibility,
|
|
218
|
+
{
|
|
219
|
+
visible: detailsVisible,
|
|
220
|
+
className: "es-uic-space-y-2",
|
|
221
|
+
children: breakpoints.map((breakpoint, i) => {
|
|
222
|
+
var _a, _b, _c, _d, _e;
|
|
223
|
+
const isOverrideSet = value[attribute[breakpoint]] !== inheritValue;
|
|
224
|
+
const aboveOverride = rawBreakpoints.slice(0, i + 1).toReversed().find((breakpoint2) => (value == null ? void 0 : value[attribute[breakpoint2]]) !== inheritValue);
|
|
225
|
+
const belowOverride = rawBreakpoints.slice(i + 2).find((breakpoint2) => (value == null ? void 0 : value[attribute[breakpoint2]]) !== inheritValue);
|
|
226
|
+
return /* @__PURE__ */ jsxs(
|
|
227
|
+
"div",
|
|
228
|
+
{
|
|
229
|
+
className: "es-uic-grid es-uic-grid-cols-[minmax(0,_auto),_minmax(0,_1fr),_minmax(0,_2.25rem)] es-uic-items-center es-uic-gap-x-2",
|
|
230
|
+
children: [
|
|
231
|
+
/* @__PURE__ */ jsx(
|
|
232
|
+
DecorativeTooltip,
|
|
233
|
+
{
|
|
234
|
+
placement: "left",
|
|
235
|
+
theme: "light",
|
|
236
|
+
offset: 7.5,
|
|
237
|
+
arrow: true,
|
|
238
|
+
text: /* @__PURE__ */ jsxs("div", { className: "es-uic-max-w-96 es-uic-p-1", children: [
|
|
239
|
+
/* @__PURE__ */ jsx("span", { className: "es-uic-block es-uic-font-semibold", children: upperFirst(breakpoint) }),
|
|
240
|
+
/* @__PURE__ */ jsxs("span", { className: "es-uic-block es-uic-text-balance es-uic-tabular-nums", children: [
|
|
241
|
+
aboveOverride && aboveOverride === breakpoint && isOverrideSet && sprintf(
|
|
242
|
+
__("Applied when the browser width is %dpx or less.", "eightshift-ui-components"),
|
|
243
|
+
breakpointData[breakpoint]
|
|
244
|
+
),
|
|
245
|
+
aboveOverride && aboveOverride !== breakpoint && isOverrideSet && sprintf(
|
|
246
|
+
__("Applied when the browser width is between %dpx and %dpx.", "eightshift-ui-components"),
|
|
247
|
+
breakpointData[aboveOverride] + 1,
|
|
248
|
+
breakpointData[breakpoint]
|
|
249
|
+
),
|
|
250
|
+
(!aboveOverride || !isOverrideSet) && sprintf(__("Up to %dpx", "eightshift-ui-components"), breakpointData[breakpoint])
|
|
251
|
+
] }),
|
|
252
|
+
(aboveOverride && !isOverrideSet || !aboveOverride) && /* @__PURE__ */ jsx("span", { className: "es-uic-mt-2 es-uic-block es-uic-font-medium es-uic-italic", children: __("Not set", "eightshift-ui-components") }),
|
|
253
|
+
aboveOverride && isOverrideSet && /* @__PURE__ */ jsx("div", { className: "es-uic-mx-auto es-uic-mt-2", children: /* @__PURE__ */ jsx(
|
|
254
|
+
BreakpointPreview,
|
|
255
|
+
{
|
|
256
|
+
blocks: [
|
|
257
|
+
belowOverride && {
|
|
258
|
+
breakpoint: belowOverride,
|
|
259
|
+
value: ((_a = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value[attribute[belowOverride]]))) == null ? void 0 : _a.label) ?? upperFirst(value == null ? void 0 : value[belowOverride]),
|
|
260
|
+
widthEnd: breakpointData[belowOverride],
|
|
261
|
+
dotsStart: true,
|
|
262
|
+
alignEnd: true
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
breakpoint,
|
|
266
|
+
value: ((_b = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value[attribute[breakpoint]]))) == null ? void 0 : _b.label) ?? upperFirst(value == null ? void 0 : value[breakpoint]),
|
|
267
|
+
widthEnd: breakpointData[breakpoint],
|
|
268
|
+
active: true,
|
|
269
|
+
alignEnd: true,
|
|
270
|
+
dotsStart: aboveOverride === breakpoint
|
|
271
|
+
},
|
|
272
|
+
aboveOverride !== defaultBreakpoint && {
|
|
273
|
+
breakpoint: aboveOverride,
|
|
274
|
+
value: ((_c = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value[attribute[aboveOverride]]))) == null ? void 0 : _c.label) ?? upperFirst(value == null ? void 0 : value[aboveOverride]),
|
|
275
|
+
dotsEnd: true
|
|
276
|
+
},
|
|
277
|
+
aboveOverride === defaultBreakpoint && {
|
|
278
|
+
breakpoint: __("Default", "eightshift-ui-components"),
|
|
279
|
+
value: ((_d = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value[attribute[defaultBreakpoint]]))) == null ? void 0 : _d.label) ?? upperFirst(value == null ? void 0 : value[defaultBreakpoint]),
|
|
280
|
+
dotsEnd: true
|
|
281
|
+
}
|
|
282
|
+
]
|
|
283
|
+
}
|
|
284
|
+
) })
|
|
285
|
+
] }),
|
|
286
|
+
children: /* @__PURE__ */ jsx(
|
|
287
|
+
"div",
|
|
288
|
+
{
|
|
289
|
+
className: classnames(
|
|
290
|
+
"es-uic-flex es-uic-size-8 es-uic-shrink-0 es-uic-items-center es-uic-justify-center es-uic-rounded es-uic-bg-gray-100 es-uic-p-0.5 es-uic-text-gray-800",
|
|
291
|
+
value[attribute[breakpoint]] === inheritValue && "[&>svg]:es-uic-opacity-25"
|
|
292
|
+
),
|
|
293
|
+
children: (_e = icons) == null ? void 0 : _e[`screen${upperFirst(breakpoint)}`]
|
|
294
|
+
}
|
|
295
|
+
)
|
|
296
|
+
}
|
|
297
|
+
),
|
|
298
|
+
children({
|
|
299
|
+
breakpoint,
|
|
300
|
+
currentValue: value == null ? void 0 : value[attribute[breakpoint]],
|
|
301
|
+
options,
|
|
302
|
+
handleChange: (newValue) => onChange(attribute[breakpoint], newValue)
|
|
303
|
+
}),
|
|
304
|
+
/* @__PURE__ */ jsx(
|
|
305
|
+
Button,
|
|
306
|
+
{
|
|
307
|
+
onPress: () => onChange(attribute[breakpoint], inheritValue),
|
|
308
|
+
icon: icons.clearAlt,
|
|
309
|
+
disabled: (value == null ? void 0 : value[attribute[breakpoint]]) === inheritValue,
|
|
310
|
+
type: "ghost"
|
|
311
|
+
}
|
|
312
|
+
)
|
|
313
|
+
]
|
|
314
|
+
},
|
|
315
|
+
breakpoint
|
|
316
|
+
);
|
|
317
|
+
})
|
|
318
|
+
}
|
|
319
|
+
)
|
|
320
|
+
]
|
|
321
|
+
}
|
|
322
|
+
);
|
|
323
|
+
};
|
|
324
|
+
export {
|
|
325
|
+
ResponsiveLegacy
|
|
326
|
+
};
|