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

Block variations transformations #26687

Merged
merged 21 commits into from
Nov 13, 2020
Merged

Conversation

ntsekouras
Copy link
Contributor

@ntsekouras ntsekouras commented Nov 4, 2020

Description

Resolves: #25231

This PR is the first step for handling block variation transformations. It introduces a transform new option for scope field in block variations. This way we can control how and when to handle these transformations, as this behavior doesn't always make sense for all variations for every block.

In this PR we support block variations that change only attributes, like the Navigation block (which is the only one adjusted for testing reasons). The design is not finalized yet and I've implemented it with a simple select control for now, just to test how this feels.

The second step in a follow up PR will be to handle transformations with InnerBlocks like Query or Columns that will need an API to manually handle such block variation transformations. For example what happens when we have Columns (4) and we want to expose the transform to Columns (3) etc...

Testing Instructions

  1. Insert and init a Navigation Block (create from top level pages)
  2. Select the Navigation block (not any child of it)
  3. The select box is shown below the Block Card after selecting the block based on the position that seems to be prevailing at issue's discussions(Add a way to transform between block variations #25231 (comment))

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 [Package] Block editor /packages/block-editor [Type] Feature New feature to highlight in changelogs. [Feature] Block Variations Block variations, including introducing new variations and variations as a feature labels Nov 4, 2020
@ntsekouras ntsekouras self-assigned this Nov 4, 2020
@github-actions
Copy link

github-actions bot commented Nov 4, 2020

Size Change: +1.47 kB (0%)

Total Size: 1.19 MB

Filename Size Change
build/annotations/index.js 3.77 kB -4 B (0%)
build/autop/index.js 2.84 kB +2 B (0%)
build/block-directory/index.js 8.71 kB -2 B (0%)
build/block-editor/index.js 133 kB +357 B (0%)
build/block-editor/style-rtl.css 11.3 kB +101 B (0%)
build/block-editor/style.css 11.2 kB +100 B (0%)
build/block-library/index.js 147 kB +31 B (0%)
build/block-serialization-default-parser/index.js 1.87 kB +1 B
build/blocks/index.js 48 kB +10 B (0%)
build/components/index.js 171 kB -50 B (0%)
build/components/style-rtl.css 15.3 kB +23 B (0%)
build/components/style.css 15.3 kB +25 B (0%)
build/compose/index.js 9.9 kB +6 B (0%)
build/core-data/index.js 14.8 kB -1 B
build/data/index.js 8.74 kB +5 B (0%)
build/dom/index.js 4.92 kB +402 B (8%) 🔍
build/edit-navigation/index.js 11.1 kB -2 B (0%)
build/edit-post/index.js 306 kB -1 B
build/edit-site/index.js 23.2 kB +406 B (1%)
build/edit-site/style-rtl.css 3.98 kB +26 B (0%)
build/edit-site/style.css 3.98 kB +25 B (0%)
build/edit-widgets/index.js 26.3 kB +1 B
build/editor/index.js 42.5 kB -1 B
build/element/index.js 4.62 kB -4 B (0%)
build/format-library/index.js 6.86 kB +1 B
build/hooks/index.js 2.16 kB +1 B
build/keyboard-shortcuts/index.js 2.52 kB -4 B (0%)
build/keycodes/index.js 1.94 kB -1 B
build/list-reusable-blocks/index.js 3.1 kB -1 B
build/media-utils/index.js 5.32 kB +2 B (0%)
build/notices/index.js 1.79 kB +19 B (1%)
build/nux/index.js 3.4 kB -2 B (0%)
build/plugins/index.js 2.56 kB -3 B (0%)
build/rich-text/index.js 13.3 kB -2 B (0%)
build/server-side-render/index.js 2.77 kB -1 B
build/url/index.js 4.06 kB -1 B
build/viewport/index.js 1.84 kB +6 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/api-fetch/index.js 3.42 kB 0 B
build/blob/index.js 664 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/editor-rtl.css 8.91 kB 0 B
build/block-library/editor.css 8.91 kB 0 B
build/block-library/style-rtl.css 8.1 kB 0 B
build/block-library/style.css 8.1 kB 0 B
build/block-library/theme-rtl.css 792 B 0 B
build/block-library/theme.css 793 B 0 B
build/block-serialization-spec-parser/index.js 3.06 kB 0 B
build/data-controls/index.js 821 B 0 B
build/date/index.js 11.2 kB 0 B
build/deprecated/index.js 768 B 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.43 kB 0 B
build/edit-post/style.css 6.42 kB 0 B
build/edit-widgets/style-rtl.css 3.16 kB 0 B
build/edit-widgets/style.css 3.16 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/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/html-entities/index.js 623 B 0 B
build/i18n/index.js 3.57 kB 0 B
build/is-shallow-equal/index.js 713 B 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/priority-queue/index.js 790 B 0 B
build/redux-routine/index.js 2.83 kB 0 B
build/reusable-blocks/index.js 3.05 kB 0 B
build/shortcode/index.js 1.69 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

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.

It's going in the right direction. It feels like it should be fine as an initial proposal to get it tested in the plugin.

@paaljoachim
Copy link
Contributor

This is what I see:

Navigation-Variations

An overview:
Variation drop down is seen in the sidebar when the Navigation startup screen is present.
Variation drop down is also seen when menu links are in place.
This gives the user the option to switch between horizontal and vertical mode, before or after having added the menu items.

I have a few comments that is outside the scope of this PR, but they show up as a natural extension of adding the Variation drop down.

We see text for selecting horizontal or vertical. Which makes it pretty clear what it does. At a later time one will likely think of other Navigation variations that can be added to the drop down. Variations where it would be beneficial to use text and icons. I am wondering if we should in general use text and icons for all variations.

Screen Shot 2020-11-06 at 13 10 41

--

/ na the Navigation (horizontal) and the Navigation (vertical) shows up. After we get this PR merged it would be natural to just have one general Navigation block that starts out horizontal. The user can select vertical/horizontal in the sidebar drop down.
Screen Shot 2020-11-06 at 13 00 09

@ntsekouras
Copy link
Contributor Author

Variation drop down is seen in the sidebar when the Navigation startup screen is present.
/ na the Navigation (horizontal) and the Navigation (vertical) shows up. After we get this PR merged it would be natural to just have one general Navigation block that starts out horizontal. The user can select vertical/horizontal in the sidebar drop down.

Maybe it would be better just to hide it during initialisation.. I'll have to check more how to make it work with every block best, as most of the blocks do not have a Placeholder for creation. I think it'll become more obvious after checking what core blocks will use that feature.

I'll do that after we have some design in place for the available options.

am wondering if we should in general use text and icons for all variations.

I agree with that. Icons will be pretty useful.

@draganescu
Copy link
Contributor

I wonder, probably silly, why do variations need to opt in to be available as transforms? Can't we default to having all variations available?

@ntsekouras
Copy link
Contributor Author

Hey @draganescu!

I wonder, probably silly, why do variations need to opt in to be available as transforms? Can't we default to having all variations available?

There are more nuances to this, especially when having variations with InnerBlocks just like Columns and Query that we have to handle the content as well and probably have to do it manually with some kind of block variation transform function(second step in a follow up PR).

For example when we have a 3 columns Columns Block should we show the transform to 2 Columns? It needs custom handling for the content. Another example is the embed block which tries to auto transform in block variations, so it wouldn't make sense at all to show this list.

@ntsekouras ntsekouras force-pushed the try/transform-block-variations branch from f1b9a1f to 1b142b3 Compare November 9, 2020 10:55
packages/blocks/src/store/test/selectors.js Outdated Show resolved Hide resolved
packages/blocks/src/store/selectors.js Outdated Show resolved Hide resolved
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.

Code wise, this PR is ready to go. There are two things that need to happen to consider it done:

  • documentation for BlockVariationTransforms component needs to be polished
  • design review is required for the first iteration

I will leave the final call to other folks but from myself it's ✅

@ntsekouras ntsekouras added the Needs Design Feedback Needs general design feedback. label Nov 9, 2020
@ntsekouras ntsekouras marked this pull request as ready for review November 9, 2020 13:11
@paaljoachim
Copy link
Contributor

I believe it will benefit the user to use thumbnails for all variations. As one would get text and a visual image. It would keep a consistency in relation to the UI for variations that all use thumbnails. As I mention in this comment: #25231 (comment)

In relation to the Navigation variation drop down in this PR.

Without thumbnails:
Nav-block-Variations-no-thumbnails

With thumbnails:
Nav-block-Variation-with-thumbnails

In relation to the horizontal and vertical variation having a thumbnail might not be that important, but if one begins to add other variations to the Navigation block then thumbnails might be needed to give a visual impression. Picking and choosing when to use thumbnails and not would break the consistency. Which means even though some variations are easy to understand with the text it would be better to have all variations using a thumbnail approach. Somewhat similar to the Styles Panel. Some people understand better with visual and some better with text, using both can be very helpful.
(Btw most of this is a repeat of what I mention in the comments I made in the issue: #25231)

@ItsJonQ @jasmussen

@jasmussen
Copy link
Contributor

Question: why does the navigation block appear as two blocks, requiring an entirely new UI to transform between them, when we already have this?

Screenshot 2020-11-10 at 08 14 12

This seems like a lot of added complexity, for reasons I can't really spot.

@ntsekouras ntsekouras force-pushed the try/transform-block-variations branch from 4247673 to 3f41afb Compare November 12, 2020 10:20
@jasmussen
Copy link
Contributor

This is what I see in the latest iteration:

transforms

Seems like there's an opportunity in the future to revisit all transforms (Shaun has lots of good thoughts). But in the mean time, and in the spirit of iterating based on based on this feedback, there are a couple of things:

The dropdown should show the selected variation when collapsed. I.e. instead of saying "Transform to variation", it should say "Horizontal" or "Vertical".

There's something up with the padding, it's too tight:

Screenshot 2020-11-12 at 11 36 13

It's this CSS that overrides it:

Screenshot 2020-11-12 at 11 36 09

Here it is with its intrinsic padding:

Screenshot 2020-11-12 at 11 36 58

That chevron on the right still looks funky and scaled down, but that looks like a separate issue with the dropdown component itself.

There doesn't seem to be a default choice. I.e. when I insert a horizontal navigation, I'd expect the checkmark to be present for the horizontal choice.

The menu jumps a bit in width, which is jarring. You probably need to provide a min-width to the popover.

Finally, instead of saying "Navigation (horizontal)", should it just say "Horizontal"?

@jasmussen
Copy link
Contributor

Please note in the above GIF, the actual variation doesn't appear to change in the content. That's the fault of my theme. It works fine in TwentyTwentyOne

@ntsekouras
Copy link
Contributor Author

Thanks for reviewing @jasmussen!

There doesn't seem to be a default choice. I.e. when I insert a horizontal navigation, I'd expect the checkmark to be present for the horizontal choice.

This is a problem quite difficult/expensive to solve and with no big value, especially when this will include transformations with InnerBlocks.

The dropdown should show the selected variation when collapsed. I.e. instead of saying "Transform to variation", it should say "Horizontal" or "Vertical".

This change would make the Component difficult to understand what is showing, no? We have no other label. I do believe though that's fine because in combination with the above comment of not knowing the variation exactly (it will be quite obvious with the InnerBlocks variations) it could be not valid information as well.

Finally, instead of saying "Navigation (horizontal)", should it just say "Horizontal"?

This is the block variation's description...

@jasmussen
Copy link
Contributor

This is a problem quite difficult/expensive to solve and with no big value, especially when this will include transformations with InnerBlocks.

Is there a hack? Showing whichever variation of block you chose, without it actually being "set"?

For example with Social Links, the default size is "Medium". It hasn't actually been set, and you can choose to explicitly set it, which adds the classname. But we still show a checkmark next to medium, because that's the size you see.

This change would make the Component difficult to understand what is showing, no? We have no other label. I do believe though that's fine because in combination with the above comment of not knowing the variation exactly (it will be quite obvious with the InnerBlocks variations) it could be not valid information as well.

I'm just thinking of this in terms of being a dropdown menu — a dropdown menu should show the selected choice. Anything else is a bit of a departure from the design, and if we can't make it work as such, I'm not sure it's as effective.

@ntsekouras
Copy link
Contributor Author

For example with Social Links, the default size is "Medium". It hasn't actually been set, and you can choose to explicitly set it, which adds the classname. But we still show a checkmark next to medium, because that's the size you see.

Yeah, that is handled with default css and can't work in a generic component like this.

I'm just thinking of this in terms of being a dropdown menu — a dropdown menu should show the selected choice. Anything else is a bit of a departure from the design, and if we can't make it work as such, I'm not sure it's as effective.

I'm not sure what other alternatives we have here. I think this component is more like an actions menu. Transform to this and that's it. I wasn't really sure about the check icon either for that reason. The check icon is something more of this what you selected last but it could potentially not be the actual representation..

If we remove the checked icon would it make more sense as a design?

@gziolo
Copy link
Member

gziolo commented Nov 12, 2020

If we remove the checked icon would it make more sense as a design?

I second that idea. The issue with the current proposal is that it will work as intended only when a user triggers the transformation in the dropdown menu. As soon the user navigates away from the visual editor, by opening a code editor mode or going to another page, there is no simple way to detect which transformation was applied. Well, in this particular case, it would be easy to detect, because there is only one attribute that gets updated. However, as @ntsekouras already mentioned, this can quickly become complex to verify when there are inner blocks involved. Regardless, we would need to extend block variations API with a logic that detects the currently applied transform if any. I can imagine a case when variations don't cover all combinations of values that attribute to be modified can cover.

Aside: rather than using block variations for the Navigation block, we could also add the same dropdown that modified attributes directly ... 😃

@jasmussen
Copy link
Contributor

Part of the problem is that this is yet another way to transform blocks. I understand it's meant to solve this problem:

The problem that needs solving here is having a way to 'update' a block to another block variation, after its creation. This has nothing to do with where the variations were available in the first place (inserter/placeholder pattern etc..).

In light of that, it seemed like like this dropdown design was a decent path forward — relatively minimal but provided a path forward. But that design is inherently a dropdown, so if it doesn't show the current variation in its resting state, the design falls apart a bit.

Pinging a few for some more thoughts: @shaunandrews @kellychoffman

@ntsekouras
Copy link
Contributor Author

But that design is inherently a dropdown, so if it doesn't show the current variation in its resting state, the design falls apart a bit.

Since we can revisit later when more complex transforms will be handled, another alternative is to check the selected variation, if there is a match, by checking the attributes for now. That means that this will be the same as now but will have the matched variation with the check icon, when clicking the Dropdown.

I have to note again though that this matching might not be possible/valid with complex variations later.

@gziolo
Copy link
Member

gziolo commented Nov 12, 2020

I had also this idea that I shared with @ntsekouras in a private message. If we assume that those transforms never use the inner blocks template but rather call a callback to apply changes, we could easily detect whether any block variation matches current attributes. There might be a limitation where only one variation could match and it would need at least one attribute provided. In fact, the case we have fits perfectly fine with the description provided. It might not work well in another case, but we better battle test it first rather than overthink.

packages/components/src/button/index.js Show resolved Hide resolved
packages/components/src/dropdown-menu/index.js Outdated Show resolved Hide resolved
@@ -0,0 +1,38 @@
.block-editor-block-variation-transforms {
Copy link
Member

@gziolo gziolo Nov 13, 2020

Choose a reason for hiding this comment

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

It looks like a lot of hassle to style the toggle button to look like something completely different.

Do we have other components that are customized to look and behave like a select control that allows custom HTML code for items? The one that allows picking a different font size might be a better fit in terms of styling and accessibility support.

It's something to think about, the current proposal is fine to test this feature as an experiment.

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 have checked that (CustomSelectControl) but would want many more additions to support better handling of content - it's not so generic for now.. I think for now it's okay and we can revisit whether to enhance the CustomSelect or create something else.

Copy link
Member

Choose a reason for hiding this comment

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

CustomSelectControl is a tiny wrapper over downshift.js which isn't opinionated about HTML used:
Screen Shot 2020-11-13 at 13 54 16

I would be very surprised if you wouldn't be able to use it here, but I agree that you might need to apply some tweaks as well. The benefit is that it better reflects its purpose from the accessibility point of view.

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 started with that, but saw that needed enough tweaks and seemed rather specific contrary to its name.

  1. You think I should change it now or in a follow up PR?
  2. The DropdownMenu suffers from accessibility point of view? Should we look how to improve this as well? (I haven't dig into accessibility yet)

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.

Quite a journey 😄 Excellent job tackling this issue, let's see how it works in action 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block Variations Block variations, including introducing new variations and variations as a feature [Package] Block editor /packages/block-editor [Type] Feature New feature to highlight in changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a way to transform between block variations
6 participants