Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add group block #13964

Merged
merged 52 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
6aebbba
Add initial container block
talldan Feb 14, 2019
9ca4d46
Add background color controls to the container block
talldan Feb 14, 2019
e806dc1
Add `anchor` support to container block
talldan Feb 15, 2019
d90b595
Add option for editing container block padding
talldan Feb 18, 2019
aeb7739
Add padding with preset narrow and wide options
talldan Feb 18, 2019
d4a073e
Add padding toggle
talldan Feb 18, 2019
1c3382c
Ensure background color class name is set in block edit
talldan Feb 18, 2019
5c74f05
Switch padding option to disable padding instead of enabling
talldan Feb 20, 2019
e3bb63c
Set a default background color
talldan Feb 20, 2019
e4ff533
Add e2e test for adding container block
talldan Feb 20, 2019
2ad9ee4
Add e2e tests for the container block
talldan Feb 20, 2019
d31a55e
updated the default toggle text and behaviour for the container's pad…
draganescu Feb 20, 2019
dc253f9
removed the padding toogle and added default padding to the container…
draganescu Feb 22, 2019
b691d94
Remove container block margin when a background is set. Allows consec…
talldan Feb 25, 2019
36efeba
Adds keywords to aid in discoverability
getdave Mar 1, 2019
551f5e9
Removes default background
getdave Mar 13, 2019
6308812
Renames Block from Container to Section
getdave Mar 13, 2019
600e963
Utilise correct spacing variable for consistency
getdave Mar 14, 2019
99ea32f
Implement same padding rules as used in columns block for container b…
talldan Mar 12, 2019
3535363
Resolve block validation error when custom background color used. Cau…
talldan Mar 15, 2019
6123430
Feature flag the section block
talldan Mar 15, 2019
2ccfd83
Update e2e tests with renamed section block
talldan Mar 15, 2019
7acf0bf
Add fixture for section block for full content test
talldan Mar 15, 2019
f1dc3a9
Adds alignment for inner blocks that support alignment controls
getdave Mar 15, 2019
1cd84d1
Fixes width of wide Media text Block within full width Section Block
getdave Mar 19, 2019
ceebdbc
Removes Block default padding
getdave Mar 20, 2019
5eb9b7c
Fixes alignment layout within Seciton Blocks for all alignable Block …
getdave Mar 20, 2019
16716b9
Adds specificity required to only target immediate child Blocks of Se…
getdave Mar 21, 2019
4e0cb9c
Reintroduces padding on request
getdave Mar 21, 2019
473ab59
Adds fix to images as edge case
getdave Mar 21, 2019
a6af16a
Removes unwanted whitespace top/bottom of Block
getdave Mar 21, 2019
908a869
Fixes wide child Block alignment within full width Section
getdave Mar 22, 2019
2ba30a9
Fixes full width image alignment within full width Section.
getdave Mar 22, 2019
89d9939
Removes usage of Block name as Sass variable
getdave Mar 22, 2019
fd8f45d
Updates hard coded spacing to variables
getdave Mar 22, 2019
0ca88ff
Fixes excessive Section Block padding on tiny screens
getdave Mar 22, 2019
1176f56
Updates to add padding only when background is added to Block
getdave Mar 25, 2019
45565e8
Fixes Block overlap between adjacent Blocks when no background applied
getdave Mar 25, 2019
ad49f6d
Restores fix for Columns Block to ensure move/drag handles visible in…
getdave Mar 26, 2019
8e383bb
Fixes 1px of overflow on full width blocks
getdave Mar 26, 2019
6648523
Applies another fix to 1px overflow issue
getdave Mar 28, 2019
a7c6d36
Makes Block reusable
getdave Mar 28, 2019
e3f30b1
Removes feature flag
getdave Mar 28, 2019
49353da
Fixes overflow issues
getdave Mar 28, 2019
91a147d
Fix width of context toolbar causing overflow-x
getdave Mar 28, 2019
1277032
Updates Section padding values to match paragraph Block
getdave Mar 29, 2019
f890830
Fixes failing Block transforms e2e test
getdave Mar 29, 2019
225c504
Fixes Block overflowing off screen on <600px full width Section
getdave Mar 29, 2019
6417586
Fix to make full width children full width when background padding added
getdave Mar 29, 2019
fcee560
Remove superflous Section keyword
getdave Mar 29, 2019
2e19d94
Removes superflous resuable setting
getdave Mar 29, 2019
0047415
Updates to use `block-editor` package and avoid proxy
getdave Apr 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions packages/block-library/src/columns/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@

// Fullwide: show margin left/right to ensure there's room for the side UI.
// This is not a 1:1 preview with the front-end where these margins would presumably be zero.
// @todo This could be revisited, by for example showing this margin only when the parent block was selected first.
// Then at least an unselected columns block would be an accurate preview.
.editor-block-list__block[data-align="full"] .wp-block-columns > .editor-inner-blocks {
.editor-block-list__block[data-align="full"] [data-type="core/columns"][data-align="full"] .wp-block-columns > .editor-inner-blocks {
padding-left: $block-padding;
padding-right: $block-padding;

@include break-small() {
padding-left: $block-padding + $block-padding + $block-side-ui-width + $block-side-ui-clearance + $block-side-ui-clearance;
padding-right: $block-padding + $block-padding + $block-side-ui-width + $block-side-ui-clearance + $block-side-ui-clearance;
padding-left: $block-container-side-padding;
padding-right: $block-container-side-padding;
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
@import "./quote/editor.scss";
@import "./rss/editor.scss";
@import "./search/editor.scss";
@import "./section/editor.scss";
@import "./shortcode/editor.scss";
@import "./spacer/editor.scss";
@import "./subhead/editor.scss";
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import * as pullquote from './pullquote';
import * as reusableBlock from './block';
import * as rss from './rss';
import * as search from './search';
import * as section from './section';
import * as separator from './separator';
import * as shortcode from './shortcode';
import * as spacer from './spacer';
Expand Down Expand Up @@ -106,6 +107,7 @@ export const registerCoreBlocks = () => {
pullquote,
rss,
search,
section,
separator,
reusableBlock,
spacer,
Expand Down
48 changes: 48 additions & 0 deletions packages/block-library/src/section/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import { Fragment } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import {
InspectorControls,
InnerBlocks,
PanelColorSettings,
withColors,
} from '@wordpress/editor';
getdave marked this conversation as resolved.
Show resolved Hide resolved

function SectionEdit( { className, setBackgroundColor, backgroundColor } ) {
const styles = {
backgroundColor: backgroundColor.color,
};

const classes = classnames( className, backgroundColor.class, {
'has-background': !! backgroundColor.color,
} );

return (
<Fragment>
<InspectorControls>
<PanelColorSettings
title={ __( 'Color Settings' ) }
colorSettings={ [
{
value: backgroundColor.color,
onChange: setBackgroundColor,
label: __( 'Background Color' ),
},
] }
/>
</InspectorControls>
<div className={ classes } style={ styles }>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋. I know this PR is already merged but I'm wondering if such a generic div element can be extracted in its own component. It will probably be an opportunity to make the Section block more cross-platform ready by not using html tags directly. WDYT @getdave ?

cc @gziolo , @Tug , @koke

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hypest, we totally should introduce View component which will work cross-platform. @koke landed a similar component yesterday. See #14361 for reference. It should be a very similar use case.

<InnerBlocks />
</div>
</Fragment>
);
}

export default withColors( 'backgroundColor' )( SectionEdit );
87 changes: 87 additions & 0 deletions packages/block-library/src/section/editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* Section: All Alignment Settings
*/
.wp-block[data-type="core/section"] {

// Ensure not rendering outside the element
// as -1px causes overflow-x scrollbars
.editor-block-list__insertion-point {
left: 0;
right: 0;
}

// Only applied when background is added to cancel out padding
> .editor-block-list__block-edit > div > .wp-block-section.has-background > .editor-inner-blocks {
margin-top: -#{$block-padding*2 + $block-spacing};
margin-bottom: -#{$block-padding*2 + $block-spacing};
}

// Full Width Blocks
// specificity required to only target immediate child Blocks of Section
> .editor-block-list__block-edit > div > .wp-block-section > .editor-inner-blocks > .editor-block-list__layout > .wp-block[data-align="full"] {
margin-left: auto;
margin-right: auto;
padding-left: $block-padding*2;
padding-right: $block-padding*2;

@include break-small() {
padding-left: $block-padding*4 + $block-spacing/2; // 58px
padding-right: $block-padding*4 + $block-spacing/2; // 58px
}
}

// Full Width Blocks with a background (ie: has padding)
> .editor-block-list__block-edit > div > .wp-block-section.has-background > .editor-inner-blocks > .editor-block-list__layout > .wp-block[data-align="full"] {
// note: using position `left` causes hoz scrollbars so
// we opt to use margin instead
// the 30px matches the hoz padding applied in `theme.scss`
// added when the Block has a background set
margin-left: -30px;

// 60px here is x2 the hoz padding from `theme.scss` added when
// the Block has a background set
// note: also duplicated below for full width Sections
width: calc(100% + 60px);
}
}

/**
* Section: Full Width Alignment
*/
.wp-block[data-type="core/section"][data-align="full"] {

// First tier of InnerBlocks must act like the container of the standard canvas
> .editor-block-list__block-edit > div > .wp-block-section > .editor-inner-blocks {
margin-left: auto;
margin-right: auto;
padding-left: 0;
padding-right: 0;

> .editor-block-list__layout {
margin-left: 0;
margin-right: 0;
}
}

// Full Width Blocks
// specificity required to only target immediate child Blocks of Section
> .editor-block-list__block-edit > div > .wp-block-section > .editor-inner-blocks > .editor-block-list__layout > .wp-block[data-align="full"] {
getdave marked this conversation as resolved.
Show resolved Hide resolved
padding-right: 0;
padding-left: 0;
left: 0;
width: 100%;
max-width: none;

// Allow to be flush with the edges of the canvas
> .editor-block-list__block-edit {
margin-left: 0;
margin-right: 0;
}
}

// Full Width Blocks with a background (ie: has padding)
// note: also duplicated above for all Section widths
> .editor-block-list__block-edit > div > .wp-block-section.has-background > .editor-inner-blocks > .editor-block-list__layout > .wp-block[data-align="full"] {
width: calc(100% + 60px);
}
}
67 changes: 67 additions & 0 deletions packages/block-library/src/section/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import { Path, SVG } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { InnerBlocks, getColorClassName } from '@wordpress/editor';
getdave marked this conversation as resolved.
Show resolved Hide resolved

/**
* Internal dependencies
*/
import edit from './edit';

export const name = 'core/section';

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

icon: <SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><Path d="M19 12h-2v3h-3v2h5v-5zM7 9h3V7H5v5h2V9zm14-6H3c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16.01H3V4.99h18v14.02z" /><Path d="M0 0h24v24H0z" fill="none" /></SVG>,

category: 'layout',

description: __( 'A wrapping section acting as a container for other blocks.' ),

keywords: [ __( 'container' ), __( 'section' ), __( 'wrapper' ), __( 'row' ) ],
getdave marked this conversation as resolved.
Show resolved Hide resolved

supports: {
align: [ 'wide', 'full' ],
anchor: true,
html: false,
reusable: true,
getdave marked this conversation as resolved.
Show resolved Hide resolved
},

attributes: {
backgroundColor: {
type: 'string',
},
customBackgroundColor: {
type: 'string',
},
},

edit,

save( { attributes } ) {
const { backgroundColor, customBackgroundColor } = attributes;

const backgroundClass = getColorClassName( 'background-color', backgroundColor );
const className = classnames( backgroundClass, {
'has-background': backgroundColor || customBackgroundColor,
} );

const styles = {
backgroundColor: backgroundClass ? undefined : customBackgroundColor,
};

return (
<div className={ className } style={ styles }>
<InnerBlocks.Content />
</div>
);
},
};
10 changes: 10 additions & 0 deletions packages/block-library/src/section/theme.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.wp-block-section {

&.has-background {
// Matches paragraph Block padding
// Todo: normalise with variables
padding: 20px 30px;
margin-top: 0;
margin-bottom: 0;
}
}
1 change: 1 addition & 0 deletions packages/block-library/src/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@import "./pullquote/theme.scss";
@import "./quote/theme.scss";
@import "./search/theme.scss";
@import "./section/theme.scss";
@import "./separator/theme.scss";
@import "./table/theme.scss";
@import "./video/theme.scss";
4 changes: 4 additions & 0 deletions packages/e2e-tests/fixtures/block-transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ export const EXPECTED_TRANSFORMS = {
originalBlock: 'Search',
availableTransforms: [],
},
core__section: {
originalBlock: 'Section',
availableTransforms: [],
},
core__separator: {
originalBlock: 'Separator',
availableTransforms: [],
Expand Down
10 changes: 10 additions & 0 deletions packages/e2e-tests/fixtures/blocks/core__section.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- wp:section {"backgroundColor":"secondary","align":"full"} -->
<div class="wp-block-section alignfull has-secondary-background-color has-background">
<!-- wp:paragraph -->
<p>This is a section block.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Section block content.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:section -->
36 changes: 36 additions & 0 deletions packages/e2e-tests/fixtures/blocks/core__section.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[
{
"clientId": "_clientId_0",
"name": "core/section",
"isValid": true,
"attributes": {
"backgroundColor": "secondary",
"align": "full"
},
"innerBlocks": [
{
"clientId": "_clientId_0",
"name": "core/paragraph",
"isValid": true,
"attributes": {
"content": "This is a section block.",
"dropCap": false
},
"innerBlocks": [],
"originalContent": "<p>This is a section block.</p>"
},
{
"clientId": "_clientId_1",
"name": "core/paragraph",
"isValid": true,
"attributes": {
"content": "Section block content.",
"dropCap": false
},
"innerBlocks": [],
"originalContent": "<p>Section block content.</p>"
}
],
"originalContent": "<div class=\"wp-block-section alignfull has-secondary-background-color has-background\">\n\t\n\n\t</div>"
}
]
46 changes: 46 additions & 0 deletions packages/e2e-tests/fixtures/blocks/core__section.parsed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"blockName": "core/section",
"attrs": {
"backgroundColor": "secondary",
"align": "full"
},
"innerBlocks": [
{
"blockName": "core/paragraph",
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n\t<p>This is a section block.</p>\n\t",
"innerContent": [
"\n\t<p>This is a section block.</p>\n\t"
]
},
{
"blockName": "core/paragraph",
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n\t<p>Section block content.</p>\n\t",
"innerContent": [
"\n\t<p>Section block content.</p>\n\t"
]
}
],
"innerHTML": "\n<div class=\"wp-block-section alignfull has-secondary-background-color has-background\">\n\t\n\n\t</div>\n",
"innerContent": [
"\n<div class=\"wp-block-section alignfull has-secondary-background-color has-background\">\n\t",
null,
"\n\n\t",
null,
"</div>\n"
]
},
{
"blockName": null,
"attrs": {},
"innerBlocks": [],
"innerHTML": "\n",
"innerContent": [
"\n"
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- wp:section {"backgroundColor":"secondary","align":"full"} -->
<div class="wp-block-section alignfull has-secondary-background-color has-background"><!-- wp:paragraph -->
<p>This is a section block.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Section block content.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:section -->
Loading