@wordpress/global-styles-ui
Version:
Global Styles UI components for WordPress.
53 lines (52 loc) • 1.59 kB
JavaScript
import { Button, Modal, __experimentalInputControl } from "@wordpress/components";
import { __ } from "@wordpress/i18n";
import { useState } from "@wordpress/element";
import { Stack } from "@wordpress/ui";
import { jsx, jsxs } from "react/jsx-runtime";
// packages/global-styles-ui/src/presets/dialogs/rename-dialog.tsx
function RenameDialog({ initialName, placeholder, toggleOpen, onRename }) {
const [newName, setNewName] = useState(initialName);
const handleConfirm = () => {
if (newName && newName.trim()) onRename(newName);
toggleOpen();
};
return /* @__PURE__ */ jsx(Modal, {
onRequestClose: toggleOpen,
focusOnMount: "firstContentElement",
title: __("Rename"),
size: "small",
children: /* @__PURE__ */ jsx("form", {
onSubmit: (event) => {
event.preventDefault();
handleConfirm();
},
children: /* @__PURE__ */ jsxs(Stack, {
gap: "sm",
direction: "column",
children: [/* @__PURE__ */ jsx(__experimentalInputControl, {
autoComplete: "off",
value: newName,
onChange: setNewName,
label: __("Name"),
placeholder
}), /* @__PURE__ */ jsxs(Stack, {
justify: "end",
direction: "row",
children: [/* @__PURE__ */ jsx(Button, {
__next40pxDefaultSize: true,
variant: "tertiary",
onClick: toggleOpen,
children: __("Cancel")
}), /* @__PURE__ */ jsx(Button, {
__next40pxDefaultSize: true,
variant: "primary",
type: "submit",
children: __("Save")
})]
})]
})
})
});
}
export { RenameDialog as default };
//# sourceMappingURL=rename-dialog.mjs.map