-
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
Conditional Duotone Toolbar Visibilty (With State) #33466
base: trunk
Are you sure you want to change the base?
Conversation
I don't think the block editor store is the right place, as it's more for general editor state. This is quite specific to an individual block feature. I think this problem is bigger than just duotone as well. Looking at the cover block there's a bunch of features that probably shouldn't be active when the placeholder is visible, for example it's possible to put a border around the placeholder state. So it might worth thinking more from a point of view of building a system that might work for various block features. One option could be that a block has some way to indicate that it's in a placeholder/setup state. Block 'supports' and other features would have access to that state and can use it to determine whether their UI should be visible. It might be good tomake an issue to discuss what generic solution to the problem might look like. |
@talldan But you like the idea of using a store as opposed to the block attributes, right?
Just indicating the setup state isn't enough. In the case of the cover block, duotone should also be disabled when the background is repeated or fixed. And in the media & text case (#32984), it should be disabled for videos, but not images. I can imagine a system where the block supports hooks have their own store for UI state. The margin/padding UI state could move there and fix #31839. I'm not thrilled about using I think another solution could be some function mapping attributes to block support hooks' options that doesn't rely on
I can also put it on the core-editor chat agenda for discussion. I'm actually in a reasonable timezone to attend that right now which is nice. |
Yep, it's preferable to block attributes, as attributes should preferably used to drive the rendered output of a block rather than the editor experience. But I think anything in the block editor store should be generic, rather than referring to a concrete feature by name. So rather than There might also be other options when it comes to fixing this though. An alternative could be adding gutenberg/packages/block-editor/src/hooks/duotone.js Lines 200 to 212 in ceaa2da
A This would become an API for duotone, and a question would be if it's possible to solve the problem for other features in the same kind of way. It's possible others working on these kind of features have had thoughts about the general problem, so definitely a good thing to gather a few more opinions. Flagging it at the meeting sounds like a good idea 👍 |
29175b5
to
c64fe6e
Compare
I was thinking too hard about the problem and overlooked the simple tools like
I'm leaning towards not building a generic API considering how simple the |
Not sure if this is the best fit for it, but another option might be using context. https://reactjs.org/docs/context.html#updating-context-from-a-nested-component |
Just to document it, #23198 is a report of the issue with the cover block I mentioned earlier where styles can be applied to the placeholder. |
Similar Styles/padding issue for the Image block - #23122. |
Thanks for staying on this! |
While I like the idea of passing a
It seems that making blocks to signal their "ready state" to the blocks store would cover more use cases, including third-party tools. Of course, we could also have specific "ready states" per feature to support cases like duotone's, although we should not encourage that. I've just seen that Nik is exploring this approach at #33823 |
Description
A block supporting duotone needs to be able to control the visibility of the toolbar. Data needs to be passed from the supporting block (i.e. image block) to the block supports (i.e. duotone).
See #31373
This change allows the image block to prevent rendering of the duotone toolbar. This has the side-effect of solving the second issue since the point where the duotone toolbar is rendered comes after the rest of the block toolbar items, so the toolbar button is now always rendered at the end.
How has this been tested?
Screenshots
Types of changes
New feature / Bug fix
Checklist:
*.native.js
files for terms that need renaming or removal).