-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Changes to theme.json #29891
Comments
It feels like |
Ah, I see how some of those comments may be a bit misleading. Here's an attempt at clarification:
The details about this need to be fleshed-out in the PR that refactors theme.json with support for the link element. I hope it becomes more clear over there. |
I've started to work on this. |
The separation of elements and blocks is clear. I do worry about the size of the file and how to keep it readable. So it is possible to both target H1, heading block H1 and Site title |
#30541 to implement this is at the latest stages (polishing, fixing some bugs). |
This might be a different issue, I don't have much experience raising issues on github, but now when I use the "elements" object in theme.json, those settings are inlined in the editor styles, and then my custom editor styles are loaded after this, which overrides the settings in theme.json. For example, I have the following in my theme.json:
However editor stylesheet begins with a reset which sets all heading levels to There seems to be an inconsistency in the order in which these styles are loaded in the editor vs the frontend. Side-question: is it possible to still use the old method of targeting "core/heading/h1" in the "styles" object? When I try it, it has no effect. |
Part of #20331
@mtias @youknowriad @mcsf @nosolosw provided thoughts for this task.
As we approach the 5.8 cycle and the merge target for the theme.json API, it’s a good time to evaluate what is working and what needs some improvement. All in all, theme.json is responsible for providing configuration settings, global customization on things like text and links, and default style attributes for blocks. The first and last points seem to be fairly well established and their use fairly clear by themes, but the second point needs a bit more formalization.
The latest round of UI design iterations for the Global Styles sidebar puts a bit more emphasis on the style settings of cross-block elements. In light of this and the feedback gathered from themes so far there are a few aspects that can be improved if we clarify these three representations (settings, elements, blocks) a bit better.
To dive into this, let's explore an example of a theme.json that:
With the current approach
Some of the struggles of the current approach are:
We currently have two mechanisms to target DOM elements of a block:
core/heading/h1
to targetH1
elements andstyles.color.link
to targeta
elements within the heading block.With the current approach theme authors can only set the color of the links but not the rest of its style properties (text-decoration, border, background-color, etc).
For blocks that use block selectors (
core/heading/h1
, etc) there's no way to provide a style or setting for all the configurations of the same block (e.g.: presets forcore/heading
or a particular color style for all headings). theme.json spec: use block names for settings & block selectors for styles #29773The current API for settings & styles promotes block-level APIs while themes have expressed the desire of being able to set things across blocks. An example we've noticed is that current themes with theme.json support use
settings["defaults"]
to target settings but notsettings["core/heading/h1"]
― this is a hint about what are the primary and secondary use cases. See the latest round of mockups for the global styles sidebar as another case in which we want to provide an API to set styles across blocks.The current "root" and "defaults" selectors have been reported to be confusing. As we allow composing theme.json objects further (for example, to change the settings for a “page” template or a template part) the presence of a nested “root” object becomes more strange.
Being able to target blocks and elements
The proposal formalizes what we have been aiming to do for Links but extends it to other elements. This makes it more clear that, in addition to blocks, themes and the global styles UI can target specific cross-block elements. Instead of using
core/heading/h1
we can useh1
directly (independently from the heading block) and instead of usingstyles.color.link
we can targeta
elements directly.The idea is that these elements are the same that were shared in the mockups for the global styles sidebar. Initially, these elements are set by core but plugins/themes (or even users through the style variations mechanisms) could be able to register custom ones in the future.
Note that:
defaults
androot
is dropped: the settings & styles that lived within them are now top-level keys that target the document (settings => control the whole editor, styles => style the corresponding body/template part/etc).blocks
key (so it's clear that's a secondary API).elements
key instyles
to target the elements suggested by the global styles sidebar mockups, including links or H1-H6 DOM tags.elements
can be nested within a particular block but a particular block can't be nested within another block.Updating the theme.json shape
While the theme.json file is still experimental the plan is to make changes in a way that the plugin can support the two versions for a couple of weeks (a release or two, depending on the schedule) to both give time to adapt and to allow comparisons. Ultimately, only the version that lands in core will be supported going forward.
The text was updated successfully, but these errors were encountered: