From a2a7f4bebfb39b7686d4f71d084d2f4e532cadf9 Mon Sep 17 00:00:00 2001 From: ray Date: Sun, 16 Aug 2020 19:47:36 +0100 Subject: [PATCH] add inner blocks, block style variation --- src/index.js | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 26345a2..3844ab5 100644 --- a/src/index.js +++ b/src/index.js @@ -1,13 +1,19 @@ import './style.scss'; import './editor.scss'; -import { registerBlockType } from '@wordpress/blocks'; +import { registerBlockStyle, registerBlockType } from '@wordpress/blocks'; +import { InnerBlocks } from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; const NAMESPACE = 'namespace'; // TODO const SLUG = 'slug'; // TODO const BLOCK_TITLE = 'Block Title'; // TODO +const INNER_TEMPLATE = [ + ['core/heading', { placeholder: 'Article Title', className: 'heading' }], + ['core/paragraph', { placeholder: 'Article Text', className: 'text' }], +]; + registerBlockType(`${NAMESPACE}/${SLUG}`, { title: __(BLOCK_TITLE, SLUG), @@ -19,19 +25,39 @@ registerBlockType(`${NAMESPACE}/${SLUG}`, { }, attributes: { - name: { + text: { type: 'string', source: 'text', selector: 'p', - default: __('A default name', NAMESPACE), + default: __('Some default text.', NAMESPACE), }, }, edit({ attributes, className }) { - return

{attributes.name}

; + return ( +
+
+ +
+

{attributes.text}

+
+ ); }, save({ attributes }) { - return

{attributes.name}

; + return ( +
+
+ +
+

{attributes.text}

+
+ ); }, }); + +registerBlockStyle(`${NAMESPACE}/${SLUG}`, { + name: 'block-style', + label: __('A Block Variation', NAMESPACE), + isDefault: false, +});