@wordpress/block-library
Version:
Block library for the WordPress editor.
68 lines (67 loc) • 3.05 kB
JavaScript
import clsx from "clsx";
import { __, _x, sprintf } from "@wordpress/i18n";
import { Warning, __experimentalGetElementClassName, store } from "@wordpress/block-editor";
import { Button } from "@wordpress/components";
import { useInstanceId } from "@wordpress/compose";
import { store as store$1, useEntityProp } from "@wordpress/core-data";
import { useSelect } from "@wordpress/data";
import { jsx, jsxs } from "react/jsx-runtime";
// packages/block-library/src/post-comments-form/form.jsx
const CommentsFormPlaceholder = () => {
const instanceId = useInstanceId(CommentsFormPlaceholder);
return /* @__PURE__ */ jsxs("div", {
className: "comment-respond",
children: [/* @__PURE__ */ jsx("h3", {
className: "comment-reply-title",
children: __("Leave a Reply")
}), /* @__PURE__ */ jsxs("form", {
noValidate: true,
className: "comment-form",
onSubmit: (event) => event.preventDefault(),
children: [/* @__PURE__ */ jsxs("p", { children: [/* @__PURE__ */ jsx("label", {
htmlFor: `comment-${instanceId}`,
children: __("Comment")
}), /* @__PURE__ */ jsx("textarea", {
id: `comment-${instanceId}`,
name: "comment",
cols: "45",
rows: "8",
readOnly: true
})] }), /* @__PURE__ */ jsx("p", {
className: "form-submit wp-block-button",
children: /* @__PURE__ */ jsx("input", {
name: "submit",
type: "submit",
className: clsx("wp-block-button__link", __experimentalGetElementClassName("button")),
label: __("Post Comment"),
value: __("Post Comment"),
"aria-disabled": "true"
})
})]
})]
});
};
const CommentsForm = ({ postId, postType }) => {
const [commentStatus, setCommentStatus] = useEntityProp("postType", postType, "comment_status", postId);
const isSiteEditor = postType === void 0 || postId === void 0;
const defaultCommentStatus = useSelect((select) => select(store).getSettings().__experimentalDiscussionSettings?.defaultCommentStatus, []);
const postTypeSupportsComments = useSelect((select) => postType ? !!select(store$1).getPostType(postType)?.supports.comments : false);
if (!isSiteEditor && "open" !== commentStatus) {
if ("closed" === commentStatus) {
const actions = [/* @__PURE__ */ jsx(Button, {
__next40pxDefaultSize: true,
onClick: () => setCommentStatus("open"),
variant: "primary",
children: _x("Enable comments", "action that affects the current post")
}, "enableComments")];
return /* @__PURE__ */ jsx(Warning, {
actions,
children: __("Post Comments Form block: Comments are not enabled for this item.")
});
} else if (!postTypeSupportsComments) return /* @__PURE__ */ jsx(Warning, { children: sprintf(__("Post Comments Form block: Comments are not enabled for this post type (%s)."), postType) });
else if ("open" !== defaultCommentStatus) return /* @__PURE__ */ jsx(Warning, { children: __("Post Comments Form block: Comments are not enabled.") });
}
return /* @__PURE__ */ jsx(CommentsFormPlaceholder, {});
};
export { CommentsForm as default };
//# sourceMappingURL=form.mjs.map