Skip to content

Allow custom style variation classNames #11763

@greatislander

Description

@greatislander

Is your feature request related to a problem? Please describe.

The block styles variations API introduced in #7362 uses an is-style-{styleName} className to the block for style variants. This works well for core blocks and new blocks, but may be overly opinionated for converting existing content that has an established approach to styling variants (see #7362 (comment)). For example, a pattern library that uses BEM conventions might use .element for a default element, and .element.element--variant for a variant of that element. I'd advocate for a solution that does not require changing an existing naming convention if one exists.

Describe the solution you'd like

A className attribute could be added to each style variation which, if supplied, would be used instead of the default generated className. Here's some pseudocode:

styles: [
    { 
        name: 'default', 
        label: __( 'Rounded' ), 
        isDefault: true 
    },
    { 
        name: 'outline', 
        label: __( 'Outline' ),
        className: 'button--outline' 
    },
    { 
        name: 'squared', 
        label: __( 'Squared' ) 
        className: 'button--squared' 
    },
],

Describe alternatives you've considered

The only alternative at present is to use the opinionated is-style-{styleName} naming convention.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good First IssueAn issue that's suitable for someone looking to contribute for the first time[Feature] Block Style VariationsIssues or PRs that are related to the style variations for blocks[Type] EnhancementA suggestion for improvement.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions