Skip to content

Custom Color Palette for Core Blocks #14110

Closed
@buhlahkay

Description

Is your feature request related to a problem? Please describe.
I can define a global color palette, but I don't want all of those colors being available for every block. I may define 5-6 colors for a theme, but I only want the button to use 1-2 colors. Or maybe I just want to define 2 styles of button that handle the colors, and remove the color panel completely. We can currently register/unregister styles for core blocks, so would like to also see something similar with colors.

Describe the solution you'd like
I believe there are currently 6 blocks that utilize the PanelColorSettings component:

  • core/paragraph
  • core/button
  • core/cover
  • core/media-text
  • core/pullquote
  • core/table

A register/unregister color functionality similar to block styles could be a solution.
Or if we passed down a "customColors" property to the PanelColorSettings's "colors" property, then we could modify the blocks with the editor.BlockEdit hook. The filter solution seems to work for me locally (and gives me the ability to remove the panel with a falsy value), but it seems like there would be a more elegant solution than adding a new property to each block's PanelColorSettings component.

const withCustomColors = createHigherOrderComponent(BlockEdit => {
  return props => {
    if (props.name === 'core/button') {
      return <BlockEdit { ...props } customColors={ [{ name: 'Green', slug: 'green', color: '#00FF00' }] } />
    }
    return <BlockEdit { ...props } />
  }
})
wp.hooks.addFilter(
  'editor.BlockEdit',
  'my-plugin/with-custom-colors',
  withCustomColors
)

Describe alternatives you've considered
Since we can edit styles for each block and we can edit colors globally, it seems like this would make sense as a new feature to sort of combine the two, but there could be more to the issue than I'm considering.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    [Feature] Block APIAPI that allows to express the block paradigm.[Feature] ExtensibilityThe ability to extend blocks or the editing experience[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