@wordpress/block-library
Version:
Block library for the WordPress editor.
58 lines (56 loc) • 1.96 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = Edit;
var _i18n = require("@wordpress/i18n");
var _components = require("@wordpress/components");
var _element = require("@wordpress/element");
var _icons = require("@wordpress/icons");
var _blockEditor = require("@wordpress/block-editor");
var _jsxRuntime = require("react/jsx-runtime");
/**
* WordPress dependencies
*/
const 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] = (0, _element.useState)(commentId);
const blockProps = (0, _blockEditor.useBlockProps)();
const innerBlocksProps = (0, _blockEditor.useInnerBlocksProps)(blockProps, {
template: TEMPLATE
});
if (!commentId) {
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
...blockProps,
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.Placeholder, {
icon: _icons.blockDefault,
label: (0, _i18n._x)('Post Comment', 'block title'),
instructions: (0, _i18n.__)('To show a comment, input the comment ID.'),
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.TextControl, {
__next40pxDefaultSize: true,
__nextHasNoMarginBottom: true,
value: commentId,
onChange: val => setCommentIdInput(parseInt(val))
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
__next40pxDefaultSize: true,
variant: "primary",
onClick: () => {
setAttributes({
commentId: commentIdInput
});
},
children: (0, _i18n.__)('Save')
})]
})
});
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
...innerBlocksProps
});
}
//# sourceMappingURL=edit.js.map
;