WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.32k stars 4.12k forks source link

Expand `ItemGroup` #64445

Open jameskoster opened 1 month ago

jameskoster commented 1 month ago

In recent times ItemGroup instances have been extended ad hoc to accommodate required features, for example:

Shadows Font Library Data view fields Block bindings Font size presets
Screenshot 2024-08-12 at 15 12 01 Screenshot 2024-08-12 at 15 13 51 Screenshot 2024-08-12 at 15 15 37 Screenshot 2024-08-12 at 15 18 41 Screenshot 2024-08-12 at 15 22 28

The more this components is arbitrarily customised the more tech debt we create. It would be good to define and implement a modern spec based on the use cases outlined above.

jameskoster commented 1 month ago

Here's an initial take on this, where I've split the items into two types; Item and DrilldownItem.

The list of props concentrate on new functionality. Any existing Item props (e.g. as and onClick are still supported).

Item

Spec-Item

Props

The states are hopefully clear enough, though one detail to decide upon here is how the hover / pressed states behave when the item itself has no on-click action. In this case a hover style is probably unnecessary.

DrilldownItem

spec-drilldown

Props

Contextual examples

If we apply these conventions to some upcoming / existing UIs, here are the results. I also included a demonstration of how the title / value truncation should work.

Examples
jasmussen commented 1 month ago

Nice, this feels mostly exhaustive and a good system. Only a few pieces feel like they are missing, and some of those are question-marks. First off, there's the stacked color-swatch:

Screenshot 2024-08-13 at 12 10 51

This feels like a pattern worth keeping. But how much can it stack? Currently in Global Styles > Colors, there's this drilldown:

Screenshot 2024-08-13 at 12 10 39

I think that drilldown works fairly well as indication of where you'll go. But does it work in this swatches-only state? Can the pattern be accommodated in these guidelines? Or should this example usage be changed, and if so, to which variant here?

jameskoster commented 1 month ago

Good catch. Agree the two-color-stack is worth keeping. It bugs me a bit how it makes the text alignment ragged though... I wonder if there's something we could do about that?

Screenshot 2024-08-13 at 16 47 45

But does it work in this swatches-only state?

This doesn't feel like the best use of ItemGroup imo, mostly because in that particular UI there will only ever be a single button. The lack of text may not be ideal from an a11y perspective too. I'd probably be inclined to explore a different treatment for that button.

jasmussen commented 1 month ago

That same river bugs me too, but making the swatches smaller creates a different kind of river, in the swatches themselves now lining up weirdly.

I think it's probably fine to keep the text river. An alternative is to start the text further in, though that might look awkward in its own way. Perhaps grouping the color stacks so they are all at the bottom would make it feel more coherent?

jameskoster commented 4 weeks ago

Yeah a guideline to group by decoration type by default could help 👍

jameskoster commented 4 weeks ago

Pinging @WordPress/gutenberg-components for any feedback on the designs, as time allows.

ciampo commented 4 weeks ago

👋 Thank you for starting the conversation on this!

I'll list a few thoughts that came up while going through the issue:

jameskoster commented 4 weeks ago

In the same way, "primary actions" and "dropdowns" could just be part of the suffix. The more generic the component is, the more flexible and open to extensibility it is.

I go a bit back and forth on this... when a component has a specific purpose – in this case grouping and listing related objects – doesn't it make sense to draw some lines in the sand? There's a reasonably narrow scope of properties we can associate with such UIs.

Could there be a case for an underlying Item component that is extensible as you described, then a ResourceItem component which consumes Item and adds the guardrails?

Is a DrilldownItem basically an Item with the chevron as a suffix? Or is there more to it?

In practise the difference is the onClick behavior. I appreciate there's no way for the component to know that natively. However a drilldown item should not have inline actions. I guess this relates a bit to the previous point... I'm unsure if it needs to be a separate component :)

Since Items can be buttons, we need to be careful in adding more interactive UI

Absolutely. Perhaps we can reuse some of the work done in the Shadow management UI:

Screenshot 2024-08-15 at 16 51 49