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 constrained/flow layout to Cover block. #45326

Merged
merged 6 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
40 changes: 23 additions & 17 deletions packages/block-editor/src/layouts/constrained.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ export default {
inspectorControls: function DefaultLayoutInspectorControls( {
layout,
onChange,
layoutBlockSupport = {},
} ) {
const { wideSize, contentSize, justifyContent = 'center' } = layout;
const { allowJustification = true } = layoutBlockSupport;
const onJustificationChange = ( value ) => {
onChange( {
...layout,
Expand Down Expand Up @@ -117,23 +119,27 @@ export default {
'Customize the width for all elements that are assigned to the center or wide columns.'
) }
</p>
<ToggleGroupControl
__nextHasNoMarginBottom
label={ __( 'Justification' ) }
value={ justifyContent }
onChange={ onJustificationChange }
>
{ justificationOptions.map( ( { value, icon, label } ) => {
return (
<ToggleGroupControlOptionIcon
key={ value }
value={ value }
icon={ icon }
label={ label }
/>
);
} ) }
</ToggleGroupControl>
{ allowJustification && (
<ToggleGroupControl
__nextHasNoMarginBottom
label={ __( 'Justification' ) }
value={ justifyContent }
onChange={ onJustificationChange }
>
{ justificationOptions.map(
( { value, icon, label } ) => {
return (
<ToggleGroupControlOptionIcon
key={ value }
value={ value }
icon={ icon }
label={ label }
/>
);
}
) }
</ToggleGroupControl>
) }
</>
);
},
Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/cover/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
"__experimentalDefaultControls": {
"fontSize": true
}
},
"__experimentalLayout": {
"allowJustification": false
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
}
},
"editorStyle": "wp-block-cover-editor",
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/cover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import edit from './edit';
import metadata from './block.json';
import save from './save';
import transforms from './transforms';
import variations from './variations';
Copy link
Member

Choose a reason for hiding this comment

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

Do we need variations? I don't think so, yea?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do need them unfortunately. The variation here is used as a workaround to apply constrained layout to all newly added blocks, without forcing it on existing blocks, which could potentially break a lot of websites.

(Making new blocks constrained is meant to match the behaviour of Group blocks, and also mitigate the experience for hybrid themes that suddenly lose all their legacy layout styles when they add a theme.json)


const { name } = metadata;

Expand Down Expand Up @@ -48,6 +49,7 @@ export const settings = {
save,
edit,
deprecated,
variations,
};

export const init = () => initBlock( { name, metadata, settings } );
20 changes: 20 additions & 0 deletions packages/block-library/src/cover/variations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { cover } from '@wordpress/icons';

const variations = [
{
name: 'cover',
title: __( 'Cover' ),
description: __(
'Add an image or video with a text overlay — great for headers.'
),
attributes: { layout: { type: 'constrained' } },
isDefault: true,
icon: cover,
},
];

export default variations;
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ exports[`Inserting blocks inserts a block in proper place after having clicked \
<p>First paragraph</p>
<!-- /wp:paragraph -->

<!-- wp:cover {"isDark":false} -->
<!-- wp:cover {"isDark":false,"layout":{"type":"constrained"}} -->
<div class="wp-block-cover is-light"><span aria-hidden="true" class="wp-block-cover__background has-background-dim-100 has-background-dim"></span><div class="wp-block-cover__inner-container"></div></div>
<!-- /wp:cover -->

Expand Down