From 66fd308403ccdafff5cf0026d94ceae525cb21b5 Mon Sep 17 00:00:00 2001 From: philcable Date: Tue, 27 Aug 2019 10:17:35 -0700 Subject: [PATCH 01/15] Consolidate aside edit function into primary file --- src/blocks/aside/aside.js | 82 ++++++++++++++++++++++++++++++++------- src/blocks/aside/edit.js | 65 ------------------------------- 2 files changed, 68 insertions(+), 79 deletions(-) delete mode 100644 src/blocks/aside/edit.js diff --git a/src/blocks/aside/aside.js b/src/blocks/aside/aside.js index 74712dd6..ccb713e1 100644 --- a/src/blocks/aside/aside.js +++ b/src/blocks/aside/aside.js @@ -14,18 +14,43 @@ import './editor.scss'; // Internal dependencies. import RegisterBlockPreset from '../../global/register-block-preset.js'; +import themeOptions from '../../global/theme-options.js'; +import allowedBlocks from '../../components/allowed-blocks'; // WordPress dependencies. -const { __ } = wp.i18n; -const { registerBlockType } = wp.blocks; -const { getColorClassName, InnerBlocks } = wp.editor; +const { + __, +} = wp.i18n; +const { + registerBlockType, +} = wp.blocks; +const { + InnerBlocks, + InspectorControls, + PanelColorSettings, + withColors, +} = wp.editor; +const { + Fragment, +} = wp.element; -// Internal dependencies. -import edit from './edit.js'; +/** + * Returns the class list for the block based on the current settings. + * + * @param {string} className Classes assigned to the block. + * @param {string} themeColor The theme color assigned to the block. + */ +const getClasses = ( className, themeColor ) => { + return classnames( + className, + { + [ `has-${themeColor}-background` ]: themeColor, + }, + ); +}; // Register the block. const asideBlock = registerBlockType( 'editorial/aside', { - title: __( 'Aside' ), description: __( 'Add an aside with related information. Accepts image, headline, paragraph, and button blocks as children.' ), icon: 'format-aside', @@ -39,18 +64,47 @@ const asideBlock = registerBlockType( 'editorial/aside', { }, }, - edit, - - save( { attributes, className } ) { - const { themeColor } = attributes; - - const classes = classnames( + edit: withColors( 'themeColor' )( props => { + const { className, - { [ getColorClassName( 'background', themeColor ) ]: getColorClassName( 'background', themeColor ) } + themeColor, + setThemeColor, + presetTemplate, + } = props; + + return ( + + + + + + ); + } ), + + save( { attributes, className } ) { + const { + themeColor + } = attributes; return ( -