From 33176192adcbbcc06382a0b6cf4a1122242da6c3 Mon Sep 17 00:00:00 2001 From: Kyle Gach Date: Tue, 2 Apr 2024 12:38:54 -0600 Subject: [PATCH 1/5] Add docs for story tags - API reference - Guide - CLI options --- docs/api/cli-options.md | 9 +++- docs/api/main-config-tags.md | 40 +++++++++++++++ docs/api/main-config.md | 1 + docs/toc.js | 12 ++++- docs/writing-stories/tags.md | 99 ++++++++++++++++++++++++++++++++++++ 5 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 docs/api/main-config-tags.md create mode 100644 docs/writing-stories/tags.md diff --git a/docs/api/cli-options.md b/docs/api/cli-options.md index 3aa9f0a3f0a1..39b366429daf 100644 --- a/docs/api/cli-options.md +++ b/docs/api/cli-options.md @@ -1,5 +1,6 @@ --- title: 'CLI options' +hideRendererSelector: true --- The Storybook command line interface (CLI) is the main tool you use to build and develop Storybook. @@ -46,9 +47,11 @@ Options include: | `--no-open` | Do not open Storybook automatically in the browser
`storybook dev --no-open` | | `--quiet` | Suppress verbose build output
`storybook dev --quiet` | | `--debug-webpack` | Display final webpack configurations for debugging purposes
`storybook dev --debug-webpack` | -| `--stats-json` | Write stats JSON to disk
`storybook dev ---stats-json /tmp/stats`
NOTE: only works for webpack. | +| `--stats-json` | Write stats JSON to disk
`storybook dev ---stats-json /tmp/stats`
NOTE: only works for webpack. | | `--docs` | Starts Storybook in documentation mode. Learn more about it in [here](../writing-docs/build-documentation.md#preview-storybooks-documentation)
`storybook dev --docs` | | `--disable-telemetry` | Disables Storybook's telemetry. Learn more about it [here](../configure/telemetry.md)
`storybook dev --disable-telemetry` | +| `--tags` | Select which [story tags](../writing-stories/tags.md) to include. Accepts a comma-seperated string.
`storybook dev --tags "dev,test"` | +| `--exclude-tags` | Select which [story tags](../writing-stories/tags.md) to exclude. Accepts a comma-seperated string.
`storybook dev --tags "docs, test"` | @@ -75,10 +78,12 @@ Options include: | `--loglevel [level]` | Controls level of logging during build.
Available options: `silly`, `verbose`, `info` (default), `warn`, `error`, `silent`
`storybook build --loglevel warn` | | `--quiet` | Suppress verbose build output
`storybook build --quiet` | | `--debug-webpack` | Display final webpack configurations for debugging purposes
`storybook build --debug-webpack` | -| `---stats-json` | Write stats JSON to disk
`storybook build -stats-json /my-storybook/-stats` | +| `---stats-json` | Write stats JSON to disk
`storybook build -stats-json /my-storybook/-stats` | | `--docs` | Builds Storybook in documentation mode. Learn more about it in [here](../writing-docs/build-documentation.md#publish-storybooks-documentation)
`storybook build --docs` | | `--disable-telemetry` | Disables Storybook's telemetry. Learn more about it [here](../configure/telemetry.md).
`storybook build --disable-telemetry` | | `--test` | Optimize Storybook's production build for performance and tests by removing unnecessary features with the `test` option. Learn more [here](../api/main-config-build.md).
`storybook build --test` | +| `--tags` | Select which [story tags](../writing-stories/tags.md) to include. Accepts a comma-seperated string.
`storybook dev --tags "dev,test"` | +| `--exclude-tags` | Select which [story tags](../writing-stories/tags.md) to exclude. Accepts a comma-seperated string.
`storybook dev --tags "docs, test"` | diff --git a/docs/api/main-config-tags.md b/docs/api/main-config-tags.md new file mode 100644 index 000000000000..cb593d36afb5 --- /dev/null +++ b/docs/api/main-config-tags.md @@ -0,0 +1,40 @@ +--- +title: 'tags' +hideRendererSelector: true +--- + +Parent: [main.js|ts configuration](./main-config.md) + +Type: `{ [key: string]: { description?: string } }` + +[Tags](../writing-stories/tags.md) allow you to control which stories are included in your Storybook. They are defined in the `tags` property of the Storybook configuration. Then they can be [applied to stories](../writing-stories/tags.md#tagging-stories) at the project, component, and story levels using the `tags` array. + +## Default tags + +The following tags are available by default in your project: + +```js +{ + dev: { description: 'Rendered in the Storybook UI, but only in development mode. They do not appear in the sidebar in production mode.' }, + docs: { description: 'Rendered in the Storybook UI, but only in the docs page. They do not appear in the sidebar.' }, + test: { description: 'Not rendered in the Storybook UI, in either development or production mode.' }, +} +``` + +## Custom tags + +You can [define your own tags](../writing-stories/tags.md#custom-tags). When doing so, the key is the tag name, and the value is an object with an optional `description` property. + +```ts +// .storybook/main.ts +import { StorybookConfig } from '@storybook/'; + +const config: StorybookConfig = { + // ...rest of config + tags: { + experimental: { description: 'Stories for experimental components or features' }, + }, +}; + +export default config; +``` diff --git a/docs/api/main-config.md b/docs/api/main-config.md index a9013268e45c..e347bc355b5f 100644 --- a/docs/api/main-config.md +++ b/docs/api/main-config.md @@ -44,6 +44,7 @@ An object to configure Storybook containing the following properties: - [`refs`](./main-config-refs.md) - [`staticDirs`](./main-config-static-dirs.md) - [`swc`](./main-config-swc.md) +- [`tags`](./main-config-tags.md) - [`typescript`](./main-config-typescript.md) - [`viteFinal`](./main-config-vite-final.md) - [`webpackFinal`](./main-config-webpack-final.md) diff --git a/docs/toc.js b/docs/toc.js index a4d3e85cf6be..7f3b62cbe9e8 100644 --- a/docs/toc.js +++ b/docs/toc.js @@ -136,6 +136,11 @@ module.exports = { title: 'Loaders', type: 'link', }, + { + pathSegment: 'tags', + title: 'Tags', + type: 'link', + }, { pathSegment: 'naming-components-and-hierarchy', title: 'Naming components and hierarchy', @@ -611,11 +616,16 @@ module.exports = { pathSegment: 'main-config-static-dirs', type: 'link', }, - { + { title: 'swc', pathSegment: 'main-config-swc', type: 'link', }, + { + title: 'tags', + pathSegment: 'main-config-tags', + type: 'link', + }, { title: 'typescript', pathSegment: 'main-config-typescript', diff --git a/docs/writing-stories/tags.md b/docs/writing-stories/tags.md new file mode 100644 index 000000000000..174cfab0183a --- /dev/null +++ b/docs/writing-stories/tags.md @@ -0,0 +1,99 @@ +--- +title: 'Tags' +--- + +Tags allow you to control which stories are included in your Storybook. + +## Default tags + +By default, the following tags are available in your project: + +- `dev`: Stories tagged with `dev` are rendered in the Storybook UI, but only in development mode. They do not appear in the sidebar in [production mode](../sharing/publish-storybook.md#build-storybook-as-a-static-web-application). +- `docs`: Stories tagged with `docs` are rendered in the Storybook UI, but only in the [docs page](../writing-docs/autodocs.md). They do not appear in the sidebar. +- `test`: Stories tagged with `test` are not rendered in the Storybook UI, in either development or production mode. + +## Custom tags + +You can define your own tags by adding them to the [`tags` property](../api/main-config-tags.md) in your `main.js|ts` file. For example: + +```ts +// .storybook/main.ts +import { StorybookConfig } from '@storybook/'; + +const config: StorybookConfig = { + // ...rest of config + tags: { + experimental: { description: 'Stories for experimental components or features' }, + }, +}; + +export default config; +``` + +## Tagging stories + +You tag stories by defining a `tags` array in the story or meta definitions: + +```ts +// Button.stories.ts +import { Meta, StoryObj } from '@storybook/'; + +import { Button } from './Button'; + +const meta = { + component: Button, + // 👇 Stories in this file will only be included for development mode, not production + tags: ['dev'], +} satisfies Meta; +export default meta; + +type Story = StoryObj; + +export const InternalStory: Story = { + /** + * 👇 This story inherits the tags from `meta` and defines its own, + * making the applied tags `['dev', 'test']`. + * It will not be included in the UI, only for testing environments + */ + tags: ['test'], +}; +``` + +If you want to add tags to all stories in your project, you can apply them in your `preview.js|ts` file: + +```ts +// .storybook/preview.ts +import { Preview } from '@storybook/'; + +const preview: Preview = { + // ...rest of preview + tags: ['dev'], +}; + +export default preview; +``` + +### Removing tags + +To remove a tag from a story, prefix it with `!`. For example: + +```ts +// Button.stories.ts +import { Meta, StoryObj } from '@storybook/'; + +import { Button } from './Button'; + +const meta = { + component: Button, + // 👇 Stories in this file will only be included for development mode, not production + tags: ['dev'], +} satisfies Meta; +export default meta; + +type Story = StoryObj; + +export const InternalStory: Story = { + // 👇 Remove the inherited `dev` tag by using the `!` prefix + tags: ['!dev'], +}; +``` From 64c67b4dbb85e2ad63d76f1599a905d2b39e4a47 Mon Sep 17 00:00:00 2001 From: Kyle Gach Date: Mon, 6 May 2024 16:32:58 -0600 Subject: [PATCH 2/5] Revise tags docs - Document new API - Add examples - Remove `main-config-tags` - Remove `--tags` and `--exclude-tags` CLI flags - Remove `autodocs: true | false | 'tag'` - Remove old snippets --- docs/api/cli-options.md | 4 - docs/api/main-config-tags.md | 40 ----- docs/api/main-config.md | 1 - .../angular/button-story-auto-docs.ts.mdx | 33 ---- .../storybook-auto-docs-full-config.js.mdx | 1 - .../storybook-auto-docs-full-config.ts.mdx | 1 - .../react/button-story-auto-docs.js.mdx | 28 ---- .../react/button-story-auto-docs.ts-4-9.mdx | 33 ---- .../react/button-story-auto-docs.ts.mdx | 33 ---- .../solid/button-story-auto-docs.js.mdx | 28 ---- .../solid/button-story-auto-docs.ts-4-9.mdx | 33 ---- .../solid/button-story-auto-docs.ts.mdx | 33 ---- .../svelte/button-story-auto-docs.js.mdx | 28 ---- .../svelte/button-story-auto-docs.ts-4-9.mdx | 33 ---- .../svelte/button-story-auto-docs.ts.mdx | 33 ---- .../vue/button-story-auto-docs.js.mdx | 28 ---- .../vue/button-story-auto-docs.ts-4-9.mdx | 33 ---- .../vue/button-story-auto-docs.ts.mdx | 33 ---- .../button-story-auto-docs.js.mdx | 26 --- .../button-story-auto-docs.ts.mdx | 31 ---- docs/toc.js | 5 - docs/writing-docs/autodocs.md | 100 +++++++++--- docs/writing-stories/tags.md | 152 +++++++++++++----- 23 files changed, 185 insertions(+), 585 deletions(-) delete mode 100644 docs/api/main-config-tags.md delete mode 100644 docs/snippets/angular/button-story-auto-docs.ts.mdx delete mode 100644 docs/snippets/react/button-story-auto-docs.js.mdx delete mode 100644 docs/snippets/react/button-story-auto-docs.ts-4-9.mdx delete mode 100644 docs/snippets/react/button-story-auto-docs.ts.mdx delete mode 100644 docs/snippets/solid/button-story-auto-docs.js.mdx delete mode 100644 docs/snippets/solid/button-story-auto-docs.ts-4-9.mdx delete mode 100644 docs/snippets/solid/button-story-auto-docs.ts.mdx delete mode 100644 docs/snippets/svelte/button-story-auto-docs.js.mdx delete mode 100644 docs/snippets/svelte/button-story-auto-docs.ts-4-9.mdx delete mode 100644 docs/snippets/svelte/button-story-auto-docs.ts.mdx delete mode 100644 docs/snippets/vue/button-story-auto-docs.js.mdx delete mode 100644 docs/snippets/vue/button-story-auto-docs.ts-4-9.mdx delete mode 100644 docs/snippets/vue/button-story-auto-docs.ts.mdx delete mode 100644 docs/snippets/web-components/button-story-auto-docs.js.mdx delete mode 100644 docs/snippets/web-components/button-story-auto-docs.ts.mdx diff --git a/docs/api/cli-options.md b/docs/api/cli-options.md index 39b366429daf..58aef51a3787 100644 --- a/docs/api/cli-options.md +++ b/docs/api/cli-options.md @@ -50,8 +50,6 @@ Options include: | `--stats-json` | Write stats JSON to disk
`storybook dev ---stats-json /tmp/stats`
NOTE: only works for webpack. | | `--docs` | Starts Storybook in documentation mode. Learn more about it in [here](../writing-docs/build-documentation.md#preview-storybooks-documentation)
`storybook dev --docs` | | `--disable-telemetry` | Disables Storybook's telemetry. Learn more about it [here](../configure/telemetry.md)
`storybook dev --disable-telemetry` | -| `--tags` | Select which [story tags](../writing-stories/tags.md) to include. Accepts a comma-seperated string.
`storybook dev --tags "dev,test"` | -| `--exclude-tags` | Select which [story tags](../writing-stories/tags.md) to exclude. Accepts a comma-seperated string.
`storybook dev --tags "docs, test"` | @@ -82,8 +80,6 @@ Options include: | `--docs` | Builds Storybook in documentation mode. Learn more about it in [here](../writing-docs/build-documentation.md#publish-storybooks-documentation)
`storybook build --docs` | | `--disable-telemetry` | Disables Storybook's telemetry. Learn more about it [here](../configure/telemetry.md).
`storybook build --disable-telemetry` | | `--test` | Optimize Storybook's production build for performance and tests by removing unnecessary features with the `test` option. Learn more [here](../api/main-config-build.md).
`storybook build --test` | -| `--tags` | Select which [story tags](../writing-stories/tags.md) to include. Accepts a comma-seperated string.
`storybook dev --tags "dev,test"` | -| `--exclude-tags` | Select which [story tags](../writing-stories/tags.md) to exclude. Accepts a comma-seperated string.
`storybook dev --tags "docs, test"` | diff --git a/docs/api/main-config-tags.md b/docs/api/main-config-tags.md deleted file mode 100644 index cb593d36afb5..000000000000 --- a/docs/api/main-config-tags.md +++ /dev/null @@ -1,40 +0,0 @@ ---- -title: 'tags' -hideRendererSelector: true ---- - -Parent: [main.js|ts configuration](./main-config.md) - -Type: `{ [key: string]: { description?: string } }` - -[Tags](../writing-stories/tags.md) allow you to control which stories are included in your Storybook. They are defined in the `tags` property of the Storybook configuration. Then they can be [applied to stories](../writing-stories/tags.md#tagging-stories) at the project, component, and story levels using the `tags` array. - -## Default tags - -The following tags are available by default in your project: - -```js -{ - dev: { description: 'Rendered in the Storybook UI, but only in development mode. They do not appear in the sidebar in production mode.' }, - docs: { description: 'Rendered in the Storybook UI, but only in the docs page. They do not appear in the sidebar.' }, - test: { description: 'Not rendered in the Storybook UI, in either development or production mode.' }, -} -``` - -## Custom tags - -You can [define your own tags](../writing-stories/tags.md#custom-tags). When doing so, the key is the tag name, and the value is an object with an optional `description` property. - -```ts -// .storybook/main.ts -import { StorybookConfig } from '@storybook/'; - -const config: StorybookConfig = { - // ...rest of config - tags: { - experimental: { description: 'Stories for experimental components or features' }, - }, -}; - -export default config; -``` diff --git a/docs/api/main-config.md b/docs/api/main-config.md index e347bc355b5f..a9013268e45c 100644 --- a/docs/api/main-config.md +++ b/docs/api/main-config.md @@ -44,7 +44,6 @@ An object to configure Storybook containing the following properties: - [`refs`](./main-config-refs.md) - [`staticDirs`](./main-config-static-dirs.md) - [`swc`](./main-config-swc.md) -- [`tags`](./main-config-tags.md) - [`typescript`](./main-config-typescript.md) - [`viteFinal`](./main-config-vite-final.md) - [`webpackFinal`](./main-config-webpack-final.md) diff --git a/docs/snippets/angular/button-story-auto-docs.ts.mdx b/docs/snippets/angular/button-story-auto-docs.ts.mdx deleted file mode 100644 index d0b433899e96..000000000000 --- a/docs/snippets/angular/button-story-auto-docs.ts.mdx +++ /dev/null @@ -1,33 +0,0 @@ -```ts -// Button.stories.ts - -import type { Meta, StoryObj } from '@storybook/angular'; - -import { Button } from './button.component'; - -const meta: Meta