-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Try moving block margins to each block #8350
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,8 @@ $block-parent-side-ui-clearance: $parent-block-padding - $block-padding; // spac | |
|
||
$block-container-side-padding: $block-side-ui-width + $block-padding + 2 * $block-side-ui-clearance; | ||
|
||
$default-block-margin: $block-padding * 2 + $block-spacing; // This is the default margin between blocks. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: We should use parentheses so the future maintainer doesn't need to recall their order of operations 😄 |
||
|
||
// Buttons & UI Widgets | ||
$button-style__radius-roundrect: 4px; | ||
$button-style__radius-round: 50%; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,8 +91,8 @@ body.gutenberg-editor-page { | |
} | ||
|
||
.gutenberg__editor { | ||
// on mobile the main content area has to scroll | ||
// otherwise you can invoke the overscroll bounce on the non-scrolling container, causing (ノಠ益ಠ)ノ彡┻━┻ | ||
// On mobile the main content area has to scroll, otherwise you can invoke | ||
// the overscroll bounce on the non-scrolling container, causing (ノಠ益ಠ)ノ彡┻━┻. | ||
@include break-small { | ||
position: absolute; | ||
top: 0; | ||
|
@@ -102,11 +102,46 @@ body.gutenberg-editor-page { | |
min-height: calc( 100vh - #{ $admin-bar-height-big } ); | ||
} | ||
|
||
// The WP header height changes at this breakpoint | ||
// The WP header height changes at this breakpoint. | ||
@include break-medium { | ||
min-height: calc( 100vh - #{ $admin-bar-height } ); | ||
} | ||
|
||
.components-navigate-regions { | ||
height: 100%; | ||
} | ||
} | ||
|
||
/** | ||
* Vanilla editor styles | ||
*/ | ||
|
||
.gutenberg__editor { | ||
|
||
// Gutenberg specific elements | ||
.editor-default-block-appender__content, | ||
.components-placeholder { | ||
margin-top: $default-block-margin; | ||
margin-bottom: $default-block-margin; | ||
} | ||
|
||
// Core blocks | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a complete list. Pushing the work in progress to decide if this approach is worth it at all. |
||
.wp-block-button, | ||
.wp-block-code, | ||
.wp-block-categories, | ||
.wp-block-cover-image, | ||
.wp-block-embed { | ||
margin-top: $default-block-margin; | ||
margin-bottom: $default-block-margin; | ||
} | ||
|
||
p, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these rules be duplicated across each and every block in the style.scss file for each, or is it fine to keep these in a global vanilla theme like these? |
||
ul, | ||
ol { | ||
margin-top: $default-block-margin; | ||
margin-bottom: $default-block-margin; | ||
} | ||
|
||
img { | ||
max-width: 100%; | ||
height: auto; | ||
|
@@ -115,10 +150,6 @@ body.gutenberg-editor-page { | |
iframe { | ||
width: 100%; | ||
} | ||
|
||
.components-navigate-regions { | ||
height: 100%; | ||
} | ||
} | ||
|
||
// Override core input styles to provide ones consistent with Gutenberg | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,16 +136,6 @@ | |
.editor-block-list__block:first-child .editor-block-list__block-edit { | ||
margin-top: $block-padding - $block-spacing / 2; | ||
} | ||
|
||
// Space every block, and the default appender, using margins. | ||
// This allows margins to collapse, which gives a better representation of how it looks on the frontend. | ||
.editor-default-block-appender__content, | ||
.editor-block-list__block .editor-block-list__block-edit, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where we, currently in Why should we not do this? Because some blocks might want their own margins, or no margins, and shouldn't have to override. Besides, the theme might not have any margins registered, and by registering them on a per-block basis, the theme will get these margins. This forces us to decide on a per block basis what, if any, margin is needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
But we apply a blanket rule to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's definitely contradicting. The thing is, I think of the Gutenberg editor style as a vanilla stylesheet. Same as if you create a stock HTML page with no CSS styles, you get the default browser stylesheet, with Times New Roman, etc. Only, for margins, we currently set those on Why does this matter? Only one reason — if you mean to style the editor itself to match the theme, it makes more sense to write:
... than it does to write:
Sure, it would be nicer even if themers could write, simply:
But unless Shadow DOM support drastically improves or we can put the editing canvas in an iframe, I doubt we can enable that. So by moving the margins to the block contents itself, at least we're taking a half-step to make styling the editor simpler, even if it's still the same margin. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can support the goal, but as implemented,
In some side-chatting with @mtias and @youknowriad some ideas have been bounced around here with how we might be able to achieve effectively this by either rewriting the CSS to prepend necessary prefixing, or iterate them automatically when rendered in the DOM via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did say, and I'll give it a try, no updates at the moment though :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For what it's worth, you can never count on dynamic/SSR blocks to match a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
While I agree that selector is not ideal or probably even feasible, it doesn't exactly target the same. I'm not trying to split hairs here, but look at the markup:
Only the third item is the same on the front-end and the back-end. I realize that having the markup be the same in the frontend and the backend is likely not feasible in the near future, without Shadow DOM or things like that, but it is a baby step towrads at least styling the same bits of markup in the editor and the frontend. The margin is the same, sure, but the selector is different. This all speaks to a larger issue that came up recently when @iseulde rewrote the table to use nested blocks. Essentially I wasn't able to write CSS that would make our nested blocks editor markup behave and look like the table on the front-end. Not easily at least. I'm not sure what the best approach is — possibly this branch isn't it. But to your point about making a build process that matches front-end selectors to backend elements, this would not address the challenge for a table with nested blocks, where the sequence of parent-to-child elements in the markup is important (at least pending There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you go #9008 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@chrisvanpatten What class do those blocks have then? How would it be possible to style them? |
||
.editor-block-list__layout .editor-block-list__block .editor-block-list__block-edit, | ||
.editor-block-list__layout .editor-default-block-appender .editor-default-block-appender__content { // Explicitly target nested blocks, as those need to override the preceding rule. | ||
margin-top: $block-padding * 2 + $block-spacing; | ||
margin-bottom: $block-padding * 2 + $block-spacing; | ||
} | ||
} | ||
|
||
.editor-block-list__layout .editor-block-list__block { | ||
|
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.
When you hover or select a block, we paint the outline outside the footprint of the block.
This means that if a block has no margin, these outlines will overlap. This variable is designed in a way so as to prevent this overlap from happening.