1

For a block I want the user to be able to set a couple of defaults for each newly generated block, think e.g colors and other attributes. Then every time a new block is created on the website, the defaults should be loaded. Each block can then be customized from the sidebar if needed (<InspectorControls>). For example the user sets text color to red, but then occasionally can choose another color.

So far I created a custom settings page for the WordPress plugin and then I load these defaults into the block when it gets registered. Feels like a hack, but works.

The new block themes now have a Site Editor and somewhere in there it is also possible to set the default styles of a block widget.

How can I access this menu and add items similar to the Sidebar of each specific block? Would be great to be able to replicate all the <InspectorControls> of the Sidebar as Defaults. How can I achieve this?

1 Answer 1

0

As far as I know the only way to get your block’s settings to show up in the Global Styles (so their defaults can be set) is by using the Supports API. It’s automatic if your block’s settings are implemented via Supports.

Here it is from the docs:

The global styles UI in the site editor has a screen for per-block styles. The list of blocks is generated dynamically using the block supports from the block.json of blocks. If a block wants to be listed there, it needs to use the block supports mechanism.

2
  • I have to admit, i have difficulty understanding what to do exactly. If that is the way it should be done, is there a tutorial or practical example somewhere? Shouldn't be something really unusual to have user defined defaults.
    – Sina
    Mar 18 at 15:28
  • Video tutorial (starting at the part about color since that was a property you mentioned). Text tutorial. Once a block is using supports for its settings then it shows up in the Global Styles so that users can define the defaults.
    – stokesman
    Mar 18 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.