Add runtime support for the wp-style directive#52645
Conversation
Co-authored-by: Carlos Bravo <c4rl0sbr4v0@users.noreply.github.com>
packages/e2e-tests/plugins/interactive-blocks/directive-style/block.json
Show resolved
Hide resolved
|
Size Change: +262 B (0%) Total Size: 1.43 MB
ℹ️ View Unchanged
|
SantosGuillamot
left a comment
There was a problem hiding this comment.
I've tested it, and it seems to be working great with context, state, and selectors 🙂
I just have one question: If I have the same property (color for example) defined in inline styles and in the wp-style directive, which one should prevail?
From my tests, it seems the directive takes over the inline styles. Not saying it is wrong, not sure which is the best approach, I just would like to understand the reasoning behind the decision. Have we considered how this might impact global styles? If I am not mistaken many of them are adding inline styles. Should it be the block developer's responsibility?
On the other hand, I think we could use this directive in part of the lightbox implementation and, in that case, it could be handy that the directive prevails over the inline styles so we are able to override them once the lightbox is opened.
|
Thanks, Mario 🙂
It's not taking over the inline styles. The Or am I missing something? |
|
I agree with this sentence:
The directive should be the source of truth in this case 🤔 |
I guess it makes sense 🙂 I was asking because I didn't think too much about it, in case you had considered different scenarios. I was just thinking that, depending on the implementation, it could cause unexpected UX combined with the Site Editor styles. But I guess that's the block's responsibility. Maybe they can even offer settings to decide the behavior. What if I want to keep the inline style until an action happens (a button is clicked for example)? Is that easy to do? If I am not mistaken, if I return null the style is going to be deleted, right? With something like: selectors.color: ( { state } ) => {
return state.isOpen ? 'red' : null
} |
I guess they could get the initial inline style color using |
|
Thanks for the reviews, by the way 🙂 Merging this now 🎉 |
What?
Add runtime support for the
wp-styledirective.Co-authored-by @c4rl0sbr4v0.
Why?
Because it's one of the core directives and it was still missing.
How?
By adding it to the list of directives.
I used a magic function 🪄 from Goober (🥜) made by @cristianbote 🧙♂️ to convert a CSS string into a style object.
Testing Instructions
data-wp-styledirective to a block and reference some part of the state/context.styleattribute changed accordingly.