Problem/Motivation
We are releasing soon UI Patterns 2, a rewrite of UI Patterns upon Drupal Core's Single Directory Components API. It exposes components:
- as blocks in Block Layout, Layout Builder ....
- as layouts in Layout Builder, Field Layout...
- within field formatters in Manage Display, Layout Builder, Views...
- as display & rows in Views
UI Patterns 2 will also be shipped with ui_patterns_library which has similar purpose than sdc_styleguide, but both have their targets:
- ui_patterns_library is more a "static" demo, as a bonus in a more fully featured package
- sdc_styleguide is a lighter, standalone solution, with interactive tools to "play" with the components
Current use in contrib theme
AFAIK, today, no contrib SDC theme are shipped sdc_styleguide or ui_patterns_library stories formats:
- https://www.drupal.org/project/dsfr4drupal (39 installs): no stories: https://git.drupalcode.org/project/dsfr4drupal/-/tree/1.x/components/acc...
- https://www.drupal.org/project/etc (1 installs): cl_server YAML format: https://git.drupalcode.org/project/etc/-/blob/1.0.x/components/content/l...
- https://www.drupal.org/project/governor (6 installs): no stories https://git.drupalcode.org/project/governor/-/tree/1.0.x/components/uswd...
- https://www.drupal.org/project/kinetic (2 installs): ???
- https://www.drupal.org/project/prototype (branch 5.x only) (17 installs): no stories https://git.drupalcode.org/project/prototype/-/tree/5.x/components/accor...
- https://github.com/danny-englander/quartz/ : cl_server YAML format: https://github.com/danny-englander/quartz/blob/dev/components/Organisms/...
- https://www.drupal.org/project/radix (branch 6.x only): no stories https://git.drupalcode.org/project/radix/-/tree/6.0.x/components/accordion
- umami (in Core): no stories, I guess
- https://www.drupal.org/project/starlight (branch 2.x only) (310 installs): no stories https://git.drupalcode.org/project/starlight/-/tree/2.x/components/block...
- https://www.drupal.org/project/nttdata_theme : no stories https://git.drupalcode.org/project/nttdata_theme/-/tree/main/components/...
- https://www.drupal.org/project/varbase_components (105 installs): cl_server JSON format https://git.drupalcode.org/project/varbase_components/-/tree/2.0.x/compo...
However, some UI Patterns 1.x theme will adopt the ui_patterns_library stories format once converted to UI Patterns 2.x (conversion will be automatic):
- https://www.drupal.org/project/ui_suite_bootstrap (168 installs)
- https://www.drupal.org/project/ui_suite_dsfr (42 installs)
- https://www.drupal.org/project/ui_suite_uswds (14 installs)
- and more...
Proposed resolution
Stories formats
The stories formats of those modules are very similar.
sdc_styleguide has a file by story ({component_id}.demo.{story_id}.yml) with this structure:
name: Card with Video
description: This shows a card with a video
slots:
media: '<iframe...></iframe>'
properties:
title: Wanna learn about Drupal Starshot?
date: 2024-05-22 - 11:38pm
ui_patterns_library currently put the stories directly in the component.yml file, with this similar structure:
title: Card with Video
description: This shows a card with a video
slots:
media:
type: html_tag
tag: iframe
props:
title: Wanna learn about Drupal Starshot?
date: 2024-05-22 - 11:38pm
The main difference is the use of Drupal render arrays in slot previews.
Proposal
Because of this similarity, it would be nice to have a single stories format, so any theme targeting ui_patterns is compatible with sdc_styleguide and the other way around.
This will boost the popularity of both modules and promote YAML as the standard way of writing a story for SDC. We can also propose this addition to Core after a while.
Are you OK to talk about this?
API changes
For ui_patterns_library, we are not afraid of breaking things because we haven't shipped yet. I hope it would be possible to made some changes in sdc_styleguide without breaking anything too.
Comments
Comment #2
pdureau commentedAdopting render arrays for slots may also be a nice way of expressing this kind of values:
https://git.drupalcode.org/project/sdc_styleguide/-/blob/1.0.x/modules/s...
in a cleaner way:
But this example raise another issue. What about
styleguide_demotheme hook? In UI Patterns 2, we are doing something similar but a bit differently. We are adding a#storykey to the regular SDC component render element.So, this sdc_styleguide example:
is written like that:
If we agree on a single story format, we may need to also agree on a shared renderable.
Comment #3
alemadleiHello!
I'm super interested in discussing this. You should be able to find me in the components slack channel.
As a quick note, I think it is better to have demos or stories live outside the component definition. This because down the road it is something added next to a component definition instead of adding more clutter within the same file.
Let me know your thoughts.
Comment #4
alemadleiHello!
Just checking in if you are still interested in discussing further.
Comment #5
pdureau commentedHi Alejandro,
Of course I do. And I am happy to collaborate with you.
I was busy on other tasks those days.
I am OK with that. So, our shared format could be:
sdc_styleguidedoui_pattens_librarydoI will share a collaborative document for us soon.Shared 😉: https://docs.google.com/document/d/1wCQLXrK1lrV2gYlqmqD2pybTql6_H1dByWIK...Comment #6
pdureau commentedCongratulation Alejandro for your new 1.1.0 release 🎉
I see it is not following yet the shared SDC Stories format proposal we were working on.
Do you have some plan to follow it in a future release? How will you manage the backward compatibility?
Maybe you want to propose some changes to it? In UI Patterns 2 side, we are open to any modification of our format which will fill the gap between us without compromising the quality.
In my opinion, the sdc_styleguide YAML format still has those 2 issues:
Comment #7
pdureau commentedHi Alejandro,
This is our current implementation of the proposal: #3455354: [2.0.0-beta4] Add a stories specific discovery
Stories are plugins with a YAML discovery looking for
component/{component_id}.{story_id}.story.yml:If the story YML is inside a SDC folder, it get "attached" automatically to the component. If it is elsewhere, we need an explicit property in the definition. That's very useful if a theme or module want to add stories to existing components.
Slots are accepting:
Stories can be loaded from the SDC render element, thanks to the additional
#storyrender property: ComponentElementAlterIt seems to work well, we may merge this work soon in UI Patterns 2 codebase. Don't hesitate to have a look.
Comment #8
alemadleiThanks pdureau, I will try to take a look soon.
Comment #9
pdureau commentedUp :)
Don't hesitate to ask for help if needed.