Support styles which are not HTML classes

Created on 2 April 2025, 7 months ago

Problem/Motivation

I have found a deisgn system (https://clarity.design/ which seems pretty good quality by the way) which is applying styles utilities with:

  • classes, as usual
  • custom attributes
    cds-text="display"
    cds-text="headline"
    cds-text="message"
    
  • inline CSS variables (which is the opposite way of UI Skins using CSS variables)
    style="--size: var(--cds-global-space-7);
    style="--size: var(--cds-global-space-14);"
    

That's crazy but that's interesting. It seems we will have more mechanism shared between UI Styles & UI skins:

  • CSS variables managements
  • Styles & scoped themes with both CSS classes & custom attributes

Proposed resolution

How can we support styles which are not HTML classes?

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡«πŸ‡·France pdureau Paris

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

Merge Requests

Comments & Activities

  • Issue created by @pdureau
  • πŸ‡«πŸ‡·France pdureau Paris

    For information, https://www.drupal.org/project/ui_skins β†’ has the same challenge for themes/modes plugins which can be classes, data-attributes or meta elements.

    Example ui_suite_dsfr.ui_skins.themes.yml:

    
    light:
      label: "Light"
      key: data-fr-scheme
      target: html
    
    dark:
      label: "Dark"
      key: data-fr-scheme
      target: html
    
    mourning_light:
      label: "Mourning light"
      key: data-fr-mourning
      target: html
      value: ""
      dependencies: [light]
    
    mourning_dark:
      label: "Mourning dark"
      key: data-fr-mourning
      target: html
      value: ""
      dependencies: [dark]
    

    Rules:

    If missing β€œvalue”: we take the plugin ID.

    This behaviour is not well documented and seems hard to understand, so let's not take it without challenging it.

    However, adopting a shared format and/or mechanism woudl be nice.

    Also, this issue needs to be considered in the context of ✨ Add a style utility API Active

  • πŸ‡«πŸ‡·France pdureau Paris

    Breaking change proposal with both:

    • merging of UI Skins themes & UI Styles definitions formats
    • support styles which are not HTML classes

    For styles, in {provider}.utilities.yml, an example of a style with different options:

    size:
      label: "Text size"
      # kind: utility/theme. Magically added by the discovery
      attribute: class # Overridable at the option level.
      options:
        - label: Small
          value: 'text-sm'
        - label: Medium
          attribute: style
          # value: 'font-size: 15px'
          value: '--size: 15px'
        - label: "Large"
          attribute: cds-text
          value: "large"
      # library: ""
    

    For themes/modes, in {provider}.modes.yml:

  • πŸ‡«πŸ‡·France pdureau Paris

    This is the opportunity of also covering ✨ Add HTML class property for styles? Active by allowing value at style level.

    So:

    So, to get the class="mask mask-star" example from ✨ Add HTML class property for styles? Active , we can do:

    mask:
      label: "Mask"
      value: "mask"
      options: 
        star:
           label: Star
           value: "mask-star"
  • Assigned to Grimreaper
Production build 0.71.5 2024