storybook-addon-sdc 0.13.2 → 0.14.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.
Files changed (3) hide show
  1. package/README.md +76 -4
  2. package/dist/preset.js +29 -11
  3. package/package.json +2 -1
package/README.md CHANGED
@@ -14,10 +14,11 @@ This addon streamlines the integration of Drupal Single Directory Components (SD
14
14
  - [Creating Experimental Stories](#creating-experimental-stories)
15
15
  - [Support for Single Story Files (\*.story.yml)](#support-for-single-story-files-storyyml)
16
16
  - [Namespaces](#namespaces)
17
+ - [Advanced Grouping and Nesting](#advanced-grouping-and-nesting)
17
18
  - [Regular Storybook](#regular-storybook)
18
19
  - [Configuration Options](#configuration-options)
19
20
  - [Setting Default Values](#setting-default-values)
20
- - [Disable Basic Story](#disable-basic-story)
21
+ - [Story Configuration via thirdPartySettings.sdcStorybook](#story-configuration-via-thirdpartysettingssdcstorybook)
21
22
  - [Why Choose SDC Storybook Over Alternatives?](#why-choose-sdc-storybook-over-alternatives)
22
23
  - [Dependencies](#dependencies)
23
24
  - [Known Issues](#known-issues)
@@ -255,6 +256,10 @@ sdcStorybookOptions: {
255
256
  }
256
257
  ```
257
258
 
259
+ ## Docs addon?
260
+
261
+ The storybook docs addon works out of the box.
262
+
258
263
  ## Support for Single Story Files (`*.story.yml`)
259
264
 
260
265
  In addition to stories defined inside `*.component.yml` files, the addon now supports standalone story files with the `.story.yml` extension.
@@ -364,6 +369,34 @@ And in story definitions within YAML files:
364
369
  {% include '@assets/icons/example.svg' %}
365
370
  ```
366
371
 
372
+ ## Advanced Grouping and Nesting
373
+
374
+ By default, the addon organizes all SDC stories under a single **SDC** [Folder](https://storybook.js.org/docs/writing-stories/naming-components-and-hierarchy#structure-and-hierarchy) at the Storybook root.
375
+
376
+ ### Grouping by SDC Properties
377
+
378
+ If your SDC component includes a [group property](https://www.drupal.org/docs/develop/theming-drupal/using-single-directory-components/annotated-example-componentyml), such as `group: Navigation`, the addon will automatically create a corresponding folder in Storybook and place the component’s stories within it.
379
+
380
+ **Note:** The `group` property has higher priority over directory structure when determining story placement.
381
+
382
+ ### Directory-Based Nesting
383
+
384
+ When your SDC components has nesting structure in the filesystem, the addon will replicate this structure in Storybook. For example, the following atomic directory structure:
385
+
386
+ ```
387
+ components/
388
+ atoms/
389
+ button/
390
+ button.component.yml
391
+ icon/
392
+ icon.component.yml
393
+ molecules/
394
+ card/
395
+ card.component.yml
396
+ ```
397
+
398
+ will result in nested folders in Storybook, mirroring the organization of your components.
399
+
367
400
  ## Regular storybook
368
401
 
369
402
  All Storybook functions work as usual, and you can import SDC YAML into `.stories.js` files.
@@ -554,17 +587,56 @@ Refer to:
554
587
  - [Drupal SDC Documentation](https://www.drupal.org/docs/develop/theming-drupal/using-single-directory-components/annotated-example-componentyml)
555
588
  - [JSON Schema Documentation](https://json-schema.org/understanding-json-schema/reference/annotations)
556
589
 
557
- ## Disable Basic Story
590
+ ## Story Configuration via `thirdPartySettings.sdcStorybook`
591
+
592
+ The **sdc-addon** now supports configuring how stories are generated from your `component.yml` file.
593
+ You can use the new key `thirdPartySettings.sdcStorybook` to define Storybook-specific settings and control which stories are created.
558
594
 
559
- By default the addon generates a `Basic` story for each component using default props and slots. This is useful for quickly previewing components, but if you prefer to create your own stories exclusively, you can disable this feature.
560
- To disable the automatic generation of the `Basic` story, set `disableBasicStory: true` in your component YAML:
595
+ ### Example
561
596
 
562
597
  ```yaml
563
598
  thirdPartySettings:
564
599
  sdcStorybook:
600
+ tags:
601
+ - autodocs
565
602
  disableBasicStory: true
603
+ parameters:
604
+ layout: 'centered'
605
+ stories:
606
+ preview:
607
+ args:
608
+ variant: 'default'
609
+ parameters:
610
+ backgrounds:
611
+ default: 'light'
612
+ ```
613
+
614
+ ### Option Reference
615
+
616
+ Below is a list of all available configuration options for `thirdPartySettings.sdcStorybook`:
617
+
618
+ | Key | Type | Description |
619
+ | ------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
620
+ | `tags` | `array` | Optional. Adds additional [Storybook tags](https://storybook.js.org/docs/writing-docs/autodocs) (e.g. `autodocs`). |
621
+ | `disableBasicStory` | `boolean` | When set to `true`, disables the automatically generated “Basic” story. |
622
+ | `parameters` | `object` | Global [Storybook parameters](https://storybook.js.org/docs/writing-stories/parameters) applied to all generated stories. |
623
+ | `stories` | `object` | Allows defining or overriding specific stories. Each key (e.g. `preview`) represents a story. Within each story, you can define `args`, `parameters`, and other Storybook options. |
624
+
625
+ ### Example: Custom Preview Story
626
+
627
+ ```yaml
628
+ thirdPartySettings:
629
+ sdcStorybook:
630
+ stories:
631
+ preview:
632
+ args:
633
+ variant: 'compact'
634
+ parameters:
635
+ layout: 'padded'
566
636
  ```
567
637
 
638
+ This configuration creates an additional story named **Preview**, rendered using the provided `args` and `parameters`.
639
+
568
640
  ## Why Choose SDC Storybook Over Alternatives?
569
641
 
570
642
  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:
package/dist/preset.js CHANGED
@@ -154,8 +154,19 @@ storyNodeRenderer.register(defaultStoryNodes);
154
154
 
155
155
  // src/storiesGenerator.ts
156
156
  var storiesGenerator_default = (stories) => Object.entries(stories).map(
157
- ([storyKey, { props = {}, slots = {}, variants = {} }]) => `
157
+ ([
158
+ storyKey,
159
+ {
160
+ props = {},
161
+ slots = {},
162
+ variants = {},
163
+ description = "",
164
+ name = void 0
165
+ }
166
+ ]) => `
158
167
  export const ${capitalize(storyKey)} = {
168
+ parameters: {docs: {description: {story: ${JSON.stringify(description, null, 2)}}}},
169
+ name: ${JSON.stringify(name ?? capitalize(storyKey), null, 2)},
159
170
  args: {
160
171
  ...Basic.baseArgs,
161
172
  ${generateArgs2(props, false)}
@@ -406,14 +417,15 @@ var dynamicImports = (stories, namespaces) => {
406
417
  );
407
418
  return Array.from(imports).join("\n");
408
419
  };
409
- var createStoryIndex = (fileName, baseTitle, stories, disableBasicStory) => {
420
+ var createStoryIndex = (fileName, baseTitle, stories, disableBasicStory, tags) => {
410
421
  const storiesIndex = [];
411
422
  if (disableBasicStory === false) {
412
423
  storiesIndex.push({
413
424
  type: "story",
414
425
  importPath: fileName,
415
426
  exportName: "Basic",
416
- title: baseTitle
427
+ title: baseTitle,
428
+ tags
417
429
  });
418
430
  }
419
431
  if (stories) {
@@ -422,7 +434,8 @@ var createStoryIndex = (fileName, baseTitle, stories, disableBasicStory) => {
422
434
  type: "story",
423
435
  importPath: fileName,
424
436
  exportName: storyKey,
425
- title: baseTitle
437
+ title: baseTitle,
438
+ tags
426
439
  });
427
440
  });
428
441
  }
@@ -471,12 +484,10 @@ var vite_plugin_storybook_yaml_stories_default = ({
471
484
  componentMetadata: metadata,
472
485
  ...content.variants && {
473
486
  variant: Object.keys(content.variants)[0]
474
- }
475
- };
476
- const basicArgs = {
477
- ...args,
487
+ },
478
488
  ...generateStorybookArgs(content, jsonSchemaFakerOptions)
479
489
  };
490
+ const basicArgs = { ...args };
480
491
  const stories = previewsStories ? storiesGenerator_default(previewsStories) : "";
481
492
  return `
482
493
  ${imports}
@@ -490,13 +501,15 @@ class TwigSafeArray extends Array {
490
501
 
491
502
  export default {
492
503
  component: COMPONENT,
504
+ parameters: {...${JSON.stringify(content?.thirdPartySettings?.sdcStorybook?.parameters ?? {}, null, 2)}, ...{docs: {description: {component: ${JSON.stringify(content.description, null, 2)}}}}},
493
505
  argTypes: ${JSON.stringify(argTypes, null, 2)},
494
506
  args: ${JSON.stringify(args, null, 2)},
495
507
  };
496
508
 
497
509
  export const Basic = {
498
- baseArgs: ${JSON.stringify(args, null, 2)},
510
+
499
511
  args: ${JSON.stringify(basicArgs, null, 2)},
512
+ baseArgs: ${JSON.stringify(args, null, 2)},
500
513
  play: async ({ canvasElement }) => {
501
514
  Drupal.attachBehaviors(canvasElement, window.drupalSettings);
502
515
  },
@@ -519,14 +532,16 @@ var yamlStoriesIndexer = {
519
532
  `${getProjectName(fileName)}/${capitalize(group)}/${content.name}`
520
533
  );
521
534
  const stories = content.thirdPartySettings?.sdcStorybook?.stories;
522
- const disableBasicStory = content.thirdPartySettings?.sdcStorybook?.disableBasicStory ?? false;
523
535
  const storiesContent = loadStoryFilesSync(fileName);
524
536
  const mergedStories = { ...stories, ...storiesContent };
537
+ const tags = content?.thirdPartySettings?.sdcStorybook?.tags ?? [];
538
+ const disableBasicStory = content.thirdPartySettings?.sdcStorybook?.disableBasicStory ?? false;
525
539
  return createStoryIndex(
526
540
  fileName,
527
541
  baseTitle,
528
542
  mergedStories,
529
- disableBasicStory
543
+ disableBasicStory,
544
+ tags
530
545
  );
531
546
  } catch (error) {
532
547
  logger.error(`Error creating index for YAML file: ${fileName}, ${error}`);
@@ -659,6 +674,9 @@ async function viteFinal(config, options) {
659
674
  ...twigPlugin ? [twigPlugin] : [],
660
675
  vite_plugin_storybook_yaml_stories_default({ ...options, globalDefs, namespaces })
661
676
  ],
677
+ optimizeDeps: {
678
+ exclude: ["vite-plugin-twig-drupal", "vite-plugin-twing-drupal"]
679
+ },
662
680
  resolve: {
663
681
  alias: [...namespaces.toViteAlias()]
664
682
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-addon-sdc",
3
- "version": "0.13.2",
3
+ "version": "0.14.2",
4
4
  "description": "Drupal Single Directory Components as stories",
5
5
  "keywords": [
6
6
  "SDC",
@@ -49,6 +49,7 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@storybook/addon-links": "^9.1.2",
52
+ "@storybook/addon-docs": "^9.1.2",
52
53
  "@storybook/html-vite": "^9.1.2",
53
54
  "@types/json-schema": "^7.0.15",
54
55
  "@types/node": "^24.2.1",