Find a way to display settings used to build story in library

Created on 6 March 2025, 28 days ago

Problem/Motivation

Library and stories are useful to see how components can be displayed, but when we found a great display, it's hard to know how to reproduce.

We can add some piece of code in \Drupal\ui_patterns_library\Template\TwigExtension::renderComponentStory() to display more informations about how the component is built, but how to make this pretty and usable ?

Here is an example ugly but working.

and how to render this :

  public function renderComponentStory(string $component_id, string $story_id, array $slots = [], array $props = [], bool $with_wrapper = FALSE) {
    $component_slots_props = json_encode(['slots' => $slots, 'props' => $props]);
    $help = [
      'rendered' => [
        '#type' => 'container',
        '#attributes' => ['class' => ['tab-pane', 'active']],
        'component' => [],
      ],
      'settings' => [
        '#type' => 'container',
        '#attributes' => ['class' => ['tab-pane']],
        'content' => [
          '#type' => 'markup',
          '#markup' => $component_slots_props,
        ],
      ]
    ];
    $renderable = [
      '#type' => 'component',
      '#component' => $component_id,
      '#story' => $story_id,
      '#slots' => $slots,
      '#props' => $props,
    ];
    if (!$with_wrapper) {
      $help['rendered']['component'] = $renderable;
      return $help;
    }
    $story = $this->storyPluginManager->getDefinition($component_id . ':' . $story_id);
    if (!isset($story["library_wrapper"]) || empty($story["library_wrapper"])) {
      $help['rendered']['component'] = $renderable;
      return $help;
    }
    $help['rendered']['component'] =  [
      [
        '#type' => 'inline_template',
        '#template' => $story["library_wrapper"],
        '#context' => $slots + $props + ['_story' => $renderable],
      ],
    ];
    return $help;
  }
Feature request
Status

Active

Version

2.0

Component

UI Patterns Library

Created by

🇫🇷France goz

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

Comments & Activities

Production build 0.71.5 2024