@wordpress/block-library
Version:
Block library for the WordPress editor.
51 lines (50 loc) • 1.61 kB
JavaScript
import { useState } from "@wordpress/element";
import { __, sprintf } from "@wordpress/i18n";
import { Button, Modal, TextControl, __experimentalHStack, __experimentalVStack } from "@wordpress/components";
import { jsx, jsxs } from "react/jsx-runtime";
// packages/block-library/src/template-part/edit/title-modal.jsx
function TitleModal({ areaLabel, onClose, onSubmit }) {
const [title, setTitle] = useState("");
const submitForCreation = (event) => {
event.preventDefault();
onSubmit(title);
};
return /* @__PURE__ */ jsx(Modal, {
title: sprintf(__("Create new %s"), areaLabel.toLowerCase()),
onRequestClose: onClose,
focusOnMount: "firstContentElement",
size: "small",
children: /* @__PURE__ */ jsx("form", {
onSubmit: submitForCreation,
children: /* @__PURE__ */ jsxs(__experimentalVStack, {
spacing: "5",
children: [/* @__PURE__ */ jsx(TextControl, {
label: __("Name"),
value: title,
onChange: setTitle,
placeholder: __("Custom Template Part")
}), /* @__PURE__ */ jsxs(__experimentalHStack, {
justify: "right",
children: [/* @__PURE__ */ jsx(Button, {
__next40pxDefaultSize: true,
variant: "tertiary",
onClick: () => {
onClose();
setTitle("");
},
children: __("Cancel")
}), /* @__PURE__ */ jsx(Button, {
variant: "primary",
type: "submit",
accessibleWhenDisabled: true,
disabled: !title.length,
__next40pxDefaultSize: true,
children: __("Create")
})]
})]
})
})
});
}
export { TitleModal as default };
//# sourceMappingURL=title-modal.mjs.map