storybook-addon-sdc 0.11.1 → 0.12.3
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 +29 -0
- package/dist/preset.js +13 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,6 +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
21
|
- [Why Choose SDC Storybook Over Alternatives?](#why-choose-sdc-storybook-over-alternatives)
|
|
21
22
|
- [Dependencies](#dependencies)
|
|
22
23
|
- [Known Issues](#known-issues)
|
|
@@ -346,6 +347,23 @@ And in story definitions within YAML files:
|
|
|
346
347
|
],
|
|
347
348
|
```
|
|
348
349
|
|
|
350
|
+
- **Non Component Namespaces**: If you want to use components from a directory that does not follow the SDC structure (i.e., does not have a `components` directory), you can define a namespace that points directly to that directory. For example, if you have an `assets` directory with SVG icons:
|
|
351
|
+
|
|
352
|
+
```js
|
|
353
|
+
sdcStorybookOptions: {
|
|
354
|
+
namespaces: {
|
|
355
|
+
'assets': join(cwd(), './assets'),
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
In this case, the addon will look for components directly in the specified directory.
|
|
361
|
+
And you can use them in twig and stories as usual:
|
|
362
|
+
|
|
363
|
+
```twig
|
|
364
|
+
{% include '@assets/icons/example.svg' %}
|
|
365
|
+
```
|
|
366
|
+
|
|
349
367
|
## Regular storybook
|
|
350
368
|
|
|
351
369
|
All Storybook functions work as usual, and you can import SDC YAML into `.stories.js` files.
|
|
@@ -536,6 +554,17 @@ Refer to:
|
|
|
536
554
|
- [Drupal SDC Documentation](https://www.drupal.org/docs/develop/theming-drupal/using-single-directory-components/annotated-example-componentyml)
|
|
537
555
|
- [JSON Schema Documentation](https://json-schema.org/understanding-json-schema/reference/annotations)
|
|
538
556
|
|
|
557
|
+
## Disable Basic Story
|
|
558
|
+
|
|
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:
|
|
561
|
+
|
|
562
|
+
```yaml
|
|
563
|
+
thirdPartySettings:
|
|
564
|
+
sdcStorybook:
|
|
565
|
+
disableBasicStory: true
|
|
566
|
+
```
|
|
567
|
+
|
|
539
568
|
## Why Choose SDC Storybook Over Alternatives?
|
|
540
569
|
|
|
541
570
|
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
|
@@ -395,15 +395,16 @@ var dynamicImports = (stories, namespaces) => {
|
|
|
395
395
|
);
|
|
396
396
|
return Array.from(imports).join("\n");
|
|
397
397
|
};
|
|
398
|
-
var createStoryIndex = (fileName, baseTitle, stories) => {
|
|
399
|
-
const storiesIndex = [
|
|
400
|
-
|
|
398
|
+
var createStoryIndex = (fileName, baseTitle, stories, disableBasicStory) => {
|
|
399
|
+
const storiesIndex = [];
|
|
400
|
+
if (disableBasicStory === false) {
|
|
401
|
+
storiesIndex.push({
|
|
401
402
|
type: "story",
|
|
402
403
|
importPath: fileName,
|
|
403
404
|
exportName: "Basic",
|
|
404
405
|
title: baseTitle
|
|
405
|
-
}
|
|
406
|
-
|
|
406
|
+
});
|
|
407
|
+
}
|
|
407
408
|
if (stories) {
|
|
408
409
|
Object.keys(stories).forEach((storyKey) => {
|
|
409
410
|
storiesIndex.push({
|
|
@@ -504,9 +505,15 @@ var yamlStoriesIndexer = {
|
|
|
504
505
|
const content = readSDC(fileName);
|
|
505
506
|
const baseTitle = makeTitle(`${getProjectName(fileName)}/${content.name}`);
|
|
506
507
|
const stories = content.thirdPartySettings?.sdcStorybook?.stories;
|
|
508
|
+
const disableBasicStory = content.thirdPartySettings?.sdcStorybook?.disableBasicStory ?? false;
|
|
507
509
|
const storiesContent = loadStoryFilesSync(fileName);
|
|
508
510
|
const mergedStories = { ...stories, ...storiesContent };
|
|
509
|
-
return createStoryIndex(
|
|
511
|
+
return createStoryIndex(
|
|
512
|
+
fileName,
|
|
513
|
+
baseTitle,
|
|
514
|
+
mergedStories,
|
|
515
|
+
disableBasicStory
|
|
516
|
+
);
|
|
510
517
|
} catch (error) {
|
|
511
518
|
logger.error(`Error creating index for YAML file: ${fileName}, ${error}`);
|
|
512
519
|
throw error;
|