-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Global Styles and Theme.json: Next Steps #62686
Comments
The big advantage for theme authors with this method is that you can define a default block style variation in This is the primary use case for me, and solves some years-old issues that have needed very hacky workarounds. It's one of the most exciting aspects of the updates for 6.6. For example, here's my {
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 3,
"title": "Section 1",
"slug": "section-1",
"blockTypes": [ "core/group" ],
"styles": {
"color": {
"background": "var:preset|color|primary-700",
"text": "var:preset|color|white"
}
}
} But this must look different in my various global style variations, and here is an example of overwriting {
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 3,
"title": "Example",
"settings": {
"blocks": {
"variations": {
"section-1": {
"blockTypes": [ "core/group" ],
"color": {
"background": "var:preset|color|primary-900"
}
}
}
}
}
} And each of my 9 global style variations add their own tweaks to
Assuming I'm understanding this proposal correctly: For me, this would mean I'd need to have even more JSON files to cover the use cases. Suddenly, my theme could go from its current 11 block style variation JSON files to 99 (that's 11 block style variations x their customizations for my 9 global style variations). That could potentially feel unmanageable. I like the idea overall, and I feel like I could build a new organizational system to handle that. But I'd want us to think through the impact such a change might have. We need to see how this is implemented in the wild before jumping too far down another path. I'd argue that we'll likely want to maintain both methods. I really like the idea of a |
Yes, this is solved by the "parent" key basically. You'll just register "section-1" multiple times with different "parent" keys. It does have the potential to increase the number of theme.json files but I feel like overall it's a better model and would be better than a huge theme.json with everything and every style variation override. The general idea is not incompatible with keeping these overrides, what I don't like principally is that today it's not just "overrides", they also register the variations. So things like |
The more we can simplify the mental model, the better. It's definitely starting to get overwhelming.
The timing of this downside is unfortunate. I don't have any strong opinions, but if it means improving the architecture of theme.json in the long run, I'm for it. |
Thanks for getting the discussion started. ❤️ Sorry for all the repetition below, I'm just writing things out so I understand the model.
As you've noted, the custom post type (CPT) Currently, if a user selects a non-default style variation in the site editor, that variation's styles will be stored in the default CPT. The incoming styles are merged with any existing user styles. WordPress doesn't know whether a style variation has been applied. This default CPT represents the actual state of the site's styles. Under the proposal, let's say a user applies a non-default style variation (example-variation.json). Right now, the data would be merged with the default CPT's data. Now the user edits example-variation.json in the editor, and it's saved in a separate CPT with a parent key. Questions:
Presumably the non-default style variation CPTs can also be "reset". Each of these would generate a revision post when edited. I know it's premature to discuss this, however I would say, therefore, that it would be useful to open up revision history for variations as well. If that happens, the above questions are also relevant, but in the case where a user restores or resets a non-default style variation that is currently active/applied.
For this idea, but more in general I like the concept of a visual representation or some other UI to explain to the user where styles are coming from, and where to edit them. Especially so if style variations add another CSS layer to the hierarchy. I'm thinking of the scenario in which a user asks, for example, "Why is this element blue? Where is it coming from and can I change it?" See: |
No, there are two separate actions:
These two actions are separately. We may offer in the UI "copy styles from variation into the active one" but that seems additional and not mandatory in the UX flows.
Good question and an implementation detail that I can't answer right now, the important thing is that if you fetch a variation using the REST API or a PHP API (to generate the styles), you get the full object.
Yep, sounds great.
In the current proposal, I'm actually not proposing another level in the hierarchy, I'm simplifying to say, for a page or template, the user just selects a variation to act as the "active" variation (so the default one is not used at all, only the active one instead). I think it allows for the same use-cases without added complexity. But we may be getting ahead of ourselves. If I were to start implementing the proposal above today, I'll probably start by implementing the mechanics to "switch active variations" and the save behavior. After that, I'll probably implement a way for users to create and edit variations in the UI. Later, we can think about these new possibilities (revisions, page level variations...) |
These changes involve: - Move shared variation definitions from styles.blocks.variations to styles.variations - Remove blockTypes from styles.variations. - Do not register shared variations from theme style variation or primary theme.json files. - Move the merging of theme.json data into the WP_Theme_JSON_Resolver and WP_Theme_JSON classes. These changes improve performance and are more future-proof API wise. See conversation at WordPress/gutenberg#62686 Props aaronrobertshaw, oandregal, andrewserong, joemcgill, talldanwp, andrewserong, ramonopoly, richtabor, youknowriad. See #61312, #61451. git-svn-id: https://develop.svn.wordpress.org/trunk@58466 602fd350-edb4-49c9-b593-d223f7449a82
These changes involve: - Move shared variation definitions from styles.blocks.variations to styles.variations - Remove blockTypes from styles.variations. - Do not register shared variations from theme style variation or primary theme.json files. - Move the merging of theme.json data into the WP_Theme_JSON_Resolver and WP_Theme_JSON classes. These changes improve performance and are more future-proof API wise. See conversation at WordPress/gutenberg#62686 Props aaronrobertshaw, oandregal, andrewserong, joemcgill, talldanwp, andrewserong, ramonopoly, richtabor, youknowriad. See #61312, #61451. Built from https://develop.svn.wordpress.org/trunk@58466 git-svn-id: http://core.svn.wordpress.org/trunk@57915 1a063a9b-81f0-0310-95a4-ce76da25c4cd
These changes involve: - Move shared variation definitions from styles.blocks.variations to styles.variations - Remove blockTypes from styles.variations. - Do not register shared variations from theme style variation or primary theme.json files. - Move the merging of theme.json data into the WP_Theme_JSON_Resolver and WP_Theme_JSON classes. These changes improve performance and are more future-proof API wise. See conversation at WordPress/gutenberg#62686 Props aaronrobertshaw, oandregal, andrewserong, joemcgill, talldanwp, andrewserong, ramonopoly, richtabor, youknowriad. See #61312, #61451. Built from https://develop.svn.wordpress.org/trunk@58466 git-svn-id: https://core.svn.wordpress.org/trunk@57915 1a063a9b-81f0-0310-95a4-ce76da25c4cd
These changes involve: - Move shared variation definitions from styles.blocks.variations to styles.variations - Remove blockTypes from styles.variations. - Do not register shared variations from theme style variation or primary theme.json files. - Move the merging of theme.json data into the WP_Theme_JSON_Resolver and WP_Theme_JSON classes. These changes improve performance and are more future-proof API wise. See conversation at WordPress/gutenberg#62686 Props aaronrobertshaw, oandregal, andrewserong, joemcgill, talldanwp, andrewserong, ramonopoly, richtabor, youknowriad. See #61312, #61451. git-svn-id: https://develop.svn.wordpress.org/trunk@58466 602fd350-edb4-49c9-b593-d223f7449a82
I've run into a bit of theme.json spaghetti while trying to parse block style variation objects for #66731. If there was a way to process individual WP_Theme_JSON objects discretely, I think it would help. As it stands it's difficult — dare I say, excruciating— to track the origin of variations, especially if they've been merged into the global styles tree. I say all this, of course, as someone with only limited experience with totality of the style variations feature. |
The Global Styles architecture and features is growing significantly and the complexity of both the implementation and the mental model is increasing due to the organic nature of the iteration process. It is a good time though to take a step back, take a look at the main issues we're having and how to address them while simplifying the mental model.
Currently supported features:
styles
folder likestyles/red.json
orstyles/blue.json
styles.blocks.core/button.variations.outline
. In a way we're using the same theme.json structure and same global styles UI to edit a style variation that applies only to a given block.styles
folder and by using the top levelblockTypes
property to choose which block type they apply to. The structure is very similar to any style variation (default theme.json, red.json or blue.json)blocks.styles.variations
. The advantage here is that theme authors can define these variations within a parent theme style variationred.json
file, so when the user picks the "red" style variation for his theme in the UI, it also changes the styles of the available style variations for the blocks.These are great features, but it's easy to see how the multiple ways to write and save these variations can start to become confusing for users, in addition to the complex mental model, here are some issues that were raised before related to this model and some that are more hypothetic issues and features that we'd want to support:
blocks.styles.variations
key introduced in 6.6 is not ideal.A potential path forward / proposal
I think there's an opportunity to simplify the mental modal and solve all of the issues above:
styles
in a theme = a style variation = 1 separate CPT entry: this means that style variations are not all saved to the same default CPT entry.Downside
This proposal mean that the configuration introduce in 6.6 under
styles.blocks.variations
is not ideal (as it breaks this mental model and becomes redundant) and might get deprecated later. Given how late we're in the release cycle of 6.6, I'm proposing that we deemphasize this feature (not remove it) in the docs / dev notes / theme.json schema... We can introduce a new apiVersion if needed to completely remove it.I'd appreciate any thoughts on this proposal. Thanks. @aaronrobertshaw @ellatrix @carolinan @richtabor @andrewserong @ndiego @mtias @ramonjd @jasmussen @oandregal @tellthemachines
The text was updated successfully, but these errors were encountered: