下面是一个示例块,取自WordPress/gutenberg-examples 添加占位符文本。
const { __, setLocaleData } = wp.i18n;
const { registerBlockType } = wp.blocks;
const { RichText } = wp.editor;
setLocaleData( window.gutenberg_examples_03_esnext.localeData, \'gutenberg-examples\' );
registerBlockType( \'gutenberg-examples/example-03-editable-esnext\', {
title: __( \'Example: Editable (esnext)\', \'gutenberg-examples\' ),
icon: \'universal-access-alt\',
category: \'layout\',
attributes: {
content: {
type: \'array\',
source: \'children\',
selector: \'p\',
},
},
edit: ( props ) => {
const { attributes: { content }, setAttributes, className } = props;
const onChangeContent = ( newContent ) => {
setAttributes( { content: newContent } );
};
return (
<RichText
tagName="p"
className={ className }
onChange={ onChangeContent }
value={ content }
placeholder={__(\'wpse316624 placeholder text\', \'custom-block\')}
/>
);
},
save: ( props ) => {
return <RichText.Content tagName="p" value={ props.attributes.content } />;
},
} );