Skip to content

Request to expose @wordpress/block-editor styling hooks/utilities into a separate package #50334

@mikejolley

Description

@mikejolley

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.

  • useBorderProps
  • useColorProps
  • useSpacingProps

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CSS StylingRelated to editor and front end styles, CSS-specific issues.Global StylesAnything related to the broader Global Styles efforts, including Styles Engine and theme.jsonNeeds DecisionNeeds a decision to be actionable or relevantNeeds Technical FeedbackNeeds testing from a developer perspective.[Package] Block editor/packages/block-editor[Type] EnhancementA suggestion for improvement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions