From 82f3fa6e224bfe9cd0cb5a95b405039ad7c22925 Mon Sep 17 00:00:00 2001 From: iberdinsky-skilld Date: Tue, 14 Oct 2025 07:17:49 +0200 Subject: [PATCH 1/5] Use case + Readme update --- README.md | 15 +++++++----- .../addon-features-examples.component.yml | 5 ++++ src/storiesGenerator.ts | 24 +++++++++++-------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 58f3399..e1cc546 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,10 @@ This addon streamlines the integration of Drupal Single Directory Components (SD - [Configuration Options](#configuration-options) - [Setting Default Values](#setting-default-values) - [Story Configuration via thirdPartySettings.sdcStorybook](#story-configuration-via-thirdpartysettingssdcstorybook) +- [UI Patterns](#ui-patterns) - [Why Choose SDC Storybook Over Alternatives?](#why-choose-sdc-storybook-over-alternatives) - [Dependencies](#dependencies) - [Known Issues](#known-issues) -- [UI Patterns](#ui-patterns) --- @@ -637,6 +637,14 @@ thirdPartySettings: This configuration creates an additional story named **Preview**, rendered using the provided `args` and `parameters`. +## UI Patterns + +Addon supports UI Patterns `library_wrapper` [for wrapping stories](https://project.pages.drupalcode.org/ui_patterns/2-authors/1-stories-and-library/#library-wrappers) in a specific HTML structure. + +--- + +- Custom Twig filters and functions are not supported ([UI Patterns TwigExtension](https://git.drupalcode.org/project/ui_patterns/-/blob/8.x-1.x/src/Template/TwigExtension.php)). + ## Why Choose SDC Storybook Over Alternatives? 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: @@ -690,8 +698,3 @@ While using Drupal to render components offers tighter integration, there are st ## Known Issues - The addon relies on [Experimental indexers](https://storybook.js.org/docs/api/main-config/main-config-indexers). - -## UI Patterns - -- Variants are partially supported ([Issue 3390712](https://www.drupal.org/project/drupal/issues/3390712)). -- Custom Twig filters and functions are not supported ([UI Patterns TwigExtension](https://git.drupalcode.org/project/ui_patterns/-/blob/8.x-1.x/src/Template/TwigExtension.php)). diff --git a/components/addon-features-examples/addon-features-examples.component.yml b/components/addon-features-examples/addon-features-examples.component.yml index e7c4317..9c9e5e4 100644 --- a/components/addon-features-examples/addon-features-examples.component.yml +++ b/components/addon-features-examples/addon-features-examples.component.yml @@ -26,6 +26,11 @@ thirdPartySettings: preview: name: Preview Example description: 'Addon Features preview description' + library_wrapper: ' +
+ UI PATTERNS library_wrapper + {{ _story }} +
' slots: content: - type: component diff --git a/src/storiesGenerator.ts b/src/storiesGenerator.ts index 6a3357f..1f2e456 100644 --- a/src/storiesGenerator.ts +++ b/src/storiesGenerator.ts @@ -25,16 +25,20 @@ export const ${capitalize(storyKey)} = { ${generateArgs(slots, true)} ${generateVariants(variants)} }, - ${library_wrapper ? `decorators: [ - (Story) => { - const wrapper = ${JSON.stringify(library_wrapper)}; - if (!wrapper) return Story(); - - // Replace {{ _story }} with the actual story component - const wrappedHtml = wrapper.replace('{{ _story }}', Story()); - return wrappedHtml; - } - ],` : ''} + ${ + library_wrapper + ? `decorators: [ + (Story) => { + const wrapper = ${JSON.stringify(library_wrapper)}; + if (!wrapper) return Story(); + + // Replace {{ _story }} with the actual story component + const wrappedHtml = wrapper.replace('{{ _story }}', Story()); + return wrappedHtml; + } + ],` + : '' + } play: async ({ canvasElement }) => { Drupal.attachBehaviors(canvasElement, window.drupalSettings); }, From 3166b6a4f3f55e376ff3e613f5ded601640ddfa6 Mon Sep 17 00:00:00 2001 From: iberdinsky-skilld Date: Tue, 14 Oct 2025 07:20:29 +0200 Subject: [PATCH 2/5] Bump --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 96c3241..e323a98 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "storybook-addon-sdc", - "version": "0.14.2", + "version": "0.15.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "storybook-addon-sdc", - "version": "0.14.2", + "version": "0.15.0", "license": "MIT", "dependencies": { "glob": "^11.0.1", diff --git a/package.json b/package.json index 2802b35..921f9f6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "storybook-addon-sdc", - "version": "0.14.2", + "version": "0.15.0", "description": "Drupal Single Directory Components as stories", "keywords": [ "SDC", From 391c4a39dd94524848d4bb7820c0f708e541d42d Mon Sep 17 00:00:00 2001 From: iberdinsky-skilld Date: Tue, 14 Oct 2025 07:20:45 +0200 Subject: [PATCH 3/5] Update CHANGELOG.md [skip ci] --- CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9562215..d33cd97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,21 @@ +# v0.14.3 (Tue Oct 14 2025) + +#### 🐛 Bug Fix + +- Add library_wrapper ui_pattern story feature [#88](https://github.com/iberdinsky-skilld/sdc-addon/pull/88) ([@Fred-Boulanger](https://github.com/Fred-Boulanger) [@iberdinsky-skilld](https://github.com/iberdinsky-skilld)) + +#### ⚠️ Pushed to `main` + +- Bump (iberdinsky@skilld.cloud) + +#### Authors: 3 + +- [@iberdinsky-skilld](https://github.com/iberdinsky-skilld) +- fredb ([@Fred-Boulanger](https://github.com/Fred-Boulanger)) +- iberdinsky-skilld (iberdinsky@skilld.cloud) + +--- + # v0.14.2 (Fri Oct 10 2025) #### ⚠️ Pushed to `main` From 2a125bb8ad1c076936d72d8dd4a0c2095349d539 Mon Sep 17 00:00:00 2001 From: iberdinsky-skilld Date: Tue, 14 Oct 2025 07:20:46 +0200 Subject: [PATCH 4/5] Bump version to: 0.15.1 [skip ci] --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index e323a98..fbbd188 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "storybook-addon-sdc", - "version": "0.15.0", + "version": "0.15.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "storybook-addon-sdc", - "version": "0.15.0", + "version": "0.15.1", "license": "MIT", "dependencies": { "glob": "^11.0.1", diff --git a/package.json b/package.json index 921f9f6..f1ef4c9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "storybook-addon-sdc", - "version": "0.15.0", + "version": "0.15.1", "description": "Drupal Single Directory Components as stories", "keywords": [ "SDC", From 72fe4690a6af9acdfcdd2dbe98807a5af462f2ca Mon Sep 17 00:00:00 2001 From: GitFred Date: Mon, 20 Oct 2025 17:18:43 +0200 Subject: [PATCH 5/5] add disabledStories feature --- README.md | 22 ++++++++- .../addon-features-examples.component.yml | 3 +- components/banner/banner.component.yml | 3 +- components/card/card.component.yml | 3 +- components/header/header.component.yml | 3 +- src/sdc.d.ts | 7 +++ src/vite-plugin-storybook-yaml-stories.ts | 47 ++++++++++++++----- 7 files changed, 69 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index e1cc546..0c45de6 100644 --- a/README.md +++ b/README.md @@ -599,7 +599,8 @@ thirdPartySettings: sdcStorybook: tags: - autodocs - disableBasicStory: true + disabledStories: + - basic parameters: layout: 'centered' stories: @@ -618,10 +619,27 @@ Below is a list of all available configuration options for `thirdPartySettings.s | Key | Type | Description | | ------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `tags` | `array` | Optional. Adds additional [Storybook tags](https://storybook.js.org/docs/writing-docs/autodocs) (e.g. `autodocs`). | -| `disableBasicStory` | `boolean` | When set to `true`, disables the automatically generated “Basic” story. | +| `disabledStories` | `array` | Optional. Array of story names to disable. Supports `basic`, `preview`, or any custom story name. Use `all` to disable all stories. **Note:** `disableBasicStory` is deprecated in favor of `disabledStories: ['basic']`. | | `parameters` | `object` | Global [Storybook parameters](https://storybook.js.org/docs/writing-stories/parameters) applied to all generated stories. | | `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. | +### Disabled Stories Examples + +```yaml +# Disable only the basic story +disabledStories: + - basic + +# Disable basic and preview stories +disabledStories: + - basic + - preview + +# Disable all stories +disabledStories: + - all +``` + ### Example: Custom Preview Story ```yaml diff --git a/components/addon-features-examples/addon-features-examples.component.yml b/components/addon-features-examples/addon-features-examples.component.yml index 9c9e5e4..d336a67 100644 --- a/components/addon-features-examples/addon-features-examples.component.yml +++ b/components/addon-features-examples/addon-features-examples.component.yml @@ -19,7 +19,8 @@ slots: thirdPartySettings: sdcStorybook: - disableBasicStory: true + disabledStories: + - basic tags: - autodocs stories: diff --git a/components/banner/banner.component.yml b/components/banner/banner.component.yml index ea60025..d558777 100644 --- a/components/banner/banner.component.yml +++ b/components/banner/banner.component.yml @@ -33,7 +33,8 @@ slots: - thirdPartySettings: sdcStorybook: - disableBasicStory: true + disabledStories: + - basic stories: preview: slots: diff --git a/components/card/card.component.yml b/components/card/card.component.yml index a3e261e..5cbf45e 100644 --- a/components/card/card.component.yml +++ b/components/card/card.component.yml @@ -37,7 +37,8 @@ slots: thirdPartySettings: sdcStorybook: - disableBasicStory: true + disabledStories: + - basic parameters: layout: 'centered' stories: diff --git a/components/header/header.component.yml b/components/header/header.component.yml index 6541f52..b5d23d0 100644 --- a/components/header/header.component.yml +++ b/components/header/header.component.yml @@ -45,7 +45,8 @@ libraryOverrides: thirdPartySettings: sdcStorybook: - disableBasicStory: true + disabledStories: + - basic stories: preview: slots: diff --git a/src/sdc.d.ts b/src/sdc.d.ts index 33c72d1..01c8f62 100644 --- a/src/sdc.d.ts +++ b/src/sdc.d.ts @@ -65,6 +65,13 @@ interface LibraryDefinition { interface ThirdPartySettings { [key: string]: Record } + +interface SDCStorybookSettings { + tags?: string[] + disabledStories?: string[] + parameters?: Record + stories?: Record +} export interface NamespaceDefinition { namespace?: string namespaces?: Record diff --git a/src/vite-plugin-storybook-yaml-stories.ts b/src/vite-plugin-storybook-yaml-stories.ts index 5064cdd..98e8843 100755 --- a/src/vite-plugin-storybook-yaml-stories.ts +++ b/src/vite-plugin-storybook-yaml-stories.ts @@ -106,11 +106,16 @@ const createStoryIndex = ( fileName: string, baseTitle: string, stories: Record, - disableBasicStory: boolean, + disabledStories: string[], tags: string[] ): IndexInput[] => { const storiesIndex: IndexInput[] = [] - if (disableBasicStory === false) { + + // Check if all stories are disabled + const isAllDisabled = disabledStories.includes('all') + + // Add Basic story if not disabled + if (!isAllDisabled && !disabledStories.includes('basic')) { storiesIndex.push({ type: 'story', importPath: fileName, @@ -120,15 +125,19 @@ const createStoryIndex = ( }) } - if (stories) { + // Add custom stories if not all disabled + if (stories && !isAllDisabled) { Object.keys(stories).forEach((storyKey) => { - storiesIndex.push({ - type: 'story', - importPath: fileName, - exportName: storyKey, - title: baseTitle, - tags, - }) + // Skip if this specific story is disabled + if (!disabledStories.includes(storyKey)) { + storiesIndex.push({ + type: 'story', + importPath: fileName, + exportName: storyKey, + title: baseTitle, + tags, + }) + } }) } @@ -246,13 +255,25 @@ export const yamlStoriesIndexer: Indexer = { const storiesContent = loadStoryFilesSync(fileName) const mergedStories = { ...stories, ...storiesContent } const tags = content?.thirdPartySettings?.sdcStorybook?.tags ?? [] - const disableBasicStory = - content.thirdPartySettings?.sdcStorybook?.disableBasicStory ?? false + + // Handle both old and new configuration formats + const oldDisableBasicStory = content.thirdPartySettings?.sdcStorybook?.disableBasicStory + const newDisabledStories = content.thirdPartySettings?.sdcStorybook?.disabledStories + + let disabledStories: string[] = [] + + // Backward compatibility: convert old boolean to new array format + if (oldDisableBasicStory === true) { + disabledStories = ['basic'] + } else if (newDisabledStories) { + disabledStories = newDisabledStories + } + return createStoryIndex( fileName, baseTitle, mergedStories, - disableBasicStory, + disabledStories, tags ) } catch (error) {