storybook-addon-sdc 0.0.18 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Storybook SDC Addon Documentation
|
|
2
|
-
Drupal Single Directory Components
|
|
2
|
+
This Storybook addon streamlines the integration of Drupal Single Directory Components(SDC) defined in YAML files (specifically *.component.yml) as stories.
|
|
3
3
|
|
|
4
|
-
[](https://gyazo.com/2dcfa650c961679430d45eef24a82ab8)
|
|
5
5
|
|
|
6
6
|
## Overview:
|
|
7
7
|
|
|
@@ -37,7 +37,7 @@ Here’s why:
|
|
|
37
37
|
- Support for `drupalSettings` and `once.js` within Storybook ensures components behave identically during testing as they will on the Drupal site.
|
|
38
38
|
|
|
39
39
|
#### 7. Twig.js vs Drupal Twig
|
|
40
|
-
While using
|
|
40
|
+
While using Drupal to render components offers tighter integration, there are strong reasons to continue using Twig.js in many scenarios:
|
|
41
41
|
|
|
42
42
|
- Many Components __Don’t Need Full Drupal Logic__. Basic components (buttons, cards, lists) rely on simple HTML and CSS, not on complex template logic. For such components, Twig.js provides sufficient rendering without the need for full Drupal preprocessing.
|
|
43
43
|
- Twig.js Works Well for Frontend-Focused Use Cases.
|
|
@@ -52,24 +52,23 @@ While using __Drupal to render components__ offers tighter integration, there ar
|
|
|
52
52
|
|
|
53
53
|
## This addon uses:
|
|
54
54
|
|
|
55
|
-
- https://github.com/larowlan/vite-plugin-twig-drupal for
|
|
55
|
+
- https://github.com/larowlan/vite-plugin-twig-drupal for loads Twig with Drupal functions.
|
|
56
56
|
- https://github.com/json-schema-faker/json-schema-faker for generation missed props and slots.
|
|
57
57
|
|
|
58
58
|
## Installation:
|
|
59
59
|
|
|
60
|
+
In `@storybook/html-vite`:
|
|
61
|
+
https://storybook.js.org/docs/builders/vite
|
|
62
|
+
|
|
60
63
|
```
|
|
61
64
|
npm i storybook-addon-sdc
|
|
62
65
|
```
|
|
63
66
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
In vite-html storybook https://storybook.js.org/docs/builders/vite
|
|
67
|
+
### Configuration:
|
|
67
68
|
|
|
68
|
-
main.
|
|
69
|
+
.storybook/main.js
|
|
69
70
|
```
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const config: StorybookConfig = {
|
|
71
|
+
const config = {
|
|
73
72
|
stories: ["../components/**/*.component.yml"], // Your components directory.
|
|
74
73
|
addons: [
|
|
75
74
|
{
|
|
@@ -92,6 +91,31 @@ const config: StorybookConfig = {
|
|
|
92
91
|
export default config;
|
|
93
92
|
```
|
|
94
93
|
|
|
94
|
+
### Default values
|
|
95
|
+
|
|
96
|
+
json-schema-faker not always generate good data. For optimal results, use `default` or `examples` for SDC schema:
|
|
97
|
+
```
|
|
98
|
+
props:
|
|
99
|
+
type: object
|
|
100
|
+
properties:
|
|
101
|
+
html_tag:
|
|
102
|
+
type: string
|
|
103
|
+
enum:
|
|
104
|
+
- article
|
|
105
|
+
- div
|
|
106
|
+
default: article
|
|
107
|
+
slots:
|
|
108
|
+
content:
|
|
109
|
+
title: Content
|
|
110
|
+
examples:
|
|
111
|
+
- Hello! I'm card content
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
- https://www.drupal.org/docs/develop/theming-drupal/using-single-directory-components/annotated-example-componentyml
|
|
115
|
+
- https://json-schema.org/understanding-json-schema/reference/annotations
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
95
119
|
## Experimental stories:
|
|
96
120
|
|
|
97
121
|
By default addon generates only Basic story for every component.
|
|
@@ -164,7 +188,7 @@ Or you can import yaml in regular storybook *.stories.js
|
|
|
164
188
|
|
|
165
189
|
### Why stories experimental?
|
|
166
190
|
|
|
167
|
-
The community will have to decide what format the
|
|
191
|
+
The [community will have to decide](https://docs.google.com/document/d/1wCQLXrK1lrV2gYlqmqD2pybTql6_H1dByWIKB5xQFcQ/edit?tab=t.0#heading=h.3949vjfiqczr) what format the YAML stories should be.
|
|
168
192
|
|
|
169
193
|
|
|
170
194
|
## Known issues:
|
|
@@ -172,7 +196,4 @@ The community will have to decide what format the yaml stories should be.
|
|
|
172
196
|
- UI Patterns stories format not yet [supported](https://www.drupal.org/project/ui_patterns/issues/3480464).
|
|
173
197
|
- Same problem will be with `$ref: json-schema-definitions://` for SDC from Experience Builder.
|
|
174
198
|
- Plugin uses [Experimental indexers](https://storybook.js.org/docs/api/main-config/main-config-indexers)
|
|
175
|
-
- json-schema-faker not always generate good data. Better to use `default` or `examples` for SDC schema
|
|
176
|
-
https://www.drupal.org/docs/develop/theming-drupal/using-single-directory-components/annotated-example-componentyml
|
|
177
|
-
https://json-schema.org/understanding-json-schema/reference/annotations
|
|
178
199
|
|