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

Post Title Block: Add alignment and heading level support #22872

Merged
merged 6 commits into from
Jun 8, 2020

Conversation

apeatling
Copy link
Contributor

Part of #21087

Description

Adds text alignment and heading level support to the Post Title block. One question is how to handle the shared code for the HeadingLevelDropdown component. I expect this needs to be extracted from the heading block so it can be shared appropriately.

How has this been tested?

  • Enable the site editor experiments.
  • Open the site editor and insert a query block.
  • Confirm that adjusting the alignment of the post title block works in the editor and front end.
  • Confirm that adjusting the heading level of the post title block works in the editor and front end.

Screenshots

2020-06-03 14 32 04

Types of changes

New feature.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@github-actions
Copy link

github-actions bot commented Jun 3, 2020

Size Change: +4.25 kB (0%)

Total Size: 1.13 MB

Filename Size Change
build/a11y/index.js 1.14 kB +1 B
build/annotations/index.js 3.62 kB +2 B (0%)
build/api-fetch/index.js 3.4 kB +1 B
build/autop/index.js 2.83 kB +2 B (0%)
build/block-directory/index.js 6.77 kB +24 B (0%)
build/block-editor/index.js 106 kB +295 B (0%)
build/block-editor/style-rtl.css 11.4 kB +14 B (0%)
build/block-editor/style.css 11.4 kB +12 B (0%)
build/block-library/editor-rtl.css 7.87 kB -4 B (0%)
build/block-library/editor.css 7.87 kB -3 B (0%)
build/block-library/index.js 127 kB +1.12 kB (0%)
build/block-library/style-rtl.css 7.72 kB +31 B (0%)
build/block-library/style.css 7.72 kB +31 B (0%)
build/block-serialization-default-parser/index.js 1.88 kB -2 B (0%)
build/block-serialization-spec-parser/index.js 3.1 kB +1 B
build/blocks/index.js 48.1 kB -9 B (0%)
build/components/index.js 194 kB +775 B (0%)
build/components/style-rtl.css 19.5 kB +9 B (0%)
build/components/style.css 19.5 kB +5 B (0%)
build/compose/index.js 9.31 kB -11 B (0%)
build/core-data/index.js 11.4 kB +2 B (0%)
build/data/index.js 8.45 kB -3 B (0%)
build/date/index.js 5.47 kB +3 B (0%)
build/dom-ready/index.js 569 B +1 B
build/dom/index.js 3.17 kB +55 B (1%)
build/edit-navigation/index.js 8.25 kB +1 B
build/edit-navigation/style-rtl.css 918 B +40 B (4%)
build/edit-navigation/style.css 919 B +43 B (4%)
build/edit-post/index.js 303 kB +311 B (0%)
build/edit-post/style-rtl.css 5.6 kB +168 B (3%)
build/edit-post/style.css 5.6 kB +168 B (3%)
build/edit-site/index.js 15.5 kB +533 B (3%)
build/edit-widgets/index.js 9.34 kB +511 B (5%) 🔍
build/editor/index.js 44.8 kB +121 B (0%)
build/format-library/index.js 7.72 kB +3 B (0%)
build/hooks/index.js 2.13 kB -3 B (0%)
build/i18n/index.js 3.56 kB +1 B
build/keyboard-shortcuts/index.js 2.51 kB -1 B
build/media-utils/index.js 5.3 kB +1 B
build/notices/index.js 1.79 kB +1 B
build/nux/index.js 3.41 kB +2 B (0%)
build/plugins/index.js 2.56 kB -1 B
build/redux-routine/index.js 2.85 kB -1 B
build/rich-text/index.js 14.8 kB -3 B (0%)
build/server-side-render/index.js 2.68 kB +3 B (0%)
build/token-list/index.js 1.28 kB -1 B
build/viewport/index.js 1.85 kB -1 B
build/wordcount/index.js 1.17 kB -1 B
ℹ️ View Unchanged
Filename Size Change
build/blob/index.js 620 B 0 B
build/block-directory/style-rtl.css 892 B 0 B
build/block-directory/style.css 892 B 0 B
build/block-library/theme-rtl.css 684 B 0 B
build/block-library/theme.css 686 B 0 B
build/data-controls/index.js 1.29 kB 0 B
build/deprecated/index.js 771 B 0 B
build/edit-site/style-rtl.css 2.96 kB 0 B
build/edit-site/style.css 2.96 kB 0 B
build/edit-widgets/style-rtl.css 2.4 kB 0 B
build/edit-widgets/style.css 2.4 kB 0 B
build/editor/editor-styles-rtl.css 425 B 0 B
build/editor/editor-styles.css 428 B 0 B
build/editor/style-rtl.css 4.26 kB 0 B
build/editor/style.css 4.27 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/html-entities/index.js 621 B 0 B
build/is-shallow-equal/index.js 711 B 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.12 kB 0 B
build/list-reusable-blocks/style-rtl.css 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/primitives/index.js 1.5 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/shortcode/index.js 1.7 kB 0 B
build/url/index.js 4.06 kB 0 B
build/warning/index.js 1.14 kB 0 B

compressed-size-action

@apeatling
Copy link
Contributor Author

Converting to WIP/draft to add font size and color support before review.

@apeatling apeatling marked this pull request as draft June 4, 2020 16:48
@apeatling
Copy link
Contributor Author

Based on #22843 (comment) will get this merged first and open a follow up PR.

@apeatling apeatling marked this pull request as ready for review June 4, 2020 17:01
"attributes": {
"align": {
"type": "string"
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think instead of handling the alignment manually, we could use the "align" support flag? Other blocks do that like "button".

Copy link
Contributor Author

@apeatling apeatling Jun 5, 2020

Choose a reason for hiding this comment

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

The support flag adds block level alignment using floats though doesn't it? Other heading blocks use text alignment, so it seems more appropriate to replicate that for the post title block and provide better continuity.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, we might want to add a support flag for text alignment later on.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ohh, I misunderstood this, I thought it was adding the text alignment support. Makes me wonder if we should rename the attribute or not? Do we already have blocks that support both text and block alignments? How do we name these things there?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it's super confusing. It should be textAlign.

$tag_name,
'wp-block-post-title' . esc_attr( $align_class_name ),
get_the_title( $block->context['postId'] )
);
Copy link
Contributor

Choose a reason for hiding this comment

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

As an aside or a potential follow-up:

The "align" support flag automatically handles the addition of the className for static blocks (save functions), but it doesn't do so on the server. Now that we have server-side registration for most blocks, we could write some hooks to do this automatically. It involves some Regex work but I think it's doable. cc @gziolo

(same for other hooks like the custom className...)

Copy link
Member

Choose a reason for hiding this comment

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

@aduth had the logic for what you described in one of his PRs :) The challenge is that we would make sure that the client and server always stay in sync. It's not only "align" and "className", but also colors, fonts, etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I have the logic here too #21420

Copy link
Contributor Author

@apeatling apeatling Jun 5, 2020

Choose a reason for hiding this comment

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

+1 to supporting this, I'm looking to add color, font and line height support to the Site Title block and it needs server side support. 👍

Copy link
Member

Choose a reason for hiding this comment

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

@aduth had the logic for what you described in one of his PRs :)

It was in #18414 (specifically c7cded6).

Copy link
Contributor Author

@apeatling apeatling Jun 9, 2020

Choose a reason for hiding this comment

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

@youknowriad I've opened the Site Title block PR that would need support on the server side for the above: #23007

What needs to be done to get that support in master? I'm very happy to help with it.

Copy link
Contributor

Choose a reason for hiding this comment

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

@apeatling I think right now the server side block registration already knows about the "supports" key (@gziolo confirm?), which means what's remaining is to write a render_block filter like that https://github.com/WordPress/gutenberg/pull/21420/files#diff-4339a9e86722fd029c231f3fb65f0ad2R392-R420 to apply the styles and classNames.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll give this one a go 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@apeatling
Copy link
Contributor Author

Thanks for the reviews, I'll fix these things up. 👍

Copy link
Contributor

@epiqueras epiqueras left a comment

Choose a reason for hiding this comment

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

Something in the JSON file is invalid and it's failing the build.

Comment on lines +47 to +62
<BlockControls>
<ToolbarGroup>
<HeadingLevelDropdown
selectedLevel={ level }
onChange={ ( newLevel ) =>
setAttributes( { level: newLevel } )
}
/>
</ToolbarGroup>
<AlignmentToolbar
value={ align }
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
} }
/>
</BlockControls>
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated to this PR.

@diegohaz @ItsJonQ

We need to document the move from ToolbarGroup to Toolbar and what each Toolbar component does. Adding things to the Toolbar is one of the main parts of developing blocks, and right now, it's even hard for Core developers to figure out what the latest way of doing it is.

@apeatling
Copy link
Contributor Author

There's a failing test with this PR that I'm unclear from the failure on how to resolve:

Screen Shot 2020-06-07 at 11 57 07 AM

@enriquesanchez or @youknowriad Any docs or pointers you can offer on this? Thanks.

@epiqueras
Copy link
Contributor

@apeatling https://github.com/WordPress/gutenberg/blob/master/packages/e2e-tests/fixtures/blocks/README.md

@apeatling
Copy link
Contributor Author

Thanks, I was looking in the wrong place. 👍

@apeatling apeatling merged commit d58f258 into master Jun 8, 2020
@apeatling apeatling deleted the add/post-title-block-options branch June 8, 2020 17:42
@github-actions github-actions bot added this to the Gutenberg 8.4 milestone Jun 8, 2020
@ellatrix ellatrix mentioned this pull request Jun 16, 2020
12 tasks
This was referenced Jun 24, 2020
"core/post-title/h4": "h4",
"core/post-title/h5": "h5",
"core/post-title/h6": "h6",
"core/post-title/p": "p"
Copy link
Member

Choose a reason for hiding this comment

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

👋 @apeatling I'm trying to understand why do we need the core/post-title/p here? It looks like this block behaves like the heading block: it can have 1-6 levels, but that's about it, right?

Copy link
Member

Choose a reason for hiding this comment

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

Prepared #24418 to fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I loosely recall there being support for using P as a selector in a previous version of the block, that I removed. This was left over. I might have that wrong but it was something like that. In any case, removing it makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Title Affects the Post Title Block
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants