From 1162ef0238bb8f560ef625ee362de197a32eb416 Mon Sep 17 00:00:00 2001 From: Jorge Date: Wed, 20 Jun 2018 16:25:17 +0100 Subject: [PATCH] Try Layout Block Half Image Half Content --- core-blocks/index.js | 17 +++- .../layout-half-image-text/editor.scss | 11 +++ core-blocks/layout-half-image-text/index.js | 91 +++++++++++++++++++ core-blocks/layout-half-image-text/style.scss | 10 ++ 4 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 core-blocks/layout-half-image-text/editor.scss create mode 100644 core-blocks/layout-half-image-text/index.js create mode 100644 core-blocks/layout-half-image-text/style.scss diff --git a/core-blocks/index.js b/core-blocks/index.js index eb19acfe8b10b..215b2ca864785 100644 --- a/core-blocks/index.js +++ b/core-blocks/index.js @@ -24,6 +24,7 @@ import * as columns from './columns'; import * as coverImage from './cover-image'; import * as embed from './embed'; import * as freeform from './freeform'; +import * as halfImageText from './layout-half-image-text'; import * as html from './html'; import * as latestPosts from './latest-posts'; import * as list from './list'; @@ -41,8 +42,17 @@ import * as textColumns from './text-columns'; import * as verse from './verse'; import * as video from './video'; +const registerArrayOfBlocks = ( blocks ) => { + blocks.forEach( ( { name, settings, children } ) => { + registerBlockType( name, settings ); + if ( children && children.length ) { + registerArrayOfBlocks( children ); + } + } ); +}; + export const registerCoreBlocks = () => { - [ + registerArrayOfBlocks( [ // Common blocks are grouped at the top to prioritize their display // in various contexts — like the inserter and auto-complete components. paragraph, @@ -64,6 +74,7 @@ export const registerCoreBlocks = () => { ...embed.common, ...embed.others, freeform, + halfImageText, html, latestPosts, more, @@ -78,9 +89,7 @@ export const registerCoreBlocks = () => { textColumns, verse, video, - ].forEach( ( { name, settings } ) => { - registerBlockType( name, settings ); - } ); + ] ); setDefaultBlockName( paragraph.name ); setUnknownTypeHandlerName( freeform.name ); diff --git a/core-blocks/layout-half-image-text/editor.scss b/core-blocks/layout-half-image-text/editor.scss new file mode 100644 index 0000000000000..be999bc63ab66 --- /dev/null +++ b/core-blocks/layout-half-image-text/editor.scss @@ -0,0 +1,11 @@ +// workaround for columns setting the width in all descend inner blocks +.half-image__content-area.half-image__content-area > .editor-inner-blocks { + grid-auto-columns: initial; +} + +.layout-column-2 > .editor-block-list__block { + width: 100%; +} +.half-image__content-area { + margin: 0; +} diff --git a/core-blocks/layout-half-image-text/index.js b/core-blocks/layout-half-image-text/index.js new file mode 100644 index 0000000000000..daad3713078ca --- /dev/null +++ b/core-blocks/layout-half-image-text/index.js @@ -0,0 +1,91 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { Fragment } from '@wordpress/element'; +import { + InnerBlocks, +} from '@wordpress/editor'; + +/** + * Internal dependencies + */ +import './style.scss'; +import './editor.scss'; + +export const name = 'core/half-image'; + +export const children = [ { + name: 'core/half-image-content-area', + settings: { + attributes: { + }, + icon: 'columns', + parent: [ 'core/half-image' ], + + category: 'layout', + title: __( 'Half Image - Content Area' ), + edit() { + return ( +
+ +
+ ); + }, + save() { + return ( +
+ +
+ ); + }, + }, +} ]; + +export const settings = { + title: __( 'Half Image' ), + + icon: 'columns', + + category: 'layout', + + attributes: { + }, + + supports: { + align: [ 'wide', 'full' ], + }, + + edit() { + return ( + +
+ +
+
+ ); + }, + + save() { + return ( +
+ +
+ ); + }, +}; diff --git a/core-blocks/layout-half-image-text/style.scss b/core-blocks/layout-half-image-text/style.scss new file mode 100644 index 0000000000000..9e74c896b5217 --- /dev/null +++ b/core-blocks/layout-half-image-text/style.scss @@ -0,0 +1,10 @@ +.layout-column-2 { + word-break: break-word; + display: flex; + flex-direction: column; + justify-content: center; +} + +.half-image__content-area { + margin-left: 28px; +}