-
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
SPT: Re implement template post title. #39809
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. |
fd0f4ff
to
941bf13
Compare
Caution: This PR has changes that must be merged to WordPress.com |
What's the benefit of using a custom block? why can't the heading block be centered? |
The idea behind this PR is copying the For instance, Twenty Twenty sets the title at the center, as while as Mayland does it at the left. Unfortunately |
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.
Nice job on this 👍
Noticed a few things on first code pass.
* This block will be unregistered once the template is inserted, | ||
* the component unmounted, modal closed, etc... | ||
*/ | ||
registerBlockType( 'a8c/spt-template-post-title', { |
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 think maybe we should add some context as to why we're adding a custom block here. You provided reasoning in the PR comments which would work well.
* the component unmounted, modal closed, etc... | ||
*/ | ||
registerBlockType( 'a8c/spt-template-post-title', { | ||
title: __( 'SPT Template post title' ), |
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.
Do we need a 2nd arg here of full-site-editing
?
*/ | ||
registerBlockType( 'a8c/spt-template-post-title', { | ||
title: __( 'SPT Template post title' ), | ||
description: __( 'Template post title.' ), |
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.
Do we need a 2nd arg here of full-site-editing
?
eg:
__( 'Template post title.', 'full-site-editing` ),
return ( | ||
<div className="editor-post-title"> | ||
<div className="wp-block editor-post-title__block"> | ||
<div> |
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.
What's the empty <div>
for?
@@ -51,10 +90,8 @@ class PageTemplateModal extends Component { | |||
* It will be remove when inserting the template |
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 will be remove when inserting the template | |
* It will be removed when the template's blocks are inserted into the editor. |
@@ -162,6 +205,10 @@ class PageTemplateModal extends Component { | |||
trackSelection( this.props.segment.id, this.props.vertical.id, slug ); | |||
this.props.saveTemplateChoice( slug ); | |||
|
|||
if ( this.props.isPostTitleBlockRegistered ) { | |||
unregisterBlockType( 'a8c/spt-template-post-title' ); |
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.
As above. Should we also be tying the registration of this block to the component mount hook?
@@ -247,6 +294,10 @@ class PageTemplateModal extends Component { | |||
}; | |||
|
|||
closeModal = event => { | |||
if ( this.props.isPostTitleBlockRegistered ) { | |||
unregisterBlockType( 'a8c/spt-template-post-title' ); |
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.
...and again.
@@ -439,14 +439,14 @@ body.admin-bar:not( .is-fullscreen-mode ) .page-template-modal-screen-overlay { | |||
} | |||
|
|||
// Manual CSS Overrides. Remove after better solutions are in place. | |||
|
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.
Random space
// Removes empty paragraph placeholders, i.e. "Write Title..." | ||
[data-type='core/paragraph'] [data-rich-text-placeholder] { | ||
display: none; | ||
} | ||
|
||
/* | ||
* Fixes jetpack .wp-block-jetpack-slideshow styles, as the /wp-content/plugins/jetpack/_inc/blocks/vendors~swiper.[hash].css | ||
* Fixes jetpack .wp-block-jetpack-slideshow styles, as the /wp-content/plugins/jetpack/_inc/blocks/vendors~swiper.[hash].css | ||
* file is loaded on block insert, not on page load. After the iframe is grabbing these styles, we can remove this code. |
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.
* file is loaded on block insert, not on page load. After the iframe is grabbing these styles, we can remove this code. | |
* file is loaded on block insert, not on page load. After the iframe has loaded these styles, we can remove this code. |
@@ -474,4 +474,13 @@ body.admin-bar:not( .is-fullscreen-mode ) .page-template-modal-screen-overlay { | |||
margin-bottom: 0; | |||
} | |||
} | |||
|
|||
// Adjust template title. | |||
.editor-post-title__input { |
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.
Is this class added so it intentionally inherits existing styles? If not and these styles are bespoke to this one block then is the classname specific enough?
overflow: hidden; | ||
overflow-wrap: break-word; | ||
resize: none; | ||
max-height: 80px; |
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.
This 80px seems risky. Why does it need to be 80px, and are we positive the title will never be multi-line? If the title goes multi-line, it would be hidden due to the max-height value.
if ( this.props.isPostTitleBlockRegistered ) { | ||
unregisterBlockType( 'a8c/spt-template-post-title' ); | ||
} | ||
|
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.
Why does this need to be unregistered anytime a template is selected?
Added a couple small comments. I don't feel qualified to review the actual registering/unregistering implementation code, as I haven't worked with that before. That said, I did a functional review, testing the implementation with three themes: 2020, Coutoire, and Varia. The implementation worked as expected in each of them 👍 |
Closing in favor of #39831 |
Changes proposed in this Pull Request
A few days ago we changed the way to render the template title, inserting a
core/heading
block among all templates blocks there. It simplifies the way to compute the scaling for the title.This PR keeps iterating over the same feature, creating a new
a8c/spt-template-post-title
and using it instead of thecore/heading
one. It allows inheriting theme styles such as font-size, alignment, etc.For instance, testing with
Mayland
theme:Editor Canvas

After (correct title alignment)

Before (wrong title alignment)

Testing instructions
Fixes #39805