@wordpress/block-library
Version:
Block library for the WordPress editor.
62 lines (61 loc) • 1.91 kB
JavaScript
// packages/block-library/src/post-comment/edit.js
import { __, _x } from "@wordpress/i18n";
import { Placeholder, TextControl, Button } from "@wordpress/components";
import { useState } from "@wordpress/element";
import { blockDefault } from "@wordpress/icons";
import { useBlockProps, useInnerBlocksProps } from "@wordpress/block-editor";
import { jsx, jsxs } from "react/jsx-runtime";
var TEMPLATE = [
["core/avatar"],
["core/comment-author-name"],
["core/comment-date"],
["core/comment-content"],
["core/comment-reply-link"],
["core/comment-edit-link"]
];
function Edit({ attributes: { commentId }, setAttributes }) {
const [commentIdInput, setCommentIdInput] = useState(commentId);
const blockProps = useBlockProps();
const innerBlocksProps = useInnerBlocksProps(blockProps, {
template: TEMPLATE
});
if (!commentId) {
return /* @__PURE__ */ jsx("div", { ...blockProps, children: /* @__PURE__ */ jsxs(
Placeholder,
{
icon: blockDefault,
label: _x("Post Comment", "block title"),
instructions: __(
"To show a comment, input the comment ID."
),
children: [
/* @__PURE__ */ jsx(
TextControl,
{
__next40pxDefaultSize: true,
__nextHasNoMarginBottom: true,
value: commentId,
onChange: (val) => setCommentIdInput(parseInt(val))
}
),
/* @__PURE__ */ jsx(
Button,
{
__next40pxDefaultSize: true,
variant: "primary",
onClick: () => {
setAttributes({ commentId: commentIdInput });
},
children: __("Save")
}
)
]
}
) });
}
return /* @__PURE__ */ jsx("div", { ...innerBlocksProps });
}
export {
Edit as default
};
//# sourceMappingURL=edit.js.map