@eightshift/ui-components 5.0.0 → 5.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/dist/Button-wERNNG0T.js +185 -0
- package/dist/Collection-CKsHTyhc.js +2363 -0
- package/dist/Color-BhgbJF5x.js +2452 -0
- package/dist/ColorSwatch-Bcn6oRSg.js +64 -0
- package/dist/ComboBox-D1LPUwWP.js +1906 -0
- package/dist/Dialog-D190gMbE.js +2298 -0
- package/dist/FieldError-DeUh5Wkw.js +42 -0
- package/dist/FocusScope-C-plSxbS.js +831 -0
- package/dist/Form-Cq3fu75_.js +5 -0
- package/dist/Group-C5iZpSAM.js +48 -0
- package/dist/Heading-D-Pboe4p.js +16 -0
- package/dist/Hidden-rE6uR-lr.js +41 -0
- package/dist/Input--mF4XVE1.js +133 -0
- package/dist/Label-Fp6AwSRn.js +17 -0
- package/dist/List-CZMUbkFU.js +593 -0
- package/dist/ListBox-4oW9kh3R.js +582 -0
- package/dist/NumberFormatter-DA8u1Ot7.js +140 -0
- package/dist/OverlayArrow-BpB9uB_I.js +637 -0
- package/dist/RSPContexts-2lR5GG9p.js +14 -0
- package/dist/Select-aab027f3.esm-BKIJGje-.js +2469 -0
- package/dist/Separator-B88tj5YD.js +323 -0
- package/dist/Slider-CyJzC1bp.js +853 -0
- package/dist/Text-DRpwWot2.js +16 -0
- package/dist/VisuallyHidden-DsKYcRQ_.js +48 -0
- package/dist/_commonjsHelpers-CUmg6egw.js +6 -0
- package/dist/assets/index.css +57 -0
- package/dist/assets/style-admin.css +5864 -0
- package/dist/assets/style-editor.css +5864 -0
- package/dist/assets/style.css +5870 -0
- package/dist/assets/wp-font-enhancements.css +8 -0
- package/dist/assets/wp-ui-enhancements.css +377 -0
- package/dist/components/animated-visibility/animated-visibility.js +105 -0
- package/dist/components/base-control/base-control.js +86 -0
- package/dist/components/breakpoint-preview/breakpoint-preview.js +161 -0
- package/dist/components/button/button.js +387 -0
- package/dist/components/checkbox/checkbox.js +320 -0
- package/dist/components/color-pickers/color-picker.js +272 -0
- package/dist/components/color-pickers/color-swatch.js +59 -0
- package/dist/components/color-pickers/gradient-editor.js +534 -0
- package/dist/components/color-pickers/solid-color-picker.js +1567 -0
- package/dist/components/component-toggle/component-toggle.js +161 -0
- package/dist/components/container-panel/container-panel.js +131 -0
- package/dist/components/draggable/draggable-context.js +5 -0
- package/dist/components/draggable/draggable-handle.js +46 -0
- package/dist/components/draggable/draggable.js +6979 -0
- package/dist/components/draggable-list/draggable-list-context.js +5 -0
- package/dist/components/draggable-list/draggable-list-item.js +77 -0
- package/dist/components/draggable-list/draggable-list.js +151 -0
- package/dist/components/expandable/expandable.js +342 -0
- package/dist/components/index.js +137 -0
- package/dist/components/input-field/input-field.js +231 -0
- package/dist/components/item-collection/item-collection.js +59 -0
- package/dist/components/layout/hstack.js +30 -0
- package/dist/components/layout/vstack.js +30 -0
- package/dist/components/link-input/link-input.js +291 -0
- package/dist/components/matrix-align/matrix-align.js +134 -0
- package/dist/components/menu/menu.js +285 -0
- package/dist/components/modal/modal.js +305 -0
- package/dist/components/notice/notice.js +123 -0
- package/dist/components/number-picker/number-picker.js +292 -0
- package/dist/components/option-select/option-select.js +264 -0
- package/dist/components/options-panel/options-panel.js +158 -0
- package/dist/components/placeholders/file-placeholder.js +42 -0
- package/dist/components/placeholders/image-placeholder.js +88 -0
- package/dist/components/placeholders/media-placeholder.js +63 -0
- package/dist/components/popover/popover.js +207 -0
- package/dist/components/radio/radio.js +579 -0
- package/dist/components/repeater/repeater-context.js +5 -0
- package/dist/components/repeater/repeater-item.js +119 -0
- package/dist/components/repeater/repeater.js +280 -0
- package/dist/components/responsive/mini-responsive.js +498 -0
- package/dist/components/responsive/responsive-legacy.js +343 -0
- package/dist/components/responsive/responsive.js +583 -0
- package/dist/components/responsive-preview/responsive-preview.js +123 -0
- package/dist/components/rich-label/rich-label.js +66 -0
- package/dist/components/select/async-multi-select.js +157 -0
- package/dist/components/select/async-single-select.js +137 -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 +151 -0
- package/dist/components/select/react-select-component-wrappers.js +90 -0
- package/dist/components/select/shared.js +26 -0
- package/dist/components/select/single-select.js +131 -0
- package/dist/components/select/styles.js +49 -0
- package/dist/components/select/v2/async-select.js +297 -0
- package/dist/components/select/v2/shared.js +24 -0
- package/dist/components/select/v2/single-select.js +991 -0
- package/dist/components/slider/column-config-slider.js +210 -0
- package/dist/components/slider/slider.js +345 -0
- package/dist/components/slider/utils.js +94 -0
- package/dist/components/spacer/spacer.js +97 -0
- package/dist/components/tabs/tabs.js +704 -0
- package/dist/components/toggle/switch.js +156 -0
- package/dist/components/toggle/toggle.js +64 -0
- package/dist/components/toggle-button/toggle-button.js +343 -0
- package/dist/components/tooltip/tooltip.js +527 -0
- package/dist/context-BYWrbm1z.js +92 -0
- package/dist/default-i18n-CT_oS1Fy.js +922 -0
- package/dist/filterDOMProps-EDDcM64A.js +28 -0
- package/dist/icons/block-icon.js +42 -0
- package/dist/icons/generic-color-swatch.js +113 -0
- package/dist/icons/icons.js +30371 -0
- package/dist/icons/index.js +11 -0
- package/dist/icons/jsx-svg.js +50 -0
- package/dist/index-641ee5b8.esm-BPU8rMZr.js +3137 -0
- package/dist/index-CFozsmNS.js +28321 -0
- package/dist/index-wl5606BX.js +44 -0
- package/dist/index.js +139 -0
- package/dist/lite-DVmmD_-j.js +7 -0
- package/dist/modifiers.esm-BuJQPI1X.js +31 -0
- package/dist/multi-select-components-Sp-JEFEX.js +3744 -0
- package/dist/number-GajL10e1.js +36 -0
- package/dist/react-jsx-parser.min-DZCiis5V.js +11753 -0
- package/dist/react-select-async.esm-D937XTWW.js +107 -0
- package/dist/react-select.esm-Ciai3aKf.js +15 -0
- package/dist/style-admin.js +1 -0
- package/dist/style-editor.js +1 -0
- package/dist/style.js +1 -0
- package/dist/textSelection-CCcyjiRP.js +46 -0
- package/dist/useButton-BOHxkGQF.js +50 -0
- package/dist/useEvent-D5o_CqDH.js +23 -0
- package/dist/useFocusRing-nMG2uzxS.js +107 -0
- package/dist/useFormReset-DlmRL87g.js +22 -0
- package/dist/useFormValidation-D0_aaK-e.js +224 -0
- package/dist/useHover-VO5tcIli.js +890 -0
- package/dist/useLabel-BKH4fVA4.js +27 -0
- package/dist/useLabels-ntF3rFY0.js +23 -0
- package/dist/useListState-Cq2Nvr-v.js +161 -0
- package/dist/useLocalizedStringFormatter-CGzwx1a0.js +121 -0
- package/dist/useNumberField-C9dmERhP.js +1207 -0
- package/dist/useNumberFormatter-MrRLgvhj.js +13 -0
- package/dist/usePress-DjNo5790.js +677 -0
- package/dist/useSingleSelectListState--r3AAhRj.js +38 -0
- package/dist/useToggle-CQaXLe-O.js +59 -0
- package/dist/useToggleState-C3DLdez5.js +19 -0
- package/dist/utilities/array-helpers.js +56 -0
- package/dist/utilities/debounce-throttle.js +123 -0
- package/dist/utilities/es-dash.js +382 -0
- package/dist/utilities/index.js +27 -0
- package/dist/utilities/text-helpers.js +136 -0
- package/dist/utils-B94NDG0v.js +370 -0
- package/dist/wp/wp-font-enhancements.js +1 -0
- package/dist/wp/wp-ui-enhancements.js +1 -0
- package/package.json +8 -8
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from "../button/button.js";
|
|
3
|
+
import { Menu, MenuSeparator, MenuItem } from "../menu/menu.js";
|
|
4
|
+
import { icons } from "../../icons/icons.js";
|
|
5
|
+
import { c as clsx } from "../../lite-DVmmD_-j.js";
|
|
6
|
+
import { useContext } from "react";
|
|
7
|
+
import { Expandable } from "../expandable/expandable.js";
|
|
8
|
+
import { _ as __ } from "../../default-i18n-CT_oS1Fy.js";
|
|
9
|
+
import { RepeaterContext } from "./repeater-context.js";
|
|
10
|
+
/**
|
|
11
|
+
* A Repeater item.
|
|
12
|
+
*
|
|
13
|
+
* @component
|
|
14
|
+
* @param {Object} props - Component props.
|
|
15
|
+
* @param {JSX.Element} [props.icon] - Icon to display in the label.
|
|
16
|
+
* @param {string} [props.label] - Label to display.
|
|
17
|
+
* @param {string} [props.subtitle] - Subtitle to display.
|
|
18
|
+
* @param {JSX.Element|JSX.Element[]} [props.actions] - Actions to display to the right of the label.
|
|
19
|
+
* @param {string} [props.textValue] - The text value of the item.
|
|
20
|
+
* @param {string} [props.className] - Classes to pass to the item.
|
|
21
|
+
* @param {JSX.Element|JSX.Element[]} [props.menuOptions] - Additional menu options to display next to the expand button.
|
|
22
|
+
* @param {bool} [props.noMenuButton] - If `true`, the menu button next to the expand button is not displayed.
|
|
23
|
+
* @param {bool} [props.expandDisabled] - If `true`, the item cannot be expanded.
|
|
24
|
+
*
|
|
25
|
+
* @returns {JSX.Element} The RepeaterItem component.
|
|
26
|
+
*
|
|
27
|
+
* @see {@link Repeater} for usage example.
|
|
28
|
+
*
|
|
29
|
+
* @preserve
|
|
30
|
+
*/
|
|
31
|
+
const RepeaterItem = (props) => {
|
|
32
|
+
const { children, icon, label, subtitle, "aria-label": ariaLabel, className, actions, textValue, expandDisabled, menuOptions, noMenuButton, ...rest } = props;
|
|
33
|
+
const { deleteItem, duplicateItem, isDragged, isOutOfBounds, isSelected, canDelete, canAdd, allOpen, setAllOpen } = useContext(RepeaterContext);
|
|
34
|
+
return /* @__PURE__ */ jsx(
|
|
35
|
+
Expandable,
|
|
36
|
+
{
|
|
37
|
+
icon: isOutOfBounds ? icons.trash : icon,
|
|
38
|
+
label: isOutOfBounds ? __("Release to delete", "eightshift-ui-components") : label,
|
|
39
|
+
subtitle: isOutOfBounds ? null : subtitle,
|
|
40
|
+
className: clsx(
|
|
41
|
+
"es:transition",
|
|
42
|
+
isDragged && "es:border es:border-secondary-100 es:bg-white/50 es:shadow-md es:backdrop-blur-lg",
|
|
43
|
+
isOutOfBounds && "es:border es:border-red-200! es:bg-red-50 es:shadow-red-500/20 es:[&_button]:invisible es:[&_svg_path]:stroke-red-500"
|
|
44
|
+
),
|
|
45
|
+
labelClassName: clsx(className, isDragged ? "es:cursor-grabbing" : "es:cursor-grab"),
|
|
46
|
+
headerClassName: clsx(
|
|
47
|
+
"es:transition es:rounded-lg es:border es:border-transparent",
|
|
48
|
+
isSelected && "es:bg-accent-50 es:border-accent-100",
|
|
49
|
+
"es:group-focus:outline-hidden es:group-focus:border-accent-500 es:group-focus:ring-2 es:group-focus:ring-accent-500/50"
|
|
50
|
+
),
|
|
51
|
+
open: allOpen,
|
|
52
|
+
onOpenChange: (open) => {
|
|
53
|
+
if (allOpen && !open) {
|
|
54
|
+
setAllOpen(false);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
customOpenButton: ({ open, toggleOpen, tooltip, disabled }) => {
|
|
58
|
+
return /* @__PURE__ */ jsxs("div", { className: "es:flex es:items-center es:gap-px", children: [
|
|
59
|
+
/* @__PURE__ */ jsxs(
|
|
60
|
+
Menu,
|
|
61
|
+
{
|
|
62
|
+
hidden: noMenuButton,
|
|
63
|
+
triggerIcon: icons.moreH,
|
|
64
|
+
triggerProps: {
|
|
65
|
+
className: "es:icon:size-5 es:icon:shrink-0",
|
|
66
|
+
size: "small",
|
|
67
|
+
type: "ghost"
|
|
68
|
+
},
|
|
69
|
+
tooltip: __("More options", "eightshift-ui-components"),
|
|
70
|
+
children: [
|
|
71
|
+
menuOptions,
|
|
72
|
+
menuOptions && /* @__PURE__ */ jsx(MenuSeparator, {}),
|
|
73
|
+
/* @__PURE__ */ jsx(
|
|
74
|
+
MenuItem,
|
|
75
|
+
{
|
|
76
|
+
disabled: !canAdd,
|
|
77
|
+
icon: icons.copy,
|
|
78
|
+
onPress: () => duplicateItem(),
|
|
79
|
+
children: __("Duplicate", "eightshift-ui-components")
|
|
80
|
+
}
|
|
81
|
+
),
|
|
82
|
+
/* @__PURE__ */ jsx(
|
|
83
|
+
MenuItem,
|
|
84
|
+
{
|
|
85
|
+
disabled: !canDelete,
|
|
86
|
+
icon: icons.trash,
|
|
87
|
+
onPress: () => deleteItem(),
|
|
88
|
+
children: __("Remove", "eightshift-ui-components")
|
|
89
|
+
}
|
|
90
|
+
)
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
),
|
|
94
|
+
/* @__PURE__ */ jsx(
|
|
95
|
+
Button,
|
|
96
|
+
{
|
|
97
|
+
type: "ghost",
|
|
98
|
+
icon: open ? icons.caretDownFill : icons.caretDown,
|
|
99
|
+
onPress: toggleOpen,
|
|
100
|
+
tooltip,
|
|
101
|
+
disabled,
|
|
102
|
+
className: clsx("es:icon:size-5 es:icon:transition-transform", open && "es:icon:-scale-y-100"),
|
|
103
|
+
size: "small"
|
|
104
|
+
}
|
|
105
|
+
)
|
|
106
|
+
] });
|
|
107
|
+
},
|
|
108
|
+
actions,
|
|
109
|
+
headerProps: { "data-movable-handle": true },
|
|
110
|
+
noFocusHandling: true,
|
|
111
|
+
...rest,
|
|
112
|
+
children
|
|
113
|
+
},
|
|
114
|
+
allOpen
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
export {
|
|
118
|
+
RepeaterItem
|
|
119
|
+
};
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useId, useState } from "react";
|
|
3
|
+
import { _ as __ } from "../../default-i18n-CT_oS1Fy.js";
|
|
4
|
+
import { Button } from "../button/button.js";
|
|
5
|
+
import { icons } from "../../icons/icons.js";
|
|
6
|
+
import { BaseControl } from "../base-control/base-control.js";
|
|
7
|
+
import { AnimatedVisibility } from "../animated-visibility/animated-visibility.js";
|
|
8
|
+
import { RepeaterContext } from "./repeater-context.js";
|
|
9
|
+
import { c as clsx } from "../../lite-DVmmD_-j.js";
|
|
10
|
+
import { L as List, a as arrayRemove, b as arrayMove } from "../../List-CZMUbkFU.js";
|
|
11
|
+
import { Menu, MenuItem, MenuSeparator } from "../menu/menu.js";
|
|
12
|
+
const fixIds = (items, itemIdBase) => {
|
|
13
|
+
return items == null ? void 0 : items.map((item, i) => ({
|
|
14
|
+
...item,
|
|
15
|
+
id: (item == null ? void 0 : item.id) ?? `${itemIdBase}-${i}`
|
|
16
|
+
}));
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A component that allows re-ordering a list of items with additional sub-options.
|
|
20
|
+
*
|
|
21
|
+
* @component
|
|
22
|
+
* @param {Object} props - Component props.
|
|
23
|
+
* @param {JSX.Element} [props.icon] - Icon to display in the label.
|
|
24
|
+
* @param {string} [props.label] - Label to display.
|
|
25
|
+
* @param {string} [props.subtitle] - Subtitle to display.
|
|
26
|
+
* @param {string} [props.help] - Help text to display below the input.
|
|
27
|
+
* @param {JSX.Element|JSX.Element[]} [props.actions] - Actions to display to the right of the label.
|
|
28
|
+
* @param {Object<string, any>[]} props.items - Data to display in the repeater.
|
|
29
|
+
* @param {boolean} [props.hideEmptyState] - If `true`, the empty state will not be displayed when there are no items.
|
|
30
|
+
* @param {Object<string, any>} [props.addDefaultItem] - Additional properties to add to a new item.
|
|
31
|
+
* @param {boolean} [props.addDisabled] - If `true`, the add button is disabled.
|
|
32
|
+
* @param {Function} props.onChange - Function to run when the items change.
|
|
33
|
+
* @param {Function} [props.onAfterItemAdd] - Function to run after an item is added.
|
|
34
|
+
* @param {Function} [props.onAfterItemRemove] - Function to run after an item is removed.
|
|
35
|
+
* @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.
|
|
36
|
+
* @param {Number} [props.maxItems] - The maximum number of items that can be present. If there are more items than this, adding items will be disabled.
|
|
37
|
+
* @param {boolean} [props.hidden] - If `true`, the component is not rendered.
|
|
38
|
+
* @param {JSX.Element} [props.addButton] - If provided, overrides the default add button. `(props: { addItem: (additional: Object<string, any>?) => void, disabled: Boolean }) => JSX.Element`.
|
|
39
|
+
* @param {string} [props.className] - Classes to pass to the item wrapper.
|
|
40
|
+
* @param {boolean} [props.noExpandAllButton] - If `true`, the "Expand all"/"Collapse all" button is not displayed.
|
|
41
|
+
* @param {JSX.Element|JSX.Element[]} [props.moreOptions] - Options to add in the "More options" menu.
|
|
42
|
+
* @param {JSX.Element} [props.emptyState] - Allows overriding the default empty state.
|
|
43
|
+
*
|
|
44
|
+
* @returns {JSX.Element} The Repeater component.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* <Repeater
|
|
48
|
+
* label='My repeater'
|
|
49
|
+
* items={items}
|
|
50
|
+
* onChange={setItems}
|
|
51
|
+
* >
|
|
52
|
+
* {(item) => {
|
|
53
|
+
* const { title, updateData } = item;
|
|
54
|
+
*
|
|
55
|
+
* return (
|
|
56
|
+
* <RepeaterItem
|
|
57
|
+
* label={title ?? 'New item'}
|
|
58
|
+
* icon={icons.myIcon}
|
|
59
|
+
* >
|
|
60
|
+
* <InputField
|
|
61
|
+
* label='Title'
|
|
62
|
+
* type='text'
|
|
63
|
+
* value={title}
|
|
64
|
+
* onChange={(value) => updateData({ title: value })}
|
|
65
|
+
* />
|
|
66
|
+
* </RepeaterItem>
|
|
67
|
+
* );
|
|
68
|
+
* }}
|
|
69
|
+
* </Repeater>
|
|
70
|
+
*
|
|
71
|
+
* @preserve
|
|
72
|
+
*/
|
|
73
|
+
const Repeater = (props) => {
|
|
74
|
+
const itemIdBase = `item-${useId().replaceAll(":", "")}`;
|
|
75
|
+
const {
|
|
76
|
+
children,
|
|
77
|
+
onChange,
|
|
78
|
+
items: rawItems,
|
|
79
|
+
icon,
|
|
80
|
+
label,
|
|
81
|
+
subtitle,
|
|
82
|
+
help,
|
|
83
|
+
actions,
|
|
84
|
+
hideEmptyState,
|
|
85
|
+
addDefaultItem = {},
|
|
86
|
+
addDisabled,
|
|
87
|
+
onAfterItemAdd,
|
|
88
|
+
onAfterItemRemove,
|
|
89
|
+
minItems,
|
|
90
|
+
maxItems,
|
|
91
|
+
addButton,
|
|
92
|
+
className,
|
|
93
|
+
emptyState,
|
|
94
|
+
noExpandAllButton,
|
|
95
|
+
moreOptions,
|
|
96
|
+
hidden
|
|
97
|
+
} = props;
|
|
98
|
+
const [allOpen, setAllOpen] = useState(false);
|
|
99
|
+
if (typeof rawItems === "undefined" || rawItems === null || !Array.isArray(rawItems)) {
|
|
100
|
+
console.warn(__("Repeater: 'items' are not an array or are undefined!", "eightshift-ui-components"));
|
|
101
|
+
}
|
|
102
|
+
const items = fixIds(rawItems ?? [], itemIdBase);
|
|
103
|
+
const canDelete = items.length > (minItems ?? 0);
|
|
104
|
+
const canAdd = items.length < (maxItems ?? Number.MAX_SAFE_INTEGER);
|
|
105
|
+
if (hidden) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
return /* @__PURE__ */ jsxs(
|
|
109
|
+
BaseControl,
|
|
110
|
+
{
|
|
111
|
+
icon,
|
|
112
|
+
label,
|
|
113
|
+
subtitle,
|
|
114
|
+
help,
|
|
115
|
+
actions: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
116
|
+
actions,
|
|
117
|
+
/* @__PURE__ */ jsxs(
|
|
118
|
+
Menu,
|
|
119
|
+
{
|
|
120
|
+
tooltip: __("More options", "eightshift-ui-components"),
|
|
121
|
+
triggerIcon: icons.moreH,
|
|
122
|
+
triggerProps: { type: "ghost", size: "small" },
|
|
123
|
+
hidden: (items == null ? void 0 : items.length) < 1 || noExpandAllButton && !moreOptions,
|
|
124
|
+
children: [
|
|
125
|
+
!noExpandAllButton && /* @__PURE__ */ jsx(
|
|
126
|
+
MenuItem,
|
|
127
|
+
{
|
|
128
|
+
endIcon: allOpen ? icons.panelCollapse : icons.panelExpand,
|
|
129
|
+
onClick: () => setAllOpen(!allOpen),
|
|
130
|
+
children: allOpen ? __("Collapse all", "eightshift-ui-components") : __("Expand all", "eightshift-ui-components")
|
|
131
|
+
}
|
|
132
|
+
),
|
|
133
|
+
moreOptions && /* @__PURE__ */ jsx(MenuSeparator, {}),
|
|
134
|
+
moreOptions
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
),
|
|
138
|
+
!addButton && /* @__PURE__ */ jsx(
|
|
139
|
+
Button,
|
|
140
|
+
{
|
|
141
|
+
onPress: () => {
|
|
142
|
+
const newItem = { id: `${itemIdBase}${items.length + 1}`, ...addDefaultItem };
|
|
143
|
+
onChange([...items, newItem]);
|
|
144
|
+
if (onAfterItemAdd) {
|
|
145
|
+
onAfterItemAdd(newItem);
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
size: "small",
|
|
149
|
+
icon: icons.add,
|
|
150
|
+
className: clsx("es:icon:size-4", !hideEmptyState && items.length < 1 && "es:invisible"),
|
|
151
|
+
tooltip: __("Add item", "eightshift-ui-components"),
|
|
152
|
+
disabled: addDisabled || !canAdd
|
|
153
|
+
}
|
|
154
|
+
),
|
|
155
|
+
addButton && /* @__PURE__ */ jsx("div", { className: clsx(!hideEmptyState && items.length < 1 && "es:invisible"), children: addButton({
|
|
156
|
+
addItem: (additional = {}) => {
|
|
157
|
+
const newItem = { id: `${itemIdBase}${items.length + 1}`, ...addDefaultItem, ...additional };
|
|
158
|
+
onChange([...items, newItem]);
|
|
159
|
+
if (onAfterItemAdd) {
|
|
160
|
+
onAfterItemAdd(newItem);
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
disabled: addDisabled
|
|
164
|
+
}) })
|
|
165
|
+
] }),
|
|
166
|
+
className: "es:w-full",
|
|
167
|
+
children: [
|
|
168
|
+
/* @__PURE__ */ jsx(
|
|
169
|
+
List,
|
|
170
|
+
{
|
|
171
|
+
values: items,
|
|
172
|
+
onChange: ({ oldIndex, newIndex }) => onChange(newIndex === -1 ? arrayRemove(items, oldIndex) : arrayMove(items, oldIndex, newIndex)),
|
|
173
|
+
renderList: ({ children: children2, props: props2 }) => {
|
|
174
|
+
const { key, ...rest } = props2;
|
|
175
|
+
return /* @__PURE__ */ jsx(
|
|
176
|
+
"ul",
|
|
177
|
+
{
|
|
178
|
+
className: clsx("es:w-full es:list-none", className),
|
|
179
|
+
...rest,
|
|
180
|
+
children: children2
|
|
181
|
+
},
|
|
182
|
+
key
|
|
183
|
+
);
|
|
184
|
+
},
|
|
185
|
+
renderItem: ({ value: item, index, isDragged, isSelected, isOutOfBounds, props: props2 }) => {
|
|
186
|
+
const { key, ...rest } = props2;
|
|
187
|
+
return /* @__PURE__ */ jsx(
|
|
188
|
+
"li",
|
|
189
|
+
{
|
|
190
|
+
className: "es:group es:w-full es:list-none es:any-focus:outline-hidden",
|
|
191
|
+
...rest,
|
|
192
|
+
children: /* @__PURE__ */ jsx(
|
|
193
|
+
RepeaterContext.Provider,
|
|
194
|
+
{
|
|
195
|
+
value: {
|
|
196
|
+
...item,
|
|
197
|
+
index,
|
|
198
|
+
deleteItem: () => {
|
|
199
|
+
onChange([...items].filter((i) => i.id !== item.id));
|
|
200
|
+
if (onAfterItemRemove) {
|
|
201
|
+
onAfterItemRemove(item);
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
duplicateItem: () => {
|
|
205
|
+
const newItem = { ...item, id: `${itemIdBase}${items.length + 1}` };
|
|
206
|
+
onChange([...items, newItem]);
|
|
207
|
+
if (onAfterItemAdd) {
|
|
208
|
+
onAfterItemAdd(newItem);
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
isDragged,
|
|
212
|
+
isOutOfBounds,
|
|
213
|
+
isSelected,
|
|
214
|
+
canDelete,
|
|
215
|
+
canAdd,
|
|
216
|
+
allOpen,
|
|
217
|
+
setAllOpen
|
|
218
|
+
},
|
|
219
|
+
children: children({
|
|
220
|
+
...item,
|
|
221
|
+
updateData: (newValue) => {
|
|
222
|
+
const updated = [...items].map((i) => i.id === item.id ? { ...i, ...newValue } : i);
|
|
223
|
+
onChange(updated);
|
|
224
|
+
},
|
|
225
|
+
itemIndex: index,
|
|
226
|
+
deleteItem: () => {
|
|
227
|
+
onChange([...items].filter((i) => i.id !== item.id));
|
|
228
|
+
if (onAfterItemRemove) {
|
|
229
|
+
onAfterItemRemove(item);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
})
|
|
233
|
+
}
|
|
234
|
+
)
|
|
235
|
+
},
|
|
236
|
+
(item == null ? void 0 : item.id) ?? key
|
|
237
|
+
);
|
|
238
|
+
},
|
|
239
|
+
removableByMove: true
|
|
240
|
+
}
|
|
241
|
+
),
|
|
242
|
+
/* @__PURE__ */ jsxs(AnimatedVisibility, { visible: items.length < 1, children: [
|
|
243
|
+
emptyState,
|
|
244
|
+
!hideEmptyState && /* @__PURE__ */ jsxs("div", { className: "es:flex es:flex-col es:items-center es:gap-2 es:rounded-md es:border es:border-dashed es:border-secondary-300 es:p-4 es:text-center es:text-sm es:text-secondary-400", children: [
|
|
245
|
+
!addButton && /* @__PURE__ */ jsx(
|
|
246
|
+
Button,
|
|
247
|
+
{
|
|
248
|
+
onPress: () => {
|
|
249
|
+
const newItem = { id: `${itemIdBase}${items.length + 1}`, ...addDefaultItem };
|
|
250
|
+
onChange([...items, newItem]);
|
|
251
|
+
if (onAfterItemAdd) {
|
|
252
|
+
onAfterItemAdd(newItem);
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
size: "small",
|
|
256
|
+
icon: icons.add,
|
|
257
|
+
className: "es:icon:size-4",
|
|
258
|
+
disabled: addDisabled,
|
|
259
|
+
children: __("Add item", "eightshift-ui-components")
|
|
260
|
+
}
|
|
261
|
+
),
|
|
262
|
+
addButton && !hideEmptyState && addButton({
|
|
263
|
+
addItem: (additional = {}) => {
|
|
264
|
+
const newItem = { id: `${itemIdBase}${items.length + 1}`, ...addDefaultItem, ...additional };
|
|
265
|
+
onChange([...items, newItem]);
|
|
266
|
+
if (onAfterItemAdd) {
|
|
267
|
+
onAfterItemAdd(newItem);
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
disabled: addDisabled
|
|
271
|
+
})
|
|
272
|
+
] })
|
|
273
|
+
] })
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
);
|
|
277
|
+
};
|
|
278
|
+
export {
|
|
279
|
+
Repeater
|
|
280
|
+
};
|