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

Styling block variations with global styles and theme.json #67444

Closed
carolinan opened this issue Nov 30, 2024 · 7 comments
Closed

Styling block variations with global styles and theme.json #67444

carolinan opened this issue Nov 30, 2024 · 7 comments
Labels
[Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed

Comments

@carolinan
Copy link
Contributor

carolinan commented Nov 30, 2024

What problem does this address?

Recently, it was made possible to set default values for block style variations in theme.json.
But there is no way to style block variations.

Block variations and block style variations are separate concepts.
A block variation can be a variation for a query loop block with specific settings, registered by a plugin or theme. Or it, can be the row and stack variations of the group block, the tag variation of the post terms, and so on.

Unblocking this would solve scenarios where a variation could be used instead of a new block, but with the full styling possibilities.

Today, if a designer want to style the categories or tags differently -like in Twenty Twenty-Five, the styling has to be done in the markup
(template, part, or pattern). When the styles are in the markup it makes it more difficult to switch themes.

@carolinan carolinan added the [Type] Enhancement A suggestion for improvement. label Nov 30, 2024
@carolinan
Copy link
Contributor Author

@aaronrobertshaw @t-hamano

@t-hamano
Copy link
Contributor

Thanks for the suggestion.

From what I understand, a block variation is technically a variation of attributes.

Some CSS class name is needed to apply styles via the Global Styles, but block variations, unlike block style variations, don't have their own CSS class name. This means I'm wondering if we need to add some special CSS class name for block variations to the block.

For example, we might be able to generate some unique string from the block name and the entire attributes object, and add the CSS class name based on that.

However, I'm not sure how complicated such an approach would be to implement.

@t-hamano t-hamano added Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Feature] Block Variations Block variations, including introducing new variations and variations as a feature labels Nov 30, 2024
@aaronrobertshaw
Copy link
Contributor

Thanks for taking the time to write up the issue @carolinan 👍

It's worth noting that this is a duplicate of some open issues:

There's also this one that might overlap a little:

Can we close this and consolidate the discussion on the existing issue? I think #47324 is probably the original.


From what I understand, a block variation is technically a variation of attributes.

Some CSS class name is needed to apply styles via the Global Styles, but block variations, unlike block style variations, don't have their own CSS class name

@t-hamano is on the money here. The catch is how we solve this problem.

To implement something that "just works" without users having to resave posts, it would need to work both JS and PHP side. Any hook/filter used probably needs to be able to check registered block variations and then know what set of attributes would match that, perform those comparisons, and finally apply some CSS class name. Achieving that in some performant manner is probably a big part of why this hasn't been tackled yet.

@carolinan
Copy link
Contributor Author

Thanks, I will close this as a duplicate.

Since there is no ETA I don't believe a variation can be used as a replacement for a new post navigation block.

@carolinan carolinan closed this as not planned Won't fix, can't repro, duplicate, stale Dec 2, 2024
@carolinan carolinan added [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed and removed [Type] Enhancement A suggestion for improvement. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Feature] Block Variations Block variations, including introducing new variations and variations as a feature labels Dec 2, 2024
@aaronrobertshaw
Copy link
Contributor

Since there is no ETA I don't believe a variation can be used as a replacement for a new post navigation block.

I'm not sure that the current inability to style block variations is a blocker for a variation-based approach to the post navigation block.

Early adopters of the block could define a block style variation (aka section style) as a workaround for Global Styles. My naive understanding of the proposed block is that it would primarily be used in templates and isn't something that would be added hundreds of times. So applying a block style to it wouldn't be a show stopper while a solution to styling block variations through Global Styles is worked on.

I appreciate that this may not be ideal but is an option for compromise when charting a path forward for #57664.

Also, my last comment wasn't meant to be taken as gospel. There are many people smarter than I involved in the project. It's possible others have viable ideas towards solving this one.

@carolinan
Copy link
Contributor Author

No, the section style would be available for all groups and not limited to the variation, creating unnecessary options that are not useful,
and a large amount of additional CSS since the section styles need to be repeated.

@gziolo
Copy link
Member

gziolo commented Dec 2, 2024

Since there is no ETA I don't believe a variation can be used as a replacement for a new post navigation block.

Yes, it's a more complex process to introduce block variations as a target for styling with Global Styles. @ockham shared the Proposal: Block Variation Aliases after WordCamp Europe, but it didn't get any traction because there are several backward compatibility concerns, and it isn't a simple task to dynamically detect block variations during front end rendering to apply the styling correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed
Projects
None yet
Development

No branches or pull requests

4 participants