storybook-addon-sdc 0.2.10 → 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 +68 -18
- package/dist/preset.js +6 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,7 +31,6 @@ This Storybook addon makes it easy to integrate Drupal Single Directory Componen
|
|
|
31
31
|
|
|
32
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
33
|
|
|
34
|
-
|
|
35
34
|
## Why Choose SDC Storybook Over Alternatives?
|
|
36
35
|
|
|
37
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:
|
|
@@ -188,34 +187,85 @@ Refer to:
|
|
|
188
187
|
|
|
189
188
|
## Creating Experimental Stories
|
|
190
189
|
|
|
191
|
-
|
|
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
|
|
192
193
|
|
|
193
194
|
```yaml
|
|
194
195
|
thirdPartySettings:
|
|
195
196
|
sdcStorybook:
|
|
196
197
|
stories:
|
|
197
|
-
|
|
198
|
-
title: Preview
|
|
198
|
+
grid:
|
|
199
199
|
props:
|
|
200
|
-
|
|
200
|
+
label: Paragraph with grid
|
|
201
|
+
extra_classes:
|
|
202
|
+
- m-paragraph--grid
|
|
201
203
|
slots:
|
|
202
204
|
content:
|
|
205
|
+
# 1. Basic Props
|
|
206
|
+
# This card uses only the basic default props defined in the component YAML.
|
|
203
207
|
- type: component
|
|
204
|
-
component: 'umami:
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
props:
|
|
210
|
-
html_tag: 'div'
|
|
211
|
-
slots:
|
|
212
|
-
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.
|
|
213
213
|
- type: component
|
|
214
|
-
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'
|
|
215
222
|
props:
|
|
216
|
-
|
|
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'
|
|
217
238
|
```
|
|
218
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!'
|
|
259
|
+
```
|
|
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
|
+
|
|
219
269
|
### Why stories experimental?
|
|
220
270
|
|
|
221
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.
|
|
@@ -228,10 +278,10 @@ All storybook functions work as usual and you can import SDC YAML into `.stories
|
|
|
228
278
|
|
|
229
279
|
```js
|
|
230
280
|
import header, {
|
|
231
|
-
|
|
281
|
+
Preview as HeaderPreview,
|
|
232
282
|
} from '../components/header/header.component.yml'
|
|
233
283
|
import banner, {
|
|
234
|
-
|
|
284
|
+
Preview as BannerPreview,
|
|
235
285
|
} from '../components/banner/banner.component.yml'
|
|
236
286
|
|
|
237
287
|
export default {
|
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
|
}
|