Problem/Motivation
"Theming": some design systems have CSS switching like light/dark theme, accessibility modes, or different tones and branding. Most of the time, the theme can be defined with a class in the HTML or BODY element (ex: Tailwind) and the theme is applied to the current element and its children.
However, it can be more complicated:
- sometimes it is not a class but a new attribute. Example: https://getbootstrap.com/docs/5.3/customize/color-modes/ with data-bs-theme
- sometimes this attribute or class can be added only on specific elements, like HTML or BODY. Example: https://www.systeme-de-design.gouv.fr/
- sometimes a theme is applied to the full document instead of the targeted element and its sub-tree. Example: https://ec.europa.eu/component-library/
- sometimes a theme has a specific library. Example: https://ec.europa.eu/component-library/
Proposed resolution
Use this issue to propose a YAML structure for plugin declarations taking into account this complexity.
Issue fork ui_skins-3335428
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
pdureau commentedComment #3
g4mbiniComment #4
duaelfrMaybe I'm missing something but why do you care about how each Design System manages its variants?
The core need is to have more than one preset of CSS vars and to be able to switch from one to another.
In this case, it would be really nice to be able to select a preset then override some values for the current project.
In this case it might be interesting to restrict the list of available presets.
My 2 cts
Comment #5
pdureau commentedHello Duaelfr
"Themes" (or "Modes") are often a "first class" artifacts in design system, they have a name, a documentation, a purpose, and a lifecycle. So, it will convenient to manipulate them as "first class" obejcts too.
Not every design systems design its themes as combinations of CSS vars. Some design systems have themes but no CSS variables. Some design have both, but they are not related.
Comment #6
pdureau commentedTheme definition is UI SKins will be needed for https://www.drupal.org/project/ui_suite_bootstrap/issues/3351580#comment...
Comment #7
pdureau commentedWe need the usual metadata:
And properties specific to theme processing:
Attachment value (string, free text)
The keyword which will be attached (as a class name or a data attribute value). If empty, it is the plugin ID, with Html:::getClass() applied.
Attachment method (string, free text)
2 values:
Examples:
Attachment target (string, enum)
3 values:
Examples:
Asset library
A single assets library definition, which will be loaded if the theme is called in a render request.
Examples: Europa
Comment #8
pdureau commentedExample for Bootstrap 5.3:
Example for Mozilla Protocol:
Example for Ant Design:
Comment #9
pdureau commentedComment #10
pdureau commentedVocabulary:
Comment #11
grimreaper- New plugin type
- new plugin definition class
- Alter theme setting form to add theme selector
- Implements hook_preprocess_html to add either in html_attributes or attributes the class or attribute
- Implements tests
- For scopable themes, how to be able to select the theme anywhere?
Comment #12
seda12 commentedComment #13
grimreaperUpdate about libraries.
Example for Ant Design:
We do not care how the libraries are declared. We simply add it when the mode is selected.
Comment #15
seda12 commentedComment #16
grimreaperNo "Theme mode" => "theme"
Comment #17
grimreaperComment #18
grimreaperComment #19
seda12 commentedComment #20
seda12 commentedComment #21
grimreaperComment #22
pdureau commentedThanks for your work.
Tested on DSFR:
It was working well at the end but I got one fatal error:
Not related to my tests, but there is an use case not met yet, but we may need to be able to add theme as a meta element. Example:
<meta name="theme" content="system">So, my proposal:
Comment #23
pdureau commentedAlso, on /admin/appearance/settings/{theme} page, the Themes select list must not be mandatory. The default value must be empty (no theme), and it is possible to select this default empty value.
Comment #24
grimreaperComment #26
grimreaper