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

Remove the default block margins from themes with theme.json file #30375

Merged
merged 3 commits into from
Apr 6, 2021
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
14 changes: 14 additions & 0 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ function gutenberg_register_packages_styles( $styles ) {
'wp-reusable-blocks',
);

// Only load the default layout and margin styles for themes without theme.json file.
if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) {
$wp_edit_blocks_dependencies[] = 'wp-editor-classic-layout-styles';
Copy link
Member

@gziolo gziolo Apr 7, 2021

Choose a reason for hiding this comment

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

This is such a nice way to ensure backward compatibility. ❤️

}

global $editor_styles;
if ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) {
// Include opinionated block styles if no $editor_styles are declared, so the editor never appears broken.
Expand All @@ -375,6 +380,15 @@ function gutenberg_register_packages_styles( $styles ) {
);
$styles->add_data( 'wp-reset-editor-styles', 'rtl', 'replace' );

gutenberg_override_style(
$styles,
'wp-editor-classic-layout-styles',
gutenberg_url( 'build/edit-post/classic.css' ),
array(),
$version
);
$styles->add_data( 'wp-editor-classic-layout-styles', 'rtl', 'replace' );

gutenberg_override_style(
$styles,
'wp-edit-blocks',
Expand Down
7 changes: 0 additions & 7 deletions packages/block-library/src/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@
* This allows us to create normalization styles that are easily overridden by editor styles.
*/

// Provide every block with a default base margin. This margin provides a consistent spacing
// between blocks in the editor.
.block-editor-block-list__block {
margin-top: $default-block-margin;
margin-bottom: $default-block-margin;
}

// This tag marks the end of the styles that apply to editing canvas contents and need to be manipulated when we resize the editor.
#end-resizable-editor-section {
display: none;
Expand Down
1 change: 0 additions & 1 deletion packages/block-library/src/spacer/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

.block-library-spacer__resize-container {
clear: both;
margin-bottom: $default-block-margin;

// Don't show the horizontal indicator.
.components-resizable-box__handle::before {
Expand Down
113 changes: 113 additions & 0 deletions packages/edit-post/src/classic.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// This needs specificity to override the editor styles.
.editor-styles-wrapper .wp-block {
margin-left: auto;
margin-right: auto;
}

// Depreacted style needed for the block widths and alignments.
// for themes that don't support the new layout (theme.json)
.wp-block {
max-width: $content-width;

// Provide every block with a default base margin. This margin provides a consistent spacing
// between blocks in the editor.
margin-top: $default-block-margin;
margin-bottom: $default-block-margin;

&[data-align="wide"] {
max-width: $wide-content-width;
}

&[data-align="full"] {
max-width: none;
}

// Alignments.
&[data-align="left"],
&[data-align="right"] {
width: 100%;

// When images are floated, the block itself should collapse to zero height.
height: 0;

&::before {
content: none;
}
}

// Left.
&[data-align="left"] > * {
/*!rtl:begin:ignore*/
float: left;
margin-right: 2em;
/*!rtl:end:ignore*/
}

// Right.
&[data-align="right"] > * {
/*!rtl:begin:ignore*/
float: right;
margin-left: 2em;
/*!rtl:end:ignore*/
}

// Wide and full-wide.
&[data-align="full"],
&[data-align="wide"] {
clear: both;
}
}

// Full Width Blocks
// specificity required to only target immediate child Blocks of a Group
.wp-block-group > [data-align="full"] {
margin-left: auto;
margin-right: auto;
}

// Full Width Blocks with a background (ie: has padding)
.wp-block-group.has-background > [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 Groups
width: calc(100% + 60px);
}

/**
* Group: Full Width Alignment
*/
[data-align="full"] .wp-block-group {
// Non-full Width Blocks
// specificity required to only target immediate child Blocks of Group
> .wp-block {
padding-left: $block-padding;
padding-right: $block-padding;

@include break-small() {
padding-left: 0;
padding-right: 0;
}
}

// Full Width Blocks
// specificity required to only target immediate child Blocks of Group
> [data-align="full"] {
padding-right: 0;
padding-left: 0;
left: 0;
width: 100%;
max-width: none;
}

// Full Width Blocks with a background (ie: has padding)
// note: also duplicated above for all Group widths
&.has-background > [data-align="full"] {
width: calc(100% + 60px);
}
}
3 changes: 0 additions & 3 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ function Layout( { styles } ) {
showIconLabels,
hasReducedUI,
showBlockBreadcrumbs,
supportsLayout,
} = useSelect( ( select ) => {
const editorSettings = select( 'core/editor' ).getEditorSettings();
return {
Expand All @@ -115,7 +114,6 @@ function Layout( { styles } ) {
isInserterOpened: select( editPostStore ).isInserterOpened(),
mode: select( editPostStore ).getEditorMode(),
isRichEditingEnabled: editorSettings.richEditingEnabled,
supportsLayout: editorSettings.supportsLayout,
hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),
previousShortcut: select(
keyboardShortcutsStore
Expand All @@ -141,7 +139,6 @@ function Layout( { styles } ) {
'has-fixed-toolbar': hasFixedToolbar,
'has-metaboxes': hasActiveMetaboxes,
'show-icon-labels': showIconLabels,
'supports-layout': supportsLayout,
} );
const openSidebarPanel = () =>
openGeneralSidebar(
Expand Down
109 changes: 0 additions & 109 deletions packages/edit-post/src/components/layout/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -115,112 +115,3 @@
height: 100%;
}
}

// Depreacted style needed for the block widths and alignments.
// for themes that don't support the new layout (theme.json)
.edit-post-layout:not(.supports-layout) {
.wp-block {
max-width: $content-width;
margin-left: auto;
margin-right: auto;

&[data-align="wide"] {
max-width: $wide-content-width;
}

&[data-align="full"] {
max-width: none;
}

// Alignments.
&[data-align="left"],
&[data-align="right"] {
width: 100%;

// When images are floated, the block itself should collapse to zero height.
height: 0;

&::before {
content: none;
}
}

// Left.
&[data-align="left"] > * {
/*!rtl:begin:ignore*/
float: left;
margin-right: 2em;
/*!rtl:end:ignore*/
}

// Right.
&[data-align="right"] > * {
/*!rtl:begin:ignore*/
float: right;
margin-left: 2em;
/*!rtl:end:ignore*/
}

// Wide and full-wide.
&[data-align="full"],
&[data-align="wide"] {
clear: both;
}

}

// Full Width Blocks
// specificity required to only target immediate child Blocks of a Group
.wp-block-group > [data-align="full"] {
margin-left: auto;
margin-right: auto;
}

// Full Width Blocks with a background (ie: has padding)
.wp-block-group.has-background > [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 Groups
width: calc(100% + 60px);
}

/**
* Group: Full Width Alignment
*/
[data-align="full"] .wp-block-group {

// Non-full Width Blocks
// specificity required to only target immediate child Blocks of Group
> .wp-block {
padding-left: $block-padding;
padding-right: $block-padding;

@include break-small() {
padding-left: 0;
padding-right: 0;
}
}

// Full Width Blocks
// specificity required to only target immediate child Blocks of Group
> [data-align="full"] {
padding-right: 0;
padding-left: 0;
left: 0;
width: 100%;
max-width: none;
}

// Full Width Blocks with a background (ie: has padding)
// note: also duplicated above for all Group widths
&.has-background > [data-align="full"] {
width: calc(100% + 60px);
}
}
}