@wordpress/global-styles-ui
Version:
Global Styles UI components for WordPress.
81 lines (80 loc) • 2.11 kB
JavaScript
// packages/global-styles-ui/src/presets/dialogs/rename-dialog.tsx
import {
__experimentalInputControl as WCInputControl,
Button,
Modal
} from "@wordpress/components";
import { __ } from "@wordpress/i18n";
import { useState } from "@wordpress/element";
import { Stack } from "@wordpress/ui";
import { jsx, jsxs } from "react/jsx-runtime";
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(
WCInputControl,
{
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