-
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
Request to expose @wordpress/block-editor
styling hooks/utilities into a separate package
#50334
Comments
The style engine, at least on the backend, already generates both classnames and styles for many properties. It returns something like array(
'css' => (string) A CSS ruleset or declarations block formatted to be placed in an HTML `style` attribute or tag.
'declarations' => (array) An array of property/value pairs representing parsed CSS declarations.
'classnames' => (string) Classnames separated by a space.
); Also Perhaps we could migrate these types of methods over to the style engine, or, better, find a way to create a generic method to return classnames along with the compiled CSS, similar to the way we do it in the backend. For backwards compatibility, we could let the existing suite of methods hang around and slowly migrate their innards to whatever generic method we create in the style engine and one day deprecate. |
Kind of a tangent but isn't it the purpose of the Interactivity API to solve this kind of use-cases. Adding dynamic behavior to the frontend without necessarily having the need to recreate the whole block output in the frontend. Meaning you could render the block in php like any other block and just add small bits of interactivity in the frontend. Now, yeah the style engine is not in a great place at the moment and we need to keep expanding its usage (while keeping its API surface small and clear |
Thanks for making the link to the Interactivity API , it's something I haven't had the time to catch up on since I've been back. I'm not sure how much overlap there is with the Interactivity API and the issues described in the issue. I still assume we'll need a way to parse block attributes and generate styles for dynamically-rendered blocks on the frontend, at least on initial render. That's what the style engine does, at least for now 😄 I'd imagine that's a case for porting more functionality to the JS version (?) The Interactivity API may need to call on helper methods when toggling classes and/or inline styles, or it may not. I'm not yet familiar enough with it to judge so I'll follow your judgement.
Things have stalled on that front. The next big, and most important (and the trickiest), hurdle to overcome is getting it to handle and output global styles. It's my dream that one day, we'll be able to throw a theme.json at it and it generates a stylesheet. It can already handle most things except all the bits like layout, duotone, global padding, and other special cases so it's not far off. I haven't personally had enough time to kickstart that again. But to address the "different ways of doing the same things" I believe it might be worth exploring whether the style engine can take over the job of these disparate methods, e.g., |
No, not really, for the frontend, there's no need to "regenerate the styles" unless you recreate the whole block in JS which is not what the Interactivity API is about. |
What problem does this address?
We have an issue in WooCommerce blocks where because blocks are rendered dynamically on the frontend (markup is converted to React components), where we use global styles we need to convert any styling rules stored as attributes into valid inline CSS. For that we need to use the hooks exported from
@wordpress/block-editor
e.g.This however is problematic because block-editor is a huge dependency not suitable for the frontend of a site.
To avoid this dependency we're forced to copy some utilities from the
@wordpress/block-editor
package into our own codebase. This is being worked on here.What is your proposed solution?
It would be fantastic if the utilities that
useBorderProps
,useColorProps
etc consume were exposed in a separate package. In the PR I'm working on, the utilities we've borrowed include:getInlineStyles
getColorClassName
getBorderClassName
getGradientClassName
getColorClassesAndStyles
getBorderClassesAndStyles
getSpacingClassesAndStyles
These utilities seem generic enough to be split out from
@wordpress/block-editor
into a new or existing package.The text was updated successfully, but these errors were encountered: