WordPress / gutenberg

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

Add theme.json presets for Border Radius #64041

Open fabiankaegy opened 1 month ago

fabiankaegy commented 1 month ago

Like spacing, color, aspect ratios etc. Border Radii are something that should be applied consistently throughout a design. Instead of having to always manually enter the raw px value it would be great to be able to use a variable instead. Ideally this would work similar to the spacing control where you can either provide a variable or enter the raw value.

fabiankaegy commented 1 month ago

@jameskoster @jasmussen @richtabor Would love to hear your thoughts on this. And I think this could use some design help to figure out how to best present it :)

carolinan commented 1 month ago

This would be a small improvement over using theme.json>settings>custom, or trying to keep consistency using a ref in theme.json.

fabiankaegy commented 1 month ago

@carolinan Yeah we already do this in our themes in code. But we often still need to select from different options for what radius should be used on a component level... Like for example two different groups may need different radii. And that is not something that we can really accomplish with just the defaults... Yeah we can hard code it in a pattern but then we loose the ability to change it site wide when the radius needs to be tweaked

jameskoster commented 1 month ago

Agree this would be a nice improvement.

The UI will need some thought. Hopefully we can reuse elements of the spacing controls. I suppose it would need to support:

Does that sound right? Perhaps something like this could work:

radius
richtabor commented 1 month ago

The UI will need some thought. Hopefully we can reuse elements of the spacing controls. I suppose it would need to support:

I like that this follows closely to the https://github.com/WordPress/gutenberg/issues/63963 concepts pitched. We could reuse that certainly.

aaronrobertshaw commented 1 month ago

Like for example two different groups may need different radii. And that is not something that we can really accomplish with just the defaults... Yeah we can hard code it in a pattern but then we loose the ability to change it site wide when the radius needs to be tweaked

A short-term option could also be to leverage block style variations. They'd be editable via Global Styles, should the need to change them arise, with the changes automatically applied anywhere the variation was applied.

jasmussen commented 1 month ago

Tiny nitpick, the footprint of the icons inside the 24x24 base in these feel a bit too large:

Screenshot 2024-07-31 at 08 53 12

asafm7 commented 1 month ago

Can we maybe build upon custom theme.json settings to expose custom presets instead of, or in addition to, using a scale? (similarly to what we have with colors currently)

For example:

image

Another way to do it might be adding "Var" to the units drop-down and then manually typing the var name to the input field (maybe in the future have a dropdown or autocomplete).

image

For example, a design might have "soft corners" (let's say border-radius: 12px) that need to be applied to many but not all elements.

We can create: "globalBorderRadius": "12px" custom setting in theme.json (or through the UI).

It isn't a small-medium-large sort of thing.

Let's say in the future the designer wants to switch from 12px to 10px, it doesn't make sense to redefine what small or medium is. Instead, we can just change the globalBorderRadius setting.

Another way of seeing it is as bringing custom CSS properties (variables) into the editor UI. In the context of border-radius It can be applied either to each corner individually, or to all corners tighter,

This is how I understand the original message by @fabiankaegy, but maybe I'm missing something.