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

Replace block variation buttons with ToggleGroupControl #45654

Merged

Conversation

TimBroddin
Copy link
Contributor

What?

The buttons to transform blocks to different variantions should be replaced with the new icon button variant of ToggleGroupControl.

Why?

Because the ToggleGroupControl is better suited for this. This will improve consistency, reduce code duplication, and add visual/semantic indications that the options are mutually exclusive.

How?

I replaced the buttons with ToggleGroupControl/ToggleGroupControlOptionIcon

Testing Instructions

  1. Create a new post or page
  2. Add a Group, Row or Column block
  3. Verify that the block variations picker still works.

Screenshots or screencast

Before After
CleanShot 2022-11-09 at 12 00 15@2x CleanShot 2022-11-09 at 11 57 36@2x

@codesandbox
Copy link

codesandbox bot commented Nov 9, 2022

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@noisysocks
Copy link
Member

It might look a bit closer to the original if we add size="__unstable-large" to <ToggleGroupControl>. This makes the control 40px high which will eventually be the default.

@noisysocks noisysocks added [Type] Code Quality Issues or PRs that relate to code quality [Block] Group Affects the Group Block labels Nov 9, 2022
@TimBroddin
Copy link
Contributor Author

It might look a bit closer to the original if we add size="__unstable-large" to <ToggleGroupControl>. This makes the control 40px high which will eventually be the default.

Thanks for pointing this out! I'll change it!

@aaronrobertshaw aaronrobertshaw added the Needs Design Feedback Needs general design feedback. label Nov 9, 2022
@andrewserong
Copy link
Contributor

andrewserong commented Nov 9, 2022

Thanks for looking into this one! Unfortunately switching over to ToggleGroupControl seems to introduce an issue if we have a large number of variations (they overflow to the right in the inspector):

image

While the Group block currently only has a few variations, it's possible that there are custom blocks out in the wild with larger numbers of variations with the transform scope.

One way to test this manually is to hard-code the social link/icon block to expose the block variations as transforms. To do this, add the following line to the variations.forEach in block-library/src/social-link/variations.js in your local environment:

variation.scope = [ 'transform' ];

All up that area in my local environment looks like:

variations.forEach( ( variation ) => {
	if ( variation.isActive ) return;
	variation.isActive = ( blockAttributes, variationAttributes ) =>
		blockAttributes.service === variationAttributes.service;
	variation.scope = [ 'transform' ];
} );

That then exposes all the social icon variations in the UI for testing.

Would it be possible to use the ToggleGroupControl only if the number of variations is lower than a certain threshold, and if it's over that amount, perhaps use the existing buttons?

@TimBroddin
Copy link
Contributor Author

Thanks for pointing this out @andrewserong. I'll add a check!

@TimBroddin
Copy link
Contributor Author

TimBroddin commented Nov 9, 2022

I've updated the PR.

Five or less options More than five options
CleanShot 2022-11-09 at 14 16 18@2x CleanShot 2022-11-09 at 14 16 08@2x

padding: 0 $grid-unit-20 $grid-unit-20 52px;
width: 100%;

.components-dropdown-menu__toggle {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the follow-ups!

Are these style removals intentional? Most of these appear to affect the dropdown list version of the list of variations, which is used when not all of the variations have unique icons.

To test this, with the changes applied to scope the social icons for transform, in packages/block-library/src/social-link/variations.js also set any of the social icon blocks to use the same icon as one of the other variations. E.g. set any of them to use the YouTubeIcon icon.

Here's a quick view of trunk versus this PR:

Trunk This PR
image image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, I need more coffee. I forgot to push the changes 😄 Thanks for your patience!

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, I need more coffee.

No worries, I have the opposite problem of having drunk too much coffee!

I've re-pulled the changes, and it looks like there are still some differences in the dropdown popover for the transform to variation list. Visually it looks like there's now additional padding / a larger width of the popover, and it overflows the area so there's a horizontal scrollbar:

Trunk This PR
image image

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

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

Nice work @TimBroddin, thanks for all the back-and-forth here! This is testing well for me in all three cases:

✅ Group block's variations use the ToggleGroupControl and toggle as expected
✅ A block with a large number of variations, each with a unique icon, correctly renders the buttons approach
✅ A block with a large number of variations, where there are not unique icons, renders the drop down list approach

This LGTM! ✨ It might be worth also getting an approval from a designer before merging, too

@andrewserong
Copy link
Contributor

@jasmussen just copying you in on this one as I think from memory you put together the original designs for this area?

@jasmussen
Copy link
Contributor

Hey, thanks for the PR, thanks for the ping, conceptually seems just right.

Just to be sure I get the context right: when there are more than a rows worth of transforms, they still become a dropdown, correct?

This is what I'm seeing in the branch:
Screenshot 2022-11-10 at 08 56 26

There should be no enclosing border around these controls. I thought actually that was removed as part of #45492, but it seems to be there after a rebase. Is there a prop that needs to be set/unset? CC: @mirka @ciampo

Comment on lines 109 to 113
<Flex>
<ToggleGroupControl
label={ __( 'Transform to variation' ) }
value={ selectedValue }
isBlock
Copy link
Member

Choose a reason for hiding this comment

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

Regarding @jasmussen point about the border: The isBlock prop is what controls the border visibility for the moment. It looks like the Flex component is being used here to undo what the isBlock prop is for anyway, so I think all we need to do is remove both the Flex and isBlock prop 🙂

variations,
} ) {
return (
<fieldset className={ className }>
Copy link
Member

Choose a reason for hiding this comment

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

Is this fieldset necessary? The ToggleGroupControl alone is semantically grouped and labeled. Maybe swap with a div if it's just for the wrapper classes?

@mirka mirka added the [Package] Block editor /packages/block-editor label Dec 14, 2022
@mirka
Copy link
Member

mirka commented Dec 13, 2023

@TimBroddin Are you available to address the remaining feedback? If not, let us know so we can find someone to take over 🙂

@TimBroddin
Copy link
Contributor Author

@TimBroddin Are you available to address the remaining feedback? If not, let us know so we can find someone to take over 🙂

If you could find someone to take over, that would be great. Sorry for not addressing this earlier.

@mirka mirka merged commit e5b995a into WordPress:trunk Dec 27, 2023
54 checks passed
@github-actions github-actions bot added this to the Gutenberg 17.4 milestone Dec 27, 2023
@bph bph removed [Block] Group Affects the Group Block Needs Design Feedback Needs general design feedback. labels Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Block editor /packages/block-editor [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BlockVariationTransforms: Replace implementation with ToggleGroupControl
7 participants