-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
+373
−7
Merged
Add group block #13964
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
6aebbba
Add initial container block
talldan 9ca4d46
Add background color controls to the container block
talldan e806dc1
Add `anchor` support to container block
talldan d90b595
Add option for editing container block padding
talldan aeb7739
Add padding with preset narrow and wide options
talldan d4a073e
Add padding toggle
talldan 1c3382c
Ensure background color class name is set in block edit
talldan 5c74f05
Switch padding option to disable padding instead of enabling
talldan e3bb63c
Set a default background color
talldan e4ff533
Add e2e test for adding container block
talldan 2ad9ee4
Add e2e tests for the container block
talldan d31a55e
updated the default toggle text and behaviour for the container's pad…
draganescu dc253f9
removed the padding toogle and added default padding to the container…
draganescu b691d94
Remove container block margin when a background is set. Allows consec…
talldan 36efeba
Adds keywords to aid in discoverability
getdave 551f5e9
Removes default background
getdave 6308812
Renames Block from Container to Section
getdave 600e963
Utilise correct spacing variable for consistency
getdave 99ea32f
Implement same padding rules as used in columns block for container b…
talldan 3535363
Resolve block validation error when custom background color used. Cau…
talldan 6123430
Feature flag the section block
talldan 2ccfd83
Update e2e tests with renamed section block
talldan 7acf0bf
Add fixture for section block for full content test
talldan f1dc3a9
Adds alignment for inner blocks that support alignment controls
getdave 1cd84d1
Fixes width of wide Media text Block within full width Section Block
getdave ceebdbc
Removes Block default padding
getdave 5eb9b7c
Fixes alignment layout within Seciton Blocks for all alignable Block …
getdave 16716b9
Adds specificity required to only target immediate child Blocks of Se…
getdave 4e0cb9c
Reintroduces padding on request
getdave 473ab59
Adds fix to images as edge case
getdave a6af16a
Removes unwanted whitespace top/bottom of Block
getdave 908a869
Fixes wide child Block alignment within full width Section
getdave 2ba30a9
Fixes full width image alignment within full width Section.
getdave 89d9939
Removes usage of Block name as Sass variable
getdave fd8f45d
Updates hard coded spacing to variables
getdave 0ca88ff
Fixes excessive Section Block padding on tiny screens
getdave 1176f56
Updates to add padding only when background is added to Block
getdave 45565e8
Fixes Block overlap between adjacent Blocks when no background applied
getdave ad49f6d
Restores fix for Columns Block to ensure move/drag handles visible in…
getdave 8e383bb
Fixes 1px of overflow on full width blocks
getdave 6648523
Applies another fix to 1px overflow issue
getdave a7c6d36
Makes Block reusable
getdave e3f30b1
Removes feature flag
getdave 49353da
Fixes overflow issues
getdave 91a147d
Fix width of context toolbar causing overflow-x
getdave 1277032
Updates Section padding values to match paragraph Block
getdave f890830
Fixes failing Block transforms e2e test
getdave 225c504
Fixes Block overflowing off screen on <600px full width Section
getdave 6417586
Fix to make full width children full width when background padding added
getdave fcee560
Remove superflous Section keyword
getdave 2e19d94
Removes superflous resuable setting
getdave 0047415
Updates to use `block-editor` package and avoid proxy
getdave File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/block-editor'; | ||
|
||
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 }> | ||
<InnerBlocks /> | ||
</div> | ||
</Fragment> | ||
); | ||
} | ||
|
||
export default withColors( 'backgroundColor' )( SectionEdit ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Path, SVG } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { InnerBlocks, getColorClassName } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* 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' ), __( 'wrapper' ), __( 'row' ) ], | ||
|
||
supports: { | ||
align: [ 'wide', 'full' ], | ||
anchor: true, | ||
html: false, | ||
}, | ||
|
||
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> | ||
); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
46
packages/e2e-tests/fixtures/blocks/core__section.parsed.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
] |
9 changes: 9 additions & 0 deletions
9
packages/e2e-tests/fixtures/blocks/core__section.serialized.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 --> |
17 changes: 17 additions & 0 deletions
17
packages/e2e-tests/specs/blocks/__snapshots__/section.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Section can be created using the block inserter 1`] = ` | ||
"<!-- wp:section --> | ||
<div class=\\"wp-block-section\\"><!-- wp:paragraph --> | ||
<p>Section block</p> | ||
<!-- /wp:paragraph --></div> | ||
<!-- /wp:section -->" | ||
`; | ||
|
||
exports[`Section can be created using the slash inserter 1`] = ` | ||
"<!-- wp:section --> | ||
<div class=\\"wp-block-section\\"><!-- wp:paragraph --> | ||
<p>Section block</p> | ||
<!-- /wp:paragraph --></div> | ||
<!-- /wp:section -->" | ||
`; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.