-
Notifications
You must be signed in to change notification settings - Fork 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
Full Site Editing: Refactor the Template block UI #35387
Conversation
This PR does not affect the size of JS and CSS bundles shipped to the user's browser. Generated by performance advisor bot at iscalypsofastyet.com. |
27680fe
to
c6cf80a
Compare
apps/full-site-editing/full-site-editing-plugin/full-site-editing/blocks/template/edit.js
Show resolved
Hide resolved
@Copons do you mind adding a before/after screen or gifs? |
@@ -23,8 +24,29 @@ import { addQueryArgs } from '@wordpress/url'; | |||
*/ | |||
import './style.scss'; | |||
|
|||
// Hide the Block Sidebar when the Template block is selected | |||
domReady( () => { |
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.
Can we see if we can add a better selector instead of targeting last-child with the addFilter hook. See example:
Line 32 in 8e51dbe
const addContentSlotClassname = createHigherOrderComponent( BlockListBlock => { |
We can also query block selection state, instead of debouncing this to apply another class.
For example we can probably keep track of https://github.com/WordPress/gutenberg/blob/15f5ff44609df48a47dee1d3e750470cdda50a5e/packages/block-editor/src/store/selectors.js#L391 and setup a boolean to match when there's a selected block + it's a template block.
Feel free to ping me if you need more info on ^^
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 haven't found any filters on the external editor wrapper that could be used for this, but only ones deeper in the DOM, closer to the blocks list (e.g. editor.BlockListBlock
, it targets the actual block, even if the name could be misleading).
In this case, we would need, for example, to add a .is-template-selected
class to, say, the body, the editor wrapper, or anything outside the blocks list, in order to target the sidebar.
The :last-child
in itself should be safe enough, considering that the sidebar header is an hardcoded list with only two elements (Document and Block), and we always need to hide the second one.
Though, maybe I'm either overthinking this or totally misunderstanding your suggestion. I'll double check if I've missed something obvious, or maybe do some lateral thinking, or eventually just ping you 😄
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.
It doesn't look like there is a good alternative for the last-child selector, but we can listen to the edit-post store and block-editor store:
So sketching this out roughly in code this might look like:
import { withSelect } from '@wordpress/data';
//wrap an appropriate component
withSelect( ( select ) => {
const selectedBlock = select( 'core/block-editor' ).getSelectedBlock();
const a8cTemplateSelected = selectedBlock && selectedBlock.name === 'a8c/template';
const blockOptionsSelected = select( 'core/edit-post' ).getActiveGeneralSidebarName() === 'edit-post/block';
return {
'hideBlockSidebarTab': a8cTemplateSelected && blockOptionsSelected,
}
} );
Two options then on how to use it, if we are able to add a modifier class in the right spot, we can add a classname + CSS
//in an appropriate component render, let's add another classname:
render() {
const { hideBlockSidebarTab } = this.props;
return <container className={ hideBlockSidebarTab ? 'my_container.isTemplateSelected' : 'my_container' } />;
}
// then in CSS add a selector that targets this state to display:none;
Otherwise we can try and use https://reactjs.org/docs/hooks-effect.html to detect this transition state from false/true and trigger the CSS toggle on blockSidebarButton
Initially, I had intentionally not added any screens as the idea was to have no visual changes between master and this refactor (with the only exception of the sidebar not hiding anymore when clicking the template), but only a tidier code. EDIT: @gwwar I've just added a gazillion of screenshots! 🕺 |
c437c7e
to
36cb23c
Compare
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.
Thanks @Copons I'm not sure if I've verified all areas that has changed but I do appreciate the smaller line count. I've smoke tested this a bit with Automattic/themes#1262
Let's get these two in, and then tidy on anything we might have missed. In the future let's try to aim to split out janitorials from feature changes as it's easier to review/safer to land.
I would still recommend getting rid of the setInterval in favor of listening to the Gutenberg redux stores, but I'd be okay with that being an immediate follow up as well.
Thanks @gwwar, I'll ship this and the theme one and start a follow up to try to get rid of the |
Changes proposed in this Pull Request
Requires Automattic/themes#1262
Refactor the Template block style, and changes the block selection behaviour.
.site-header
) from the block most external wrapper, to one more inside. This should simplify the overrides, as now the theme styles are only applied to the rendered part of the block, and not to its wrapper too.SCREENSHOTS GALORE!
Show
Clean Slate
Note: the colophon positioning is off compared to how it's supposed to look in the theme (which is a bit awkward, what with calculated margins that attempt to almost center position it, instead of just
text-align: center
it and call it a day. tl;dr it's technicallytext-align: left
, but looks more centered)Header with Logo
Note: the header elements spacings are off in both current and refactor, compared to how the theme is supposed to look.
Header with Full Width Image
Note: in both current and refactor, on the front end, the image has a negative right margin that triggers the horizontal scrollbar.
Footer Alignment
Note: imho this has a very bad UX.
Blocks have an alignment option, but then some of them are forced with a predetermined alignment. Imho, we should not force any alignment via CSS, but instead letting people do their thing with the editor.
Selecting a Template Doesn't Hide the Sidebar Anymore
Note: the sidebar stays open (if already open), and the "Block" tab gets hidden.
Testing instructions
Fixes #35378