Collaboration with UI Patterns 2

Created on 31 July 2024, 5 months ago

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:

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):

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.

🌱 Plan
Status

Active

Version

1.1

Component

Code

Created by

🇫🇷France pdureau Paris

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

Comments & Activities

  • Issue created by @pdureau
  • 🇫🇷France pdureau Paris

    Adopting render arrays for slots may also be a nice way of expressing this kind of values:

    name: Card grid with variable cards
    description: This shows a card with a video that comes from vimeo
    properties:
      title: 'My card grid'
      description: 'This is a demo card grid that reuses demos to generate the cards in the grid.'
    slots:
      cards: "{{ {'#theme': 'styleguide_demo', '#demo': 'sdc_styleguide_demo_components:card.demo.image' } }}
              {{ {'#theme': 'styleguide_demo', '#demo': 'sdc_styleguide_demo_components:card.demo.video' } }}
              {{ {'#theme': 'styleguide_demo', '#demo': 'sdc_styleguide_demo_components:card.demo.vimeo_video' } }}
              {{ {'#theme': 'styleguide_demo', '#demo': 'sdc_styleguide_demo_components:card.demo.image' } }}
              {{ {'#theme': 'styleguide_demo', '#demo': 'sdc_styleguide_demo_components:card.demo.video' } }}
              {{ {'#theme': 'styleguide_demo', '#demo': 'sdc_styleguide_demo_components:card.demo.vimeo_video' } }}
              {{ {'#theme': 'styleguide_demo', '#demo': 'sdc_styleguide_demo_components:card.demo.image' } }}
              {{ {'#theme': 'styleguide_demo', '#demo': 'sdc_styleguide_demo_components:card.demo.video' } }}
              {{ {'#theme': 'styleguide_demo', '#demo': 'sdc_styleguide_demo_components:card.demo.vimeo_video' } }}
    

    https://git.drupalcode.org/project/sdc_styleguide/-/blob/1.0.x/modules/s...

    in a cleaner way:

    name: Card grid with variable cards
    description: This shows a card with a video that comes from vimeo
    properties:
      title: 'My card grid'
      description: 'This is a demo card grid that reuses demos to generate the cards in the grid.'
    slots:
      cards:
        - theme: styleguide_demo
           demo:  'sdc_styleguide_demo_components:card.demo.image' 
        - theme: styleguide_demo
           demo:  'sdc_styleguide_demo_components:card.demo.video' 
        - theme: styleguide_demo
           demo:  'sdc_styleguide_demo_components:card.demo.vimeo_video' 
        - theme: styleguide_demo
           demo:  'sdc_styleguide_demo_components:card.demo.image' 
        - theme: styleguide_demo
           demo:  'sdc_styleguide_demo_components:card.demo.video' 
        - theme: styleguide_demo
           demo:  'sdc_styleguide_demo_components:card.demo.vimeo_video' 
        - theme: styleguide_demo
           demo:  'sdc_styleguide_demo_components:card.demo.image' 
        - theme: styleguide_demo
           demo:  'sdc_styleguide_demo_components:card.demo.video' 
        - theme: styleguide_demo
           demo:  'sdc_styleguide_demo_components:card.demo.vimeo_video' 
    

    But this example raise another issue. What about styleguide_demo theme hook? In UI Patterns 2, we are doing something similar but a bit differently. We are adding a #story key to the regular SDC component render element.

    So, this sdc_styleguide example:

    {
      '#theme': 'styleguide_demo', 
      '#demo': 'sdc_styleguide_demo_components:card.demo.image'
    }

    is written like that:

    {
      '#type': 'component',
       '#component': 'card',
      '#story': 'image'
    }

    If we agree on a single story format, we may need to also agree on a shared renderable.

  • 🇨🇷Costa Rica alemadlei

    Hello!

    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.

  • 🇨🇷Costa Rica alemadlei

    Hello!

    Just checking in if you are still interested in discussing further.

  • 🇫🇷France pdureau Paris

    Hi Alejandro,

    Of course I do. I am busy on other tasks those days.

    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.

    I am OK with that. So, our shared format could be:

    • in its own file like sdc_styleguide do
    • using render arrays in slots, like ui_pattens_library do

    I will share a collaborative document for us soon.

  • 🇫🇷France pdureau Paris

    Congratulation 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:

    • the slots are not conform to the SDC render element because they accepting markup string instead of render arrays (SDC render element accept only plain text scalars in slots)
    • the filename structure may not be compatible with plugin managers YML discoveries
  • Status changed to Needs work about 2 months ago
  • 🇫🇷France pdureau Paris

    Hi Alejandro,

    This is our current implementation of the proposal: ✨ [2.0.0-beta4] Add a stories specific discovery Needs work

    Stories are plugins with a YAML discovery looking for component/{component_id}.{story_id}.story.yml:

    Slots are accepting:

    • scalars, loaded as plain text as expected by the SDC's render element
    • render arrays, which can be written written without "#" thanks to StoriesSyntaxConverter

    Stories can be loaded from the SDC render element, thanks to the additional #story render property:

    It seems to work well, we may merge this work soon in UI Patterns 2 codebase. Don't hesitate to have a look.

  • 🇨🇷Costa Rica alemadlei

    Thanks pdureau, I will try to take a look soon.

Production build 0.71.5 2024