Problem/Motivation
In UI Patterns 1.x it i possible to specify templates for previews (there is only one story by component in UI Patterns 1.x, and it is always called "preview")
Examples:
- https://git.drupalcode.org/project/ui_suite_bootstrap/-/blob/5.0.x/templ...
- https://git.drupalcode.org/project/ui_suite_bootstrap/-/blob/5.0.x/templ...
- https://git.drupalcode.org/project/ui_suite_bootstrap/-/blob/5.0.x/templ...
Sometimes, it is used to disabled the preview: https://git.drupalcode.org/project/ui_suite_uswds/-/blob/3.0.x/templates...
Proposed resolution
They don't belong to the components/{component_id} folder but anywhere in the templates/ folder. They are regular Drupal theme templates from hook_theme(): component-story--{component_id}.html.twig
Examples:
- component-story--modal.html.twig
- component-story--card-body.html.twig
By story: component-story--{component_id}--{story_id}.html.twig
Examples:
- component-story--modal–preview.html.twig
- component-story--card-body–long-text.html.twig
No templates suggestions per variant.
Alternative
Can we provide this feature without this hook_theme ?
Issue fork ui_patterns-3462325
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
pdureau commentedCan we "adopt" https://www.drupal.org/project/storybook (411 installs) format ?
The deep purpose of this module (stories as Twig templates) is far away from UI Patterns philosophy (stories as Drupal renderable), however:
{component_id}.stories.twig) while we plan to use hook_theme templates from templates/ directoryLet's list SDC themes using this format in drupal.org first
Comment #4
pdureau commentedhttps://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...
Comment #5
pdureau commentedComment #6
pdureau commentedHere are all the preview templates of the public U Suite :
ui_suite_bootstrap
ui_suite_dsfr
ui_suite_material
ui_suite_uswds
So, we have:
So, for only 5 use cases in our most complete themes, do we still really need those story templates?
Comment #7
pdureau commentedProposal to cover both "HTML wrapper" and "Add a button" without the need of such a template, let's introduce a
library_wrapperproperty, with a Twig template as a value.This property will be ignored by ComponentElementAlter but used by the library pages controller (or formatter, after #3438360: Use Drupal entities & plugins for the Library pages).
It will be resolved as an inline_template render element, with those values in #context:
storyvariable with the renderable of the storySo, if a story miss
library_wrapper(which will be the case for 90% of the stories), it will be processed as:library_wrapper: '{{ story }}'For example, to replace this template: https://git.drupalcode.org/project/ui_suite_bootstrap/-/blob/5.0.x/templ...
What will happen if there is already a
storyslot or prop? Maybe_storywould be safer.Comment #8
grimreaperParticipating in the discussion in off with @pdureau ;)
Comment #9
pdureau commentedComment #10
pdureau commentedComment #11
pdureau commentedLet's do #3455354: [2.0.0-beta4] Add a stories specific discovery first
Comment #12
pdureau commentedComment #13
pdureau commentedComment #14
pdureau commentedWe can start this task
Comment #15
pdureau commentedComment #17
pdureau commentedGrimreaper, what do you think about the current state of work? https://git.drupalcode.org/project/ui_patterns/-/merge_requests/261/diffs
It is not finished, I will need to inject the
plugin.manager.component_storydependency for example, but it works and it is advanced enough to talk:ui-patterns-stories-full.html.twig) ?_storyorstoryfor the variable injected inlibrary_wrapper?Comment #18
grimreaperOk for me.
Code review we made together addressed.
Comment #20
pdureau commented