storybook-addon-sdc 0.2.9 → 0.3.2
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 +76 -23
- package/dist/preset.js +6 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Storybook SDC Addon
|
|
1
|
+
# Storybook SDC Addon
|
|
2
2
|
|
|
3
3
|
This addon streamlines the integration of Drupal Single Directory Components (SDC) into Storybook, allowing YAML-configured components (e.g., `*.component.yml`) to be dynamically loaded as stories in Storybook.
|
|
4
4
|
|
|
@@ -7,6 +7,7 @@ This addon streamlines the integration of Drupal Single Directory Components (SD
|
|
|
7
7
|
## Table of Contents
|
|
8
8
|
|
|
9
9
|
- [Overview](#overview)
|
|
10
|
+
- [Storybook Example Live](#storybook-example-live)
|
|
10
11
|
- [Why Choose SDC Storybook Over Alternatives?](#why-choose-sdc-storybook-over-alternatives)
|
|
11
12
|
- [Features of the Addon](#features-of-the-addon)
|
|
12
13
|
- [Dependencies](#dependencies)
|
|
@@ -15,7 +16,6 @@ This addon streamlines the integration of Drupal Single Directory Components (SD
|
|
|
15
16
|
- [Setting Default Values](#setting-default-values)
|
|
16
17
|
- [Creating Experimental Stories](#creating-experimental-stories)
|
|
17
18
|
- [Regular Storybook](#regular-storybook)
|
|
18
|
-
- [Storybook Example Live](#storybook-example-live)
|
|
19
19
|
- [Known Issues](#known-issues)
|
|
20
20
|
- [UI Patterns](#ui-patterns)
|
|
21
21
|
|
|
@@ -25,6 +25,12 @@ This addon streamlines the integration of Drupal Single Directory Components (SD
|
|
|
25
25
|
|
|
26
26
|
This Storybook addon makes it easy to integrate Drupal Single Directory Components (SDC) into Storybook using YAML configurations and Twig templates. It dynamically loads components, allowing you to quickly create and manage stories with minimal configuration.
|
|
27
27
|
|
|
28
|
+
**It is still regular Storybook** but now with the added option to import and manage Drupal Single Directory Components (SDC).
|
|
29
|
+
|
|
30
|
+
## Storybook Example Live
|
|
31
|
+
|
|
32
|
+
You can view a [live example of the SDC Addon in Storybook](https://iberdinsky-skilld.github.io/sdc-addon), hosted on GitHub Pages, showcasing components in the `/components` directory of that repository.
|
|
33
|
+
|
|
28
34
|
## Why Choose SDC Storybook Over Alternatives?
|
|
29
35
|
|
|
30
36
|
While solutions like [SDC Styleguide](https://www.drupal.org/project/sdc_styleguide) and [Drupal Storybook](https://www.drupal.org/project/storybook) are valuable, the SDC Storybook addon offers distinct advantages:
|
|
@@ -181,34 +187,85 @@ Refer to:
|
|
|
181
187
|
|
|
182
188
|
## Creating Experimental Stories
|
|
183
189
|
|
|
184
|
-
|
|
190
|
+
The `thirdPartySettings` configuration in the SDC YAML file provides a flexible way to define custom stories for your components. This feature allows you to use predefined props, custom slots, or even reuse stories defined elsewhere. Here's how it works:
|
|
191
|
+
|
|
192
|
+
### Example Configuration
|
|
185
193
|
|
|
186
194
|
```yaml
|
|
187
195
|
thirdPartySettings:
|
|
188
196
|
sdcStorybook:
|
|
189
197
|
stories:
|
|
190
|
-
|
|
191
|
-
title: Preview
|
|
198
|
+
grid:
|
|
192
199
|
props:
|
|
193
|
-
|
|
200
|
+
label: Paragraph with grid
|
|
201
|
+
extra_classes:
|
|
202
|
+
- m-paragraph--grid
|
|
194
203
|
slots:
|
|
195
204
|
content:
|
|
205
|
+
# 1. Basic Props
|
|
206
|
+
# This card uses only the basic default props defined in the component YAML.
|
|
196
207
|
- type: component
|
|
197
|
-
component: 'umami:
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
props:
|
|
203
|
-
html_tag: 'div'
|
|
204
|
-
slots:
|
|
205
|
-
content:
|
|
208
|
+
component: 'umami:card'
|
|
209
|
+
|
|
210
|
+
# 2. Predefined Story
|
|
211
|
+
# This card references an existing story (e.g., "Preview")
|
|
212
|
+
# from the component YAML, which includes predefined props and slots.
|
|
206
213
|
- type: component
|
|
207
|
-
component: 'umami:
|
|
214
|
+
component: 'umami:card'
|
|
215
|
+
story: Preview
|
|
216
|
+
|
|
217
|
+
# 3. Custom Props and Slots
|
|
218
|
+
# This card defines custom props to modify its behavior (e.g., setting
|
|
219
|
+
# the HTML tag to 'div') and custom slots to override specific content.
|
|
220
|
+
- type: component
|
|
221
|
+
component: 'umami:card'
|
|
208
222
|
props:
|
|
209
|
-
|
|
223
|
+
html_tag: 'div' # Custom HTML tag for the card container
|
|
224
|
+
slots:
|
|
225
|
+
content: 'Hello from third grid card!'
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Key Features
|
|
229
|
+
|
|
230
|
+
This configuration provides three distinct options for creating stories:
|
|
231
|
+
|
|
232
|
+
1. **Render Using Basic Args**
|
|
233
|
+
The first card in the `grid` example uses only its basic arguments (`Basic.args`). No additional configuration or props are required for this component.
|
|
234
|
+
|
|
235
|
+
```yaml
|
|
236
|
+
- type: component
|
|
237
|
+
component: 'umami:card'
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
2. **Reuse an Existing Story**
|
|
241
|
+
The second card uses the `Preview` story defined earlier. This is particularly useful for reusing pre-configured props and slots without redefining them in each story.
|
|
242
|
+
|
|
243
|
+
```yaml
|
|
244
|
+
- type: component
|
|
245
|
+
component: 'umami:card'
|
|
246
|
+
story: Preview
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
3. **Define Custom Slots**
|
|
250
|
+
The third card defines a custom `content` slot. This allows you to override or enhance the default behavior of the component with specific content.
|
|
251
|
+
|
|
252
|
+
```yaml
|
|
253
|
+
- type: component
|
|
254
|
+
component: 'umami:card'
|
|
255
|
+
props:
|
|
256
|
+
html_tag: 'div'
|
|
257
|
+
slots:
|
|
258
|
+
content: 'Hello from third grid card!'
|
|
210
259
|
```
|
|
211
260
|
|
|
261
|
+
### How It Works in Practice
|
|
262
|
+
|
|
263
|
+
The addon dynamically renders the components and stories as defined:
|
|
264
|
+
|
|
265
|
+
- **Basic Args:** The default `Basic.args` of the `umami:card` component are used.
|
|
266
|
+
- **Existing Story:** The `Preview` story is loaded, ensuring consistency across the Storybook environment.
|
|
267
|
+
- **Custom Slots and Props:** Overrides the default slots and props behavior with unique content for that instance.
|
|
268
|
+
|
|
212
269
|
### Why stories experimental?
|
|
213
270
|
|
|
214
271
|
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.
|
|
@@ -221,10 +278,10 @@ All storybook functions work as usual and you can import SDC YAML into `.stories
|
|
|
221
278
|
|
|
222
279
|
```js
|
|
223
280
|
import header, {
|
|
224
|
-
|
|
281
|
+
Preview as HeaderPreview,
|
|
225
282
|
} from '../components/header/header.component.yml'
|
|
226
283
|
import banner, {
|
|
227
|
-
|
|
284
|
+
Preview as BannerPreview,
|
|
228
285
|
} from '../components/banner/banner.component.yml'
|
|
229
286
|
|
|
230
287
|
export default {
|
|
@@ -243,10 +300,6 @@ export default {
|
|
|
243
300
|
export const Basic = {}
|
|
244
301
|
```
|
|
245
302
|
|
|
246
|
-
## Storybook Example Live
|
|
247
|
-
|
|
248
|
-
You can view a [live example of the SDC Addon in Storybook](https://iberdinsky-skilld.github.io/sdc-addon), hosted on GitHub Pages, showcasing components in the `/components` directory of that repository.
|
|
249
|
-
|
|
250
303
|
## Known Issues
|
|
251
304
|
|
|
252
305
|
- `$ref: json-schema-definitions://` for SDC from Experience Builder is unsupported.
|
package/dist/preset.js
CHANGED
|
@@ -5541,7 +5541,7 @@ var argTypesGenerator_default = (content) => {
|
|
|
5541
5541
|
init_esm_shims();
|
|
5542
5542
|
var storiesGenerator_default = (stories) => Object.entries(stories).map(
|
|
5543
5543
|
([storyKey, { props = {}, slots = {} }]) => `
|
|
5544
|
-
export const ${storyKey} = {
|
|
5544
|
+
export const ${storyKey[0].toUpperCase() + storyKey.slice(1)} = {
|
|
5545
5545
|
args: {
|
|
5546
5546
|
...Basic.args,
|
|
5547
5547
|
${generateArgs2(props)}
|
|
@@ -5564,10 +5564,10 @@ var formatArgValue = (value, isSlot) => {
|
|
|
5564
5564
|
return JSON.stringify(value);
|
|
5565
5565
|
};
|
|
5566
5566
|
var generateComponent = (item) => {
|
|
5567
|
-
const
|
|
5568
|
-
const kebabCaseName = componentName.replace(/-/g, "");
|
|
5567
|
+
const kebabCaseName = item.component.replace(/[-:]/g, "");
|
|
5569
5568
|
const componentProps = { ...item.props, ...item.slots };
|
|
5570
|
-
|
|
5569
|
+
const storyArgs = item.story ? `...${kebabCaseName}.${item.story}.args` : "...{}";
|
|
5570
|
+
return `${kebabCaseName}.default.component({...Basic.args, ${storyArgs}, ...${JSON.stringify(componentProps)}})`;
|
|
5571
5571
|
};
|
|
5572
5572
|
|
|
5573
5573
|
// src/customRefsTransform.ts
|
|
@@ -5637,9 +5637,10 @@ var dynamicImports = (stories) => {
|
|
|
5637
5637
|
if (item.type === "component") {
|
|
5638
5638
|
const [namespace, componentName] = item.component.split(":");
|
|
5639
5639
|
const resolvedPath = resolveComponentPath(namespace, componentName);
|
|
5640
|
+
const kebabCaseName = item.component.replace(/[-:]/g, "");
|
|
5640
5641
|
if (resolvedPath) {
|
|
5641
5642
|
imports.add(
|
|
5642
|
-
`import ${
|
|
5643
|
+
`import * as ${kebabCaseName} from '${resolvedPath}';`
|
|
5643
5644
|
);
|
|
5644
5645
|
}
|
|
5645
5646
|
}
|