-
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: composable styles for different contexts #27233
Comments
That was part of the reason why I recently converted all block-styles to use |
I'd like to do some little braindump here. At the moment, theme.json is only able to target top-level blocks ― meaning that the stylesheet generated by "global styles" creates unbounded CSS selectors: In the PR that introduced these semantics (and many others I find difficult to find at the moment), we also discussed how we could address nested content. Some entities we discussed were:
However, now that I've revisited those conversations and have worked more with FSE, I've realized that the main struggle the site editor is trying to fix is how to work with templates ― the same way the main struggle for the block editor was to figure out how to work with blocks. In that sense, "global styles" is unconventional because it doesn't work with templates, it doesn't have any notion of them. Hence, my question: shouldn't it? What if there's no "global" theme.json? What if a theme.json is bounded to a template? This is, theme.json can't live in isolation but is collocated with templates: if there's a
Note that the idea would be that templates can have a theme.json, but they don't need a theme.json. You could, for example, create a single theme.json for the top-level template ( What do you all think about this? |
Hmmm right now we basically have 2 levels of styling:
The global styles affect the overall site styles and also act as "defaults" for blocks. If we add per-template-part global styles, we'll be able to have the "bounded" settings/options as mentioned above. So we'd be able to have different styles for the header/footer/sidebar etc as mentioned above. But template-parts are not even mandatory... I don't have to use a header template-part, it can all live in the root level. So theoretically on my theme I could add a In my mind template-specific styles as well as template-part-specific styles are one-offs. They are deviations from the global, consistent styles that the global-styles enforce. As one-offs, they can/should be done on the block level, I don't think it warrants a separate json file. |
I think #28533 (comment) by @mtias captures the direction for this. Copied verbatim below: I see now where the difference is coming from. For me the { // implicit site root
"styles": {},
"settings": {},
"blocks": {}
} Because I think of every global styles object as something that defines a styling context and is composable. In this example site = index = root, since I guess we'd want the flexibility of specifying different settings for something like a page template vs the main index template: // :root = body
"site": {
"styles": {},
"settings": {},
"blocks": {}
}
// :root = body.page
"page": {
...site /* inherits the configuration of the site and overrides specific parts */
"styles": {},
"settings": {},
"blocks": {}
}
// :root = .template-part-header
"template-header": {
... // inherits from whatever main template contains it
"styles": {},
"settings": {},
"blocks": {}
} One scenario the above doesn't cover is a different configuration for "template-header" if it's used in "page" vs when it's used in "index", but I'm sure we can find a way to express that ("index:template-heder" and "page:template-header"). Or we might prefer to always declare sub-contexts within the "blocks" object as just "core/template-part". That's more of a detail. I haven't been using the latest iterations in depth on a theme, so take my feedback as just my impression on the overall appearance of the system. |
Another use case here is the ability to set a specific background color (or frankly, entire palette) for a specific post/page template. For example, users might want to use a different background color for their homepage only, or they might want to use a specific accent color for certain post types. |
Definitely, what the original proposal encapsulates for templates extends not just to the root one |
Closing this issue as #40318 can include it. |
Should we allow nested styles for semantic contexts? For example, apply a specific base font size for things inside a sidebar.
The text was updated successfully, but these errors were encountered: