Created
November 22, 2019 02:45
-
-
Save wadadanet/fa62c4418d67060c29e23c1e4c62a5bd to your computer and use it in GitHub Desktop.
フキダシ用GutenbergBlock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* BLOCK: fukidashi-block | |
* | |
* フキダシ表示ができるブロック | |
*/ | |
// Import CSS. | |
import './editor.scss'; | |
import './style.scss'; | |
const { registerBlockType } = wp.blocks; // Import registerBlockType() from wp.blocks | |
import { RichText, InnerBlocks } from '@wordpress/block-editor'; | |
const ALLOWED_BLOCKS = [ 'core/image' ]; | |
const TEMPLATE = [ | |
[ 'core/image' ], | |
]; | |
registerBlockType( 'cgb/block-fukidashi-block', { | |
title: 'フキダシ', | |
icon: 'format-chat', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/. | |
category: 'common', | |
keywords: [ 'fukidashi', 'comment' ], | |
attributes: { | |
comment: { | |
type: 'string', | |
source: 'html', | |
selector: '.comment', | |
}, | |
}, | |
// @link https://wordpress.org/gutenberg/handbook/block-api/block-edit-save/ | |
edit: ( { attributes, setAttributes, className } ) => { | |
const updateComment = ( val ) => { | |
setAttributes( { comment: val } ); | |
}; | |
return <div className={ className }> | |
<div className="image"> | |
<InnerBlocks allowedBlocks={ ALLOWED_BLOCKS } template={ TEMPLATE } templateLock="all" /> | |
</div> | |
<div className="comment"> | |
<RichText | |
label="発言" | |
onChange={ updateComment } | |
value={ attributes.comment } | |
/> | |
</div> | |
</div>; | |
}, | |
// @link https://wordpress.org/gutenberg/handbook/block-api/block-edit-save/ | |
save: ( { attributes, className } ) => { | |
return ( | |
<div className={ className }> | |
<div className="image"><InnerBlocks.Content /></div> | |
<div className="comment"> | |
<RichText.Content value={ attributes.comment } /> | |
</div> | |
</div> | |
); | |
}, | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment