Skip to content

Commit

Permalink
Try fixing post editor layout for wide/full Post Content blocks (#49565)
Browse files Browse the repository at this point in the history
* Try fixing post editor layout for wide/full Post Content blocks

* Alter rules to not affect children of constrained layout
  • Loading branch information
tellthemachines authored Apr 11, 2023
1 parent be3360b commit 748c517
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/edit-post/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export default function VisualEditor( { styles } ) {
postContentAttributes,
] );

const layout = newestPostContentAttributes?.layout || {};
const { layout = {}, align = '' } = newestPostContentAttributes || {};

const postContentLayoutClasses = useLayoutClasses(
newestPostContentAttributes,
Expand All @@ -272,7 +272,8 @@ export default function VisualEditor( { styles } ) {
{
'is-layout-flow': ! themeSupportsLayout,
},
themeSupportsLayout && postContentLayoutClasses
themeSupportsLayout && postContentLayoutClasses,
align && `align${ align }`
);

const postContentLayoutStyles = useLayoutStyles(
Expand Down Expand Up @@ -327,6 +328,12 @@ export default function VisualEditor( { styles } ) {
[ styles ]
);

// Add some styles for alignwide/alignfull Post Content and its children.
const alignCSS = `.is-root-container.alignwide { max-width: var(--wp--style--global--wide-size); margin-left: auto; margin-right: auto;}
.is-root-container.alignwide:where(.is-layout-flow) > :not(.alignleft):not(.alignright) { max-width: var(--wp--style--global--wide-size);}
.is-root-container.alignfull { max-width: none; margin-left: auto; margin-right: auto;}
.is-root-container.alignfull:where(.is-layout-flow) > :not(.alignleft):not(.alignright) { max-width: none;}`;

return (
<BlockTools
__unstableContentRef={ ref }
Expand Down Expand Up @@ -382,6 +389,9 @@ export default function VisualEditor( { styles } ) {
globalLayoutSettings?.definitions
}
/>
{ align && (
<LayoutStyle css={ alignCSS } />
) }
{ postContentLayoutStyles && (
<LayoutStyle
layout={ postContentLayout }
Expand Down

0 comments on commit 748c517

Please sign in to comment.