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

SPT: Re implement template post title. #39809

Closed
wants to merge 5 commits into from

Conversation

retrofox
Copy link
Contributor

@retrofox retrofox commented Mar 2, 2020

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 the core/heading one. It allows inheriting theme styles such as font-size, alignment, etc.
For instance, testing with Mayland theme:

Editor Canvas
image

After (correct title alignment)
Screen Shot 2020-03-02 at 9 49 40 AM

Before (wrong title alignment)
Screen Shot 2020-03-02 at 9 50 20 AM

Testing instructions

  • Apply these changes in your testing environment.
  • Test how the template post title looks compared one the template is inserted in the editor-canvas.

Fixes #39805

@retrofox retrofox requested a review from a team as a code owner March 2, 2020 12:52
@matticbot
Copy link
Contributor

@matticbot
Copy link
Contributor

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.

@retrofox retrofox force-pushed the update/spt-add-post-title-block branch from fd0f4ff to 941bf13 Compare March 2, 2020 15:40
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello retrofox! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D39685-code before merging this PR. Thank you!

@obenland
Copy link
Member

obenland commented Mar 2, 2020

What's the benefit of using a custom block? why can't the heading block be centered?

@retrofox
Copy link
Contributor Author

retrofox commented Mar 2, 2020

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 core/post-title behavior. This block implements a proper markup (also adding CSS classes) which gives the theme the ability to apply custom style to the title.

For instance, Twenty Twenty sets the title at the center, as while as Mayland does it at the left. Unfortunately core/post-title is an experiment block so far and even when it rolls out we have to keep in mind that it couldn' t work for some Atomic sites.

@retrofox retrofox self-assigned this Mar 2, 2020
@retrofox retrofox added the [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it label Mar 2, 2020
Copy link
Contributor

@getdave getdave left a 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', {
Copy link
Contributor

@getdave getdave Mar 2, 2020

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' ),
Copy link
Contributor

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.' ),
Copy link
Contributor

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>
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* 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' );
Copy link
Contributor

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' );
Copy link
Contributor

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.

Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* 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 {
Copy link
Contributor

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;
Copy link
Contributor

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.

Comment on lines +208 to +211
if ( this.props.isPostTitleBlockRegistered ) {
unregisterBlockType( 'a8c/spt-template-post-title' );
}

Copy link
Contributor

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?

@jeryj
Copy link
Contributor

jeryj commented Mar 2, 2020

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 👍

@jeryj
Copy link
Contributor

jeryj commented Mar 2, 2020

Actually, I missed one thing. Left aligned title have extra spacing on the left that is not there in the editor or front-end:

Coutoire Menu template in SPT Preview:
Screen Shot 2020-03-02 at 11 12 00 AM

In Editor:
Screen Shot 2020-03-02 at 11 12 03 AM

@retrofox
Copy link
Contributor Author

retrofox commented Mar 3, 2020

Closing in favor of #39831

@retrofox retrofox closed this Mar 3, 2020
@sirreal sirreal deleted the update/spt-add-post-title-block branch December 4, 2020 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SPT: Tweak template title.
5 participants