Skip to content

Commit

Permalink
Blocks: Render columns as nested column (wrapper)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Jun 8, 2018
1 parent a9fab4d commit a8d9202
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 35 deletions.
33 changes: 33 additions & 0 deletions core-blocks/columns/column.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { InnerBlocks } from '@wordpress/editor';

/**
* Internal dependencies
*/
import './style.scss';
import './editor.scss';

export const name = 'core/column';

export const settings = {
title: __( 'Column' ),

supportedBlocks: [ 'core/columns' ],

icon: 'columns',

description: __( 'A single column within a columns block.' ),

category: 'common',

edit() {
return <InnerBlocks />;
},

save() {
return <div><InnerBlocks.Content /></div>;
},
};
12 changes: 5 additions & 7 deletions core-blocks/columns/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@
.wp-block-columns {
display: block;

.editor-inner-blocks {
display: grid;
grid-auto-flow: dense;
}
> .editor-inner-blocks > .editor-block-list__layout {
display: flex;

@for $i from 2 through 6 {
&.has-#{ $i }-columns .editor-inner-blocks {
grid-auto-columns: #{ 100% / $i };
> [data-type="core/column"] {
flex: 1;
width: 0;
}
}
}
13 changes: 6 additions & 7 deletions core-blocks/columns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ import './editor.scss';
*
* @return {Object[]} Columns layout configuration.
*/
const getColumnLayouts = memoize( ( columns ) => {
return times( columns, ( n ) => ( {
name: `column-${ n + 1 }`,
label: sprintf( __( 'Column %d' ), n + 1 ),
icon: 'columns',
} ) );
const getColumnsTemplate = memoize( ( columns ) => {
return times( columns, () => [ 'core/column' ] );
} );

export const name = 'core/columns';
Expand Down Expand Up @@ -86,7 +82,10 @@ export const settings = {
</PanelBody>
</InspectorControls>
<div className={ classes }>
<InnerBlocks layouts={ getColumnLayouts( columns ) } />
<InnerBlocks
template={ getColumnsTemplate( columns ) }
templateLock
allowedBlocks={ [ 'core/column' ] } />
</div>
</Fragment>
);
Expand Down
17 changes: 4 additions & 13 deletions core-blocks/columns/style.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
.wp-block-columns {
display: grid;
grid-auto-flow: dense;

@for $i from 2 through 6 {
&.has-#{ $i }-columns {
grid-auto-columns: #{ 100% / $i };
}
}
display: flex;
}

@for $i from 1 through 6 {
.layout-column-#{ $i } {
grid-column: #{ $i };
}
}
.wp-block-column {
flex: 1;
}
2 changes: 2 additions & 0 deletions core-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as button from './button';
import * as categories from './categories';
import * as code from './code';
import * as columns from './columns';
import * as column from './columns/column';
import * as coverImage from './cover-image';
import * as embed from './embed';
import * as freeform from './freeform';
Expand Down Expand Up @@ -59,6 +60,7 @@ export const registerCoreBlocks = () => {
categories,
code,
columns,
column,
coverImage,
embed,
...embed.common,
Expand Down
14 changes: 9 additions & 5 deletions editor/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ import { withSelect } from '@wordpress/data';
import './style.scss';
import BlockListLayout from './layout';

const UngroupedLayoutBlockList = withSelect(
( select, ownProps ) => ( {
blockUIDs: select( 'core/editor' ).getBlockOrder( ownProps.rootUID ),
} )
)( BlockListLayout );
const UngroupedLayoutBlockList = withSelect( ( select, ownProps ) => {
const { getBlockOrder, getEditorSettings } = select( 'core/editor' );
const { templateLock = getEditorSettings().templateLock } = ownProps;

return {
blockUIDs: getBlockOrder( ownProps.rootUID ),
templateLock,
};
} )( BlockListLayout );

const GroupedLayoutBlockList = withSelect(
( select, ownProps ) => ( {
Expand Down
2 changes: 2 additions & 0 deletions editor/components/block-list/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class BlockListLayout extends Component {
isGroupedByLayout,
rootUID,
renderBlockMenu,
templateLock,
} = this.props;

let defaultLayout;
Expand Down Expand Up @@ -227,6 +228,7 @@ class BlockListLayout extends Component {
rootUID={ rootUID }
lastBlockUID={ last( blockUIDs ) }
layout={ defaultLayout }
isLocked={ templateLock }
/>
</IgnoreNestedEvents>
</div>
Expand Down
3 changes: 1 addition & 2 deletions editor/components/default-block-appender/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,11 @@ export default compose(
const isEmpty = ! getBlockCount( ownProps.rootUID );
const lastBlock = getBlock( ownProps.lastBlockUID );
const isLastBlockDefault = get( lastBlock, [ 'name' ] ) === getDefaultBlockName();
const { templateLock, bodyPlaceholder } = getEditorSettings();
const { bodyPlaceholder } = getEditorSettings();

return {
isVisible: isEmpty || ! isLastBlockDefault,
showPrompt: isEmpty,
isLocked: !! templateLock,
placeholder: bodyPlaceholder,
hasTip: isTipVisible( 'core/editor.inserter' ),
};
Expand Down
3 changes: 2 additions & 1 deletion editor/components/inner-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function InnerBlocks( {
layouts,
allowedBlocks,
template,
templateLock,
isSmallScreen,
isSelectedBlockInRoot,
} ) {
Expand All @@ -30,7 +31,7 @@ function InnerBlocks( {

return (
<div className={ classes }>
<BlockList { ...{ layouts, allowedBlocks, template } } />
<BlockList { ...{ layouts, allowedBlocks, template, templateLock } } />
</div>
);
}
Expand Down

0 comments on commit a8d9202

Please sign in to comment.