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

Buttons: Add variations for vertical layout #27297

Merged
merged 5 commits into from
Dec 2, 2020

Conversation

ntsekouras
Copy link
Contributor

@ntsekouras ntsekouras commented Nov 26, 2020

Description

Resolves: #20081

This PR adds block variations to Buttons block for enabling the switch to vertical and horizontal orientation, in the same fashion Navigation block handles this.

How has this been tested?

Manually and by ensuring that previous versions of Buttons blocks would remain unaffected by this change.

Screenshots

verticalButtons

Types of changes

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.

@ntsekouras ntsekouras added [Block] Buttons Affects the Buttons Block [Type] Feature New feature to highlight in changelogs. labels Nov 26, 2020
@ntsekouras ntsekouras self-assigned this Nov 26, 2020
@github-actions
Copy link

github-actions bot commented Nov 26, 2020

Size Change: -808 B (0%)

Total Size: 1.19 MB

Filename Size Change
build/a11y/index.js 1.14 kB -1 B
build/block-directory/index.js 8.72 kB -3 B (0%)
build/block-editor/index.js 128 kB -49 B (0%)
build/block-editor/style-rtl.css 11.2 kB -55 B (0%)
build/block-editor/style.css 11.2 kB -52 B (0%)
build/block-library/editor-rtl.css 8.89 kB -60 B (0%)
build/block-library/editor.css 8.89 kB -62 B (0%)
build/block-library/index.js 148 kB +324 B (0%)
build/block-library/style-rtl.css 8.3 kB +34 B (0%)
build/block-library/style.css 8.3 kB +35 B (0%)
build/block-serialization-default-parser/index.js 1.88 kB +8 B (0%)
build/blocks/index.js 48.1 kB -6 B (0%)
build/components/index.js 172 kB +39 B (0%)
build/components/style-rtl.css 15.3 kB -8 B (0%)
build/components/style.css 15.3 kB -8 B (0%)
build/compose/index.js 9.95 kB -3 B (0%)
build/core-data/index.js 14.8 kB -3 B (0%)
build/data-controls/index.js 827 B -1 B
build/data/index.js 8.98 kB +1 B
build/date/index.js 11.2 kB -3 B (0%)
build/deprecated/index.js 768 B -1 B
build/dom/index.js 4.95 kB +1 B
build/edit-navigation/index.js 11.1 kB +13 B (0%)
build/edit-post/index.js 306 kB -17 B (0%)
build/edit-site/index.js 24.1 kB +2 B (0%)
build/edit-site/style-rtl.css 4.06 kB +156 B (3%)
build/edit-site/style.css 4.06 kB +155 B (3%)
build/edit-widgets/index.js 26.3 kB -8 B (0%)
build/editor/index.js 43.3 kB -13 B (0%)
build/element/index.js 4.63 kB +2 B (0%)
build/hooks/index.js 2.27 kB -1 B
build/html-entities/index.js 623 B +1 B
build/i18n/index.js 3.56 kB -1 B
build/keyboard-shortcuts/index.js 2.54 kB -3 B (0%)
build/media-utils/index.js 5.32 kB -2 B (0%)
build/notices/index.js 1.82 kB -2 B (0%)
build/nux/index.js 3.42 kB +1 B
build/plugins/index.js 2.56 kB +1 B
build/priority-queue/index.js 791 B +1 B
build/redux-routine/index.js 2.84 kB +3 B (0%)
build/rich-text/index.js 13.4 kB -2 B (0%)
build/server-side-render/index.js 2.77 kB -3 B (0%)
build/shortcode/index.js 1.69 kB +1 B
build/url/index.js 2.84 kB -1.22 kB (42%) 🎉
build/viewport/index.js 1.86 kB -1 B
ℹ️ View Unchanged
Filename Size Change
build/annotations/index.js 3.8 kB 0 B
build/api-fetch/index.js 3.42 kB 0 B
build/autop/index.js 2.84 kB 0 B
build/blob/index.js 665 B 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-library/theme-rtl.css 789 B 0 B
build/block-library/theme.css 790 B 0 B
build/block-serialization-spec-parser/index.js 3.06 kB 0 B
build/dom-ready/index.js 571 B 0 B
build/edit-navigation/style-rtl.css 881 B 0 B
build/edit-navigation/style.css 885 B 0 B
build/edit-post/style-rtl.css 6.42 kB 0 B
build/edit-post/style.css 6.4 kB 0 B
build/edit-widgets/style-rtl.css 3.13 kB 0 B
build/edit-widgets/style.css 3.13 kB 0 B
build/editor/editor-styles-rtl.css 476 B 0 B
build/editor/editor-styles.css 478 B 0 B
build/editor/style-rtl.css 3.85 kB 0 B
build/editor/style.css 3.85 kB 0 B
build/escape-html/index.js 735 B 0 B
build/format-library/index.js 6.86 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/is-shallow-equal/index.js 698 B 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.1 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/primitives/index.js 1.43 kB 0 B
build/reusable-blocks/index.js 2.92 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.22 kB 0 B

compressed-size-action

@ntsekouras ntsekouras force-pushed the add/buttons-vertical-variation branch 2 times, most recently from 52e9602 to 60c4cae Compare November 26, 2020 18:28
@ntsekouras ntsekouras marked this pull request as ready for review November 26, 2020 18:43
@guarani
Copy link
Contributor

guarani commented Nov 26, 2020

Smoke tested on react-native-editor and there are no regressions there. If in the future we want to add this to mobile, it can be added.

@talldan
Copy link
Contributor

talldan commented Nov 27, 2020

This is mostly working really nicely, though the spacing between blocks looks different in my local env to your screen capture:
Screenshot 2020-11-27 at 12 55 31 pm

Not sure if this is a theme issue, it does look better in Twenty Nineteen and Twenty Twenty One Blocks, but the spacing is bigger in Twenty Twenty and Twenty Twenty One (non-blocks).

The 'Use Theme Styles' toggle doesn't seem to be working anymore, so that's making it hard to check.

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

Technical implementation of the block looks good. It works similar to how Navigation block allows transforming its variations. save method was updated but it should produce the same output for existing content.

Let's make sure that the comment about CSS from @talldan is addressed before proceeding. @mapk or @jasmussen can you help with that?

@gziolo
Copy link
Member

gziolo commented Nov 27, 2020

It looks like integration tests for the Buttons block need to be regenerated to work with the new orientation attribute added.

@ntsekouras
Copy link
Contributor Author

This is mostly working really nicely, though the spacing between blocks looks different in my local env to your screen capture

Hey @talldan - thanks for reviewing!

This is something that can be affected by theme styles but your screenshot has big gaps :) . I tested with 2021(both blocks and non-blocks) and 2019 and seem quite good. In 2020 there are theme styles that cause that (margin top and bottom are 30px). Also previously the Buttons block had bigger top-margins that I removed it in this PR to have the same as every block. Maybe css was cached in browser? Do you mind checking once again and make sure the new css is loaded?

The 'Use Theme Styles' toggle doesn't seem to be working anymore, so that's making it hard to check.

What is this toggle?

@ntsekouras ntsekouras requested review from mapk and jasmussen November 27, 2020 08:09
@talldan
Copy link
Contributor

talldan commented Nov 27, 2020

What is this toggle?

In the editor preferences
Screenshot 2020-11-27 at 4 34 20 pm

Pretty useful for testing whether the default styling looks ok!

I'll give it a re-test to see what's happening with the margins.

@ntsekouras ntsekouras force-pushed the add/buttons-vertical-variation branch from c37c86c to f499ced Compare November 27, 2020 08:42
@talldan
Copy link
Contributor

talldan commented Nov 27, 2020

@ntsekouras It's this style in Twenty Twenty One non-blocks that's causing the gap in my local environment:
https://github.com/WordPress/twentytwentyone/blob/4c83b2781ae9cc9002ef8e0a5c275b2cea8a7f08/assets/sass/05-blocks/utilities/_editor.scss#L73-L76

I wonder if we're using different versions of the theme. Can you see this style if you inspect the button block wrapper?
Screenshot 2020-11-27 at 4 50 39 pm

It might not be something to worry about in the core block styles, but perhaps we should make an issue over on the theme repo if we can validate the issue (I'm happy to do that):
https://github.com/WordPress/twentytwentyone

@ntsekouras
Copy link
Contributor Author

This is what I see..

Screenshot 2020-11-27 at 11 03 48 AM

It might not be something to worry about in the core block styles, but perhaps we should make an issue over on the theme repo if we can validate the issue

Since is not merged I could ping some people who work on that theme to validate. I'll do that now.

@jasmussen
Copy link
Contributor

This is what I see:

movers

My immediate instinct was that vertical or horizontal should just be style variations for the block. However as Nik kindly explained — the challenge with this block is the same as it is for the navigation block: style variations are just CSS changes, but these blocks need their horizontal movers swapped out with vertical movers, which require a different kind of transform.

Because that is the case, this approach is okay.


However, and not necessarily as part of this PR, but we really need to improve this selector:

Screenshot 2020-11-27 at 10 29 53

It looks like a dropdown, but it doesn't act like a dropdown. It doesn't know its own transform, and it doesn't show it inside the dropdown field, as it should. Also because of that, when you click it the first time, there's no checkbox, which suggests you can transform a horizontal block to a horizontal block. It's not a good UI, and we really should improve it before we expand it that much further.

Secondly, I wish there was a way to revisit the mover control so it could know itself whether to be vertical or horizontal, and avoid having us build these UIs on top of it. Could it simply read the flex-direction of its parent?

@talldan
Copy link
Contributor

talldan commented Nov 27, 2020

@ntsekouras The screenshot looks like the styles for the buttons block. How about the styles for an individual button?

@ntsekouras
Copy link
Contributor Author

The screenshot looks like the styles for the buttons block. How about the styles for an individual button?

Screenshot 2020-11-27 at 11 55 01 AM

I saw now that the margin applies on selecting the Buttons. I do believe this is for themes to style though, since is a new layout? This affects all themes and I think that every new thing like that would cause themes to handle the styles, no?

@scruffian
Copy link
Contributor

This is great, thank you!

Copy link
Member

@ZebulanStanphill ZebulanStanphill left a comment

Choose a reason for hiding this comment

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

Let's add an orientation prop to the <ContentJustificationDropdown> component, in order to provide a way to change the options shown to match the orientation. (Technically it would just rename them, I guess.)

In hindsight, when I implemented the content justification controls, I think I should have gone with start and end terminology for the variable/prop names rather than left and right, which don't make sense in a vertical context. Let's try and fix that while we're at it.

packages/block-library/src/button/editor.scss Outdated Show resolved Hide resolved
@@ -18,10 +29,16 @@

&.is-content-justification-left {
Copy link
Member

@ZebulanStanphill ZebulanStanphill Nov 30, 2020

Choose a reason for hiding this comment

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

Perhaps this className should have been is-content-justification-start, because "left" doesn't make sense in the vertical context, and the actual value of align-items that gets set is flex-start anyway. Same for is-content-justification-right which should probably be is-content-justification-end.

Copy link
Member

Choose a reason for hiding this comment

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

Just realized the above comment was incorrect, since I got horizontal/vertical controls confused in my head.

Anyway, there is an actual problem here, though: this class is being used to align-items for vertical Buttons blocks, but the class name implies it can only set justify-content. Additionally, the justify-content styles are being applied to both vertical and horizontal orientations. That's not technically correct.

Copy link
Contributor Author

@ntsekouras ntsekouras Nov 30, 2020

Choose a reason for hiding this comment

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

Why not? You can have vertically stacked buttons and align them for example to the right. What do you propose exactly? If it's about the term/component names, do you think it's okay to have in a follow up PR?

Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't be setting justify-content for the vertical case... only align-items. But also, the class "is-content-justification-xxx" is kind of confusing if it's actually applying item alignment in the vertical cases. I think ideally, we'd want to tackle this stuff sooner rather than later to reduce the number of deprecations and legacy styles we have to keep on the front-end.

Copy link
Member

Choose a reason for hiding this comment

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

The problem here is basically that I named the is-content-justification-xxx classes with the assumption that they would only be used to apply different justify-content styles, but that's no longer true in this case.

Maybe a new class name that can work both cases would be appropriate. I'm not sure what the correct term is, though.

Or maybe the solution is to apply different classes for the vertical cases, e.g. is-item-alignment-xxx. I'm not sure.

Copy link
Member

@ZebulanStanphill ZebulanStanphill Dec 1, 2020

Choose a reason for hiding this comment

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

personally I think of alignment as the positioning of the block itself, in this case the container block, and justificiation as the positioning of content inside.

It's worth remembering that in addition to align-items and justify-content, there's also align-content and justify-items, though justify-items doesn't do anything in Flexbox.

By looking at how these properties work, we can learn the following about how CSS is using these terms:

In a horizontally-flowing container, "align" refers to vertical positioning and "justify" refers to horizontal positioning. In a vertically-flowing container, "align" refers to horizontal positioning and "justify" refers to vertical positioning. In other words, "justify" refers to positioning along the primary axis that content is flowing, and "align" refers to the secondary (AKA "cross") axis.

"content" applies to all the children as a single block within the container, and "items" applies to each child as an individual unit.

Technically, the kind of alignment/justification we want for the horizontal variant is actually conceptually different from the control we want on the vertical variant. Technically, justify-content's cross-axis equivalent is align-content, not align-items. 😖

Copy link
Member

@ZebulanStanphill ZebulanStanphill Dec 1, 2020

Choose a reason for hiding this comment

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

If I had to come up with a better class name than what we're using right now, I guess something like is-content-horizontal-placement-xxx might work. I'm drawing the "placement" term here from the shorthand properties place-content and place-items. The CSS "placement" term is apparently its generic way of referring to both "alignment" and "justification".

Of course, in my suggested class name here, the meaning of "content" is slightly different from what CSS uses it for, since in the case of my suggested class name, it can refer to either CSS's "content" or "items". But I guess it's good enough for our purposes?

Copy link
Contributor

Choose a reason for hiding this comment

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

For me it's too late to change the class names, this is already shipped and themes might be relying on it. The renaming doesn't seem to add a lot of value.

Copy link
Member

Choose a reason for hiding this comment

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

As far as I can tell, it's only shipped in the plugin, not core, right? Does that change anything?

Copy link
Contributor

Choose a reason for hiding this comment

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

Does that change anything?

It does, we have more luxury to change things that way but are we certain of that? It's also a bit late if it's in WP 5.6 as we're on RC2 and the stable is supposed to happen next week.

We need to do a few things if we want to rename the classnames:

  • try to check usage of the classname in the plugins/theme repository
  • backport the fix to WP 5.6 (so it needs to be in its own separate PR and not block this one)

cc @tellthemachines

@talldan
Copy link
Contributor

talldan commented Nov 30, 2020

ContentJustificationDropdown only handles horizontal alignments, so I don't really see an issue. The buttons block can't be made bigger than the content, so I don't think there's a need to align vertically right now.

@ZebulanStanphill
Copy link
Member

@talldan Oh, right. Sorry, I got mixed up about what was going on in this PR.

Taking a closer look, it's kind of weird that the component called ContentJustificationDropdown is actually setting align-items when the block is using the vertical orientation. And the same goes for the classes. I wonder what the proper term would be to refer to a setting that can change either align-items or justify-content depending on the context.

@ntsekouras ntsekouras force-pushed the add/buttons-vertical-variation branch from f499ced to 6d50534 Compare November 30, 2020 07:44
@ntsekouras
Copy link
Contributor Author

Based on the above discussion about css classes (#27297 (comment)), I'm going to merge this.

The next steps will be determined by:

We need to do a few things if we want to rename the classnames:

  • try to check usage of the classname in the plugins/theme repository
  • backport the fix to WP 5.6 (so it needs to be in its own separate PR and not block this one)

@ntsekouras ntsekouras merged commit 7b45a9d into master Dec 2, 2020
@ntsekouras ntsekouras deleted the add/buttons-vertical-variation branch December 2, 2020 10:09
@github-actions github-actions bot added this to the Gutenberg 9.6 milestone Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Buttons Affects the Buttons Block [Type] Feature New feature to highlight in changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add "Vertical" block style to buttons block
8 participants