Specify rules for when certain styles need to be available

Created on 18 September 2023, 9 months ago
Updated 19 September 2023, 9 months ago

Problem/Motivation

I might be missing something, is it possible to set some sort of rules for when styles need to be available on a specific plugin?

Let's say i have heading styles h1-h6, i would want to have them available for block titles, and inside CKeditor, whilst not have them show up in the block content styles on a quote component added through layout builder.

Proposed resolution

Maybe introduce style rules in the way that layout_options does. That way we can have a general set of styles maintained in a yml file by the designer/frontender, and still be able to decide when to make the styles available in the backend.

User interface changes

Have a way for the plugins to only show styles that need to be there in that specific context

Data model changes

Introduce a new definition for rules

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium svdhout

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @svdhout
  • πŸ‡§πŸ‡ͺBelgium svdhout

    Another approach could be to be able to configure the visibility rules on the entity type itself, that would be a more sitebuilder centric approach

  • Status changed to Postponed: needs info 9 months ago
  • πŸ‡«πŸ‡·France pdureau Paris

    Hi Steven,

    Interesting proposal. Is it possible to think about rules related to the design systems business domains and not Drupal API domain ?

    I have the feeling it would be a mistake to add Drupal related to stuff to styles definitions like entity types (config or content) or plugins types:

    background:
      label: Background color
      rules:
         entities:
           - view
           - flag
         plugins:
           - field_formatter
           - block
      options:
        fr-background-action-high--red-marianne: Action-high red Marianne
        fr-background-alt--blue-france: Alt Blue France
        fr-background-alt--grey: Alt gray
    

    Because it is introducing reverse dependency and the front developer is not a agnostic provider anymore.

    We can introduce rules related to design and frotn dev. For example, we can add a "levels" or "target" property as defined in the HTML5 specification:

    Example:

    background:
      label: Background color
      target:
        - flow
        - phrasing
      options:
        fr-background-action-high--red-marianne: Action-high red Marianne
        fr-background-alt--blue-france: Alt Blue France
        fr-background-alt--grey: Alt gray
    

    And then, it would be possible for UI Styles consumers (Blocks, Layouts, CKeditor5, Views pager, Views rows, Paragraphs...) to only display the styles related to one target.

    This HTML5 content levels list is only an example of "rule", maybe there is a better one. However, it is an example of something not coming from Drupal API.

    Is it compatible with your request?

  • πŸ‡§πŸ‡ͺBelgium svdhout

    I can follow the approach you suggest.
    If i look at it purely from the design system domain i can see some rules that a design system wants to decide upon.

    • Only one primary button per page
    • A specific font can only be used on a red background
    • ...

    I'm not sure someone would want to enforce rules like that though.

    My question started from looking at it from the backend interface perspective.

    We build webplatforms that will mostly be used by non technical webmasters. Therefor we always strive to keep all configuration for webmasters / content editors as minimal as possible.
    Using ui styles for heading styling will add a heading style dropdown on every block entity, in 3 fieldset (block styles, block title styles, and block content styles) which would be to much configuration options for our webmasters.

    The design system / frontend dev can build a list of utility styles. Maybe even combined with guides on how or when to use them.

    Based on that an interface designer can design the drupal backend pages to be user friendly for webmasters and content editors, and decide on what styles should be available for specific purposes.

    E.g.
    the heading style can be used from CKEditor, and only on block titles.
    The background-color style can only be used on block content styles.
    The button style should never be used through the interface, as it would always need to use a ui pattern.

    I would love to have a way for a developer to control what style should be applicable for each use case.

    That doesn't need to be in the yaml file for me.
    Layout options however did take a similar approach for this using the Layout Options Section (Rules) β†’ in their yaml files.
    It would make sense for all of the modules in ui suite to have a similar way of defining things.

  • Status changed to Active 9 months ago
  • πŸ‡«πŸ‡·France pdureau Paris
Production build 0.69.0 2024