@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.
Files changed (112) hide show
  1. package/README.md +27 -0
  2. package/dist/Checkbox-BLcVbhiO.js +178 -0
  3. package/dist/ColorSwatch-Cmlex_kT.js +66 -0
  4. package/dist/FieldError-wtMA4667.js +42 -0
  5. package/dist/FocusScope-1u9yyfIN.js +725 -0
  6. package/dist/Form-Cq3fu75_.js +5 -0
  7. package/dist/GridList-BZPXp3_O.js +1256 -0
  8. package/dist/Group-DyqpTRPe.js +49 -0
  9. package/dist/Input-jsbb4ugq.js +130 -0
  10. package/dist/Label-BPzS-sR7.js +17 -0
  11. package/dist/ListBox-w9gDaJkV.js +4423 -0
  12. package/dist/LiveAnnouncer-IsokfWQ5.js +73 -0
  13. package/dist/NumberFormatter-LzoKy975.js +160 -0
  14. package/dist/RSPContexts-CrNYmadY.js +14 -0
  15. package/dist/Select-49a62830.esm-C-RFtLiD.js +2541 -0
  16. package/dist/SelectionManager-mefd0ThJ.js +2155 -0
  17. package/dist/Separator-DHn0CwdK.js +325 -0
  18. package/dist/Slider-Pyh2V4bY.js +885 -0
  19. package/dist/Text-BM136LvS.js +17 -0
  20. package/dist/VisuallyHidden-BYRI1Lfo.js +51 -0
  21. package/dist/_commonjsHelpers-CUmg6egw.js +6 -0
  22. package/dist/ariaHideOutside-ByKBPHmX.js +113 -0
  23. package/dist/assets/style.css +1 -0
  24. package/dist/button-BkkdyHfJ.js +307 -0
  25. package/dist/components/animated-visibility/animated-visibility.js +7165 -0
  26. package/dist/components/base-control/base-control.js +97 -0
  27. package/dist/components/breakpoint-preview/breakpoint-preview.js +218 -0
  28. package/dist/components/button/button.js +10 -0
  29. package/dist/components/checkbox/checkbox.js +119 -0
  30. package/dist/components/color-pickers/color-picker.js +242 -0
  31. package/dist/components/color-pickers/color-swatch.js +62 -0
  32. package/dist/components/color-pickers/gradient-editor.js +516 -0
  33. package/dist/components/color-pickers/solid-color-picker.js +1633 -0
  34. package/dist/components/component-toggle/component-toggle.js +71 -0
  35. package/dist/components/container-panel/container-panel.js +39 -0
  36. package/dist/components/expandable/expandable.js +144 -0
  37. package/dist/components/input-field/input-field.js +224 -0
  38. package/dist/components/link-input/link-input.js +937 -0
  39. package/dist/components/list-box/list-box.js +152 -0
  40. package/dist/components/matrix-align/matrix-align.js +185 -0
  41. package/dist/components/menu/menu.js +1608 -0
  42. package/dist/components/notice/notice.js +119 -0
  43. package/dist/components/number-picker/number-picker.js +277 -0
  44. package/dist/components/popover/popover.js +9 -0
  45. package/dist/components/radio/radio.js +552 -0
  46. package/dist/components/repeater/repeater-item.js +127 -0
  47. package/dist/components/repeater/repeater.js +248 -0
  48. package/dist/components/responsive/responsive-legacy.js +326 -0
  49. package/dist/components/responsive/responsive.js +499 -0
  50. package/dist/components/responsive-preview/responsive-preview.js +119 -0
  51. package/dist/components/rich-label/rich-label.js +56 -0
  52. package/dist/components/select/async-multi-select.js +144 -0
  53. package/dist/components/select/async-single-select.js +126 -0
  54. package/dist/components/select/custom-select-default-components.js +38 -0
  55. package/dist/components/select/multi-select-components.js +8 -0
  56. package/dist/components/select/multi-select.js +134 -0
  57. package/dist/components/select/react-select-component-wrappers.js +90 -0
  58. package/dist/components/select/shared.js +45 -0
  59. package/dist/components/select/single-select.js +116 -0
  60. package/dist/components/select/styles.js +55 -0
  61. package/dist/components/slider/column-config-slider.js +225 -0
  62. package/dist/components/slider/slider.js +362 -0
  63. package/dist/components/slider/utils.js +45 -0
  64. package/dist/components/spacer/spacer.js +93 -0
  65. package/dist/components/tabs/tabs.js +626 -0
  66. package/dist/components/toggle/switch.js +140 -0
  67. package/dist/components/toggle/toggle.js +58 -0
  68. package/dist/components/toggle-button/toggle-button.js +206 -0
  69. package/dist/components/tooltip/tooltip.js +10 -0
  70. package/dist/context-jMy6xdVq.js +98 -0
  71. package/dist/default-i18n-BhE-OUmt.js +873 -0
  72. package/dist/filterDOMProps-DG2RfOUr.js +30 -0
  73. package/dist/focusSafely-C3K8zAKj.js +743 -0
  74. package/dist/hooks/use-cell-edit-mode.js +35 -0
  75. package/dist/icons/block-icon.js +42 -0
  76. package/dist/icons/generic-color-swatch.js +21 -0
  77. package/dist/icons/icons.js +3636 -0
  78. package/dist/index-Bfb9bWcb.js +28844 -0
  79. package/dist/index-a301f526.esm-Bioi4cGX.js +3576 -0
  80. package/dist/index.js +109 -0
  81. package/dist/intlStrings-CUhoK9EN.js +2484 -0
  82. package/dist/isScrollable-PcyglExV.js +10 -0
  83. package/dist/modifiers.esm-BuJQPI1X.js +31 -0
  84. package/dist/multi-select-components-CjVpCNko.js +3677 -0
  85. package/dist/number-rWqELA8W.js +39 -0
  86. package/dist/popover-Dx3vKXUX.js +1061 -0
  87. package/dist/react-select-async.esm-TFb_ZX6C.js +111 -0
  88. package/dist/react-select.esm-BjRWqf0E.js +15 -0
  89. package/dist/style.js +1 -0
  90. package/dist/textSelection-BosCCRVE.js +89 -0
  91. package/dist/tooltip-CkCndvTI.js +1094 -0
  92. package/dist/useButton-CuG5UzUw.js +74 -0
  93. package/dist/useEvent-DHv-yhOH.js +24 -0
  94. package/dist/useFocusRing-Cc-4eouh.js +41 -0
  95. package/dist/useFocusable-5q1Gek1J.js +81 -0
  96. package/dist/useFormReset-Buc9YJcv.js +23 -0
  97. package/dist/useFormValidationState-BAPPNXic.js +238 -0
  98. package/dist/useHasTabbableChild-D3uUNhJ0.js +37 -0
  99. package/dist/useLabel-CGlkoFG0.js +28 -0
  100. package/dist/useLabels-Dg62M_3P.js +25 -0
  101. package/dist/useListData-BelKu4kx.js +211 -0
  102. package/dist/useListState-Domq0blV.js +137 -0
  103. package/dist/useLocalizedStringFormatter-Prmz0h0A.js +130 -0
  104. package/dist/useNumberFieldState-BLU3uhSR.js +1253 -0
  105. package/dist/useNumberFormatter-BLc2xjZn.js +13 -0
  106. package/dist/usePress-BQgVor4T.js +698 -0
  107. package/dist/useToggle-C9ETOBaZ.js +58 -0
  108. package/dist/useToggleState-DJ_z5E2S.js +21 -0
  109. package/dist/utilities/classnames.js +16 -0
  110. package/dist/utilities/text-helpers.js +79 -0
  111. package/dist/utils-BsiH7-5Y.js +488 -0
  112. package/package.json +71 -0
@@ -0,0 +1,499 @@
1
+ import { jsxs, jsx, Fragment } 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 { Menu, MenuItem, MenuSeparator } from "../menu/menu.js";
10
+ import { T as TriggeredPopover } from "../../popover-Dx3vKXUX.js";
11
+ import { ResponsivePreview } from "../responsive-preview/responsive-preview.js";
12
+ import { a as ButtonGroup, B as Button } from "../../button-BkkdyHfJ.js";
13
+ import { RichLabel } from "../rich-label/rich-label.js";
14
+ import { AnimatedVisibility } from "../animated-visibility/animated-visibility.js";
15
+ import { ToggleButton } from "../toggle-button/toggle-button.js";
16
+ import { BaseControl } from "../base-control/base-control.js";
17
+ /**
18
+ * A component that allows the user to set different values for different breakpoints.
19
+ *
20
+ * Inner items should be passed as a render function.
21
+ * The following props are passed to the render function:
22
+ * - `breakpoint: string` - Name of the current breakpoint.
23
+ * - `currentValue: any` - Current value.
24
+ * - `handleChange: Function<(attributeName: string, value: any) => void>` - A function to change the value for the breakpoint..
25
+ * - `options: Object<string, any>` - (Optional) Options list passed to the `ResponsiveLegacy` component. (optional)
26
+ *
27
+ * @component
28
+ * @param {Object} props - Component props.
29
+ * @param {Object} props.value - The current value of the component.
30
+ * @param {Function} props.onChange - Function to run when the value changes. `(newValue: Object) => void`.
31
+ * @param {JSX.Element} props.icon - The icon of the component.
32
+ * @param {string} props.help - The help text of the component.
33
+ * @param {string} props.label - The label of the component.
34
+ * @param {string} props.subtitle - The subtitle of the component.
35
+ * @param {{label: string, value: string}[]} props.options - Options of the attribute the component is linked to. `{ value: string, label: string }[]`.
36
+ * @param {string[]} props.breakpoints - Breakpoints to use.
37
+ * @param {string[]} [props.desktopFirstBreakpoints] - Breakpoints to use in desktop-first mode. If not provided, the breakpoints will be used in reverse order.
38
+ * @param {Object<string, number>} [props.breakpointData] - Currently used breakpoint data. `{ [breakpoint: string]: number }`.
39
+ *
40
+ * @returns {JSX.Element} The Responsive component.
41
+ *
42
+ * @example
43
+ * <Responsive
44
+ * value={value}
45
+ * onChange={onChange}
46
+ * icon={icons.myIcon}
47
+ * label={__('Label', 'eightshift-ui-components')}
48
+ * options={[
49
+ * { value: 'value1', label: 'Value 1' },
50
+ * { value: 'value2', label: 'Value 2' },
51
+ * { value: 'value3', label: 'Value 3' },
52
+ * ]}
53
+ * breakpoints={['mobile', 'tablet', 'desktop', 'large']}
54
+ * breakpointData={breakpointData}
55
+ * >
56
+ * {({ breakpoint, currentValue, options, handleChange }) => (
57
+ * <Select
58
+ * label={breakpoint}
59
+ * value={currentValue}
60
+ * options={options}
61
+ * onChange={handleChange}
62
+ * />
63
+ * )}
64
+ * </Responsive>
65
+ *
66
+ * @preserve
67
+ */
68
+ const Responsive = (props) => {
69
+ const {
70
+ value,
71
+ onChange,
72
+ icon,
73
+ help,
74
+ label,
75
+ subtitle,
76
+ options,
77
+ breakpoints,
78
+ desktopFirstBreakpoints = breakpoints.map((bp) => `max-${bp}`),
79
+ breakpointData,
80
+ children
81
+ } = props;
82
+ const [detailsVisible, setDetailsVisible] = useState(false);
83
+ const isDesktopFirst = (value == null ? void 0 : value["_mobileFirst"]) === true;
84
+ const firstMobileFirstOverride = breakpoints.find((breakpoint) => value == null ? void 0 : value[breakpoint]);
85
+ const lastDesktopFirstOverride = desktopFirstBreakpoints.toReversed().find((breakpoint) => value == null ? void 0 : value[breakpoint]);
86
+ const breakpointsToMap = isDesktopFirst ? desktopFirstBreakpoints : breakpoints;
87
+ const DefaultTooltip = () => {
88
+ var _a, _b, _c, _d;
89
+ return /* @__PURE__ */ jsx(
90
+ DecorativeTooltip,
91
+ {
92
+ placement: "left",
93
+ className: "es-uic-p-3",
94
+ theme: "light",
95
+ offset: 7.5,
96
+ arrow: true,
97
+ text: /* @__PURE__ */ jsxs("div", { className: "es-uic-max-w-64 es-uic-p-1", children: [
98
+ /* @__PURE__ */ jsx("span", { className: "es-uic-block es-uic-text-balance es-uic-font-semibold es-uic-tabular-nums", children: __("Default", "eightshift-ui-components") }),
99
+ /* @__PURE__ */ jsxs("span", { className: "es-uic-block es-uic-text-balance es-uic-tabular-nums", children: [
100
+ !firstMobileFirstOverride && !lastDesktopFirstOverride && __("Always applied, regardless of browser width.", "eightshift-ui-components"),
101
+ firstMobileFirstOverride && sprintf(
102
+ __("Applies when the browser width is %dpx or narrower.", "eightshift-ui-components"),
103
+ breakpointData[firstMobileFirstOverride] - 1
104
+ ),
105
+ lastDesktopFirstOverride && sprintf(
106
+ __("Applies when the browser width is %dpx or more.", "eightshift-ui-components"),
107
+ breakpointData[breakpoints.at(-1)]
108
+ )
109
+ ] }),
110
+ /* @__PURE__ */ jsxs("div", { className: "es-uic-mx-auto", children: [
111
+ firstMobileFirstOverride && /* @__PURE__ */ jsx(
112
+ BreakpointPreview,
113
+ {
114
+ blocks: [
115
+ {
116
+ breakpoint: __("Default", "eightshift-ui-components"),
117
+ widthEnd: breakpointData[firstMobileFirstOverride] - 1,
118
+ 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"]),
119
+ dotsStart: true,
120
+ alignEnd: true,
121
+ active: true
122
+ },
123
+ {
124
+ breakpoint: firstMobileFirstOverride,
125
+ value: ((_b = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value[firstMobileFirstOverride]))) == null ? void 0 : _b.label) ?? upperFirst(value == null ? void 0 : value[firstMobileFirstOverride]),
126
+ dotsEnd: true
127
+ }
128
+ ]
129
+ }
130
+ ),
131
+ lastDesktopFirstOverride && /* @__PURE__ */ jsx(
132
+ BreakpointPreview,
133
+ {
134
+ blocks: [
135
+ {
136
+ breakpoint: lastDesktopFirstOverride.replace("max-", ""),
137
+ value: ((_c = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value[lastDesktopFirstOverride]))) == null ? void 0 : _c.label) ?? upperFirst(value == null ? void 0 : value[lastDesktopFirstOverride]),
138
+ dotsStart: true,
139
+ alignEnd: true
140
+ },
141
+ {
142
+ breakpoint: __("Default", "eightshift-ui-components"),
143
+ value: ((_d = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value["_default"]))) == null ? void 0 : _d.label) ?? upperFirst(value == null ? void 0 : value["_default"]),
144
+ width: breakpointData[breakpoints.at(-1)],
145
+ dotsEnd: true,
146
+ active: true
147
+ }
148
+ ]
149
+ }
150
+ )
151
+ ] })
152
+ ] }),
153
+ children: /* @__PURE__ */ jsx("div", { className: "es-uic-flex es-uic-size-8 es-uic-cursor-help 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.play })
154
+ }
155
+ );
156
+ };
157
+ return /* @__PURE__ */ jsxs(
158
+ BaseControl,
159
+ {
160
+ icon,
161
+ label,
162
+ subtitle,
163
+ help,
164
+ actions: /* @__PURE__ */ jsxs(ButtonGroup, { children: [
165
+ /* @__PURE__ */ jsxs(
166
+ Menu,
167
+ {
168
+ tooltip: __("Responsive options", "eightshift-ui-components"),
169
+ popoverProps: { placement: "bottom right" },
170
+ children: [
171
+ /* @__PURE__ */ jsx(
172
+ MenuItem,
173
+ {
174
+ className: "!es-uic-pb-0 !es-uic-pt-1",
175
+ disabled: true,
176
+ children: __("Breakpoint mode", "eightshift-ui-components")
177
+ }
178
+ ),
179
+ /* @__PURE__ */ jsx(
180
+ MenuItem,
181
+ {
182
+ selected: !isDesktopFirst,
183
+ onClick: () => {
184
+ const thingsToDelete = [...breakpoints, ...desktopFirstBreakpoints].reduce(
185
+ (prev, curr) => ({ ...prev, [curr]: void 0 }),
186
+ {}
187
+ );
188
+ onChange({
189
+ ...value,
190
+ ...thingsToDelete,
191
+ _mobileFirst: false
192
+ });
193
+ },
194
+ children: /* @__PURE__ */ jsx(
195
+ RichLabel,
196
+ {
197
+ label: __("Mobile-first", "eightshift-ui-components"),
198
+ subtitle: __("Recommended", "eightshift-ui-components")
199
+ }
200
+ )
201
+ }
202
+ ),
203
+ /* @__PURE__ */ jsx(
204
+ MenuItem,
205
+ {
206
+ selected: isDesktopFirst,
207
+ onClick: () => {
208
+ const thingsToDelete = [...breakpoints, ...desktopFirstBreakpoints].reduce(
209
+ (prev, curr) => ({ ...prev, [curr]: void 0 }),
210
+ {}
211
+ );
212
+ onChange({
213
+ ...value,
214
+ ...thingsToDelete,
215
+ _mobileFirst: true
216
+ });
217
+ },
218
+ children: __("Desktop-first", "eightshift-ui-components")
219
+ }
220
+ ),
221
+ /* @__PURE__ */ jsx(MenuSeparator, {}),
222
+ /* @__PURE__ */ jsx(
223
+ MenuItem,
224
+ {
225
+ icon: icons.clearAlt,
226
+ onClick: () => {
227
+ const thingsToDelete = [...breakpoints, ...desktopFirstBreakpoints].reduce(
228
+ (prev, curr) => ({ ...prev, [curr]: void 0 }),
229
+ {}
230
+ );
231
+ onChange({
232
+ ...value,
233
+ ...thingsToDelete
234
+ });
235
+ },
236
+ children: __("Clear all overrides", "eightshift-ui-components")
237
+ }
238
+ )
239
+ ]
240
+ }
241
+ ),
242
+ /* @__PURE__ */ jsx(
243
+ TriggeredPopover,
244
+ {
245
+ "aria-label": props["aria-label"] ?? __("Breakpoint preview", "eightshift-ui-components"),
246
+ trigger: /* @__PURE__ */ jsx(
247
+ Button,
248
+ {
249
+ disabled: !Object.keys(value).some((key) => !(key == null ? void 0 : key.startsWith("_")) && (value == null ? void 0 : value[key]) !== void 0),
250
+ icon: icons.previewResponsive,
251
+ tooltip: __("Breakpoint preview", "eightshift-ui-components")
252
+ }
253
+ ),
254
+ children: /* @__PURE__ */ jsx(
255
+ ResponsivePreview,
256
+ {
257
+ value,
258
+ isDesktopFirst,
259
+ breakpoints,
260
+ desktopFirstBreakpoints,
261
+ options,
262
+ breakpointData
263
+ }
264
+ )
265
+ }
266
+ ),
267
+ /* @__PURE__ */ jsx(
268
+ ToggleButton,
269
+ {
270
+ icon: isDesktopFirst ? icons.responsiveOverridesAlt : icons.responsiveOverridesAlt2,
271
+ onChange: () => setDetailsVisible(!detailsVisible),
272
+ selected: detailsVisible,
273
+ tooltip: detailsVisible ? __("Hide responsive overrides", "eightshift-ui-components") : __("Show responsive overrides", "eightshift-ui-components")
274
+ }
275
+ )
276
+ ] }),
277
+ children: [
278
+ !isDesktopFirst && /* @__PURE__ */ jsxs(
279
+ "div",
280
+ {
281
+ className: classnames(
282
+ "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",
283
+ 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)]"
284
+ ),
285
+ children: [
286
+ detailsVisible && /* @__PURE__ */ jsx(DefaultTooltip, {}),
287
+ /* @__PURE__ */ jsx("div", { className: classnames(detailsVisible ? "es-uic-col-start-2 es-uic-col-end-2" : "es-uic-col-span-full"), children: children({
288
+ breakpoint: "_default",
289
+ currentValue: value == null ? void 0 : value["_default"],
290
+ handleChange: (newValue) => onChange({
291
+ ...value,
292
+ _default: newValue
293
+ }),
294
+ options
295
+ }) })
296
+ ]
297
+ },
298
+ "_default-mobile-first"
299
+ ),
300
+ /* @__PURE__ */ jsx(
301
+ AnimatedVisibility,
302
+ {
303
+ visible: detailsVisible,
304
+ className: "es-uic-space-y-2",
305
+ children: breakpointsToMap.map((breakpoint, i) => {
306
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
307
+ const realBreakpointName = breakpoint.replace("max-", "");
308
+ const filterBreakpoints = isDesktopFirst ? [...breakpointsToMap, "_default"] : ["_default", ...breakpointsToMap];
309
+ const aboveOverride = isDesktopFirst ? filterBreakpoints.slice(i + 1).find((breakpoint2) => value == null ? void 0 : value[breakpoint2]) : filterBreakpoints.slice(0, i + 1).toReversed().find((breakpoint2) => value == null ? void 0 : value[breakpoint2]);
310
+ const belowOverride = isDesktopFirst ? filterBreakpoints.slice(0, i).toReversed().find((breakpoint2) => value == null ? void 0 : value[breakpoint2]) : filterBreakpoints.slice(i + 2).find((breakpoint2) => value == null ? void 0 : value[breakpoint2]);
311
+ return /* @__PURE__ */ jsxs(
312
+ "div",
313
+ {
314
+ 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",
315
+ children: [
316
+ /* @__PURE__ */ jsx(
317
+ DecorativeTooltip,
318
+ {
319
+ placement: "left",
320
+ theme: "light",
321
+ offset: 7.5,
322
+ arrow: true,
323
+ text: /* @__PURE__ */ jsxs("div", { className: "es-uic-max-w-96 es-uic-p-1", children: [
324
+ /* @__PURE__ */ jsx("span", { className: "es-uic-block es-uic-font-semibold", children: upperFirst(realBreakpointName) }),
325
+ /* @__PURE__ */ jsxs("span", { className: "es-uic-block es-uic-text-balance es-uic-tabular-nums", children: [
326
+ !isDesktopFirst && /* @__PURE__ */ jsxs(Fragment, { children: [
327
+ !belowOverride && value[breakpoint] && sprintf(
328
+ __("Applied when the browser width is %dpx or more.", "eightshift-ui-components"),
329
+ breakpointData[realBreakpointName]
330
+ ),
331
+ belowOverride && value[breakpoint] && sprintf(
332
+ __(
333
+ "Applied when the browser width is between %dpx and %dpx.",
334
+ "eightshift-ui-components"
335
+ ),
336
+ breakpointData[realBreakpointName],
337
+ breakpointData[belowOverride] - 1
338
+ ),
339
+ !value[breakpoint] && sprintf(__("From %dpx", "eightshift-ui-components"), breakpointData[realBreakpointName])
340
+ ] }),
341
+ isDesktopFirst && /* @__PURE__ */ jsxs(Fragment, { children: [
342
+ !belowOverride && value[breakpoint] && sprintf(
343
+ __("Applied when the browser width is %dpx or less.", "eightshift-ui-components"),
344
+ breakpointData[realBreakpointName] - 1
345
+ ),
346
+ belowOverride && value[breakpoint] && sprintf(
347
+ __(
348
+ "Applied when the browser width is between %dpx and %dpx.",
349
+ "eightshift-ui-components"
350
+ ),
351
+ breakpointData[belowOverride == null ? void 0 : belowOverride.replace("max-", "")],
352
+ breakpointData[realBreakpointName] - 1
353
+ ),
354
+ !value[breakpoint] && sprintf(
355
+ __("Up to %dpx", "eightshift-ui-components"),
356
+ breakpointData[belowOverride == null ? void 0 : belowOverride.replace("max-", "")]
357
+ )
358
+ ] })
359
+ ] }),
360
+ !value[breakpoint] && /* @__PURE__ */ jsx("span", { className: "es-uic-mt-2 es-uic-block es-uic-font-medium es-uic-italic", children: __("Not set", "eightshift-ui-components") }),
361
+ value[breakpoint] && /* @__PURE__ */ jsxs("div", { className: "es-uic-mx-auto es-uic-mt-2", children: [
362
+ !isDesktopFirst && /* @__PURE__ */ jsx(
363
+ BreakpointPreview,
364
+ {
365
+ dotsStart: belowOverride,
366
+ blocks: [
367
+ aboveOverride !== "_default" && {
368
+ breakpoint: aboveOverride,
369
+ value: ((_a = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value[aboveOverride]))) == null ? void 0 : _a.label) ?? upperFirst(value == null ? void 0 : value[aboveOverride]),
370
+ dotsStart: !belowOverride,
371
+ alignEnd: !belowOverride
372
+ },
373
+ aboveOverride === "_default" && {
374
+ breakpoint: __("Default", "eightshift-ui-components"),
375
+ 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"]),
376
+ dotsStart: !belowOverride,
377
+ alignEnd: !belowOverride
378
+ },
379
+ {
380
+ breakpoint: realBreakpointName,
381
+ value: ((_c = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value[breakpoint]))) == null ? void 0 : _c.label) ?? upperFirst(value == null ? void 0 : value[breakpoint]),
382
+ width: breakpointData[realBreakpointName],
383
+ active: true,
384
+ dotsEnd: !belowOverride
385
+ },
386
+ belowOverride && {
387
+ breakpoint: belowOverride,
388
+ value: ((_d = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value[belowOverride]))) == null ? void 0 : _d.label) ?? upperFirst(value == null ? void 0 : value[belowOverride]),
389
+ width: breakpointData[belowOverride],
390
+ dotsEnd: true
391
+ }
392
+ ]
393
+ }
394
+ ),
395
+ isDesktopFirst && /* @__PURE__ */ jsx(
396
+ BreakpointPreview,
397
+ {
398
+ dotsStart: true,
399
+ dotsEnd: aboveOverride !== "_default",
400
+ blocks: [
401
+ belowOverride && {
402
+ breakpoint: belowOverride == null ? void 0 : belowOverride.replace("max-", ""),
403
+ value: ((_e = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value[belowOverride == null ? void 0 : belowOverride.replace("max-", "")]))) == null ? void 0 : _e.label) ?? upperFirst(value == null ? void 0 : value[belowOverride])
404
+ },
405
+ {
406
+ breakpoint: realBreakpointName,
407
+ value: ((_f = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value[breakpoint]))) == null ? void 0 : _f.label) ?? upperFirst(value == null ? void 0 : value[realBreakpointName]),
408
+ width: breakpointData[(_g = filterBreakpoints[i - 1]) == null ? void 0 : _g.replace("max-", "")],
409
+ active: true
410
+ },
411
+ aboveOverride !== "_default" && {
412
+ breakpoint: aboveOverride == null ? void 0 : aboveOverride.replace("max-", ""),
413
+ value: ((_h = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value[aboveOverride]))) == null ? void 0 : _h.label) ?? upperFirst(value == null ? void 0 : value[aboveOverride]),
414
+ width: breakpointData[breakpoint == null ? void 0 : breakpoint.replace("max-", "")]
415
+ },
416
+ aboveOverride === "_default" && {
417
+ breakpoint: __("Default", "eightshift-ui-components"),
418
+ value: ((_i = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value["_default"]))) == null ? void 0 : _i.label) ?? upperFirst(value == null ? void 0 : value["_default"]),
419
+ width: breakpointData[breakpoint == null ? void 0 : breakpoint.replace("max-", "")],
420
+ dotsEnd: true
421
+ }
422
+ ]
423
+ }
424
+ )
425
+ ] })
426
+ ] }),
427
+ children: /* @__PURE__ */ jsx(
428
+ "div",
429
+ {
430
+ className: classnames(
431
+ "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",
432
+ !value[breakpoint] && "[&>svg]:es-uic-opacity-25"
433
+ ),
434
+ children: (_j = icons) == null ? void 0 : _j[`screen${upperFirst(realBreakpointName)}`]
435
+ }
436
+ )
437
+ }
438
+ ),
439
+ children({
440
+ breakpoint,
441
+ currentValue: value == null ? void 0 : value[breakpoint],
442
+ handleChange: (newValue) => {
443
+ onChange({
444
+ ...value,
445
+ [breakpoint]: newValue
446
+ });
447
+ },
448
+ options
449
+ }),
450
+ /* @__PURE__ */ jsx(
451
+ Button,
452
+ {
453
+ onPress: () => {
454
+ onChange({
455
+ ...value,
456
+ [breakpoint]: void 0
457
+ });
458
+ },
459
+ icon: icons.clearAlt,
460
+ disabled: !(value == null ? void 0 : value[breakpoint]),
461
+ type: "ghost"
462
+ }
463
+ )
464
+ ]
465
+ },
466
+ realBreakpointName
467
+ );
468
+ })
469
+ }
470
+ ),
471
+ isDesktopFirst && /* @__PURE__ */ jsxs(
472
+ "div",
473
+ {
474
+ className: classnames(
475
+ "es-uic-grid es-uic-items-center es-uic-gap-x-2 es-uic-transition-[grid-template-columns,_margin-block-start] es-uic-duration-150",
476
+ detailsVisible ? "!es-uic-mt-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)]"
477
+ ),
478
+ children: [
479
+ detailsVisible && /* @__PURE__ */ jsx(DefaultTooltip, {}),
480
+ /* @__PURE__ */ jsx("div", { className: classnames(detailsVisible ? "es-uic-col-start-2 es-uic-col-end-2" : "es-uic-col-span-full"), children: children({
481
+ breakpoint: "_default",
482
+ currentValue: value == null ? void 0 : value["_default"],
483
+ handleChange: (newValue) => onChange({
484
+ ...value,
485
+ _default: newValue
486
+ }),
487
+ options
488
+ }) })
489
+ ]
490
+ },
491
+ "_default-desktop-first"
492
+ )
493
+ ]
494
+ }
495
+ );
496
+ };
497
+ export {
498
+ Responsive
499
+ };
@@ -0,0 +1,119 @@
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { _ as __ } from "../../default-i18n-BhE-OUmt.js";
3
+ import { upperFirst } from "../../utilities/text-helpers.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
+ *
21
+ * @returns {JSX.Element} The ResponsivePreview component.
22
+ *
23
+ * @example
24
+ * <ResponsivePreview
25
+ * value={value}
26
+ * isDesktopFirst={isDesktopFirst}
27
+ * breakpoints={breakpoints}
28
+ * options={options}
29
+ * breakpointData={breakpointData} // e.g. from global manifest
30
+ * />
31
+ *
32
+ * @preserve
33
+ */
34
+ const ResponsivePreview = (props) => {
35
+ var _a, _b;
36
+ const {
37
+ value,
38
+ isDesktopFirst,
39
+ breakpoints,
40
+ desktopFirstBreakpoints = breakpoints.map((bp) => `max-${bp}`),
41
+ options,
42
+ breakpointData
43
+ } = props;
44
+ const firstMobileFirstOverride = breakpoints.find((breakpoint) => value == null ? void 0 : value[breakpoint]);
45
+ const lastDesktopFirstOverride = desktopFirstBreakpoints.toReversed().find((breakpoint) => value == null ? void 0 : value[breakpoint]);
46
+ let previewItems = [];
47
+ if (firstMobileFirstOverride) {
48
+ previewItems = [
49
+ ...previewItems,
50
+ {
51
+ breakpoint: __("Default", "eightshift-ui-components"),
52
+ 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"])
53
+ }
54
+ ];
55
+ breakpoints.forEach((breakpoint) => {
56
+ var _a2;
57
+ if (!(value == null ? void 0 : value[breakpoint])) {
58
+ return;
59
+ }
60
+ previewItems = [
61
+ ...previewItems,
62
+ {
63
+ width: breakpointData[breakpoint],
64
+ breakpoint,
65
+ value: ((_a2 = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value[firstMobileFirstOverride]))) == null ? void 0 : _a2.label) ?? upperFirst(value == null ? void 0 : value[firstMobileFirstOverride])
66
+ }
67
+ ];
68
+ });
69
+ }
70
+ if (lastDesktopFirstOverride) {
71
+ desktopFirstBreakpoints.forEach((breakpoint, i) => {
72
+ var _a2;
73
+ if (!(value == null ? void 0 : value[breakpoint])) {
74
+ return;
75
+ }
76
+ previewItems = [
77
+ ...previewItems,
78
+ {
79
+ width: breakpointData[breakpoints[i - 1]],
80
+ breakpoint: breakpoint.replace("max-", ""),
81
+ value: ((_a2 = options == null ? void 0 : options.find((opt) => opt.value === (value == null ? void 0 : value[breakpoint]))) == null ? void 0 : _a2.label) ?? upperFirst(value == null ? void 0 : value[breakpoint])
82
+ }
83
+ ];
84
+ });
85
+ previewItems = [
86
+ ...previewItems,
87
+ {
88
+ width: breakpointData[breakpoints.at(-1)],
89
+ breakpoint: __("Default", "eightshift-ui-components"),
90
+ 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"])
91
+ }
92
+ ];
93
+ previewItems.at(0).width = null;
94
+ }
95
+ return /* @__PURE__ */ jsxs("div", { className: "es-uic-flex es-uic-min-w-72 es-uic-flex-col es-uic-items-start es-uic-gap-4 es-uic-p-2", children: [
96
+ /* @__PURE__ */ jsxs("div", { className: "es-uic-flex es-uic-w-full es-uic-items-center es-uic-gap-2.5", children: [
97
+ /* @__PURE__ */ jsx(
98
+ RichLabel,
99
+ {
100
+ icon: icons.previewResponsive,
101
+ label: __("Responsive preview", "eightshift-ui-components")
102
+ }
103
+ ),
104
+ /* @__PURE__ */ jsx("span", { className: "es-uic-ml-auto es-uic-select-none es-uic-rounded es-uic-bg-gray-100 es-uic-px-1 es-uic-py-0.5 es-uic-text-xs es-uic-text-gray-500", children: isDesktopFirst ? __("Desktop-first", "eightshift-ui-components") : __("Mobile-first", "eightshift-ui-components") })
105
+ ] }),
106
+ previewItems.length === 0 && /* @__PURE__ */ jsx("span", { className: "es-uic-text-gray-500 es-uic-text-sm es-uic-italic", children: __("No overrides applied", "eightshift-ui-components") }),
107
+ /* @__PURE__ */ jsx(
108
+ BreakpointPreview,
109
+ {
110
+ blocks: previewItems,
111
+ dotsStart: true,
112
+ dotsEnd: true
113
+ }
114
+ )
115
+ ] });
116
+ };
117
+ export {
118
+ ResponsivePreview
119
+ };
@@ -0,0 +1,56 @@
1
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
+ import { classnames } from "../../utilities/classnames.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 {boolean} [props.fullWidth=false] - If `true`, the component will take up as much space as it can.
14
+ * @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.
15
+ *
16
+ * @returns {JSX.Element} The RichLabel component.
17
+ *
18
+ * @example
19
+ * <RichLabel
20
+ * icon={icons.myIcon}
21
+ * label='My label'
22
+ * />
23
+ *
24
+ * @preserve
25
+ */
26
+ const RichLabel = (props) => {
27
+ const { icon, label, subtitle, as, className, fullWidth = false, contentsOnly } = props;
28
+ const ComponentToRender = as ?? "div";
29
+ if (contentsOnly) {
30
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
31
+ icon && /* @__PURE__ */ jsx("span", { className: "es-uic-text-slate-500 [&>svg]:es-uic-size-5.5", children: icon }),
32
+ label && /* @__PURE__ */ jsx("span", { className: "es-uic-text-balance", children: label }),
33
+ subtitle && /* @__PURE__ */ jsx("span", { className: "es-uic-text-xs es-uic-text-gray-500 es-uic-text-balance", children: subtitle })
34
+ ] });
35
+ }
36
+ return /* @__PURE__ */ jsxs(
37
+ ComponentToRender,
38
+ {
39
+ className: classnames(
40
+ "es-uic-flex es-uic-items-center es-uic-gap-1.5 es-uic-text-sm es-uic-leading-tight es-uic-text-gray-800",
41
+ fullWidth && "es-uic-grow",
42
+ className
43
+ ),
44
+ children: [
45
+ icon && /* @__PURE__ */ jsx("span", { className: "es-uic-text-slate-500 [&>svg]:es-uic-size-5.5", children: icon }),
46
+ (label || subtitle) && /* @__PURE__ */ jsxs("div", { className: "es-uic-flex es-uic-flex-col es-uic-items-start es-uic-text-start es-uic-text-balance", children: [
47
+ label && /* @__PURE__ */ jsx("span", { children: label }),
48
+ subtitle && /* @__PURE__ */ jsx("span", { className: "es-uic-text-xs es-uic-text-gray-500", children: subtitle })
49
+ ] })
50
+ ]
51
+ }
52
+ );
53
+ };
54
+ export {
55
+ RichLabel
56
+ };