-
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
Next iteration of block supports mechanism #28913
Comments
I've started working on this as per #29142 Also added an initial list of tasks to implement. |
@mkaz @jasmussen I think you were involved in the social links block. Wanted to give you a heads-up that I've started to work on this issue and I'm targeting the colors of the social links block as a demo for this, so expect some PRs for that block soon. |
I'd be very happy to review that! Awesome. |
Using
|
@scruffian yes! That's what I meant with: There are cases in which block selectors will need to be bounded to the support properties instead of bounded to the block, given that they may apply to different inner elements. 😅 Happy you all were thinking along the same lines. I've already started working on this so expect to have something in your review queues in the coming days. |
Update on this task: I added an initial list of blocks that could benefit from this and also the hooks for which |
My next step is to fix #29381 |
I've updated the issue with the ongoing tasks and their owners. Please, feel free to add yourself/edit/etc as things evolve (also leaving a comment so subscribers of the task know there are changes). |
Re-sharing a comment on #30879 (review) here for better visibility as this issue seems to include other support mechanism changes: Our block.json supports API right now has inconsistencies in how we handle typography vs colors:
It is also inconsistent with theme.json given that there we have:
I guess we can change the shape of block.json and be back-compatible. We can have a back-compatibility layer that checks if things like fontSize and lineHeight are present in the data structure and if yes nests them under typography. Our code excluding the back-compatibility layer would only rely on the new structure. |
Re-sharing from #30879 (comment) my response to the question from @jorgefilipecosta:
It's already documented at https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/, but it would be good to validate whether it was released in the previous major version of WordPress. If not then we can simply change it and keep the backward compatibility layer only in the plugin for a few more releases. In general, the question goes to @oandregal how much Concluding, if this is only a simple mapping layer that would have to map some properties from their deprecated names, then we should definitely go for it. In the documentation, we should simply remove old variants in favor of the refined approach. |
I think we should either group those things together as in theme.json or have them all unnested (do not have the A question I have (that's why I'm posting here instead of in the font-size PR) is whether |
I tend to prefer the idea of grouping theme together as per theme.json. If nothing else it's neater and allows opting into a set of features via a single support flag e.g.
Skipping serialization per "feature set" or "area" would get my vote. As more blocks adopt the various block support features, I think the extra flexibility will pay off. It will cut down on the manual retrieval and application of classes and styles. In a lot of cases, applying the block classes and styles on the wrapper combined with a CSS style to inherit values if needed, gets the job done cleanly. That leaves only the cases that truly need to skip serialization to manually apply things to the inner elements. If the idea is to reduce the number of flags in the config in certain cases, could we get the best of both worlds by supporting a top level In a block that wants to skip all serialization it is one simple flag. For one that needs to keep its border styles on the wrapper element but apply colors selectively to an inner element, it can skip the colors serialization and manage only those manually. |
The initial switch to block support colors for the Table block has been merged and a follow up issue created to track the requested iterations |
Yes, I think serialization per area is a good tradeoff in what it allows to do and the effort required to disable each serialization. I'm not sure if __experimentalSkipSerialization is the right name for the flag that disables the output of the styles. On server-side rendered blocks, there is no serialization, so one may think this flag does nothing, but that's not the case; the flag disables the dynamic server-side mechanism that outputs the styles. |
I checked the "Color for navigation" task because it seems the navigation block is already using the color supports mechanism. |
I'm not sure if __experimentalSkipSerialization is the right name for the flag that disables the output of the styles. On server-side rendered blocks there is no serialization so one may think this flag does nothing but that's not the case the flag disables the dynamic server-side mechanism that outputs the styles. |
|
Personally, I find the I agree with the point regarding there being no serialization on the server-side rendered blocks though.
The same goes for background, text and border colors. The flag name is getting rather long but maybe something along the lines of |
|
All properties have gotten the |
Inspired by the discussion with @luisherranz and @c4rl0sbr4v0 in #35473, I wanted to summarize my understanding of how the experimental flag Code examples from the Button block present how you can use gutenberg/packages/block-library/src/button/block.json Lines 60 to 61 in b55cede
gutenberg/packages/block-library/src/button/block.json Lines 69 to 70 in b55cede
gutenberg/packages/block-library/src/button/block.json Lines 76 to 78 in b55cede
There are corresponding hooks that let you read those skipped features and apply them to any other nested HTML element: gutenberg/packages/block-library/src/button/edit.js Lines 123 to 125 in b55cede
They need to be mapped to class names and styles: gutenberg/packages/block-library/src/button/edit.js Lines 170 to 185 in b55cede
I'm not sure how it could be translated to code in |
Thank you @gziolo that helped me understand it quickly after looking around the various issues without success! |
Here we have an interation of applying different styles to different components both in JS and in PHP. |
Part of #20331
Implementing this would enable some interactions expressed in #26313
Kudos to @mtias @youknowriad for helping to identify the next steps for this.
What we have now
The block support mechanism allows block authors to easily make their blocks customizable via adding support for style properties: font size, color, etc.
Under the hood, this mechanism does three things:
There are some use cases that aren't absorbed by this mechanism, including:
The struggle boils down to the third point above: cast the implicit attribute to some DOM characteristic to the root node.
Next steps
A path to explore is allowing block authors a finer-grained control of how block supports work. We want to retain the bounding of UI controls to specific attributes so that block authors don't need to fiddle with controls and attribute flow. Hence, we'd allow declaring support in a way that the framework will handle rendering the UI and keeping the attribute in sync (1 and 2 in the list above) but the block author is responsible for casting the attribute on the right element (3).
Related to this fits into the global styles mechanism. Currently, blocks declare a single selector for all their style properties, so when theme authors do:
this is transformed to:
There are cases in which block selectors will need to be bounded to the support properties instead of bounded to the block, given that they may apply to different inner elements. If we have the selector bounded to a block support, the framework could also try to absorb the casting (3 in the list above) client-side.
Tasks
Adapt a single property and make one block use it: update how colors work in the social links block.
Framework implementation
Migrate these blocks & properties to the block supports system:
The text was updated successfully, but these errors were encountered: