Skip to content
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

Better block style registration : organize and create styles by category #33093

Closed
LeoSeyers opened this issue Jun 30, 2021 · 1 comment
Closed
Labels
[Feature] Theme Style Variations Related to style variations provided by block themes [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed

Comments

@LeoSeyers
Copy link

What problem does this address?

As a custom theme developer, I'd like to give editors a finer control on how they control margins to give them a great tailor-made editor experiences.

Many time lately I've asked to add additional option controls for margins and I've done it in two different ways :
– By registering block style (wp.blocks.registerBlockStyle) : e.g I can register a 'no-margin' or 'lg-margin' preset and add styles accordingly both in the editor and the frontend. This becomes tricky when they want a more granular controls for both top and bottom margins (but potentially side margins, padding, you name it).
In addition to that, I struggle to control the style preview and would prefer to disable the style image preview rather than having something irrelevant (= decreasing cognitive load). Also styles are already registered for other things which can quickly become messy if you have a lot of them so that would help to organize them by category.
– By adding custom classes : this is a bulletproof approach but not an ideal experience for editors

What is your proposed solution?

Currently I love how we can extend native Gutenberg appearance with registerBlockStyle method, it is simple and effective to controls how the blocks look with the help of CSS classes.

Now, let's say with we want to extend our Columns block with upper and lower margins options (let's say 4 presets : xs, sm, md, lg) + multiple gutter options, that would be nice if you could do something like this :

  wp.blocks.registerBlockStyleCategory( 'core/columns', {
    name: 'upper-margin',
    label: 'Upper Margin',
    preview: false, // disable image preview if neeeded
    display: 'select'  // switch style layout to a select list to better organize space
  } );

  wp.blocks.registerBlockStyle( 'core/columns', {
    name: 'sm',
    label: 'Small margin',
    category: 'upper-margin', // set style to category
  } );

If editor were to choose this style, a is-style-upper-margin-sm would be added to the block.

@LeoSeyers LeoSeyers changed the title Better Block Style registration : organize and create styles by category Better block style registration : organize and create styles by category Jun 30, 2021
@talldan talldan added [Feature] Theme Style Variations Related to style variations provided by block themes [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed labels Jul 5, 2021
@talldan
Copy link
Contributor

talldan commented Jul 5, 2021

@LeoSeyers Thanks for reporting this. There's an existing discussion about the same thing - #14598. I would definitely recommend adding the details above as a comment there.

It seems like there's also a bit of overlap between the proposals for the theme.json / global styles features and this, especially when it comes to controlling aspects of a block like margin. I think block styles were intended more changing the visual appearance of a block at a higher level rather than individual css properties. So it might be that there are other editor features in the works that might also interest you.

Some high level issues worth reading (although they're quite long):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Theme Style Variations Related to style variations provided by block themes [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed
Projects
None yet
Development

No branches or pull requests

2 participants