UNPKG

@wordpress/block-library

Version:
74 lines (73 loc) 2.13 kB
// packages/block-library/src/template-part/edit/title-modal.js import { useState } from "@wordpress/element"; import { __, sprintf } from "@wordpress/i18n"; import { TextControl, Button, Modal, __experimentalHStack as HStack, __experimentalVStack as VStack } from "@wordpress/components"; import { jsx, jsxs } from "react/jsx-runtime"; function TitleModal({ areaLabel, onClose, onSubmit }) { const [title, setTitle] = useState(""); const submitForCreation = (event) => { event.preventDefault(); onSubmit(title); }; return /* @__PURE__ */ jsx( Modal, { title: sprintf( // Translators: %s as template part area title ("Header", "Footer", etc.). __("Create new %s"), areaLabel.toLowerCase() ), onRequestClose: onClose, focusOnMount: "firstContentElement", size: "small", children: /* @__PURE__ */ jsx("form", { onSubmit: submitForCreation, children: /* @__PURE__ */ jsxs(VStack, { spacing: "5", children: [ /* @__PURE__ */ jsx( TextControl, { label: __("Name"), value: title, onChange: setTitle, placeholder: __("Custom Template Part"), __nextHasNoMarginBottom: true, __next40pxDefaultSize: true } ), /* @__PURE__ */ jsxs(HStack, { 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.js.map