gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Presets and CSS classes

Open arpadkdweb opened this issue 5 years ago • 1 comments

What problem does this address?

I've come across an issue with the editor that is quite frustrating with project that I do with my company. We mostly do stricter designs and our clients don't want total style freedom, they want something more along the line of useful, currated styles and presets that are pre-designed and non-technical or non-visual people can't mess up. We are currently using a system with ACF to achieve this, but want to adapt the block editor. However, with a lot of core blocks, despite the advancements in the past few months (theme.json, ability to disable custom color, etc) it's still difficult to make a more structured, strict design interface with the editor.

What is your proposed solution?

My proposed solution is a more granular system. I propose adding selectable presets for a lot of settings like column width, borders, padding, margin instead of allowing users to freely choose any number. And instread of using inline styling, we could use css classes associated with he presets. We could even have larger presets that control multiple settings at once, and generate classes (I'm thinking of a typographic setting for example, where users can choose a "lead" typography setting that controls font size, weight color as well as borders or even padding and all of this at the same time - and in the end generate a class) This would also in theory make us able to use utility classes like tailwind offers, or just regular pre-designed options that we stup in our css. This is a much more restrictive approach, but in a lot of cases where clients edit their own website, it's preferable, even for them, as they don't have design, or any technical skills. So they look for a bit more handholding.

An additional benefit of this approach is easier control for responsive designs. As inlineing widths, border or padding settings can be cumbersome to overwrite if we want to have a limit for mobile, or give more space here and there on large screens.

My proposal is obviously open for discussion, and as an example would consists of:

Media Text block:

  • ability to disable chosing stacking on mobile and have a default either way instead (we don't want users disabling stacking most of the time)
  • ability to have presets for media widths (as a dropdown and outputting css classes instead of inline styles) or setup a step size and min and max values

Column block:

  • ability to set column ratio presets (as a dropdown and outputting css classes instead of inline styles) and the ability to disable the free column width tool or setup a step size and min and max values

Spacer block:

  • presets for different amounts of space controlled by css classes instead of

Multiple blocks:

  • ability to enable/disable richtext toolbar options suck as strikethrough, inline image, etc per block (maybe in theme.json)
  • ability to have presets for borders as opposed to

Global:

  • enable and disable granular editing options by user role or capability

arpadkdweb avatar Jun 04 '21 15:06 arpadkdweb

Thanks for taking the time to write this up. Coming back to this, even if years later, most of what's requested here has shipped.

Presets instead of free numeric input, in theme.json settings:

  • Spacing: spacing.spacingSizes and spacing.spacingScale define the presets, and spacing.customSpacingSize: false plus spacing.defaultSpacingSizes: false remove free input and the built-in presets, so users pick only from the theme's scale.
  • Borders: border.radiusSizes provides radius presets, and border.color, border.radius, border.style and border.width can each be disabled individually.
  • Typography: typography.fontSizes with typography.customFontSize: false and typography.defaultFontSizes: false, plus typography.textShadowPresets.

The "larger presets that control multiple settings at once and generate a class" part is covered by block style variations defined in theme.json, including variation partials with a blockTypes property (section styles), which apply a set of styles — and a class — across a block and its inner blocks.

What isn't covered here, and is better tracked elsewhere:

  • Classes rather than inline styles is still mixed: colors and font sizes emit has-{slug}-* classes, while spacing is emitted as inline declarations by the style engine. That's part of the scope of #38998 on standardising block markup, design tokens and CSS classes.
  • Enabling and disabling editing options per user role or capability hasn't shipped and is discussed in #41547.
  • The block-specific requests (Columns ratio presets, disabling stacking on Media & Text, per-block rich text format toggles) would each be more actionable as their own issue, where they can be found and scoped individually.

Based on all this, it seems the general request has largely been implemented, and the remainder is either tracked in the issues above or too broad to action in this form. So I will close this one as fixed. But specific follow-ups are very welcome as separate issues.

jasmussen avatar Sep 23 '26 11:09 jasmussen