storybook-addon-sdc 0.13.2 → 0.14.1

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 +47 -4
  2. package/dist/preset.js +29 -11
  3. package/package.json +2 -1
package/README.md CHANGED
@@ -17,7 +17,7 @@ This addon streamlines the integration of Drupal Single Directory Components (SD
17
17
  - [Regular Storybook](#regular-storybook)
18
18
  - [Configuration Options](#configuration-options)
19
19
  - [Setting Default Values](#setting-default-values)
20
- - [Disable Basic Story](#disable-basic-story)
20
+ - [Story Configuration via thirdPartySettings.sdcStorybook](#story-configuration-via-thirdpartysettingssdcstorybook)
21
21
  - [Why Choose SDC Storybook Over Alternatives?](#why-choose-sdc-storybook-over-alternatives)
22
22
  - [Dependencies](#dependencies)
23
23
  - [Known Issues](#known-issues)
@@ -255,6 +255,10 @@ sdcStorybookOptions: {
255
255
  }
256
256
  ```
257
257
 
258
+ ## Docs addon?
259
+
260
+ The storybook docs addon works out of the box.
261
+
258
262
  ## Support for Single Story Files (`*.story.yml`)
259
263
 
260
264
  In addition to stories defined inside `*.component.yml` files, the addon now supports standalone story files with the `.story.yml` extension.
@@ -554,17 +558,56 @@ Refer to:
554
558
  - [Drupal SDC Documentation](https://www.drupal.org/docs/develop/theming-drupal/using-single-directory-components/annotated-example-componentyml)
555
559
  - [JSON Schema Documentation](https://json-schema.org/understanding-json-schema/reference/annotations)
556
560
 
557
- ## Disable Basic Story
561
+ ## Story Configuration via `thirdPartySettings.sdcStorybook`
562
+
563
+ The **sdc-addon** now supports configuring how stories are generated from your `component.yml` file.
564
+ You can use the new key `thirdPartySettings.sdcStorybook` to define Storybook-specific settings and control which stories are created.
558
565
 
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:
566
+ ### Example
561
567
 
562
568
  ```yaml
563
569
  thirdPartySettings:
564
570
  sdcStorybook:
571
+ tags:
572
+ - autodocs
565
573
  disableBasicStory: true
574
+ parameters:
575
+ layout: 'centered'
576
+ stories:
577
+ preview:
578
+ args:
579
+ variant: 'default'
580
+ parameters:
581
+ backgrounds:
582
+ default: 'light'
566
583
  ```
567
584
 
585
+ ### Option Reference
586
+
587
+ Below is a list of all available configuration options for `thirdPartySettings.sdcStorybook`:
588
+
589
+ | Key | Type | Description |
590
+ | ------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
591
+ | `tags` | `array` | Optional. Adds additional [Storybook tags](https://storybook.js.org/docs/writing-docs/autodocs) (e.g. `autodocs`). |
592
+ | `disableBasicStory` | `boolean` | When set to `true`, disables the automatically generated “Basic” story. |
593
+ | `parameters` | `object` | Global [Storybook parameters](https://storybook.js.org/docs/writing-stories/parameters) applied to all generated stories. |
594
+ | `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. |
595
+
596
+ ### Example: Custom Preview Story
597
+
598
+ ```yaml
599
+ thirdPartySettings:
600
+ sdcStorybook:
601
+ stories:
602
+ preview:
603
+ args:
604
+ variant: 'compact'
605
+ parameters:
606
+ layout: 'padded'
607
+ ```
608
+
609
+ This configuration creates an additional story named **Preview**, rendered using the provided `args` and `parameters`.
610
+
568
611
  ## Why Choose SDC Storybook Over Alternatives?
569
612
 
570
613
  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.1",
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",