UNPKG

@wordpress/block-library

Version:
47 lines (44 loc) 1.68 kB
import { createElement } from "@wordpress/element"; /** * WordPress dependencies */ 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'; const ALLOWED_BLOCKS = ['core/avatar', 'core/comment-author-name', 'core/comment-content', 'core/comment-date', 'core/comment-edit-link', 'core/comment-reply-link']; const TEMPLATE = [['core/avatar'], ['core/comment-author-name'], ['core/comment-date'], ['core/comment-content'], ['core/comment-reply-link'], ['core/comment-edit-link']]; export default function Edit(_ref) { let { attributes: { commentId }, setAttributes } = _ref; const [commentIdInput, setCommentIdInput] = useState(commentId); const blockProps = useBlockProps(); const innerBlocksProps = useInnerBlocksProps(blockProps, { template: TEMPLATE, allowedBlocks: ALLOWED_BLOCKS }); if (!commentId) { return createElement("div", blockProps, createElement(Placeholder, { icon: blockDefault, label: _x('Post Comment', 'block title'), instructions: __('To show a comment, input the comment ID.') }, createElement(TextControl, { value: commentId, onChange: val => setCommentIdInput(parseInt(val)) }), createElement(Button, { variant: "primary", onClick: () => { setAttributes({ commentId: commentIdInput }); } }, __('Save')))); } return createElement("div", innerBlocksProps); } //# sourceMappingURL=edit.js.map