Make block style slug available to render callback #56278
Labels
[Feature] Block API
API that allows to express the block paradigm.
[Feature] Block Style Variations
Issues or PRs that are related to the style variations for blocks
[Type] Enhancement
A suggestion for improvement.
What problem does this address?
Normally when you want to change a block based on the selected style, it's enough to just add styles to the stylesheet. The are some situations where you need to do more than that, though, like changing the Google Map styles that a map block uses. Those are stored in a JSON variable.
I don't see a way to easily access the slug of the selected style. I can parse it out of
attributes.className
, but that's kind of hacky. I have to use a regex, or loop through my style slugs and do a string search.I also don't see a way to get a list of styles registered for my block, so I have to restructure my code to maintain an array of styles, and then loop through them passing them to
registerBlockStyle
, rather than just calling it directly.What is your proposed solution?
Add something like
attributes.style
which equals the slug of the selected style. It's not technically an attribute, though.Another idea would be to expose it via something like:
The text was updated successfully, but these errors were encountered: