`,
diff --git a/docs/_snippets/list-story-unchecked.md b/docs/_snippets/list-story-unchecked.md
index de9f24fed7ad..fa1e77b3f2b6 100644
--- a/docs/_snippets/list-story-unchecked.md
+++ b/docs/_snippets/list-story-unchecked.md
@@ -198,7 +198,7 @@ export const OneItem = {
//👇 The args will now be passed down to the template
return { args };
},
- template: '',
+ template: '',
}),
};
```
@@ -231,7 +231,7 @@ export const OneItem: Story = {
//👇 The args will now be passed down to the template
return { args };
},
- template: '',
+ template: '',
}),
args: {
...Unchecked.args,
@@ -264,7 +264,7 @@ export const OneItem = meta.story({
//👇 The args will now be passed down to the template
return { args };
},
- template: '',
+ template: '',
}),
args: {
...Unchecked.input.args,
@@ -299,7 +299,7 @@ export const OneItem = meta.story({
//👇 The args will now be passed down to the template
return { args };
},
- template: '',
+ template: '',
}),
args: {
...Unchecked.input.args,
diff --git a/docs/_snippets/my-component-story-basic-and-props.md b/docs/_snippets/my-component-story-basic-and-props.md
index 38294f8af1c4..06d09ceee5c9 100644
--- a/docs/_snippets/my-component-story-basic-and-props.md
+++ b/docs/_snippets/my-component-story-basic-and-props.md
@@ -251,7 +251,7 @@ export const Basic = {
export const WithProp = {
render: () => ({
components: { MyComponent },
- template: '',
+ template: '',
}),
};
```
@@ -278,7 +278,7 @@ export const Basic: Story = {
export const WithProp: Story = {
render: () => ({
components: { MyComponent },
- template: '',
+ template: '',
}),
};
```
@@ -302,7 +302,7 @@ export const Basic = meta.story({
export const WithProp = meta.story({
render: () => ({
components: { MyComponent },
- template: '',
+ template: '',
}),
});
```
@@ -326,7 +326,7 @@ export const Basic = meta.story({
export const WithProp = meta.story({
render: () => ({
components: { MyComponent },
- template: '',
+ template: '',
}),
});
```
diff --git a/docs/addons/addon-knowledge-base.mdx b/docs/addons/addon-knowledge-base.mdx
index 5dd7c2387d6e..fbe8767c0c84 100644
--- a/docs/addons/addon-knowledge-base.mdx
+++ b/docs/addons/addon-knowledge-base.mdx
@@ -13,20 +13,12 @@ It’s possible to disable the addon panel for a particular story.
To make that possible, you need to pass the `paramKey` element when you register the panel:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Then when adding a story, you can pass a disabled parameter.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Style your addon
Storybook uses [Emotion](https://emotion.sh/docs/introduction) for styling. Alongside with a theme that you can customize!
@@ -38,41 +30,41 @@ If you don’t want to use Emotion, you can use inline styles or another css-in-
Addon authors can develop their UIs using any React library. But we recommend using Storybook’s UI components in `storybook/internal/components` to build addons faster. When you use Storybook components, you get:
-* Battle-tested off-the-shelf components
-* Storybook native look and feel
-* Built-in support for Storybook theming
+- Battle-tested off-the-shelf components
+- Storybook native look and feel
+- Built-in support for Storybook theming
Use the components listed below with your next addon.
-| Component | Source | Story |
-| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
-| Action Bar | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/ActionBar/ActionBar.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-actionbar--single-item) |
-| Addon Panel | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/addon-panel/addon-panel.tsx) | N/A |
-| Badge | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/Badge/Badge.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-badge--all-badges) |
-| Button | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/Button/Button.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-button--all-buttons) |
-| Form | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/form/index.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-form-button--sizes) |
-| Loader | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/Loader/Loader.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-loader--progress-bar) |
-| PlaceHolder | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/placeholder/placeholder.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-placeholder--single-child) |
-| Scroll Area | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/ScrollArea/ScrollArea.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-scrollarea--vertical) |
-| Space | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/spaced/Spaced.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-spaced--row) |
-| Syntax Highlighter | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/syntaxhighlighter/syntaxhighlighter.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-syntaxhighlighter--bash) |
-| Tabs | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/tabs/tabs.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-tabs--stateful-static) |
-| ToolBar | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/bar/bar.tsx) | N/A |
-| ToolTip | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/tooltip/Tooltip.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-tooltip-tooltip--basic-default) |
-| Zoom | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/Zoom/Zoom.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-zoom--element-actual-size) |
+| Component | Source | Story |
+| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
+| Action Bar | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/ActionBar/ActionBar.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-actionbar--single-item) |
+| Addon Panel | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/addon-panel/addon-panel.tsx) | N/A |
+| Badge | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/Badge/Badge.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-badge--all-badges) |
+| Button | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/Button/Button.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-button--all-buttons) |
+| Form | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/form/index.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-form-button--sizes) |
+| Loader | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/Loader/Loader.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-loader--progress-bar) |
+| PlaceHolder | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/placeholder/placeholder.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-placeholder--single-child) |
+| Scroll Area | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/ScrollArea/ScrollArea.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-scrollarea--vertical) |
+| Space | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/spaced/Spaced.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-spaced--row) |
+| Syntax Highlighter | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/syntaxhighlighter/syntaxhighlighter.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-syntaxhighlighter--bash) |
+| Tabs | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/tabs/tabs.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-tabs--stateful-static) |
+| ToolBar | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/bar/bar.tsx) | N/A |
+| ToolTip | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/tooltip/Tooltip.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-tooltip-tooltip--basic-default) |
+| Zoom | [See component implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/Zoom/Zoom.tsx) | [See component story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-zoom--element-actual-size) |
Complementing the components, also included is a set of UI primitives. Use the content listed below as a reference for styling your addon.
-| Component | Source | Story |
-| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------| -------------------------------------------------------------------------------------------------------- |
-| Color Palette (see note below) | [See implementation](https://github.com/storybookjs/storybook/blob/next/code/addons/docs/src/blocks/components/ColorPalette.tsx) | [See story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-colorpalette--page) |
-| Icon | [See implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/icon/icon.tsx) | [See story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-icon--labels) |
-| Typography | [See implementation](https://github.com/storybookjs/storybook/tree/next/code/core/src/components/components/typography) | [See story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-typography--all) |
+| Component | Source | Story |
+| ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
+| Color Palette (see note below) | [See implementation](https://github.com/storybookjs/storybook/blob/next/code/addons/docs/src/blocks/components/ColorPalette.tsx) | [See story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-colorpalette--page) |
+| Icon | [See implementation](https://github.com/storybookjs/storybook/blob/next/code/core/src/components/components/icon/icon.tsx) | [See story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-icon--labels) |
+| Typography | [See implementation](https://github.com/storybookjs/storybook/tree/next/code/core/src/components/components/typography) | [See story](https://main--5a375b97f4b14f0020b0cda3.chromatic.com/?path=/story/basics-typography--all) |
- The color palette implemented by `@storybook/addon-docs/blocks` is a high-level abstraction of the [`storybook/theming`](https://github.com/storybookjs/storybook/tree/next/code/core/src/theming) module.
-
+The color palette implemented by `@storybook/addon-docs/blocks` is a high-level abstraction of the [`storybook/theming`](https://github.com/storybookjs/storybook/tree/next/code/core/src/theming) module.
+
## Build system
@@ -88,7 +80,9 @@ When you're developing your addon as a package, you can’t use `npm link` to ad
```
- Run either `yarn` or `npm install` to install the addon.
+
+Run either `yarn` or `npm install` to install the addon.
+
## Hot module replacement
@@ -115,10 +109,6 @@ If you're developing a local Storybook addon built on top of an existing Storybo
If you're working on a preset that loads third-party addons, which you don't have control over, and you need access to certain features (e.g., decorators) or provide additional configurations. In that case, you'll need to update your preset to the following to allow you to load and configure the other addons:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
If you have control over the addons you want to customize. In that case, you can update your preset and implement a custom function to load any additional presets and provide the necessary configuration.
diff --git a/docs/addons/addon-migration-guide.mdx b/docs/addons/addon-migration-guide.mdx
index ca15e5876ca3..a6abb969960f 100644
--- a/docs/addons/addon-migration-guide.mdx
+++ b/docs/addons/addon-migration-guide.mdx
@@ -8,7 +8,9 @@ sidebar:
We sincerely appreciate the dedication and effort addon creators put into keeping the Storybook ecosystem vibrant and up-to-date. As Storybook evolves to version 10.0, bringing new features and improvements, this guide is here to assist you in migrating your addons from 9.x to 10.0. If you need to migrate your addon from an earlier version of Storybook, please first refer to the [Addon migration guide for Storybook 9.0](../../../release-9-1/docs/addons/addon-migration-guide.mdx).
- We also have a general [Storybook migration guide](../releases/migration-guide.mdx) that covers updates to your Storybook instance rather than your addon code.
+
+We also have a general [Storybook migration guide](../releases/migration-guide.mdx) that covers updates to your Storybook instance rather than your addon code.
+
## Dependency updates
@@ -20,11 +22,11 @@ You will need to update your Storybook dependencies. Peer dependencies must poin
"devDependencies": {
"@storybook/addon-docs": "next",
"@storybook/react-vite": "next",
- "storybook": "next"
+ "storybook": "next",
},
"peerDependencies": {
- "storybook": "^10.0.0"
- }
+ "storybook": "^10.0.0",
+ },
}
```
@@ -38,15 +40,16 @@ If your addon supports multiple major versions of Storybook, you can specify a w
{
"name": "your-storybook-addon",
"peerDependencies": {
- "storybook": "^9.0.0 || ^10.0.0"
+ "storybook": "^9.0.0 || ^10.0.0",
},
"devDependencies": {
- "storybook": ">=10.0.0-0 <11.0.0-0" // For local development
- }
+ "storybook": ">=10.0.0-0 <11.0.0-0", // For local development
+ },
}
```
However, we recommend releasing a new major version of your addon alongside new major versions of Storybook. This practice:
+
1. Makes it easier to maintain your code
2. Allows you to take advantage of new features and improvements
3. Provides a clearer upgrade path for your users
@@ -60,11 +63,12 @@ Here are the changes in version 10.0 that impact addon development.
Storybook 10 requires all addons to be built as ESM-only. This change simplifies the build process and reduces maintenance overhead. You'll need to make many changes to `tsup.config.ts`, so it can be easier to copy the reference file in the [`addon-kit` repository](https://github.com/storybookjs/addon-kit/blob/main/tsup.config.ts).
This update brings the following changes:
-* The Node target moves from Node 20.0 to Node 20.19
-* You no longer need to build CJS files
-* You no longer need to pass `globalManagerPackages` and `globalPreviewPackages`
-* The `bundler` config in `package.json` no longer needs to be manually typed
-* We recommend you stop using `exportEntries` and switch exported entries to `previewEntries` and `managerEntries` instead based on where they are consumed by your users
+
+- The Node target moves from Node 20.0 to Node 20.19
+- You no longer need to build CJS files
+- You no longer need to pass `globalManagerPackages` and `globalPreviewPackages`
+- The `bundler` config in `package.json` no longer needs to be manually typed
+- We recommend you stop using `exportEntries` and switch exported entries to `previewEntries` and `managerEntries` instead based on where they are consumed by your users
```diff title="tsup.config.ts"
- import { readFile } from "node:fs/promises";
@@ -259,21 +263,20 @@ Finally, change the `preset.js` file at the top-level of your addon to be ESM. T
Because addons are now ESM-only, you must change how you load your own addon in your development Storybook instance. Imports and exports must now follow ESM syntax, and relative paths must use `import.meta.resolve`.
-
Remove `.storybook/local-preset.cjs` and create `.storybook/local-preset.ts` with the following content:
```ts title=".storybook/local-preset.ts"
-import { fileURLToPath } from "node:url";
+import { fileURLToPath } from 'node:url';
export function previewAnnotations(entry = []) {
- return [...entry, fileURLToPath(import.meta.resolve("../dist/preview.js"))];
+ return [...entry, fileURLToPath(import.meta.resolve('../dist/preview.js'))];
}
export function managerEntries(entry = []) {
- return [...entry, fileURLToPath(import.meta.resolve("../dist/manager.js"))];
+ return [...entry, fileURLToPath(import.meta.resolve('../dist/manager.js'))];
}
-export * from "../dist/preset.js";
+export * from '../dist/preset.js';
```
Next, update your `main.ts` to reference the new preset file:
@@ -288,6 +291,7 @@ Next, update your `main.ts` to reference the new preset file:
The following changes are not strictly required yet, but we recommend making them to improve your users' experience.
### CSF Factories support
+
To support CSF Factories annotations in your addon, you will need to update your `src/index.ts` file to use the new `definePreviewAddon`. This feature will be part of [CSF Next](../api/csf/csf-next.mdx). This change is highly recommended, as it will help your own users reap the benefits of CSF Factories.
With CSF Factories, users can chain their preview configuration and benefit from better typing and more flexibility. Addons must export annotations to be compatible with this new syntax. CSF Factories will be the default way to write stories in Storybook 11.
diff --git a/docs/addons/addon-types.mdx b/docs/addons/addon-types.mdx
index f8d5b48f3a3e..b81d6864b7d6 100644
--- a/docs/addons/addon-types.mdx
+++ b/docs/addons/addon-types.mdx
@@ -1,8 +1,7 @@
---
-title: 'Types of addons'
+title: Types of addons
sidebar:
order: 6
- title: Types of addons
---
Each Storybook addon is classified into two general categories, UI-based or Presets. Each type of addons feature is documented here. Use this as a reference when creating your addon.
@@ -19,12 +18,8 @@ Panel addons allow you to add your own UI in Storybook's addon panel. This is th
Use this boilerplate code to add a new `Panel` to Storybook's UI:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Toolbars
Toolbar addons allow you to add your own custom tools in Storybook's Toolbar. For example, the official [`@storybook/addon-themes`](https://storybook.js.org/addons/@storybook/addon-themes) uses this pattern.
@@ -33,14 +28,12 @@ Toolbar addons allow you to add your own custom tools in Storybook's Toolbar. Fo
Use this boilerplate code to add a new `button` to Storybook's Toolbar:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- The `match` property allows you to conditionally render your toolbar addon, [based on the current view](./writing-addons.mdx#conditionally-render-the-addon). The `icon` element used in the example loads the icons from the `storybook/internal/components` module. See [here](../faq.mdx#what-icons-are-available-for-my-toolbar-or-my-addon) for the list of available icons that you can use.
+
+The `match` property allows you to conditionally render your toolbar addon, [based on the current view](./writing-addons.mdx#conditionally-render-the-addon). The `icon` element used in the example loads the icons from the `storybook/internal/components` module. See [here](../faq.mdx#what-icons-are-available-for-my-toolbar-or-my-addon) for the list of available icons that you can use.
+
### Tabs
@@ -51,14 +44,12 @@ Tab addons allow you to create your own custom tabs in Storybook.
Use this boilerplate code to add a new `Tab` to Storybook's UI:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- Learn how to write your own addon that includes these UI elements [here](./writing-addons.mdx).
+
+Learn how to write your own addon that includes these UI elements [here](./writing-addons.mdx).
+
## Preset addons
@@ -67,16 +58,12 @@ Storybook preset addons are grouped collections of `babel`, `webpack`, and `addo
Use this boilerplate code while writing your own preset addon.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
**Learn more about the Storybook addon ecosystem**
-* Types of addons for other types of addons
-* [Writing addons](./writing-addons.mdx) for the basics of addon development
-* [Presets](./writing-presets.mdx) for preset development
-* [Integration catalog](./integration-catalog.mdx) for requirements and available recipes
-* [API reference](./addons-api.mdx) to learn about the available APIs
+- Types of addons for other types of addons
+- [Writing addons](./writing-addons.mdx) for the basics of addon development
+- [Presets](./writing-presets.mdx) for preset development
+- [Integration catalog](./integration-catalog.mdx) for requirements and available recipes
+- [API reference](./addons-api.mdx) to learn about the available APIs
diff --git a/docs/addons/addons-api.mdx b/docs/addons/addons-api.mdx
index d2b518e44adb..454123eea161 100644
--- a/docs/addons/addons-api.mdx
+++ b/docs/addons/addons-api.mdx
@@ -1,8 +1,7 @@
---
-title: 'Addon API'
+title: Addon API
sidebar:
order: 8
- title: Addon API
---
Storybook's API allows developers to interact programmatically with Storybook. With the API, developers can build and deploy custom addons and other tools that enhance Storybook's functionality.
@@ -11,43 +10,33 @@ Storybook's API allows developers to interact programmatically with Storybook. W
Our API is exposed via two distinct packages, each one with a different purpose:
-* `storybook/manager-api` used to interact with the Storybook manager UI or access the Storybook API.
-* `storybook/preview-api` used to control and configure the addon's behavior.
-
-{/* prettier-ignore-start */}
+- `storybook/manager-api` used to interact with the Storybook manager UI or access the Storybook API.
+- `storybook/preview-api` used to control and configure the addon's behavior.
-{/* prettier-ignore-end */}
-
### addons.add()
The `add` method allows you to register the type of UI component associated with the addon (e.g., panels, toolbars, tabs). For a minimum viable Storybook addon, you should provide the following arguments:
-* `type`: The type of UI component to register.
-* `title`: The title to feature in the Addon Panel.
-* `render`: The function that renders the addon's UI component.
-
-{/* prettier-ignore-start */}
+- `type`: The type of UI component to register.
+- `title`: The title to feature in the Addon Panel.
+- `render`: The function that renders the addon's UI component.
-{/* prettier-ignore-end */}
-
- The render function is called with `active`. The `active` value will be true when the panel is focused on the UI.
+
+The render function is called with `active`. The `active` value will be true when the panel is focused on the UI.
+
### addons.register()
Serves as the entry point for all addons. It allows you to register an addon and access the Storybook [API](#storybook-api). For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Now you'll get an instance to our StorybookAPI. See the [api docs](#storybook-api) for Storybook API regarding using that.
### addons.getChannel()
@@ -56,34 +45,28 @@ Get an instance to the channel to communicate with the manager and the preview.
It has a NodeJS [EventEmitter](https://nodejs.org/api/events.html) compatible API. So, you can use it to emit events and listen to events.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### makeDecorator
Use the `makeDecorator` API to create decorators in the style of the official addons. Like so:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- If the story's parameters include `{ exampleParameter: { disable: true } }` (where `exampleParameter` is the `parameterName` of your addon), your decorator will not be called.
+
+If the story's parameters include `{ exampleParameter: { disable: true } }` (where `exampleParameter` is the `parameterName` of your addon), your decorator will not be called.
+
The `makeDecorator` API requires the following arguments:
-* `name`: Unique name to identify the custom addon decorator.
-* `parameterName`: Sets a unique parameter to be consumed by the addon.
-* `skipIfNoParametersOrOptions`: (Optional) Doesn't run the decorator if the user hasn't options either via [decorators](../writing-stories/decorators.mdx) or [parameters](../writing-stories/parameters.mdx).
-* `wrapper`: your decorator function. Takes the `getStory`, `context`, and both the `options` and `parameters` (as defined in `skipIfNoParametersOrOptions` above).
+- `name`: Unique name to identify the custom addon decorator.
+- `parameterName`: Sets a unique parameter to be consumed by the addon.
+- `skipIfNoParametersOrOptions`: (Optional) Doesn't run the decorator if the user hasn't options either via [decorators](../writing-stories/decorators.mdx) or [parameters](../writing-stories/parameters.mdx).
+- `wrapper`: your decorator function. Takes the `getStory`, `context`, and both the `options` and `parameters` (as defined in `skipIfNoParametersOrOptions` above).
-***
+---
## Storybook API
@@ -93,68 +76,40 @@ Storybook's API allows you to access different functionalities of Storybook UI.
The `selectStory` API method allows you to select a single story. It accepts the following two parameters; story kind name and an optional story name. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
This is how you can select the above story:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### api.selectInCurrentKind()
Similar to the `selectStory` API method, but it only accepts the story as the only parameter.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### api.setQueryParams()
This method allows you to set query string parameters. You can use that as temporary storage for addons. Here's how you define query params:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Additionally, if you need to remove a query parameter, set it as `null` instead of removing them from the addon. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### api.getQueryParam()
Allows retrieval of a query parameter enabled via the `setQueryParams` API method. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### api.getUrlState(overrideParams)
This method allows you to get the application URL state, including any overridden or custom parameter values. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### api.getStoryHrefs(storyId, options?)
Get the manager and preview URLs for a story. URLs are relative to the current Storybook, unless `base` is set, or in case of previewHref with `refId` set.
@@ -168,22 +123,14 @@ Get the manager and preview URLs for a story. URLs are relative to the current S
- `refId`: ID of the ref to get the URL for (for composed Storybooks)
- `viewMode`: The view mode to use, defaults to 'story'.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### api.on(eventName, fn)
This method allows you to register a handler function called whenever the user navigates between stories.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### api.openInEditor(payload)
Opens a file in the configured code editor. Useful for "Edit in IDE" functionality in addons.
@@ -194,77 +141,53 @@ Opens a file in the configured code editor. Useful for "Edit in IDE" functionali
Returns a Promise that resolves with information about whether the operation was successful.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### api.getCurrentStoryData()
Returns the current story's data, including its ID, kind, name, and parameters.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### api.toggleFullscreen(toggled?)
Toggles the fullscreen mode of the Storybook UI. Pass `true` to enable fullscreen, `false` to disable, or omit to toggle the current state.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### api.togglePanel(toggled?)
Toggles the visibility of the addon panel. Pass `true` to show the panel, `false` to hide, or omit to toggle the current state.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### api.addNotification(notification)
Displays a notification in the Storybook UI. The notification object should contain `id`, `content`, and optionally `duration` and `icon`.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### addons.setConfig(config)
This method allows you to override the default Storybook UI configuration (e.g., set up a [theme](../configure/user-interface/theming.mdx) or hide UI elements):
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
The following table details how to use the API values:
-| Name | Type | Description | Example Value |
-| --------------------- | --------------- | ------------------------------------------------------- | ------------------------------------- |
-| **navSize** | Number (pixels) | The size of the sidebar that shows a list of stories | `300` |
-| **bottomPanelHeight** | Number (pixels) | The size of the addon panel when in the bottom position | `200` |
-| **rightPanelWidth** | Number (pixels) | The size of the addon panel when in the right position | `200` |
-| **panelPosition** | String | Where to show the addon panel | `'bottom'` or `'right'` |
-| **enableShortcuts** | Boolean | Enable/disable shortcuts | `true` |
-| **showToolbar** | Boolean | Show/hide toolbar | `true` |
-| **theme** | Object | Storybook Theme, see next section | `undefined` |
-| **selectedPanel** | String | Id to select an addon panel | `storybook/actions/panel` |
-| **initialActive** | String | Select the default active tab on Mobile | `sidebar` or `canvas` or `addons` |
-| **sidebar** | Object | Sidebar options, see below | `{ showRoots: false }` |
-| **toolbar** | Object | Modify the tools in the toolbar using the addon id | `{ fullscreen: { hidden: false } }` |
+| Name | Type | Description | Example Value |
+| --------------------- | --------------- | ------------------------------------------------------- | ----------------------------------- |
+| **navSize** | Number (pixels) | The size of the sidebar that shows a list of stories | `300` |
+| **bottomPanelHeight** | Number (pixels) | The size of the addon panel when in the bottom position | `200` |
+| **rightPanelWidth** | Number (pixels) | The size of the addon panel when in the right position | `200` |
+| **panelPosition** | String | Where to show the addon panel | `'bottom'` or `'right'` |
+| **enableShortcuts** | Boolean | Enable/disable shortcuts | `true` |
+| **showToolbar** | Boolean | Show/hide toolbar | `true` |
+| **theme** | Object | Storybook Theme, see next section | `undefined` |
+| **selectedPanel** | String | Id to select an addon panel | `storybook/actions/panel` |
+| **initialActive** | String | Select the default active tab on Mobile | `sidebar` or `canvas` or `addons` |
+| **sidebar** | Object | Sidebar options, see below | `{ showRoots: false }` |
+| **toolbar** | Object | Modify the tools in the toolbar using the addon id | `{ fullscreen: { hidden: false } }` |
The following options are configurable under the `sidebar` namespace:
@@ -276,11 +199,11 @@ The following options are configurable under the `sidebar` namespace:
The following options are configurable under the `toolbar` namespace:
-| Name | Type | Description | Example Value |
-| --------- | ------ | -------------------------------------------------------------------- | ------------------- |
-| **[id]** | String | Toggle visibility for a specific toolbar item (e.g. `title`, `zoom`) | `{ hidden: false }` |
+| Name | Type | Description | Example Value |
+| -------- | ------ | -------------------------------------------------------------------- | ------------------- |
+| **[id]** | String | Toggle visibility for a specific toolbar item (e.g. `title`, `zoom`) | `{ hidden: false }` |
-***
+---
## Storybook hooks
@@ -290,78 +213,50 @@ To help streamline addon development and reduce boilerplate code, the API expose
It allows access to Storybook's internal state. Similar to the [`useglobals`](#useglobals) hook, we recommend optimizing your addon to rely on [`React.memo`](https://react.dev/reference/react/memo), or the following hooks; [`useMemo`](https://react.dev/reference/react/useMemo), [`useCallback`](https://react.dev/reference/react/useCallback) to prevent a high volume of re-render cycles.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### useStorybookApi
The `useStorybookApi` hook is a convenient helper to allow you full access to the [Storybook API](#storybook-api) methods.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### useChannel
Allows setting subscriptions to events and getting the emitter to emit custom events to the channel.
The messages can be listened to on both the iframe and the manager.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### useAddonState
The `useAddonState` is a useful hook for addons that require data persistence, either due to Storybook's UI lifecycle or for more complex addons involving multiple types (e.g., toolbars, panels).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### useParameter
The `useParameter` retrieves the current story's parameters. If the parameter's value is not defined, it will automatically default to the second value defined.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### useGlobals
Extremely useful hook for addons that rely on Storybook [Globals](../essentials/toolbars-and-globals.mdx). It allows you to obtain and update `global` values. We also recommend optimizing your addon to rely on [`React.memo`](https://react.dev/reference/react/memo), or the following hooks; [`useMemo`](https://react.dev/reference/react/useMemo), [`useCallback`](https://react.dev/reference/react/useCallback) to prevent a high volume of re-render cycles.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### useArgs
Hook that allows you to retrieve or update a story's [`args`](../writing-stories/args.mdx).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
**Learn more about the Storybook addon ecosystem**
-* [Types of addons](./addon-types.mdx) for other types of addons
-* [Writing addons](./writing-addons.mdx) for the basics of addon development
-* [Presets](./writing-presets.mdx) for preset development
-* [Integration catalog](./integration-catalog.mdx) for requirements and available recipes
-* API reference to learn about the available APIs
+- [Types of addons](./addon-types.mdx) for other types of addons
+- [Writing addons](./writing-addons.mdx) for the basics of addon development
+- [Presets](./writing-presets.mdx) for preset development
+- [Integration catalog](./integration-catalog.mdx) for requirements and available recipes
+- API reference to learn about the available APIs
diff --git a/docs/addons/configure-addons.mdx b/docs/addons/configure-addons.mdx
index 72e4d73d5c1f..af651eee284b 100644
--- a/docs/addons/configure-addons.mdx
+++ b/docs/addons/configure-addons.mdx
@@ -1,5 +1,5 @@
---
-title: 'Configure and communicate with an addon'
+title: Configure and communicate with an addon
sidebar:
order: 3
title: Configure addons
@@ -11,7 +11,7 @@ The addon API is designed for customization. It offers addon authors different w
Presets offload the burden of configuration from the user to the addon. Preset options are global and are accessible from NodeJS. They're ideal for pre-configuring Webpack loaders, Babel plugins, and other library or framework-specific configurations.
-For example, many libraries require that the app be wrapped by a `Provider` which *provides* data to components down the tree. Presets can describe behavior like adding wrappers automatically, without users having to do any manual configuration. If a user installs an addon that has Presets, the addon can instruct Storybook to wrap all stories in `Provider`. This allows folks to start using your library with Storybook, with just 1 line of config!
+For example, many libraries require that the app be wrapped by a `Provider` which _provides_ data to components down the tree. Presets can describe behavior like adding wrappers automatically, without users having to do any manual configuration. If a user installs an addon that has Presets, the addon can instruct Storybook to wrap all stories in `Provider`. This allows folks to start using your library with Storybook with a single line of config.
For more on presets, see: [Write a preset addon](./writing-presets.mdx)
diff --git a/docs/addons/index.mdx b/docs/addons/index.mdx
index f164e16f0746..f92656eb489a 100644
--- a/docs/addons/index.mdx
+++ b/docs/addons/index.mdx
@@ -1,5 +1,5 @@
---
-title: 'Introduction to addons'
+title: Introduction to addons
hideRendererSelector: true
sidebar:
order: 9
@@ -17,10 +17,10 @@ Before writing your first [addon](https://storybook.js.org/addons), let’s take
The **Manager** is the UI responsible for rendering the:
-* 🔍 Search
-* 🧭 Navigation
-* 🔗 Toolbars
-* 📦 Addons
+- 🔍 Search
+- 🧭 Navigation
+- 🔗 Toolbars
+- 📦 Addons
The **Preview** area is an `iframe` where your stories are rendered.
diff --git a/docs/addons/install-addons.mdx b/docs/addons/install-addons.mdx
index c4e8f66defcf..2abbc89fdf28 100644
--- a/docs/addons/install-addons.mdx
+++ b/docs/addons/install-addons.mdx
@@ -1,5 +1,5 @@
---
-title: 'Install addons'
+title: Install addons
sidebar:
order: 1
title: Install
@@ -13,14 +13,12 @@ Storybook includes a [`storybook add`](../api/cli-options.mdx#add) command to au
Run the `storybook add` command using your chosen package manager, and the CLI will update your Storybook configuration to include the addon and install any necessary dependencies.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- If you're attempting to install multiple addons at once, it will only install the first addon that was specified. This is a known limitation of the current implementation and will be addressed in a future release.
+
+If you're attempting to install multiple addons at once, it will only install the first addon that was specified. This is a known limitation of the current implementation and will be addressed in a future release.
+
### Manual installation
@@ -29,20 +27,12 @@ Storybook addons are always added through the [`addons`](../api/main-config/main
Run the following command with your package manager of choice to install the addon.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Next, update `.storybook/main.js|ts` to the following:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
When you run Storybook, the accessibility testing addon will be enabled.

@@ -51,8 +41,4 @@ When you run Storybook, the accessibility testing addon will be enabled.
To remove an addon from Storybook, you can choose to manually uninstall it and remove it from the configuration file (i.e., [`.storybook/main.js|ts`](../configure/index.mdx)) or opt-in to do it automatically via the CLI with the [`remove`](../api/cli-options.mdx#remove) command. For example, to remove the [Accessibility addon](https://storybook.js.org/addons/@storybook/addon-a11y) from Storybook with the CLI, run the following command:
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/addons/integration-catalog.mdx b/docs/addons/integration-catalog.mdx
index e92266353666..ba3a172ed2f6 100644
--- a/docs/addons/integration-catalog.mdx
+++ b/docs/addons/integration-catalog.mdx
@@ -1,5 +1,5 @@
---
-title: 'Add to the integration catalog'
+title: Add to the integration catalog
sidebar:
order: 5
title: Add to catalog
@@ -13,13 +13,15 @@ Storybook addons are distributed via npm. The catalog is populated by querying n
Add your addon to the catalog by publishing a npm package that follows these requirements:
-* `package.json` with [module information](./writing-addons.mdx#setup) and [addon metadata](#addon-metadata)
-* `README.md` file with installation and configuration instructions
-* `/dist` directory containing transpiled ES5 code
-* `preset.js` file written as an ES5 module at the root level
+- `package.json` with [module information](./writing-addons.mdx#setup) and [addon metadata](#addon-metadata)
+- `README.md` file with installation and configuration instructions
+- `/dist` directory containing transpiled ES5 code
+- `preset.js` file written as an ES5 module at the root level
- Get a refresher on how to [write a Storybook addon](./writing-addons.mdx).
+
+Get a refresher on how to [write a Storybook addon](./writing-addons.mdx).
+
### Addon metadata
@@ -31,32 +33,34 @@ We rely on metadata to organize your addon in the catalog. You must add the
- Make sure to copy each item **exactly** as listed so that we can properly index your addon in our catalog.
+
+Make sure to copy each item **exactly** as listed so that we can properly index your addon in our catalog.
+
```json title="package.json"
@@ -103,8 +107,8 @@ If you'd like to request a recipe, open a [new discussion](https://github.com/st
**Learn more about the Storybook addon ecosystem**
-* [Types of addons](./addon-types.mdx) for other types of addons
-* [Writing addons](./writing-addons.mdx) for the basics of addon development
-* [Presets](./writing-presets.mdx) for preset development
-* Integration catalog for requirements and available recipes
-* [API reference](./addons-api.mdx) to learn about the available APIs
+- [Types of addons](./addon-types.mdx) for other types of addons
+- [Writing addons](./writing-addons.mdx) for the basics of addon development
+- [Presets](./writing-presets.mdx) for preset development
+- Integration catalog for requirements and available recipes
+- [API reference](./addons-api.mdx) to learn about the available APIs
diff --git a/docs/addons/writing-addons.mdx b/docs/addons/writing-addons.mdx
index 9fe4f23b0e4f..7f0ee73b8d48 100644
--- a/docs/addons/writing-addons.mdx
+++ b/docs/addons/writing-addons.mdx
@@ -1,5 +1,5 @@
---
-title: 'Write an addon'
+title: Write an addon
sidebar:
order: 2
title: Write
@@ -24,14 +24,12 @@ There are two main categories of addons, each with its role:
The addon built in this guide is a UI-based addon, specifically a [toolbar](./addon-types.mdx#toolbars) addon, enabling users to draw outlines around each element in the story through a shortcut or click of a button. UI addons can create other types of UI elements, each with its function: [panels](./addon-types.mdx#panels) and [tabs](./addon-types.mdx#tabs), providing users with various ways to interact with the UI.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
+
Addons with a UI must use the same React version as Storybook. If your component library uses a different React version, you must use addons that are built and published as standalone packages. We'll cover how to do this with the [Addon Kit](https://github.com/storybookjs/addon-kit).
+
## Setup
@@ -42,15 +40,13 @@ To create your first addon, you're going to use the [Addon Kit](https://github.c
Clone the repository you just created and install its dependencies. When the installation process finishes, you will be prompted with questions to configure your addon. Answer them, and when you're ready to start building your addon, run the following command to start Storybook in development mode and develop your addon in watch mode:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- The Addon Kit uses [Typescript](https://www.typescriptlang.org/) by default. If you want to use
- JavaScript instead, you can run the `eject-ts` command to convert the project to JavaScript.
+
+The Addon Kit uses [Typescript](https://www.typescriptlang.org/) by default. If you want to use
+JavaScript instead, you can run the `eject-ts` command to convert the project to JavaScript.
+
### Understanding the build system
@@ -65,12 +61,8 @@ The `tsup` configuration handles these complexities by default, but you can cust
By default, code for the UI-based addons is located in one of the following files, depending on the type of addon built: **`src/Tool.tsx`**, **`src/Panel.tsx`**, or **`src/Tab.tsx`**. Since we're building a toolbar addon, we can safely remove the `Panel` and `Tab` files and update the remaining file to the following:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Going through the code blocks in sequence:
```ts title="src/Tool.tsx"
@@ -125,12 +117,8 @@ The `Tool` component is the entry point of the addon. It renders the UI elements
Moving onto the manager, here we register the addon with Storybook using a unique name and identifier. Since we've removed the `Panel` and `Tab` files, we'll need to adjust the file to only reference the addon we're building.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Conditionally render the addon
Notice the `match` property. It allows you to control the view mode (story or docs) and tab (the story canvas or [custom tabs](./addon-types.mdx#tabs)) where the toolbar addon is visible. For example:
@@ -148,28 +136,16 @@ Run the `start` script to build and start Storybook and verify that the addon is
In Storybook, applying styles for addons is considered a side-effect. Therefore, we'll need to make some changes to our addon to allow it to use the styles when it is active and remove them when it's disabled. We're going to rely on two of Storybook's features to handle this: [decorators](../writing-stories/decorators.mdx) and [globals](../essentials/toolbars-and-globals.mdx#globals). To handle the CSS logic, we must include some helper functions to inject and remove the stylesheets from the DOM. Start by creating the helper file with the following content:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Next, create the file with the styles we want to inject with the following content:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Since the addon can be active in both the story and documentation modes, the DOM node for Storybook's preview `iframe` is different in these two modes. In fact, Storybook renders multiple story previews on one page when in documentation mode. Therefore, we'll need to choose the correct selector for the DOM node where the styles will be injected and ensure the CSS is scoped to that particular selector. That mechanism is provided as an example within the `src/withGlobals.ts` file, which we'll use to connect the styling and helper functions to the addon logic. Update the file to the following:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Packaging and publishing
Storybook addons, similar to most packages in the JavaScript ecosystem, are distributed as NPM packages. However, they have specific criteria that need to be met to be published to NPM and crawled by the integration catalog:
@@ -232,9 +208,11 @@ The second metadata category is related to the [integration catalog](https://sto
```
- The `storybook` configuration element includes additional properties that help customize the
- addon's searchability and indexing. For more information, see the [Integration catalog
- documentation](./integration-catalog.mdx).
+
+The `storybook` configuration element includes additional properties that help customize the
+addon's searchability and indexing. For more information, see the [Integration catalog
+documentation](./integration-catalog.mdx).
+
One essential item to note is the `keywords` property as it maps to the catalog's tag system. Adding the `storybook-addon` keyword ensures that the addon is discoverable in the catalog when searching for addons. The remaining keywords help with the searchability and categorization of the addon.
@@ -261,12 +239,8 @@ npx auto create-labels
Finally, run the following command to create a release for your addon. This will build and package the addon code, bump the version, push the release into GitHub and npm, and generate a changelog.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### CI automation
By default, the Addon Kit comes pre-configured with a GitHub Actions workflow, enabling you to automate the release management process. This ensures that the package is always up to date with the latest changes and that the changelog is updated accordingly. However, you'll need additional configuration to use your NPM and GitHub tokens to publish the package successfully. In your repository, click the **Settings** tab, then the **Secrets and variables** dropdown, followed by the **Actions** item. You should see the following screen:
diff --git a/docs/addons/writing-presets.mdx b/docs/addons/writing-presets.mdx
index 9c9896a0ab7d..2c91b1f74b32 100644
--- a/docs/addons/writing-presets.mdx
+++ b/docs/addons/writing-presets.mdx
@@ -1,5 +1,5 @@
---
-title: 'Write a preset addon'
+title: Write a preset addon
sidebar:
order: 4
title: Write a preset
@@ -15,22 +15,14 @@ Preset addons allow developers to compose various configuration options and plug
This type of preset allows you to encapsulate and organize configurations specific to the addon, including [builder](../builders/index.mdx) support, [Babel](https://babeljs.io/), or third-party integrations. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Root-level presets
This type of preset is user-facing and responsible for registering the addon without any additional configuration from the user by bundling Storybook-related features (e.g., [parameters](../writing-stories/parameters.mdx)) via the [`previewAnnotations`](../api/main-config/main-config-preview-annotations.mdx) and UI related features (e.g., addons) via the `managerEntries` API. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Presets API
When writing a preset, you can access a select set of APIs to interact with the Storybook environment, including the supported builders (e.g., Webpack, Vite), the Storybook configuration, and UI. Below are the available APIs you can use when writing a preset addon.
@@ -39,14 +31,12 @@ When writing a preset, you can access a select set of APIs to interact with the
To customize Storybook's Babel configuration and add support for additional features, you can use the [`babelDefault`](../api/main-config/main-config-babel-default.mdx) API. It will apply the provided configuration ahead of any other user presets, which can be further customized by the end user via the [`babel`](../api/main-config/main-config-babel.mdx) configuration option. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- The Babel configuration is only applied to frameworks that use Babel internally. If you enable it for a framework that uses a different compiler, like [SWC](https://swc.rs/) or [esbuild](https://esbuild.github.io/), it will be ignored.
+
+The Babel configuration is only applied to frameworks that use Babel internally. If you enable it for a framework that uses a different compiler, like [SWC](https://swc.rs/) or [esbuild](https://esbuild.github.io/), it will be ignored.
+
### Builders
@@ -57,62 +47,38 @@ By default, Storybook provides support for the leading industry builders, includ
If you are creating a preset and want to include Vite support, the `viteFinal` API can be used to modify the default configuration and enable additional features. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### Webpack
To customize the Webpack configuration in Storybook to add support for additional file types, apply specific loaders, configure plugins, or make any other necessary modifications, you can use the `webpackFinal` API. Once invoked, it will extend the default Webpack configuration with the provided configuration. An example of this would be:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### ManagerEntries
If you're writing a preset that loads third-party addons, which you may not have control over, but require access to specific features or additional configuration, you can use the `managerEntries` API. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### PreviewAnnotations
If you need additional settings to render stories for a preset, like [decorators](../writing-stories/decorators.mdx) or [parameters](../writing-stories/parameters.mdx), you can use the `previewAnnotations` API. For example, to apply a decorator to all stories, create a preview file that includes the decorator and make it available to the preset as follows:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Advanced configuration
The presets API is designed to be flexible and allow you to customize Storybook to your specific needs, including using presets for more advanced use cases without publishing them. In such cases, you can rely on a private preset. These private presets contain configuration options meant for development purposes and not for end-users. The `.storybook/main.js|ts` file is an example of such a private preset that empowers you to modify the behavior and functionality of Storybook.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Addons
For addon consumers, the [`managerEntries`](#managerentries) API can be too technical, making it difficult to use. To make it easier to add addons to Storybook, the preset API provides the [`addons`](../api/main-config/main-config-addons.mdx) API, which accepts an array of addon names and will automatically load them for you. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
The array of values supports references to additional presets and addons that should be included in the manager. Storybook will automatically detect whether the provided value is a preset or an addon and load it accordingly.
### Entries
@@ -123,20 +89,12 @@ Entries are the place to register entry points for the preview. This feature can
The Storybook preset API also provides access to the UI configuration, including the `head` and `body` HTML elements of the preview, configured by the [`previewHead`](../api/main-config/main-config-preview-head.mdx) and [`previewBody`](../api/main-config/main-config-preview-body.mdx) APIs. Both allow you to set up Storybook in a way that is similar to using the [`preview-head.html`](../configure/story-rendering.mdx#adding-to-head) and [`preview-body.html`](../configure/story-rendering.mdx#adding-to-body) files. These methods accept a string and return a modified version, injecting the provided content into the HTML element.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Additionally, if you need to customize the manager (i.e., where Storybook’s search, navigation, toolbars, and addons render), you can use the [`managerHead`](../api/main-config/main-config-manager-head.mdx) to modify the UI, similar to how you would do it with the `manager-head.html` file. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
However, if you need, you can also customize the template used by Storybook to render the UI. To do so, you can use the `previewMainTemplate` API and provide a reference for a custom template created as a `ejs` file. For an example of how to do this, see the [template](https://github.com/storybookjs/storybook/blob/next/code/builders/builder-webpack5/templates/preview.ejs) used by the Webpack 5 builder.
## Troubleshooting
@@ -147,8 +105,8 @@ As Storybook relies on [esbuild](https://esbuild.github.io/) instead of Webpack
**Learn more about the Storybook addon ecosystem**
-* [Types of addons](./addon-types.mdx) for other types of addons
-* [Writing addons](./writing-addons.mdx) for the basics of addon development
-* Presets for preset development
-* [Integration catalog](./integration-catalog.mdx) for requirements and available recipes
-* [API reference](./addons-api.mdx) to learn about the available APIs
+- [Types of addons](./addon-types.mdx) for other types of addons
+- [Writing addons](./writing-addons.mdx) for the basics of addon development
+- Presets for preset development
+- [Integration catalog](./integration-catalog.mdx) for requirements and available recipes
+- [API reference](./addons-api.mdx) to learn about the available APIs
diff --git a/docs/ai/best-practices.mdx b/docs/ai/best-practices.mdx
index 3143c2d8c303..efa101fa403e 100644
--- a/docs/ai/best-practices.mdx
+++ b/docs/ai/best-practices.mdx
@@ -4,11 +4,13 @@ sidebar:
order: 2
title: Best practices
---
-
+
- The best practices here relate to the [generated manifests](./manifests.mdx), which are currently only supported for [React](?renderer=react) projects.
- Additionally, the API may change in future releases. We welcome feedback and contributions to help improve this feature.
+The best practices here relate to the [generated manifests](./manifests.mdx), which are currently only supported for [React](?renderer=react) projects.
+
+Additionally, the API may change in future releases. We welcome feedback and contributions to help improve this feature.
+
@@ -74,17 +76,20 @@ export interface ButtonProps {
For unattached MDX docs pages (such as documentation for design tokens, guidelines, etc.), you can provide a summary in the `Meta` tag, which will be included in the manifest and provided to the agent.
-```jsx title="Colors.mdx"
+```mdx title="Colors.mdx"
import { Meta } from '@storybook/addon-docs/blocks';
-
+
```
## Docs content
Storybook generates this docs manifest through static analysis of your MDX files, which means it is limited to the information that is explicitly present in those files. For example, the manifest will _not_ include the color tokens in the document below, because their values are not explicitly in the source:
-```jsx title="Colors.mdx"
+```mdx title="Colors.mdx"
import { Meta, ColorPalette, ColorItem } from '@storybook/addon-docs/blocks';
import { colors } from '../src/tokens/colors';
@@ -93,6 +98,7 @@ import { colors } from '../src/tokens/colors';
# Colors
{/* 👇 These colors are *not* included in the manifest, because their values are not explicitly in the source */}
+
{colors.map((color) => (
@@ -116,7 +122,7 @@ You can also remove an entire component from the manifest, by removing the tag i
Similarly, to exclude an entire MDX docs page from the manifests, you can remove the `manifest` tag from the page's metadata:
-```jsx title="DocForHumansOnly.mdx"
+```mdx title="DocForHumansOnly.mdx"
import { Meta } from '@storybook/addon-docs/blocks';
@@ -131,5 +137,3 @@ import { Meta } from '@storybook/addon-docs/blocks';
- [MCP server API](./mcp/api.mdx)
- [Sharing your MCP server](./mcp/sharing.mdx)
- [Manifests](./manifests.mdx)
-
-
diff --git a/docs/ai/index.mdx b/docs/ai/index.mdx
index 809e20ad6533..5e6efb14d5ba 100644
--- a/docs/ai/index.mdx
+++ b/docs/ai/index.mdx
@@ -4,11 +4,13 @@ sidebar:
order: 5
title: AI
---
-
+
- While they are in [preview](../releases/features.mdx#preview), Storybook's AI capabilities (specifically, the [manifests](./manifests.mdx) and [MCP server](./mcp/overview.mdx)) are currently only supported for [React](?renderer=react) projects.
- Additionally, the API may change in future releases. We welcome feedback and contributions to help improve this feature.
+While they are in [preview](../releases/features.mdx#preview), Storybook's AI capabilities (specifically, the [manifests](./manifests.mdx) and [MCP server](./mcp/overview.mdx)) are currently only supported for [React](?renderer=react) projects.
+
+Additionally, the API may change in future releases. We welcome feedback and contributions to help improve this feature.
+
diff --git a/docs/ai/manifests.mdx b/docs/ai/manifests.mdx
index 5ecab4c782f3..5dad6f60c9a9 100644
--- a/docs/ai/manifests.mdx
+++ b/docs/ai/manifests.mdx
@@ -5,9 +5,11 @@ sidebar:
---
- While they are in [preview](../releases/features.mdx#preview), Storybook's AI capabilities (specifically, the manifests and [MCP server](./mcp/overview.mdx)) are currently only supported for [React](?renderer=react) projects.
- Additionally, the API may change in future releases. We welcome feedback and contributions to help improve this feature.
+While they are in [preview](../releases/features.mdx#preview), Storybook's AI capabilities (specifically, the manifests and [MCP server](./mcp/overview.mdx)) are currently only supported for [React](?renderer=react) projects.
+
+Additionally, the API may change in future releases. We welcome feedback and contributions to help improve this feature.
+
@@ -38,11 +40,15 @@ type ButtonProps = {
* Button is used for user interactions that do not navigate to another route.
* For navigation, use [Link](?path=/docs/link--default) instead.
*/
-export const Button: React.FC = ({ onClick }) => { /* ... */ };
+export const Button: React.FC = ({ onClick }) => {
+ //...
+};
```
-
- Check the [best practices](./best-practices.mdx) guide for tips on writing effective JSDoc comments for your components and other ways to provide helpful context for the agents.
+
+
+Check the [best practices](./best-practices.mdx) guide for tips on writing effective JSDoc comments for your components and other ways to provide helpful context for the agents.
+
If a story file declares [`subcomponents`](../writing-stories/stories-for-multiple-components.mdx#subcomponents), the components manifest will also include a `subcomponents` object for that component. This gives agents supplemental API documentation for child components, even when those subcomponents are only meant to be used together with the parent.
@@ -53,7 +59,9 @@ The raw JSON components manifest can be accessed at `http://localhost:6006/manif
Example components manifest entry
- While in [preview](../releases/features.mdx#preview), this manifest schema is not yet stable and should not be considered a public API. We include it here only as an aid for understanding.
+
+While in [preview](../releases/features.mdx#preview), this manifest schema is not yet stable and should not be considered a public API. We include it here only as an aid for understanding.
+
```json
@@ -76,9 +84,7 @@ The raw JSON components manifest can be accessed at `http://localhost:6006/manif
}
],
"import": "import { Button } from \"@mealdrop/ui\";",
- "jsDocTags": {
-
- },
+ "jsDocTags": {},
"description": "Primary UI component for user interaction",
"reactDocgen": {
"description": "Primary UI component for user interaction",
@@ -219,6 +225,7 @@ The raw JSON components manifest can be accessed at `http://localhost:6006/manif
}
}
```
+
## Docs (MDX) manifest
@@ -228,14 +235,18 @@ The docs manifest is generated from the [MDX files](../writing-docs/mdx.mdx) in
The raw JSON docs manifest can be accessed at `http://localhost:6006/manifests/docs.json` (your port may vary) when your Storybook is running or at the `/manifests/docs.json` route in a built Storybook.
- Check the [best practices](./best-practices.mdx) guide for tips on writing effective documentation and providing helpful context for the agents.
+
+Check the [best practices](./best-practices.mdx) guide for tips on writing effective documentation and providing helpful context for the agents.
+
Example docs manifest entry
- While in [preview](../releases/features.mdx#preview), this manifest schema is not yet stable and should not be considered a public API. We include it here only as an aid for understanding.
+
+While in [preview](../releases/features.mdx#preview), this manifest schema is not yet stable and should not be considered a public API. We include it here only as an aid for understanding.
+
```json
@@ -251,6 +262,7 @@ The raw JSON docs manifest can be accessed at `http://localhost:6006/manifests/d
}
}
```
+
## Debugging
@@ -271,7 +283,7 @@ You can also remove an entire component from the manifest by removing the tag in
Similarly, to exclude an entire MDX docs page from the manifests, you can remove the `manifest` tag from the page's metadata:
-```jsx title="DocForHumansOnly.mdx"
+```mdx title="DocForHumansOnly.mdx"
import { Meta } from '@storybook/addon-docs/blocks';
diff --git a/docs/ai/mcp/api.mdx b/docs/ai/mcp/api.mdx
index 7d825cab597a..dc94a2efaf0e 100644
--- a/docs/ai/mcp/api.mdx
+++ b/docs/ai/mcp/api.mdx
@@ -4,11 +4,13 @@ sidebar:
order: 2
title: API
---
-
+
- While they are in [preview](../../releases/features.mdx#preview), Storybook's AI capabilities (specifically, the [manifests](../manifests.mdx) and MCP server) are currently only supported for [React](?renderer=react) projects.
- Additionally, the API may change in future releases. We welcome feedback and contributions to help improve this feature.
+While they are in [preview](../../releases/features.mdx#preview), Storybook's AI capabilities (specifically, the [manifests](../manifests.mdx) and MCP server) are currently only supported for [React](?renderer=react) projects.
+
+Additionally, the API may change in future releases. We welcome feedback and contributions to help improve this feature.
+
@@ -31,7 +33,7 @@ Type:
}
```
-Default:
+Default:
```ts
{
diff --git a/docs/ai/mcp/overview.mdx b/docs/ai/mcp/overview.mdx
index dab0b2f8a7a4..f487fc94e7d4 100644
--- a/docs/ai/mcp/overview.mdx
+++ b/docs/ai/mcp/overview.mdx
@@ -6,9 +6,11 @@ sidebar:
---
- While they are in [preview](../../releases/features.mdx#preview), Storybook's AI capabilities (specifically, the [manifests](../manifests.mdx) and MCP server) are currently only supported for [React](?renderer=react) projects.
- Additionally, the API may change in future releases. We welcome feedback and contributions to help improve this feature.
+While they are in [preview](../../releases/features.mdx#preview), Storybook's AI capabilities (specifically, the [manifests](../manifests.mdx) and MCP server) are currently only supported for [React](?renderer=react) projects.
+
+Additionally, the API may change in future releases. We welcome feedback and contributions to help improve this feature.
+
diff --git a/docs/ai/mcp/sharing.mdx b/docs/ai/mcp/sharing.mdx
index 0ec12a48d753..633787a464c7 100644
--- a/docs/ai/mcp/sharing.mdx
+++ b/docs/ai/mcp/sharing.mdx
@@ -6,9 +6,11 @@ sidebar:
---
- While they are in [preview](../../releases/features.mdx#preview), Storybook's AI capabilities (specifically, the [manifests](../manifests.mdx) and [MCP server](./overview.mdx)) are currently only supported for [React](?renderer=react) projects.
- Additionally, the API may change in future releases. We welcome feedback and contributions to help improve this feature.
+While they are in [preview](../../releases/features.mdx#preview), Storybook's AI capabilities (specifically, the [manifests](../manifests.mdx) and [MCP server](./overview.mdx)) are currently only supported for [React](?renderer=react) projects.
+
+Additionally, the API may change in future releases. We welcome feedback and contributions to help improve this feature.
+
@@ -56,11 +58,11 @@ import { createStorybookMcpHandler } from '@storybook/mcp';
const storybookMcpHandler = await createStorybookMcpHandler();
export async function handleRequest(request: Request): Promise {
- if (new URL(request.url).pathname === '/mcp') {
- return storybookMcpHandler(request);
- }
+ if (new URL(request.url).pathname === '/mcp') {
+ return storybookMcpHandler(request);
+ }
- return new Response('Not found', { status: 404 });
+ return new Response('Not found', { status: 404 });
}
```
diff --git a/docs/api/arg-types.mdx b/docs/api/arg-types.mdx
index 83e46470f211..8a802bfc0142 100644
--- a/docs/api/arg-types.mdx
+++ b/docs/api/arg-types.mdx
@@ -1,8 +1,7 @@
---
-title: "ArgTypes"
+title: ArgTypes
sidebar:
order: 3
- title: ArgTypes
---
ArgTypes specify the behavior of [args](../writing-stories/args.mdx). By specifying the type of an arg, you constrain the values that it can accept and provide information about args that are not explicitly set (i.e., [description](#description)).
@@ -35,28 +34,16 @@ For most Storybook projects, argTypes are [automatically inferred](#automatic-ar
ArgTypes are most often specified at the component level, in the [meta (or default export)](../writing-stories/index.mdx#default-export) of the CSF file:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
They can apply to all stories when specified at the project (global) level, in the `preview.*` configuration file:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Or they can apply only to a [specific story](../writing-stories/index.mdx#defining-stories):
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## `argTypes`
Type:
@@ -110,12 +97,8 @@ Default:
Specify the behavior of the [controls panel](../essentials/controls.mdx) for the arg. If you specify a string, it's used as the [`type`](#controltype) of the control. If you specify an object, you can provide additional configuration. Specifying `false` will prevent the control from rendering.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### `control.type`
Type: `ControlType | null`
@@ -143,10 +126,9 @@ Specifies the type of control used to change the arg value with the [controls pa
| | `'text'` | Provides a freeform text input. `{ control: 'text' }` |
- The `date` control will convert the date into a UNIX timestamp when the value
- changes. It's a known limitation that will be fixed in a future release. If
- you need to represent the actual date, you'll need to update the story's
- implementation and convert the value into a date object.
+
+The `date` control will convert the date into a UNIX timestamp when the value changes. It's a known limitation that will be fixed in a future release. If you need to represent the actual date, you'll need to update the story's implementation and convert the value into a date object.
+
#### `control.accept`
@@ -193,12 +175,8 @@ Default: [Inferred](#automatic-argtype-inference)
Describe the arg. (If you intend to describe the type of the arg, you should use [`table.type`](#tabletype), instead.)
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### `if`
Type:
@@ -215,12 +193,8 @@ Type:
Conditionally render an argType based on the value of another [arg](../writing-stories/args.mdx) or [global](../essentials/toolbars-and-globals.mdx).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### `mapping`
Type: `{ [key: string]: { [option: string]: any } }`
@@ -231,26 +205,19 @@ When dealing with non-primitive values, you'll notice that you'll run into some
`mapping` doesn't have to be exhaustive. If the currently selected option is not listed, it's used verbatim. Can be used with [`control.labels`](#labels).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### `name`
Type: `string`
The `argTypes` object uses the name of the arg as the key. By default, that key is used when displaying the argType in Storybook. You can override the displayed name by specifying a `name` property.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- Be careful renaming args in this way. Users of the component you're documenting will not be able to use the documented name as a property of your component and the actual name will not displayed.
+
+Be careful renaming args in this way. Users of the component you're documenting will not be able to use the documented name as a property of your component and the actual name will not displayed.
For this reason, the `name` property is best used when defining an `argType` that is only used for documentation purposes and not an actual property of the component. For example, when [providing argTypes for each property of an object](https://stackblitz.com/edit/github-uplqzp?file=src/stories/Button.stories.tsx).
@@ -264,12 +231,8 @@ Default: [Inferred](#automatic-argtype-inference)
If the arg accepts a finite set of values, you can specify them with `options`. If those values are [complex](../essentials/controls.mdx#dealing-with-complex-values), like JSX elements, you can use [`mapping`](#mapping) to map them to string values. You can use [`control.labels`](#labels) to provide custom labels for the options.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### `table`
Type:
@@ -294,12 +257,8 @@ Default: [Inferred](#automatic-argtype-inference)
Specify how the arg is documented in the [`ArgTypes` doc block](./doc-blocks/doc-block-argtypes.mdx), [`Controls` doc block](./doc-blocks/doc-block-controls.mdx), and [Controls panel](../essentials/controls.mdx).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### `table.category`
Type: `string`
@@ -351,7 +310,7 @@ Type: `'boolean' | 'function' | 'number' | 'string' | 'symbol' | SBType`
The full type of `SBType` is:
- SBType
+SBType
```ts
interface SBBaseType {
@@ -360,31 +319,31 @@ interface SBBaseType {
}
type SBScalarType = SBBaseType & {
- name: "boolean" | "string" | "number" | "function" | "symbol";
+ name: 'boolean' | 'string' | 'number' | 'function' | 'symbol';
};
type SBArrayType = SBBaseType & {
- name: "array";
+ name: 'array';
value: SBType;
};
type SBObjectType = SBBaseType & {
- name: "object";
+ name: 'object';
value: Record;
};
type SBEnumType = SBBaseType & {
- name: "enum";
+ name: 'enum';
value: (string | number)[];
};
type SBIntersectionType = SBBaseType & {
- name: "intersection";
+ name: 'intersection';
value: SBType[];
};
type SBUnionType = SBBaseType & {
- name: "union";
+ name: 'union';
value: SBType[];
};
type SBOtherType = SBBaseType & {
- name: "other";
+ name: 'other';
value: string;
};
@@ -406,12 +365,8 @@ Specifies the semantic type of the argType. When an argType is [inferred](#autom
If you only need to specify the documented type, you should use [`table.type`](#tabletype), instead.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### `defaultValue`
(⛔️ **Deprecated**)
@@ -420,8 +375,4 @@ Type: `any`
Define the default value of the argType. Deprecated in favor of defining the [`arg`](../writing-stories/args.mdx) value directly.
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/api/cli-options.mdx b/docs/api/cli-options.mdx
index ccbd8fa769b4..9257662b9ca8 100644
--- a/docs/api/cli-options.mdx
+++ b/docs/api/cli-options.mdx
@@ -1,17 +1,18 @@
---
-title: 'CLI options'
+title: CLI options
hideRendererSelector: true
sidebar:
order: 8
- title: CLI options
---
The Storybook command line interface (CLI) is the main tool you use to build and develop Storybook.
- Storybook collects completely anonymous data to help us improve user experience. Participation is
- optional, and you may [opt-out](../configure/telemetry.mdx#how-to-opt-out) if you'd not like to
- share any information.
+
+Storybook collects completely anonymous data to help us improve user experience. Participation is
+optional, and you may [opt-out](../configure/telemetry.mdx#how-to-opt-out) if you'd not like to
+share any information.
+
## CLI commands
@@ -19,9 +20,11 @@ The Storybook command line interface (CLI) is the main tool you use to build and
All of the following documentation is available in the CLI by running `storybook --help`.
- Passing options to these commands works slightly differently if you're using npm instead of Yarn.
- You must prefix all of your options with `--`. For example, `npm run storybook build -- -o
- ./path/to/build --quiet`.
+
+Passing options to these commands works slightly differently if you're using npm instead of Yarn.
+You must prefix all of your options with `--`. For example, `npm run storybook build -- -o
+./path/to/build --quiet`.
+
### `dev`
@@ -42,7 +45,7 @@ Options include:
| `--exact-port` | Attempts to run Storybook on the exact port number specified. If the port is already in use, Storybook will exit with an error message. `storybook dev -p 9009 --exact-port` |
| `-h`, `--host [string]` | Host to run Storybook. `storybook dev -h my-host.com` |
| `-c`, `--config-dir [dir-name]` | Storybook configuration directory. `storybook dev -c .storybook` |
-| `--loglevel [level]` | Controls level of logging during build. Available options: `trace`, `debug`, `info` (default), `warn`, `error`, `silent` `storybook dev --loglevel warn` |
+| `--loglevel [level]` | Controls level of logging during build. Available options: `trace`, `debug`, `info` (default), `warn`, `error`, `silent` `storybook dev --loglevel warn` |
| `--https` | Serve Storybook over HTTPS. Note: You must provide your own certificate information. `storybook dev --https` |
| `--ssl-ca` | Provide an SSL certificate authority. (Optional with --https, required if using a self-signed certificate) `storybook dev --ssl-ca my-certificate` |
| `--ssl-cert` | Provide an SSL certificate. (Required with --https) `storybook dev --ssl-cert my-ssl-certificate` |
@@ -64,9 +67,11 @@ Options include:
| `--preview-only` | Skips Storybook's manager from building and opens the app in "preview only" mode, which is designed to be used in [unsupported browsers](../sharing/publish-storybook.mdx#build-storybook-for-older-browsers). `storybook dev --preview-only` |
- With the release of Storybook 8, the `-s` CLI flag was removed. We recommend using the [static
- directory](../configure/integration/images-and-assets.mdx#serving-static-files-via-storybook)
- instead if you need to serve static files.
+
+With the release of Storybook 8, the `-s` CLI flag was removed. We recommend using the [static
+directory](../configure/integration/images-and-assets.mdx#serving-static-files-via-storybook)
+instead if you need to serve static files.
+
### `build`
@@ -85,7 +90,7 @@ Options include:
| `-V`, `--version` | Output the version number. `storybook build -V` |
| `-o`, `--output-dir [dir-name]` | Directory where to store built files. `storybook build -o /my-deployed-storybook` |
| `-c`, `--config-dir [dir-name]` | Storybook configuration directory. `storybook build -c .storybook` |
-| `--loglevel [level]` | Controls level of logging during build. Available options: `trace`, `debug`, `info` (default), `warn`, `error`, `silent`. `storybook build --loglevel warn` |
+| `--loglevel [level]` | Controls level of logging during build. Available options: `trace`, `debug`, `info` (default), `warn`, `error`, `silent`. `storybook build --loglevel warn` |
| `--quiet` | Suppress verbose build output. `storybook build --quiet` |
| `--debug` | Outputs more logs in the CLI to assist debugging. `storybook build --debug` |
| `--debug-webpack` | Display final webpack configurations for debugging purposes. `storybook build --debug-webpack` |
@@ -101,8 +106,10 @@ Options include:
### `init`
- We recommend [`create-storybook`](#create-storybook) for new projects. The `init` command will
- remain available for backwards compatibility.
+
+We recommend [`create-storybook`](#create-storybook) for new projects. The `init` command will
+remain available for backwards compatibility.
+
Installs and initializes the specified version (e.g., `@latest`, `@8`, `@next`) of Storybook into your project. If no version is specified, the latest version is installed. Read more in the [installation guide](../get-started/install.mdx).
@@ -123,7 +130,7 @@ Options include:
| `-s`, `--skip-install` | Skips the dependency installation step. Used only when you need to configure Storybook manually. `storybook init --skip-install` |
| `-t`, `--type` | Defines the [framework](../configure/integration/frameworks.mdx) to use for your Storybook instance. `storybook init --type solid` |
| `-y`, `--yes` | Skips interactive prompts and automatically installs Storybook per specified version, including all features. `storybook init --yes` |
-| `--features [...values]` | Use these features when installing, skipping the prompt. Supported values are `docs`, `test`, and `a11y`, space separated. `storybook init --features docs test a11y` |
+| `--features [...values]` | Use these features when installing, skipping the prompt. Supported values are `docs`, `test`, and `a11y`, space separated. `storybook init --features docs test a11y` |
| `--package-manager` | Sets the package manager to use when installing Storybook. Available package managers include `npm`, `yarn`, and `pnpm`. `storybook init --package-manager pnpm` |
| `--use-pnp` | Enables [Plug'n'Play](https://yarnpkg.com/features/pnp) support for Yarn. This option is only available when using Yarn as your package manager. `storybook init --use-pnp` |
| `-p`, `--parser` | Sets the [jscodeshift parser](https://github.com/facebook/jscodeshift#parser). Available parsers include `babel`, `babylon`, `flow`, `ts`, and `tsx`. `storybook init --parser tsx` |
@@ -131,7 +138,7 @@ Options include:
| `--disable-telemetry` | Disables Storybook's telemetry. Learn more about it [here](../configure/telemetry.mdx#how-to-opt-out). `storybook init --disable-telemetry` |
| `--enable-crash-reports` | Enables sending crash reports to Storybook's telemetry. Learn more about it [here](../configure/telemetry.mdx#crash-reports-disabled-by-default). `storybook init --enable-crash-reports` |
| `--loglevel ` | Controls level of logging during initialization. Available options: `trace`, `debug`, `info` (default), `warn`, `error`, `silent` `storybook init --loglevel debug` |
-| `--logfile [path]` | Write all debug logs to the specified file at the end of the run. Defaults to debug-storybook.log when [path] is not provided. `storybook init --logfile /tmp/debug-storybook.log` |
+| `--logfile [path]` | Write all debug logs to the specified file at the end of the run. Defaults to debug-storybook.log when [path] is not provided. `storybook init --logfile /tmp/debug-storybook.log` |
| `--no-dev` | Complete the initialization of Storybook without running the Storybook dev server. `storybook init --no-dev` |
### `add`
@@ -144,15 +151,15 @@ storybook add [addon] [options]
Options include:
-| Option | Description |
-| -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `-h`, `--help` | Output usage information. `storybook add --help` |
-| `-c`, `--config-dir` | Storybook configuration directory. `storybook migrate --config-dir .storybook` |
-| `--package-manager` | Sets the package manager to use when installing the addon. Available package managers include `npm`, `yarn`, and `pnpm`. `storybook add [addon] --package-manager pnpm` |
-| `-s`, `--skip-postinstall` | Skips post-install configuration. Used only when you need to configure the addon yourself. `storybook add [addon] --skip-postinstall` |
-| `--debug` | Outputs more logs in the CLI to assist debugging. `storybook add --debug` |
-| `--loglevel ` | Controls level of logging during addon installation. Available options: `trace`, `debug`, `info` (default), `warn`, `error`, `silent` `storybook add [addon] --loglevel debug` |
-| `--logfile [path]` | Write all debug logs to the specified file at the end of the run. Defaults to debug-storybook.log when [path] is not provided. `storybook add [addon] --logfile /tmp/debug-storybook.log` |
+| Option | Description |
+| ------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `-h`, `--help` | Output usage information. `storybook add --help` |
+| `-c`, `--config-dir [dir-name]` | Storybook configuration directory. `storybook add --config-dir .storybook` |
+| `--package-manager` | Sets the package manager to use when installing the addon. Available package managers include `npm`, `yarn`, and `pnpm`. `storybook add [addon] --package-manager pnpm` |
+| `-s`, `--skip-postinstall` | Skips post-install configuration. Used only when you need to configure the addon yourself. `storybook add [addon] --skip-postinstall` |
+| `--debug` | Outputs more logs in the CLI to assist debugging. `storybook add --debug` |
+| `--loglevel ` | Controls level of logging during addon installation. Available options: `trace`, `debug`, `info` (default), `warn`, `error`, `silent` `storybook add [addon] --loglevel debug` |
+| `--logfile [path]` | Write all debug logs to the specified file at the end of the run. Defaults to debug-storybook.log when [path] is not provided. `storybook add [addon] --logfile /tmp/debug-storybook.log` |
### `remove`
@@ -184,20 +191,20 @@ For example, `storybook@latest upgrade --dry-run` will perform a dry run (no act
Options include:
-| Option | Description |
-| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `-h`, `--help` | Output usage information. `storybook upgrade --help` |
-| `-c, --config-dir ` | Directory or directories to find Storybook configurations `storybook upgrade --config-dir .storybook` |
-| `-n`, `--dry-run` | Checks for version upgrades without installing them. `storybook upgrade --dry-run` |
-| `-s`, `--skip-check` | Skips the migration check step during the upgrade process. `storybook upgrade --skip-check` |
-| `-y`, `--yes` | Skips interactive prompts and automatically upgrades Storybook to the latest version. `storybook upgrade --yes` |
-| `-f`,`--force` | Force the upgrade, skipping autoblockers check. `storybook upgrade --force` |
-| `--package-manager` | Sets the package manager to use when upgrading Storybook. Available package managers include `npm`, `yarn`, and `pnpm`. `storybook upgrade --package-manager pnpm` |
-| `--debug` | Outputs more logs in the CLI to assist debugging. `storybook upgrade --debug` |
-| `--disable-telemetry` | Disables Storybook's telemetry. Learn more about it [here](../configure/telemetry.mdx#how-to-opt-out). `storybook upgrade --disable-telemetry` |
-| `--enable-crash-reports` | Enables sending crash reports to Storybook's telemetry. Learn more about it [here](../configure/telemetry.mdx#crash-reports-disabled-by-default). `storybook upgrade --enable-crash-reports` |
-| `-logfile [path]` | Write all debug logs to the specified file at the end of the run. Defaults to debug-storybook.log when [path] is not provided. `storybook upgrade --logfile /tmp/debug-storybook.log` |
-| `--loglevel ` | Define log level: `debug`, `error`, `info`, `silent`, `trace`, or `warn` (default: `info`). `storybook upgrade --loglevel debug` |
+| Option | Description |
+| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `-h`, `--help` | Output usage information. `storybook upgrade --help` |
+| `-c, --config-dir ` | Directory or directories to find Storybook configurations `storybook upgrade --config-dir .storybook` |
+| `-n`, `--dry-run` | Checks for version upgrades without installing them. `storybook upgrade --dry-run` |
+| `-s`, `--skip-check` | Skips the migration check step during the upgrade process. `storybook upgrade --skip-check` |
+| `-y`, `--yes` | Skips interactive prompts and automatically upgrades Storybook to the latest version. `storybook upgrade --yes` |
+| `-f`,`--force` | Force the upgrade, skipping autoblockers check. `storybook upgrade --force` |
+| `--package-manager` | Sets the package manager to use when upgrading Storybook. Available package managers include `npm`, `yarn`, and `pnpm`. `storybook upgrade --package-manager pnpm` |
+| `--debug` | Outputs more logs in the CLI to assist debugging. `storybook upgrade --debug` |
+| `--disable-telemetry` | Disables Storybook's telemetry. Learn more about it [here](../configure/telemetry.mdx#how-to-opt-out). `storybook upgrade --disable-telemetry` |
+| `--enable-crash-reports` | Enables sending crash reports to Storybook's telemetry. Learn more about it [here](../configure/telemetry.mdx#crash-reports-disabled-by-default). `storybook upgrade --enable-crash-reports` |
+| `--logfile [path]` | Write all debug logs to the specified file at the end of the run. Defaults to debug-storybook.log when [path] is not provided. `storybook upgrade --logfile /tmp/debug-storybook.log` |
+| `--loglevel ` | Define log level: `debug`, `error`, `info`, `silent`, `trace`, or `warn` (default: `info`). `storybook upgrade --loglevel debug` |
### `migrate`
@@ -208,25 +215,27 @@ storybook[@version] migrate [codemod] [options]
```
- The command requires the codemod name (e.g., `csf-2-to-3`) as an argument to apply the necessary
- changes to your project. You can find the list of available codemods by running `storybook migrate
- --list`.
+
+The command requires the codemod name (e.g., `csf-2-to-3`) as an argument to apply the necessary
+changes to your project. You can find the list of available codemods by running `storybook migrate
+--list`.
+
For example, `storybook@latest migrate csf-2-to-3 --dry-run`, checks your project to verify if the codemod can be applied without making any changes, providing you with a report of which files would be affected.
Options include:
-| Option | Description |
-| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
-| `-h`, `--help` | Output usage information. `storybook migrate --help` |
-| `-c`, `--config-dir` | Storybook configuration directory. `storybook migrate --config-dir .storybook` |
-| `-n`, `--dry-run` | Verify the migration exists and show the files to which it will be applied. `storybook migrate --dry-run` |
-| `-l`, `--list` | Shows a list of available codemods. `storybook migrate --list` |
-| `-g`, `--glob` | Glob for files upon which to apply the codemods. `storybook migrate --glob src/**/*.stories.tsx` |
-| `-p`, `--parser` | Sets the [jscodeshift parser](https://github.com/facebook/jscodeshift#parser). Available parsers include `babel`, `babylon`, `flow`, `ts`, and `tsx`. `storybook migrate --parser tsx` |
-| `-r`, `--rename [from-to]` | Renames the files affected by the codemod to include the provided suffix. `storybook migrate --rename ".js:.ts"` |
-| `--debug` | Outputs more logs in the CLI to assist debugging. `storybook migrate --debug` |
+| Option | Description |
+| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
+| `-h`, `--help` | Output usage information. `storybook migrate --help` |
+| `-c`, `--config-dir [dir-name]` | Storybook configuration directory. `storybook migrate --config-dir .storybook` |
+| `-n`, `--dry-run` | Verify the migration exists and show the files to which it will be applied. `storybook migrate --dry-run` |
+| `-l`, `--list` | Shows a list of available codemods. `storybook migrate --list` |
+| `-g`, `--glob` | Glob for files upon which to apply the codemods. `storybook migrate --glob src/**/*.stories.tsx` |
+| `-p`, `--parser` | Sets the [jscodeshift parser](https://github.com/facebook/jscodeshift#parser). Available parsers include `babel`, `babylon`, `flow`, `ts`, and `tsx`. `storybook migrate --parser tsx` |
+| `-r`, `--rename [from-to]` | Renames the files affected by the codemod to include the provided suffix. `storybook migrate --rename ".js:.ts"` |
+| `--debug` | Outputs more logs in the CLI to assist debugging. `storybook migrate --debug` |
### `automigrate`
@@ -240,23 +249,23 @@ For example, `storybook@latest automigrate --dry-run` scans your project for pot
Options include:
-| Option | Description |
-| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `-h`, `--help` | Output usage information. `storybook automigrate --help` |
-| `-c`, `--config-dir` | Storybook configuration directory. `storybook automigrate --config-dir .storybook` |
-| `-n`, `--dry-run` | Checks for available migrations without applying them. `storybook automigrate --dry-run` |
-| `-s`, `--skip-install` | Skip installing dependencies whenever applicable. `storybook automigrate --skip-install` |
-| `-y`, `--yes` | Applies available migrations automatically without prompting for confirmation. `storybook automigrate --yes` |
-| `-l`, `--list` | Shows a list of available automigrations. `storybook automigrate --list` |
-| `--package-manager` | Sets the package manager to use when running the auto migration. Available package managers include `npm`, `yarn`, and `pnpm`. `storybook automigrate --package-manager pnpm` |
-| `--renderer` | Specifies Storybook's renderer to use when running the automigration. Useful for monorepo environments where multiple Storybook instances can exist in the same project. `storybook automigrate --renderer vue` |
-| `--debug` | Outputs more logs in the CLI to assist debugging. `storybook automigrate --debug` |
-| `--disable-telemetry` | Disables Storybook's telemetry. Learn more about it [here](../configure/telemetry.mdx#how-to-opt-out). `storybook automigrate --disable-telemetry` |
-| `--enable-crash-reports` | Enables sending crash reports to Storybook's telemetry. Learn more about it [here](../configure/telemetry.mdx#crash-reports-disabled-by-default). `storybook automigrate --enable-crash-reports` |
+| Option | Description |
+| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `-h`, `--help` | Output usage information. `storybook automigrate --help` |
+| `-c`, `--config-dir [dir-name]` | Storybook configuration directory. `storybook automigrate --config-dir .storybook` |
+| `-n`, `--dry-run` | Checks for available migrations without applying them. `storybook automigrate --dry-run` |
+| `-s`, `--skip-install` | Skip installing dependencies whenever applicable. `storybook automigrate --skip-install` |
+| `-y`, `--yes` | Applies available migrations automatically without prompting for confirmation. `storybook automigrate --yes` |
+| `-l`, `--list` | Shows a list of available automigrations. `storybook automigrate --list` |
+| `--package-manager` | Sets the package manager to use when running the auto migration. Available package managers include `npm`, `yarn`, and `pnpm`. `storybook automigrate --package-manager pnpm` |
+| `--renderer` | Specifies Storybook's renderer to use when running the automigration. Useful for monorepo environments where multiple Storybook instances can exist in the same project. `storybook automigrate --renderer vue` |
+| `--debug` | Outputs more logs in the CLI to assist debugging. `storybook automigrate --debug` |
+| `--disable-telemetry` | Disables Storybook's telemetry. Learn more about it [here](../configure/telemetry.mdx#how-to-opt-out). `storybook automigrate --disable-telemetry` |
+| `--enable-crash-reports` | Enables sending crash reports to Storybook's telemetry. Learn more about it [here](../configure/telemetry.mdx#crash-reports-disabled-by-default). `storybook automigrate --enable-crash-reports` |
### `doctor`
-Performs a health check on your Storybook project for common issues (e.g., duplicate dependencies, incompatible addons or mismatched versions) and provides suggestions on how to fix them. Applicable when [upgrading](../releases/upgrading.mdx#verifying-the-upgrade) Storybook versions.
+Performs a health check on your Storybook project for common issues (e.g., duplicate dependencies, incompatible addons or mismatched versions) and provides suggestions on how to fix them. Applicable when [upgrading](../releases/upgrading.mdx#automatic-health-check) Storybook versions.
```shell
storybook doctor [options]
@@ -264,12 +273,12 @@ storybook doctor [options]
Options include:
-| Option | Description |
-| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `-h`, `--help` | Output usage information. `storybook doctor --help` |
-| `-c`, `--config-dir` | Storybook configuration directory. `storybook doctor --config-dir .storybook` |
-| `--package-manager` | Sets the package manager to use when running the health check. Available package managers include `npm`, `yarn`, and `pnpm`. `storybook doctor --package-manager pnpm` |
-| `--debug` | Outputs more logs in the CLI to assist debugging. `storybook doctor --debug` |
+| Option | Description |
+| ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `-h`, `--help` | Output usage information. `storybook doctor --help` |
+| `-c`, `--config-dir [dir-name]` | Storybook configuration directory. `storybook doctor --config-dir .storybook` |
+| `--package-manager` | Sets the package manager to use when running the health check. Available package managers include `npm`, `yarn`, and `pnpm`. `storybook doctor --package-manager pnpm` |
+| `--debug` | Outputs more logs in the CLI to assist debugging. `storybook doctor --debug` |
### `info`
@@ -315,7 +324,7 @@ Options include:
| Option | Description |
| --------------------------------- | ------------------------------------------------------ |
| `-o`, `--output-file ` | JSON file to output index |
-| `-c`, `--config-dir ` | Storybook configuration directory |
+| `-c`, `--config-dir ` | Storybook configuration directory |
| `--quiet` | Suppress verbose build output |
| `--loglevel ` | Control level of logging during build |
| `--disable-telemetry` | Disables Storybook's telemetry |
@@ -346,8 +355,10 @@ Options include:
| `--enable-crash-reports` | Enables sending crash reports to Storybook's telemetry. Learn more about it [here](../configure/telemetry.mdx#crash-reports-disabled-by-default). `storybook sandbox --enable-crash-reports` |
- If you're looking for a hosted version of the available sandboxes, see
- [storybook.new](https://storybook.new).
+
+If you're looking for a hosted version of the available sandboxes, see
+[storybook.new](https://storybook.new).
+
## `create-storybook`
@@ -377,6 +388,6 @@ Options include:
| `--debug` | Outputs more logs in the CLI to assist debugging. `create storybook --debug` |
| `--disable-telemetry` | Disables Storybook's telemetry. Learn more about it [here](../configure/telemetry.mdx#how-to-opt-out). `create storybook --disable-telemetry` |
| `--enable-crash-reports` | Enables sending crash reports to Storybook's telemetry. Learn more about it [here](../configure/telemetry.mdx#crash-reports-disabled-by-default). `create storybook --enable-crash-reports` |
-| `--loglevel ` | Controls level of logging during initialization. Available options: `trace`, `debug`, `info` (default), `warn`, `error`, `silent` `storybook init --loglevel debug` |
-| `--logfile [path]` | Write all debug logs to the specified file at the end of the run. Defaults to debug-storybook.log when [path] is not provided. `storybook init --logfile /tmp/debug-storybook.log` |
+| `--loglevel ` | Controls level of logging during initialization. Available options: `trace`, `debug`, `info` (default), `warn`, `error`, `silent` `create storybook --loglevel debug` |
+| `--logfile [path]` | Write all debug logs to the specified file at the end of the run. Defaults to debug-storybook.log when [path] is not provided. `create storybook --logfile /tmp/debug-storybook.log` |
| `--no-dev` | Complete the initialization of Storybook without running the Storybook dev server. `create storybook --no-dev` |
diff --git a/docs/api/csf/csf-next.mdx b/docs/api/csf/csf-next.mdx
index d5dfa5dd811e..15ab36d98fbe 100644
--- a/docs/api/csf/csf-next.mdx
+++ b/docs/api/csf/csf-next.mdx
@@ -1,5 +1,5 @@
---
-title: 'Component Story Format (CSF)'
+title: Component Story Format (CSF)
isTab: true
tab:
order: 2
@@ -8,8 +8,10 @@ tab:
-
- CSF Next is currently only supported in [React](?renderer=react), [Vue](?renderer=vue), [Angular](?renderer=angular), and [Web Components](?renderer=web-components) projects.
+
+
+CSF Next is currently in [preview](../../releases/features.mdx#preview) and only supported in [React](?renderer=react), [Vue](?renderer=vue), [Angular](?renderer=angular), and [Web Components](?renderer=web-components) projects.
+
@@ -17,7 +19,9 @@ tab:
- This is a [**preview**](../../releases/features.mdx#preview) feature and (though unlikely) the API may change in future releases. We [welcome feedback](https://github.com/storybookjs/storybook/discussions/30112) and contributions to help improve this feature.
+
+This is a [**preview**](../../releases/features.mdx#preview) feature and (though unlikely) the API may change in future releases. We [welcome feedback](https://github.com/storybookjs/storybook/discussions/30112) and contributions to help improve this feature.
+
CSF Next is the next evolution of Storybook's Component Story Format (CSF). This new API uses a pattern called factory functions to provide full type safety to your Storybook stories, making it easier to configure addons correctly and unlocking the full potential of Storybook's features.
@@ -69,7 +73,9 @@ export default definePreview({
```
- The preview configuration will be automatically updated to reference the [necessary addons](#preview-addons) when installing an addon via `npx storybook add ` or running `storybook dev`.
+
+The preview configuration will be automatically updated to reference the [necessary addons](#preview-addons) when installing an addon via `npx storybook add ` or running `storybook dev`.
+
### `preview.meta`
@@ -86,7 +92,7 @@ const meta = preview.meta({
parameters: {
// type-safe!
layout: 'centered',
- }
+ },
});
```
@@ -114,8 +120,8 @@ To configure subpath imports, add the following to your `package.json`:
```json title="package.json"
{
"imports": {
- "#*": ["./*", "./*.ts", "./*.tsx"],
- },
+ "#*": ["./*", "./*.ts", "./*.tsx"]
+ }
}
```
@@ -147,7 +153,11 @@ type CustomProps = React.ComponentProps & { customProp: string };
const meta = preview.type<{ args: CustomProps }>().meta({
component: Button,
// 👇 Correct types
- render: ({ customProp, ...args }) => <>{customProp} >,
+ render: ({ customProp, ...args }) => (
+ <>
+ {customProp}
+ >
+ ),
});
export const Primary = meta.story({
@@ -166,7 +176,9 @@ Finally, the `story` function on the `meta` object defines the stories. This fun
```ts title="Button.stories.js|ts"
// ...from above
-const meta = preview.meta({ /* ... */ });
+const meta = preview.meta({
+ //...
+});
export const Primary = meta.story({
args: {
@@ -190,7 +202,9 @@ Properties are merged intelligently:
```ts title="Button.stories.js|ts"
// ...from above
-const meta = preview.meta({ /* ... */ });
+const meta = preview.meta({
+ //...
+});
export const Example = meta.story({
args: {
@@ -205,7 +219,7 @@ export const Example = meta.story({
tags: ['a'],
});
-/*
+/*
* 👇 Final values applied:
* {
* args: {
@@ -240,7 +254,9 @@ export const ExtendedExample = Example.extend({
```ts title="Button.stories.js|ts"
// ...from above
-const meta = preview.meta({ /* ... */ });
+const meta = preview.meta({
+ //...
+});
export const Primary = meta.story({
args: {
@@ -329,6 +345,7 @@ Update your `.storybook/main.*` file to use the new [`defineMain`](#definemain)
```
**2. Update your preview config file**
+
Update your `.storybook/preview.*` file to use the new [`definePreview`](#definepreview) function.
@@ -374,7 +391,9 @@ Story files have been updated for improved usability. With the new format:
- Stories are now created from the meta object, via the [`meta.story`](#metastory) function
+
The examples below show the changes needed to upgrade a story file from CSF 3 to CSF Next. You can also upgrade from CSF 1 or 2 using similar steps.
+
```diff title="Button.stories.js|ts"
@@ -465,9 +484,11 @@ All of the story properties are now contained within a new property called `comp
```
- The property name "composed" was chosen because the values within are composed from the story, its component meta, and the preview configuration.
- If you want to access the direct input to the story, you can use `Story.input` instead of `Story.composed`.
+The property name "composed" was chosen because the values within are composed from the story, its component meta, and the preview configuration.
+
+If you want to access the direct input to the story, you can use `Story.input` instead of `Story.composed`.
+
**4. Update your Vitest setup file**
@@ -477,7 +498,9 @@ If you're using [Storybook's Vitest addon](../../writing-tests/integrations/vite
If you are using [portable stories in Vitest](../portable-stories/portable-stories-vitest.mdx), you may use a Vitest setup file to configure your stories. This file must be updated to use the new CSF Next format.
+
Note that this only applies if you use CSF Next for all your tested stories. If you use a mix of CSF 1, 2, or 3 and CSF Next, you must maintain two separate setup files.
+
```diff title="vitest.setup.js|ts"
@@ -526,9 +549,7 @@ The `Story` object also provides a `Component` property, enabling you to render
Here's an example of how you can reuse a story in a test file by rendering its component:
-{/* prettier-ignore-start */}
-{/* prettier-ignore-end */}
## Frequently asked questions (FAQ)
@@ -546,4 +567,4 @@ Yes, the [doc blocks](../../writing-docs/doc-blocks.mdx) used to reference stori
For more information on this experimental format's original proposal, refer to its [RFC on GitHub](https://github.com/storybookjs/storybook/discussions/30112). We welcome your comments!
-
\ No newline at end of file
+
diff --git a/docs/api/csf/index.mdx b/docs/api/csf/index.mdx
index b0a50147f1f4..c77e480071af 100644
--- a/docs/api/csf/index.mdx
+++ b/docs/api/csf/index.mdx
@@ -1,8 +1,7 @@
---
-title: 'Component Story Format (CSF)'
+title: Component Story Format (CSF)
sidebar:
order: 2
- title: Component Story Format (CSF)
isTab: true
tab:
order: 1
@@ -21,7 +20,7 @@ The default export defines metadata about your component, including the `compone
-When writing Svelte CSF stories, you use the `defineMeta` function instead of the default export to define the metadata for your component.
+When writing Svelte CSF stories, you use the `defineMeta` function instead of the default export to define the metadata for your component.
@@ -29,12 +28,8 @@ When writing Svelte CSF stories, you use the `defineMeta` function instead of th
The `component` field is required and used by addons for automatic prop table generation and display of other component metadata. The `title` field is optional and should be unique (i.e., not re-used across files).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
For more examples, see [writing stories](../../writing-stories/index.mdx).
## Named story exports
@@ -51,21 +46,17 @@ With Svelte CSF, you use the `Story` component returned by `defineMeta` instead
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
The exported identifiers will be converted to "start case" using Lodash's [startCase](https://lodash.com/docs/#startCase) function. For example:
-| Identifier | Transformation |
-| ---------------- | ------------------- |
-| name | Name |
-| someName | Some Name |
-| someNAME | Some NAME |
-| some\_custom\_NAME | Some Custom NAME |
-| someName1234 | Some Name 1 2 3 4 |
+| Identifier | Transformation |
+| ---------------- | ----------------- |
+| name | Name |
+| someName | Some Name |
+| someNAME | Some NAME |
+| some_custom_NAME | Some Custom NAME |
+| someName1234 | Some Name 1 2 3 4 |
We recommend that all export names to start with a capital letter.
@@ -73,40 +64,24 @@ Story objects can be annotated with a few different fields to define story-level
Storybook's `name` configuration element is helpful in specific circumstances. Common use cases are names with special characters or Javascript restricted words. If not specified, Storybook defaults to the named export.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Args story inputs
Starting in SB 6.0, stories accept named inputs called Args. Args are dynamic data that are provided (and possibly updated by) Storybook and its addons.
Consider Storybook’s ["Button" example](../../writing-stories/index.mdx#defining-stories) of a text button that logs its click events:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Now consider the same example, re-written with args:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Or even more simply:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Not only are these versions shorter and more accessible to write than their no-args counterparts, but they are also more portable since the code doesn't depend on the actions feature specifically.
For more information on setting up [Docs](../../writing-docs/index.mdx) and [Actions](../../essentials/actions.mdx), see their respective documentation.
@@ -117,40 +92,31 @@ Storybook's `play` functions are small snippets of code executed when the story
A good use case for the `play` function is a form component. With previous Storybook versions, you'd write your set of stories and had to interact with the component to validate it. With Storybook's play functions, you could write the following story:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
When the story renders in the UI, Storybook executes each step defined in the `play` function and runs the assertions without the need for user interaction.
-
- ## Custom render functions
+
- Starting in Storybook 6.4, you can write your stories as JavaScript objects, reducing the boilerplate code you need to generate to test your components, thus improving functionality and usability. `Render` functions are helpful methods to give you additional control over how the story renders. For example, if you were writing a story as an object and you wanted to specify how your component should render, you could write the following:
+## Custom render functions
- {/* prettier-ignore-start */}
+Starting in Storybook 6.4, you can write your stories as JavaScript objects, reducing the boilerplate code you need to generate to test your components, thus improving functionality and usability. `Render` functions are helpful methods to give you additional control over how the story renders. For example, if you were writing a story as an object and you wanted to specify how your component should render, you could write the following:
-
+
- {/* prettier-ignore-end */}
+When Storybook loads this story, it will detect the existence of a `render` function and adjust the component rendering accordingly based on what's defined.
- When Storybook loads this story, it will detect the existence of a `render` function and adjust the component rendering accordingly based on what's defined.
-
+
-
- ## Custom render functions
+
- If you're using Svelte CSF to write your stories, you can add a custom snippet to allow you additional control over how your story renders. For example, if you were writing a story and you wanted to specify how your component should render, you could write the following:
+## Custom render functions
- {/* prettier-ignore-start */}
+If you're using Svelte CSF to write your stories, you can add a custom snippet to allow you additional control over how your story renders. For example, if you were writing a story and you wanted to specify how your component should render, you could write the following:
-
+
- {/* prettier-ignore-end */}
-
-
+
## Storybook export vs. name handling
@@ -160,12 +126,8 @@ Storybook will always use the named export to determine the story ID and URL.
If you specify the `name` option, it will be used as the story display name in the UI. Otherwise, it defaults to the named export, processed through Storybook's `storyNameFromExport` and `lodash.startCase` functions.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
When you want to change the name of your story, rename the CSF export. It will change the name of the story and also change the story's ID and URL.
It would be best if you used the `name` configuration element in the following cases:
@@ -181,22 +143,18 @@ You can use the optional configuration fields `includeStories` and `excludeStori
Consider the following story file:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
When this file renders in Storybook, it treats `ComplexStory` and `SimpleStory` as stories and ignores the `data` named exports.
For this particular example, you could achieve the same result in different ways, depending on what's convenient:
-* `includeStories: /^[A-Z]/`
-* `includeStories: /.*Story$/`
-* `includeStories: ['SimpleStory', 'ComplexStory']`
-* `excludeStories: /^[a-z]/`
-* `excludeStories: /.*Data$/`
-* `excludeStories: ['simpleData', 'complexData']`
+- `includeStories: /^[A-Z]/`
+- `includeStories: /.*Story$/`
+- `includeStories: ['SimpleStory', 'ComplexStory']`
+- `excludeStories: /^[a-z]/`
+- `excludeStories: /.*Data$/`
+- `excludeStories: ['simpleData', 'complexData']`
The first option is the recommended solution if you follow the best practice of starting story exports with an uppercase letter (i.e., use UpperCamelCase).
@@ -212,22 +170,14 @@ Storybook provides a codemod to help you upgrade from CSF 2 to CSF 3. You can ru
In CSF 2, the named exports are always functions that instantiate a component, and those functions can be annotated with configuration options. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
This declares a Primary story for a Button that renders itself by spreading `{ primary: true }` into the component. The `default.title` metadata says where to place the story in a navigation hierarchy.
Here's the CSF 3 equivalent:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Let's go through the changes individually to understand what's going on.
### Spreadable story objects
@@ -238,76 +188,52 @@ Consider the following addition to the intro example, which creates a `PrimaryOn
Here's the CSF 2 implementation:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
`Primary.bind({})` copies the story function, but it doesn't copy the annotations hanging off the function, so we must add `PrimaryOnDark.args = Primary.args` to inherit the args.
In CSF 3, we can spread the `Primary` object to carry over all its annotations:
-{/* prettier-ignore-start */}
-
Learn more about [named story exports](#named-story-exports).
-{/* prettier-ignore-end */}
-
### Default render functions
In CSF 3, you specify how a story renders through a `render` function. We can rewrite a CSF 2 example to CSF 3 through the following steps.
Let's start with a simple CSF 2 story function:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Now, let's rewrite it as a story object in CSF 3 with an explicit `render` function that tells the story how to render itself. Like CSF 2, this gives us full control of how we render a component or even a collection of components.
-{/* prettier-ignore-start */}
-
-
- Learn more about [render functions](#custom-render-functions).
-
+
+
+Learn more about [render functions](#custom-render-functions).
-{/* prettier-ignore-end */}
+
But in CSF 2, a lot of story functions are identical: take the component specified in the default export and spread args into it. What's interesting about these stories is not the function, but the args passed into the function.
CSF 3 provides default render functions for each renderer. If all you're doing is spreading args into your component—which is the most common case—you don't need to specify any `render` function at all:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
+
+
+For more information, see the section on [custom render functions](#custom-render-functions).
-
- For more information, see the section on [custom render functions](#custom-render-functions).
-
+
### Generate titles automatically
Finally, CSF 3 can automatically generate titles.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
You can still specify a title like in CSF 2, but if you don't specify one, it can be inferred from the story's path on disk. For more information, see the section on [configuring story loading](../../configure/index.mdx#configure-story-loading).
diff --git a/docs/api/doc-blocks/doc-block-argtypes.mdx b/docs/api/doc-blocks/doc-block-argtypes.mdx
index 43a2e801c350..ff95dc1794aa 100644
--- a/docs/api/doc-blocks/doc-block-argtypes.mdx
+++ b/docs/api/doc-blocks/doc-block-argtypes.mdx
@@ -1,31 +1,28 @@
---
-title: 'ArgTypes'
+title: ArgTypes
sidebar:
order: 1
- title: ArgTypes
---
The `ArgTypes` block can be used to show a static table of [arg types](../arg-types.mdx) for a given component, as a way to document its interface.
- If you’re looking for a dynamic table that shows a story’s current arg values for a story and supports users changing them, see the [`Controls`](./doc-block-controls.mdx) block instead.
+
+If you’re looking for a dynamic table that shows a story’s current arg values for a story and supports users changing them, see the [`Controls`](./doc-block-controls.mdx) block instead.
+

-{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"
+```mdx title="ButtonDocs.mdx"
import { Meta, ArgTypes } from '@storybook/addon-docs/blocks';
-import * as ButtonStories from './Button.stories';
+import \* as ButtonStories from './Button.stories';
```
-{/* prettier-ignore-end */}
-
## ArgTypes
```js
@@ -33,27 +30,20 @@ import { ArgTypes } from '@storybook/addon-docs/blocks';
```
- Configuring with props and parameters
+Configuring with props and parameters
- ℹ️ Like most blocks, the `ArgTypes` block is configured with props in MDX. Many of those props derive their default value from a corresponding [parameter](../../writing-stories/parameters.mdx) in the block's namespace, `parameters.docs.argTypes`.
+ℹ️ Like most blocks, the `ArgTypes` block is configured with props in MDX. Many of those props derive their default value from a corresponding [parameter](../../writing-stories/parameters.mdx) in the block's namespace, `parameters.docs.argTypes`.
- The following `exclude` configurations are equivalent:
+The following `exclude` configurations are equivalent:
- {/* prettier-ignore-start */}
+
-
-
- {/* prettier-ignore-end */}
-
- {/* prettier-ignore-start */}
-
- ```md title="ButtonDocs.mdx"
-
- ```
+```mdx title="ButtonDocs.mdx"
+
+```
- {/* prettier-ignore-end */}
+The example above applied the parameter at the [component](../../writing-stories/parameters.mdx#component-parameters) (or meta) level, but it could also be applied at the [project](../../writing-stories/parameters.mdx#global-parameters) or [story](../../writing-stories/parameters.mdx#story-parameters) level.
- The example above applied the parameter at the [component](../../writing-stories/parameters.mdx#component-parameters) (or meta) level, but it could also be applied at the [project](../../writing-stories/parameters.mdx#global-parameters) or [story](../../writing-stories/parameters.mdx#story-parameters) level.
### `exclude`
@@ -86,6 +76,6 @@ Default: `parameters.docs.argTypes.sort` or `'none'`
Specifies how the arg types are sorted.
-* **none**: Unsorted, displayed in the same order the arg types are processed in
-* **alpha**: Sorted alphabetically, by the arg type's name
-* **requiredFirst**: Same as `alpha`, with any required arg types displayed first
+- **none**: Unsorted, displayed in the same order the arg types are processed in
+- **alpha**: Sorted alphabetically, by the arg type's name
+- **requiredFirst**: Same as `alpha`, with any required arg types displayed first
diff --git a/docs/api/doc-blocks/doc-block-canvas.mdx b/docs/api/doc-blocks/doc-block-canvas.mdx
index c5ee604f447d..db6c65b9a5c5 100644
--- a/docs/api/doc-blocks/doc-block-canvas.mdx
+++ b/docs/api/doc-blocks/doc-block-canvas.mdx
@@ -1,19 +1,16 @@
---
-title: 'Canvas'
+title: Canvas
sidebar:
order: 2
- title: Canvas
---
-The `Canvas` block is a wrapper around a [`Story`](./doc-block-story.mdx), featuring a toolbar that allows you to interact with its content while automatically providing the required [`Source`](./doc-block-source.mdx) snippets.
+The `Canvas` block is a wrapper around a [`Story`](./doc-block-story.mdx), featuring a toolbar that allows you to interact with its content while automatically providing the required [`Source`](./doc-block-source.mdx) snippets.

When using the Canvas block in MDX, it references a story with the `of` prop:
-{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"
+```mdx title="ButtonDocs.mdx"
import { Meta, Canvas } from '@storybook/addon-docs/blocks';
import * as ButtonStories from './Button.stories';
@@ -22,10 +19,10 @@ import * as ButtonStories from './Button.stories';
```
-{/* prettier-ignore-end */}
-
- In previous versions of Storybook it was possible to pass in arbitrary components as children to `Canvas`. That is deprecated and the `Canvas` block now only supports a single story.
+
+In previous versions of Storybook it was possible to pass in arbitrary components as children to `Canvas`. That is deprecated and the `Canvas` block now only supports a single story.
+
## Canvas
@@ -35,35 +32,26 @@ import { Canvas } from '@storybook/addon-docs/blocks';
```
- Configuring with props and parameters
+Configuring with props and parameters
- ℹ️ Like most blocks, the `Canvas` block is configured with props in MDX. Many of those props derive their default value from a corresponding [parameter](../../writing-stories/parameters.mdx) in the block's namespace, `parameters.docs.canvas`.
+ℹ️ Like most blocks, the `Canvas` block is configured with props in MDX. Many of those props derive their default value from a corresponding [parameter](../../writing-stories/parameters.mdx) in the block's namespace, `parameters.docs.canvas`.
- The following `sourceState` configurations are equivalent:
+The following `sourceState` configurations are equivalent:
- {/* prettier-ignore-start */}
+
-
-
- {/* prettier-ignore-end */}
-
- {/* prettier-ignore-start */}
-
- ```md title="ButtonDocs.mdx"
-
- ```
+```mdx title="ButtonDocs.mdx"
+
+```
- {/* prettier-ignore-end */}
+The example above applied the parameter at the [story](../../writing-stories/parameters.mdx#story-parameters) level, but it could also be applied at the [component](../../writing-stories/parameters.mdx#component-parameters) (or meta) level or [project](../../writing-stories/parameters.mdx#global-parameters) level.
- The example above applied the parameter at the [story](../../writing-stories/parameters.mdx#story-parameters) level, but it could also be applied at the [component](../../writing-stories/parameters.mdx#component-parameters) (or meta) level or [project](../../writing-stories/parameters.mdx#global-parameters) level.
### `additionalActions`
Type:
-{/* prettier-ignore-start */}
-
```ts
Array<{
title: string | JSX.Element;
@@ -73,21 +61,18 @@ Array<{
}>;
```
-{/* prettier-ignore-end */}
-
Default: `parameters.docs.canvas.additionalActions`
Provides any additional custom actions to show in the bottom right corner. These are simple buttons that do anything you specify in the `onClick` function.
-{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"
+```mdx title="ButtonDocs.mdx"
import { Meta, Story, Canvas, SourceState } from '@storybook/addon-docs/blocks';
import * as ButtonStories from './Button.stories';
{/* With an additional action */}
+
```
-
{/* prettier-ignore-end */}
## ColorPalette
@@ -87,7 +84,7 @@ import { ColorItem } from '@storybook/addon-docs/blocks';
Type: `string[] | { [key: string]: string }`
-Provides the list of colors to be displayed. Accepts any valid CSS color format (hex, RGB, HSL, etc.). When an object is provided, the keys will be displayed above the values. Additionally, it supports gradients such as 'linear-gradient(to right, white, black)' or 'linear-gradient(65deg, white, black)', etc.
+Provides the list of colors to be displayed. Accepts any valid CSS color format (hex, RGB, HSL, etc.). When an object is provided, the keys will be displayed above the values. Additionally, it supports gradients such as 'linear-gradient(to right, white, black)' or 'linear-gradient(65deg, white, black)', etc.
### `subtitle`
diff --git a/docs/api/doc-blocks/doc-block-controls.mdx b/docs/api/doc-blocks/doc-block-controls.mdx
index 561cf8203dd9..a97292fe921a 100644
--- a/docs/api/doc-blocks/doc-block-controls.mdx
+++ b/docs/api/doc-blocks/doc-block-controls.mdx
@@ -1,23 +1,22 @@
---
-title: 'Controls'
+title: Controls
sidebar:
order: 4
- title: Controls
---
The `Controls` block can be used to show a dynamic table of args for a given story, as a way to document its interface, and to allow you to change the args for a (separately) rendered story (via the [`Story`](./doc-block-story.mdx) or [`Canvas`](./doc-block-canvas.mdx) blocks).
- If you’re looking for a static table that shows a component's arg types with no controls, see the [`ArgTypes`](./doc-block-argtypes.mdx) block instead.
+
+If you’re looking for a static table that shows a component's arg types with no controls, see the [`ArgTypes`](./doc-block-argtypes.mdx) block instead.
+

-{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"
+```mdx title="ButtonDocs.mdx"
import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks';
-import * as ButtonStories from './Button.stories'
+import * as ButtonStories from './Button.stories';
@@ -26,11 +25,9 @@ import * as ButtonStories from './Button.stories'
```
-{/* prettier-ignore-end */}
-
- The Controls doc block will only have functioning UI controls if you haven't turned off inline stories with the [`inline`](./doc-block-story.mdx#inline) configuration option.
+The Controls doc block will only have functioning UI controls if you haven't turned off inline stories with the [`inline`](./doc-block-story.mdx#inline) configuration option.
@@ -41,32 +38,25 @@ import { Controls } from '@storybook/addon-docs/blocks';
```
- Configuring with props and parameters
+Configuring with props and parameters
- ℹ️ Like most blocks, the `Controls` block is configured with props in MDX. Many of those props derive their default value from a corresponding [parameter](../../writing-stories/parameters.mdx) in the block's namespace, `parameters.docs.controls`.
+ℹ️ Like most blocks, the `Controls` block is configured with props in MDX. Many of those props derive their default value from a corresponding [parameter](../../writing-stories/parameters.mdx) in the block's namespace, `parameters.docs.controls`.
- The following `exclude` configurations are equivalent:
+The following `exclude` configurations are equivalent:
- {/* prettier-ignore-start */}
+
-
-
- {/* prettier-ignore-end */}
-
- {/* prettier-ignore-start */}
-
- ```md title="ButtonDocs.mdx"
-
- ```
+```mdx title="ButtonDocs.mdx"
+
+```
- {/* prettier-ignore-end */}
+The example above applied the parameter at the [component](../../writing-stories/parameters.mdx#component-parameters) (or meta) level, but it could also be applied at the [project](../../writing-stories/parameters.mdx#global-parameters) or [story](../../writing-stories/parameters.mdx#story-parameters) level.
- The example above applied the parameter at the [component](../../writing-stories/parameters.mdx#component-parameters) (or meta) level, but it could also be applied at the [project](../../writing-stories/parameters.mdx#global-parameters) or [story](../../writing-stories/parameters.mdx#story-parameters) level.
- This API configures the `Controls` blocks used within docs pages. To configure the Controls panel, see the [feature documentation](../../essentials/controls.mdx). To configure individual controls, specify [argTypes](../arg-types.mdx#control) for each.
+This API configures the `Controls` blocks used within docs pages. To configure the Controls panel, see the [feature documentation](../../essentials/controls.mdx). To configure individual controls, specify [argTypes](../arg-types.mdx#control) for each.
@@ -100,6 +90,6 @@ Default: `parameters.docs.controls.sort` or `'none'`
Specifies how the controls are sorted.
-* **none**: Unsorted, displayed in the same order the controls are processed in
-* **alpha**: Sorted alphabetically, by the arg type's name
-* **requiredFirst**: Same as `alpha`, with any required controls displayed first
+- **none**: Unsorted, displayed in the same order the controls are processed in
+- **alpha**: Sorted alphabetically, by the arg type's name
+- **requiredFirst**: Same as `alpha`, with any required controls displayed first
diff --git a/docs/api/doc-blocks/doc-block-description.mdx b/docs/api/doc-blocks/doc-block-description.mdx
index e7dcc8bb7b5f..7bf1fd291ce8 100644
--- a/docs/api/doc-blocks/doc-block-description.mdx
+++ b/docs/api/doc-blocks/doc-block-description.mdx
@@ -1,17 +1,14 @@
---
-title: 'Description'
+title: Description
sidebar:
order: 5
- title: Description
---
The `Description` block displays the description for a component, story, or meta, obtained from their respective JSDoc comments.

-{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"
+```mdx title="ButtonDocs.mdx"
import { Meta, Description } from '@storybook/addon-docs/blocks';
import * as ButtonStories from './Button.stories';
@@ -20,8 +17,6 @@ import * as ButtonStories from './Button.stories';
```
-{/* prettier-ignore-end */}
-
## Description
```js
@@ -66,27 +61,21 @@ This flow gives you powerful ways to override the description for each scenario.
export const Button = () => ;
```
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"
+```mdx title="ButtonDocs.mdx"
import { Meta, Description } from '@storybook/addon-docs/blocks';
import * as ButtonStories from './Button.stories';
{/* Shows the description for the default export (the meta).
- If that didn't have any comments, it would show the
- comments from the component instead */}
+If that didn't have any comments, it would show the
+comments from the component instead */}
{/* Shows the description for the Primary export */}
```
-
{/* prettier-ignore-end */}
diff --git a/docs/api/doc-blocks/doc-block-icongallery.mdx b/docs/api/doc-blocks/doc-block-icongallery.mdx
index 533bdede03d4..741c0975031e 100644
--- a/docs/api/doc-blocks/doc-block-icongallery.mdx
+++ b/docs/api/doc-blocks/doc-block-icongallery.mdx
@@ -1,8 +1,7 @@
---
-title: 'IconGallery'
+title: IconGallery
sidebar:
order: 6
- title: IconGallery
---
The `IconGallery` block enables you to easily document React icon components associated with your project, displayed in a neat grid.
@@ -13,9 +12,7 @@ The `IconGallery` block enables you to easily document React icon components ass
To document a set of icons, use the `IconGallery` block to display them in a grid. Each icon is wrapped in an `IconItem` block, enabling you to specify its properties, such as the name and the icon itself.
-{/* prettier-ignore-start */}
-
-```md title="Iconography.mdx"
+```mdx title="Iconography.mdx"
import { Meta, IconGallery, IconItem } from '@storybook/addon-docs/blocks';
import { Icon as IconExample } from './Icon';
@@ -40,16 +37,16 @@ import { Icon as IconExample } from './Icon';
-
+
-
+
-
+
@@ -58,15 +55,11 @@ import { Icon as IconExample } from './Icon';
```
-{/* prettier-ignore-end */}
-
### Automate icon documentation
If you're working on a project that contains a large number of icons that you want to document, you can extend the `IconGallery` block, wrap `IconItem` in a loop, and iterate over the icons you want to document, including their properties. For example:
-{/* prettier-ignore-start */}
-
-```md title="Iconography.mdx"
+```mdx title="Iconography.mdx"
import { Meta, IconGallery, IconItem } from '@storybook/addon-docs/blocks';
import { Icon as IconExample } from './Icon';
@@ -83,8 +76,6 @@ import * as icons from './icons';
```
-{/* prettier-ignore-end */}
-
## IconGallery
```js
diff --git a/docs/api/doc-blocks/doc-block-markdown.mdx b/docs/api/doc-blocks/doc-block-markdown.mdx
index 8d34cadc9325..48015af01dd9 100644
--- a/docs/api/doc-blocks/doc-block-markdown.mdx
+++ b/docs/api/doc-blocks/doc-block-markdown.mdx
@@ -1,8 +1,7 @@
---
-title: 'Markdown'
+title: Markdown
sidebar:
order: 7
- title: Markdown
---
The `Markdown` block allows you to import and include plain markdown in your MDX files.
@@ -11,23 +10,17 @@ The `Markdown` block allows you to import and include plain markdown in your MD
When importing markdown files, it’s important to use the `?raw` suffix on the import path to ensure the content is imported as-is, and isn’t being evaluated:
-{/* prettier-ignore-start */}
-
````md title="README.md"
# Button
Primary UI component for user interaction
```js
-import { Button } from "@storybook/design-system";
+import { Button } from '@storybook/design-system';
```
````
-{/* prettier-ignore-end */}
-
-{/* prettier-ignore-start */}
-
-```md title="Header.mdx"
+```mdx title="Header.mdx"
// DON'T do this, will error
import ReadMe from './README.md';
// DO this, will work
@@ -35,13 +28,11 @@ import ReadMe from './README.md?raw';
import { Markdown } from '@storybook/addon-docs/blocks';
-# A header
+# A header
{ReadMe}
```
-{/* prettier-ignore-end */}
-
## Markdown
```js
@@ -64,24 +55,18 @@ Specifies the options passed to the underlying [`markdown-to-jsx` library](https
From a purely technical standpoint, we could include the imported markdown directly in the MDX file like this:
-{/* prettier-ignore-start */}
-
-```md
+```mdx
{/* THIS WON'T WORK, THIS IS TO DEMONSTRATE AN ERROR */}
import ReadMe from './README.md';
-# A header
+# A header
{ReadMe}
```
-{/* prettier-ignore-end */}
-
However, there are small syntactical differences between plain markdown and MDX2. MDX2 is more strict and will interpret certain content as JSX expressions. Here’s an example of a perfectly valid markdown file, that would break if it was handled directly by MDX2:
-{/* prettier-ignore-start */}
-
```md
# A header
@@ -90,12 +75,8 @@ However, there are small syntactical differences between plain markdown and MDX2
```
-{/* prettier-ignore-end */}
-
Furthermore, MDX2 wraps all strings on newlines in `p` tags or similar, meaning that content would render differently between a plain `.md` file and an `.mdx` file.
-{/* prettier-ignore-start */}
-
```md
# A header
@@ -111,5 +92,3 @@ The example above will remain as-is in plain markdown, but MDX2 will compile it
Some text
```
-
-{/* prettier-ignore-end */}
diff --git a/docs/api/doc-blocks/doc-block-meta.mdx b/docs/api/doc-blocks/doc-block-meta.mdx
index cf686e569941..39812947df3f 100644
--- a/docs/api/doc-blocks/doc-block-meta.mdx
+++ b/docs/api/doc-blocks/doc-block-meta.mdx
@@ -1,28 +1,25 @@
---
-title: 'Meta'
+title: Meta
sidebar:
order: 8
- title: Meta
---
The `Meta` block is used to [attach](#attached-vs-unattached) a custom MDX docs page alongside a component’s list of stories. It doesn’t render any content, but serves two purposes in an MDX file:
-* Attaches the MDX file to a component and its stories, or
-* Controls the location of the unattached docs entry in the sidebar.
+- Attaches the MDX file to a component and its stories, or
+- Controls the location of the unattached docs entry in the sidebar.
-{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"
+```mdx title="ButtonDocs.mdx"
import { Meta } from '@storybook/addon-docs/blocks';
import * as ButtonStories from './Button.stories';
```
-{/* prettier-ignore-end */}
-
- The Meta block doesn’t render anything visible.
+
+The Meta block doesn’t render anything visible.
+
## Meta
@@ -45,35 +42,28 @@ Type: `string`
Sets the name of the [attached](#attached-vs-unattached) doc entry. You can attach more than one MDX file to the same component in the sidebar by setting different names for each file's `Meta`.
-{/* prettier-ignore-start */}
-
-```md title="Component.mdx"
+```mdx title="Component.mdx"
import { Meta } from '@storybook/addon-docs/blocks';
import * as ComponentStories from './component.stories';
{/* This MDX file is now called "Special Docs" */}
+
```
-{/* prettier-ignore-end */}
-
### `of`
Type: CSF file exports
Specifies which CSF file is [attached](#attached-vs-unattached) to this MDX file. Pass the **full set of exports** from the CSF file (not the default export!).
-{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"
+```mdx title="ButtonDocs.mdx"
import { Meta, Story } from '@storybook/addon-docs/blocks';
import * as ButtonStories from './Button.stories';
```
-{/* prettier-ignore-end */}
-
Attaching an MDX file to a component’s stories with the `of` prop serves two purposes:
1. Ensures the MDX content appears in the sidebar inside the component’s story list. By default, it will be named whatever the `docs.defaultName` (which defaults to `"Docs"`) option is set to in `main.js`. But this can be overridden with the [`name` prop](#name).
@@ -81,7 +71,7 @@ Attaching an MDX file to a component’s stories with the `of` prop serves two p
- The `of` prop is optional. If you don’t want to attach a specific CSF file to this MDX file, you can either use the `title` prop to control the location, or emit `Meta` entirely, and let [autotitle](../../configure/user-interface/sidebar-and-urls.mdx#csf-30-auto-titles) decide where it goes.
+The `of` prop is optional. If you don’t want to attach a specific CSF file to this MDX file, you can either use the `title` prop to control the location, or emit `Meta` entirely, and let [autotitle](../../configure/user-interface/sidebar-and-urls.mdx#csf-30-auto-titles) decide where it goes.
@@ -92,22 +82,18 @@ Type: `string`
Sets the title of an [unattached](#attached-vs-unattached) MDX file.
{/* prettier-ignore-start */}
-
-```md
-{/* Introduction.mdx */}
-
+```mdx title="Introduction.mdx"
import { Meta } from '@storybook/addon-docs/blocks';
{/* Override the docs entry's location in the sidebar with title */}
```
-
{/* prettier-ignore-end */}
- If you want to change the sorting of the docs entry with the component’s stories, use [Story Sorting](../../writing-stories/naming-components-and-hierarchy.mdx#sorting-stories), or add specific MDX files to your `stories` field in `main.js` in order.
-
+If you want to change the sorting of the docs entry with the component’s stories, use [Story Sorting](../../writing-stories/naming-components-and-hierarchy.mdx#sorting-stories), or add specific MDX files to your `stories` field in `main.js` in order.
+
## Attached vs. unattached
diff --git a/docs/api/doc-blocks/doc-block-primary.mdx b/docs/api/doc-blocks/doc-block-primary.mdx
index 0179811d4bc1..2c6b72e4833f 100644
--- a/docs/api/doc-blocks/doc-block-primary.mdx
+++ b/docs/api/doc-blocks/doc-block-primary.mdx
@@ -1,17 +1,14 @@
---
-title: 'Primary'
+title: Primary
sidebar:
order: 9
- title: Primary
---
The `Primary` block displays the primary (first defined in the stories file) story, in a [`Story`](./doc-block-story.mdx) block. It is typically rendered immediately under the title in a docs entry.

-{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"
+```mdx title="ButtonDocs.mdx"
import { Meta, Primary } from '@storybook/addon-docs/blocks';
import * as ButtonStories from './Button.stories';
@@ -20,8 +17,6 @@ import * as ButtonStories from './Button.stories';
```
-{/* prettier-ignore-end */}
-
## Primary
```js
diff --git a/docs/api/doc-blocks/doc-block-source.mdx b/docs/api/doc-blocks/doc-block-source.mdx
index 782e26fe114d..4ee44a526d87 100644
--- a/docs/api/doc-blocks/doc-block-source.mdx
+++ b/docs/api/doc-blocks/doc-block-source.mdx
@@ -1,17 +1,14 @@
---
-title: 'Source'
+title: Source
sidebar:
order: 10
- title: Source
---
The `Source` block is used to render a snippet of source code directly.

-{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"
+```mdx title="ButtonDocs.mdx"
import { Meta, Source } from '@storybook/addon-docs/blocks';
import * as ButtonStories from './Button.stories';
@@ -20,8 +17,6 @@ import * as ButtonStories from './Button.stories';
```
-{/* prettier-ignore-end */}
-
## Source
```js
@@ -29,27 +24,20 @@ import { Source } from '@storybook/addon-docs/blocks';
```
- Configuring with props and parameters
-
- ℹ️ Like most blocks, the `Source` block is configured with props in MDX. Many of those props derive their default value from a corresponding [parameter](../../writing-stories/parameters.mdx) in the block's namespace, `parameters.docs.source`.
+Configuring with props and parameters
- The following `language` configurations are equivalent:
+ℹ️ Like most blocks, the `Source` block is configured with props in MDX. Many of those props derive their default value from a corresponding [parameter](../../writing-stories/parameters.mdx) in the block's namespace, `parameters.docs.source`.
- {/* prettier-ignore-start */}
+The following `language` configurations are equivalent:
-
+
- {/* prettier-ignore-end */}
-
- {/* prettier-ignore-start */}
-
- ```md title="ButtonDocs.mdx"
-
- ```
+```mdx title="ButtonDocs.mdx"
+
+```
- {/* prettier-ignore-end */}
+The example above applied the parameter at the [story](../../writing-stories/parameters.mdx#story-parameters) level, but it could also be applied at the [component](../../writing-stories/parameters.mdx#component-parameters) (or meta) level or [project](../../writing-stories/parameters.mdx#global-parameters) level.
- The example above applied the parameter at the [story](../../writing-stories/parameters.mdx#story-parameters) level, but it could also be applied at the [component](../../writing-stories/parameters.mdx#component-parameters) (or meta) level or [project](../../writing-stories/parameters.mdx#global-parameters) level.
### `code`
@@ -60,22 +48,20 @@ Default: `parameters.docs.source.code`
Provides the source code to be rendered.
-{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"
+```mdx title="ButtonDocs.mdx"
import { Meta, Source } from '@storybook/addon-docs/blocks';
import * as ButtonStories from './Button.stories';
-
+}`}
+/>
```
-{/* prettier-ignore-end */}
-
### `dark`
Type: `boolean`
@@ -86,30 +72,30 @@ Determines if the snippet is rendered in dark mode.
- Light mode is only supported when the `Source` block is rendered independently. When rendered as part of a [`Canvas` block](./doc-block-canvas.mdx)—like it is in [autodocs](../../writing-docs/autodocs.mdx)—it will always use dark mode.
+Light mode is only supported when the `Source` block is rendered independently. When rendered as part of a [`Canvas` block](./doc-block-canvas.mdx)—like it is in [autodocs](../../writing-docs/autodocs.mdx)—it will always use dark mode.
-
- ### `excludeDecorators`
+
- Type: `boolean`
+### `excludeDecorators`
+
+Type: `boolean`
- Default: `parameters.docs.source.excludeDecorators`
+Default: `parameters.docs.source.excludeDecorators`
- Determines if [decorators](../../writing-stories/decorators.mdx) are rendered in the source code snippet.
-
+Determines if [decorators](../../writing-stories/decorators.mdx) are rendered in the source code snippet.
+
+
### `language`
Type:
{/* prettier-ignore-start */}
-
```ts
'jsextra' | 'jsx' | 'json' | 'yml' | 'md' | 'bash' | 'css' | 'html' | 'tsx' | 'typescript' | 'graphql'
```
-
{/* prettier-ignore-end */}
Default: `parameters.docs.source.language` or `'jsx'`
@@ -143,12 +129,12 @@ Default: `parameters.docs.source.type` or `'auto'`
Specifies how the source code is rendered.
-* **auto**: Same as **dynamic**, if the story's `render` function accepts args inputs and **dynamic** is supported by the framework in use; otherwise same as **code**
-* **code**: Renders the value of [`code` prop](#code), otherwise renders static story source
-* **dynamic**: Renders the story source with dynamically updated arg values
+- **auto**: Same as **dynamic**, if the story's `render` function accepts args inputs and **dynamic** is supported by the framework in use; otherwise same as **code**
+- **code**: Renders the value of [`code` prop](#code), otherwise renders static story source
+- **dynamic**: Renders the story source with dynamically updated arg values
- Note that dynamic snippets will only work if the story uses [`args`](../../writing-stories/args.mdx) and the [`Story` block](./doc-block-story.mdx) for that story is rendered along with the `Source` block.
-
+Note that dynamic snippets will only work if the story uses [`args`](../../writing-stories/args.mdx) and the [`Story` block](./doc-block-story.mdx) for that story is rendered along with the `Source` block.
+
diff --git a/docs/api/doc-blocks/doc-block-stories.mdx b/docs/api/doc-blocks/doc-block-stories.mdx
index 27916a1ec2ee..c1a24775d251 100644
--- a/docs/api/doc-blocks/doc-block-stories.mdx
+++ b/docs/api/doc-blocks/doc-block-stories.mdx
@@ -1,17 +1,14 @@
---
-title: 'Stories'
+title: Stories
sidebar:
order: 11
- title: Stories
---
The `Stories` block renders the full collection of stories in a stories file.

-{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"
+```mdx title="ButtonDocs.mdx"
import { Meta, Stories } from '@storybook/addon-docs/blocks';
import * as ButtonStories from './Button.stories';
@@ -20,8 +17,6 @@ import * as ButtonStories from './Button.stories';
```
-{/* prettier-ignore-end */}
-
## Stories
```js
@@ -40,8 +35,8 @@ Determines if the collection of stories includes the primary (first) story.
- If a stories file contains only one story and `includePrimary={true}`, the `Stories` block will render nothing to avoid a potentially confusing situation.
-
+If a stories file contains only one story and `includePrimary={true}`, the `Stories` block will render nothing to avoid a potentially confusing situation.
+
### `title`
diff --git a/docs/api/doc-blocks/doc-block-story.mdx b/docs/api/doc-blocks/doc-block-story.mdx
index d4822d9e223b..ad171e40488f 100644
--- a/docs/api/doc-blocks/doc-block-story.mdx
+++ b/docs/api/doc-blocks/doc-block-story.mdx
@@ -1,8 +1,7 @@
---
-title: 'Story'
+title: Story
sidebar:
order: 12
- title: Story
---
[Stories](../../writing-stories/index.mdx) are Storybook's fundamental building blocks.
@@ -11,15 +10,13 @@ In Storybook Docs, you can render any of your stories from your CSF files in the
- Typically you want to use the [`Canvas` block](./doc-block-canvas.mdx) to render a story with a surrounding border and the source block, but you can use the `Story` block to render just the story.
-
+Typically you want to use the [`Canvas` block](./doc-block-canvas.mdx) to render a story with a surrounding border and the source block, but you can use the `Story` block to render just the story.
+

-{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"+
+```mdx title="ButtonDocs.mdx"
import { Meta, Story } from '@storybook/addon-docs/blocks';
import * as ButtonStories from './Button.stories';
@@ -28,8 +25,6 @@ import * as ButtonStories from './Button.stories';
```
-{/* prettier-ignore-end */}
-
## Story
```js
@@ -37,27 +32,20 @@ import { Story } from '@storybook/addon-docs/blocks';
```
- Configuring with props and parameters
-
- ℹ️ Like most blocks, the `Story` block is configured with props in MDX. Many of those props derive their default value from a corresponding [parameter](../../writing-stories/parameters.mdx) in the block's namespace, `parameters.docs.story`.
-
- The following `autoplay` configurations are equivalent:
-
- {/* prettier-ignore-start */}
+Configuring with props and parameters
-
+ℹ️ Like most blocks, the `Story` block is configured with props in MDX. Many of those props derive their default value from a corresponding [parameter](../../writing-stories/parameters.mdx) in the block's namespace, `parameters.docs.story`.
- {/* prettier-ignore-end */}
+The following `autoplay` configurations are equivalent:
- {/* prettier-ignore-start */}
+
- ```md title="ButtonDocs.mdx"
-
- ```
+```mdx title="ButtonDocs.mdx"
+
+```
- {/* prettier-ignore-end */}
+The example above applied the parameter at the [story](../../writing-stories/parameters.mdx#story-parameters) level, but it could also be applied at the [component](../../writing-stories/parameters.mdx#component-parameters) (or meta) level or [project](../../writing-stories/parameters.mdx#global-parameters) level.
- The example above applied the parameter at the [story](../../writing-stories/parameters.mdx#story-parameters) level, but it could also be applied at the [component](../../writing-stories/parameters.mdx#component-parameters) (or meta) level or [project](../../writing-stories/parameters.mdx#global-parameters) level.
### `autoplay`
@@ -73,7 +61,9 @@ Because all stories render simultaneously in docs entries, play functions can pe
However, if you know your play function is “safe” to run in docs, you can use this prop to run it automatically.
- If a story uses [`mount` in its play function](../../writing-tests/interaction-testing.mdx#run-code-before-the-component-gets-rendered), it will not render in docs unless `autoplay` is set to `true`.
+
+If a story uses [`mount` in its play function](../../writing-tests/interaction-testing.mdx#run-code-before-the-component-gets-rendered), it will not render in docs unless `autoplay` is set to `true`.
+
### `height`
@@ -94,8 +84,8 @@ Determines whether the story is rendered `inline` (in the same browser frame as
- Setting the `inline` option to false will prevent the associated [controls](./doc-block-controls.mdx) from updating the story within the documentation page. This is a known limitation of the current implementation and will be addressed in a future release.
-
+Setting the `inline` option to false will prevent the associated [controls](./doc-block-controls.mdx) from updating the story within the documentation page. This is a known limitation of the current implementation and will be addressed in a future release.
+
### `meta`
@@ -107,8 +97,7 @@ Specifies the CSF file to which the story is associated.
You can render a story from a CSF file that you haven’t attached to the MDX file (via `Meta`) by using the `meta` prop. Pass the **full set of exports** from the CSF file (not the default export!).
{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"
+```mdx title="ButtonDocs.mdx"
import { Meta, Story } from '@storybook/addon-docs/blocks';
import * as ButtonStories from './Button.stories';
import * as HeaderStories from './Header.stories';
@@ -116,10 +105,9 @@ import * as HeaderStories from './Header.stories';
{/* Although this MDX file is largely concerned with Button,
- it can render Header stories too */}
+it can render Header stories too */}
```
-
{/* prettier-ignore-end */}
### `of`
@@ -127,4 +115,3 @@ import * as HeaderStories from './Header.stories';
Type: Story export
Specifies which story is rendered by the `Story` block. If no `of` is defined and the MDX file is [attached](./doc-block-meta.mdx#attached-vs-unattached), the primary (first) story will be rendered.
-
diff --git a/docs/api/doc-blocks/doc-block-subtitle.mdx b/docs/api/doc-blocks/doc-block-subtitle.mdx
index afe93fa17e28..f8a7ed56410d 100644
--- a/docs/api/doc-blocks/doc-block-subtitle.mdx
+++ b/docs/api/doc-blocks/doc-block-subtitle.mdx
@@ -1,24 +1,19 @@
---
-title: 'Subtitle'
+title: Subtitle
sidebar:
order: 13
- title: Subtitle
---
The `Subtitle` block can serve as a secondary heading for your docs entry.

-{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"
+```mdx title="ButtonDocs.mdx"
import { Subtitle } from '@storybook/addon-docs/blocks';
This is the subtitle
```
-{/* prettier-ignore-end */}
-
## Subtitle
```js
diff --git a/docs/api/doc-blocks/doc-block-tableofcontents.mdx b/docs/api/doc-blocks/doc-block-tableofcontents.mdx
index 96b282affee7..d32d9b3a55d8 100644
--- a/docs/api/doc-blocks/doc-block-tableofcontents.mdx
+++ b/docs/api/doc-blocks/doc-block-tableofcontents.mdx
@@ -1,8 +1,7 @@
---
-title: 'TableOfContents'
+title: TableOfContents
sidebar:
order: 14
- title: TableOfContents
---
The `TableOfContents` block renders a table of contents for the current documentation page, allowing users to navigate between sections quickly. It appears as a fixed sidebar on the right side of the documentation page and is hidden on smaller screens (below 768px).
@@ -11,7 +10,7 @@ The table of contents is enabled and configured via the `docs.toc` [parameter](.
- For a step-by-step guide on enabling and customizing the table of contents, see the [Generate a table of contents](../../writing-docs/autodocs.mdx#generate-a-table-of-contents) section in the Autodocs documentation.
+For a step-by-step guide on enabling and customizing the table of contents, see the [Generate a table of contents](../../writing-docs/autodocs.mdx#generate-a-table-of-contents) section in the Autodocs documentation.
@@ -19,20 +18,12 @@ The table of contents is enabled and configured via the `docs.toc` [parameter](.
Enable the table of contents globally in your Storybook preview configuration:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
You can also enable or disable it for specific components in their stories file:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## `toc` parameter options
The `docs.toc` parameter accepts either `true` (to enable with defaults) or an object with the following properties:
@@ -83,8 +74,4 @@ Type: `object`
Provides additional configuration options passed directly to the underlying [`Tocbot`](https://tscanlin.github.io/tocbot/) library. These options are not guaranteed to remain available in future versions of Storybook.
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/api/doc-blocks/doc-block-title.mdx b/docs/api/doc-blocks/doc-block-title.mdx
index 1c40d97e7499..1c9b17c464c2 100644
--- a/docs/api/doc-blocks/doc-block-title.mdx
+++ b/docs/api/doc-blocks/doc-block-title.mdx
@@ -1,24 +1,19 @@
---
-title: 'Title'
+title: Title
sidebar:
order: 15
- title: Title
---
The `Title` block serves as the primary heading for your docs entry. It is typically used to provide the component or page name.

-{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"
+```mdx title="ButtonDocs.mdx"
import { Title } from '@storybook/addon-docs/blocks';
This is the title
```
-{/* prettier-ignore-end */}
-
## Title
```js
diff --git a/docs/api/doc-blocks/doc-block-typeset.mdx b/docs/api/doc-blocks/doc-block-typeset.mdx
index f7c49b5dabe6..056efbcd8b79 100644
--- a/docs/api/doc-blocks/doc-block-typeset.mdx
+++ b/docs/api/doc-blocks/doc-block-typeset.mdx
@@ -1,17 +1,14 @@
---
-title: 'Typeset'
+title: Typeset
sidebar:
order: 16
- title: Typeset
---
The `Typeset` block helps document the fonts used throughout your project.

-{/* prettier-ignore-start */}
-
-```md title="Typography.mdx"
+```mdx title="Typography.mdx"
import { Meta, Typeset } from '@storybook/addon-docs/blocks';
@@ -65,8 +62,6 @@ export const SampleText = 'Lorem ipsum dolor sit amet, consectetur adipiscing el
/>
```
-{/* prettier-ignore-end */}
-
## Typeset
```js
diff --git a/docs/api/doc-blocks/doc-block-unstyled.mdx b/docs/api/doc-blocks/doc-block-unstyled.mdx
index addc5f677448..1b9ec7dd51be 100644
--- a/docs/api/doc-blocks/doc-block-unstyled.mdx
+++ b/docs/api/doc-blocks/doc-block-unstyled.mdx
@@ -1,19 +1,16 @@
---
-title: 'Unstyled'
+title: Unstyled
sidebar:
order: 17
- title: Unstyled
---
The `Unstyled` block is a special block that disables Storybook's default styling in MDX docs wherever it is added.
By default, most elements (like `h1`, `p`, etc.) in docs have a few default styles applied to ensure the docs look good. However, sometimes you might want some of your content to not have these styles applied. In those cases, wrap the content with the `Unstyled` block to remove the default styles.
-{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"
-import { Meta, Unstyled } from "@storybook/addon-docs/blocks";
-import { Header } from "./Header.tsx";
+```mdx title="ButtonDocs.mdx"
+import { Meta, Unstyled } from '@storybook/addon-docs/blocks';
+import { Header } from './Header.tsx';
@@ -24,9 +21,9 @@ import { Header } from "./Header.tsx";
> This block quote will not be styled
- ... neither will this paragraph, nor the following component (which contains an \
):
+... neither will this paragraph, nor the following component (which contains an \
):
-
+
```
@@ -39,24 +36,22 @@ Yields:
- The other blocks like [`Story`](./doc-block-story.mdx) and [`Canvas`](./doc-block-canvas.mdx) are already unstyled, so there’s no need to wrap those in the `Unstyled` block to ensure that Storybook’s styles don’t bleed into the stories. However, if you import your components directly in the MDX, you most likely want to wrap them in the Unstyled block.
-
+The other blocks like [`Story`](./doc-block-story.mdx) and [`Canvas`](./doc-block-canvas.mdx) are already unstyled, so there’s no need to wrap those in the `Unstyled` block to ensure that Storybook’s styles don’t bleed into the stories. However, if you import your components directly in the MDX, you most likely want to wrap them in the Unstyled block.
+
- Due to how CSS inheritance works it’s best to always add the Unstyled block to the root of your MDX, and not nested into other elements. The following example will cause some Storybook styles like `color` to be inherited into `CustomComponent` because they are applied to the root `div`:
- {/* prettier-ignore-start */}
+Due to how CSS inheritance works it’s best to always add the Unstyled block to the root of your MDX, and not nested into other elements. The following example will cause some Storybook styles like `color` to be inherited into `CustomComponent` because they are applied to the root `div`:
- ```md
-
-
-
-
-
- ```
+```md
+
+
+
+
+
+```
- {/* prettier-ignore-end */}
## Unstyled
@@ -71,4 +66,4 @@ import { Unstyled } from '@storybook/addon-docs/blocks';
Type: `React.ReactNode`
-Provides the content to which you do *not* want to apply default docs styles.
+Provides the content to which you do _not_ want to apply default docs styles.
diff --git a/docs/api/doc-blocks/doc-block-useof.mdx b/docs/api/doc-blocks/doc-block-useof.mdx
index a47517330bad..455d74e8f6db 100644
--- a/docs/api/doc-blocks/doc-block-useof.mdx
+++ b/docs/api/doc-blocks/doc-block-useof.mdx
@@ -1,8 +1,7 @@
---
-title: 'useOf'
+title: useOf
sidebar:
order: 18
- title: useOf
---
The default blocks supplied by Storybook do not fit all use cases, so you might want to write your own blocks.
@@ -35,8 +34,7 @@ export const StoryName = ({ of }) => {
```
{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"
+```mdx title="ButtonDocs.mdx"
import { Meta } from '@storybook/addon-docs/blocks';
import { StoryName } from '../.storybook/blocks/StoryName';
import * as ButtonStories from './Button.stories';
@@ -52,24 +50,19 @@ import * as ButtonStories from './Button.stories';
{/* Renders "Button" */}
```
-
{/* prettier-ignore-end */}
## useOf
### Type
-{/* prettier-ignore-start */}
-
```ts
(
moduleExportOrType: ModuleExport | 'story' | 'meta' | 'component',
- validTypes?: Array<'story' | 'meta' | 'component'>
-) => EnhancedResolvedModuleExportType
+ validTypes?: Array<'story' | 'meta' | 'component'>,
+) => EnhancedResolvedModuleExportType;
```
-{/* prettier-ignore-end */}
-
### Parameters
#### `moduleExportOrType`
@@ -82,9 +75,9 @@ Provides the story export, meta export, component export, or CSF file exports fr
When the custom block is in an [attached doc](./doc-block-meta.mdx#attached-vs-unattached), it’s also possible to get the primary (first) story, meta, or component by passing in a string instead. This is useful as a fallback, so the `of` prop can be omitted in your block. The most common pattern is using this as `useOf(props.of || 'story')` which will fall back to the primary story if no `of` prop is defined.
-* `useOf('story')` returns the annotated primary story in attached mode; error in unattached mode
-* `useOf('meta')` returns the annotated meta in attached mode; error in unattached mode
-* `useOf('component')` returns the annotated component specified in the meta in attached mode; error in unattached mode
+- `useOf('story')` returns the annotated primary story in attached mode; error in unattached mode
+- `useOf('meta')` returns the annotated meta in attached mode; error in unattached mode
+- `useOf('component')` returns the annotated component specified in the meta in attached mode; error in unattached mode
#### `validTypes`
diff --git a/docs/api/doc-blocks/index.mdx b/docs/api/doc-blocks/index.mdx
index d71c4eb2a286..d0279fecff66 100644
--- a/docs/api/doc-blocks/index.mdx
+++ b/docs/api/doc-blocks/index.mdx
@@ -2,5 +2,4 @@
title: Doc Blocks
sidebar:
order: 5
- title: Doc Blocks
----
\ No newline at end of file
+---
diff --git a/docs/api/index.mdx b/docs/api/index.mdx
index 36be8e4c9114..59b274404ecc 100644
--- a/docs/api/index.mdx
+++ b/docs/api/index.mdx
@@ -1,17 +1,15 @@
---
-title: 'API references'
+title: API references
hideRendererSelector: true
sidebar:
order: 12
title: API
----
-
-{/*
+note: |
We intentionally do not use markdown tables here because the required formatting (one row per line)
makes it very difficult to read, particularly when comparing changes.
Also, using HTML directly allows us to apply a consistent width to the first column.
However, this means the links won't work when viewing in GitHub. :(
-*/}
+---
An overview of all available API references for Storybook.
@@ -61,6 +59,7 @@ An overview of all available API references for Storybook.
version of your Storybook.
+
@@ -102,6 +101,7 @@ An overview of all available API references for Storybook.
Parameters are static metadata used to configure your storiesaddons in Storybook. They are specified at the story, meta (component), project (global) levels.
+
@@ -124,5 +124,6 @@ An overview of all available API references for Storybook.
your project.
+
diff --git a/docs/api/main-config/index.mdx b/docs/api/main-config/index.mdx
index 18d625a5de5f..750ca73e9eab 100644
--- a/docs/api/main-config/index.mdx
+++ b/docs/api/main-config/index.mdx
@@ -2,5 +2,4 @@
title: 'main.js|ts configuration'
sidebar:
order: 1
- title: main.js|ts configuration
----
\ No newline at end of file
+---
diff --git a/docs/api/main-config/main-config-addons.mdx b/docs/api/main-config/main-config-addons.mdx
index cb2df239cdf0..b1eb51ff4dc5 100644
--- a/docs/api/main-config/main-config-addons.mdx
+++ b/docs/api/main-config/main-config-addons.mdx
@@ -1,8 +1,7 @@
---
-title: 'addons'
+title: addons
sidebar:
order: 4
- title: addons
---
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -13,8 +12,4 @@ Registers the [addons](../../addons/install-addons.mdx) loaded by Storybook.
For each addon's available options, see their respective [documentation](https://storybook.js.org/integrations).
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/api/main-config/main-config-babel-default.mdx b/docs/api/main-config/main-config-babel-default.mdx
index 25a763fe8006..ba7f14ddacf1 100644
--- a/docs/api/main-config/main-config-babel-default.mdx
+++ b/docs/api/main-config/main-config-babel-default.mdx
@@ -1,8 +1,7 @@
---
-title: 'babelDefault'
+title: babelDefault
sidebar:
order: 6
- title: babelDefault
---
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -13,16 +12,12 @@ Type: `(config: Babel.Config, options: Options) => Babel.Config | Promise
- To adjust your Storybook's Babel setup directly—not via an addon—use [`babel`](./main-config-babel.mdx) instead.
-
-
+To adjust your Storybook's Babel setup directly—not via an addon—use [`babel`](./main-config-babel.mdx) instead.
-{/* prettier-ignore-start */}
+
-{/* prettier-ignore-end */}
-
## `Babel.Config`
The options provided by [Babel](https://babeljs.io/docs/options) are only applicable if you've enabled the [`@storybook/addon-webpack5-compiler-babel`](https://storybook.js.org/addons/@storybook/addon-webpack5-compiler-babel) addon.
diff --git a/docs/api/main-config/main-config-babel.mdx b/docs/api/main-config/main-config-babel.mdx
index 88203adceb03..0ee8759f4df2 100644
--- a/docs/api/main-config/main-config-babel.mdx
+++ b/docs/api/main-config/main-config-babel.mdx
@@ -1,8 +1,7 @@
---
-title: 'babel'
+title: babel
sidebar:
order: 5
- title: babel
---
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -13,24 +12,20 @@ Customize Storybook's [Babel](https://babeljs.io/) setup.
- [Addon authors](../../addons/writing-presets.mdx#babel) should use [`babelDefault`](./main-config-babel-default.mdx) instead, which is applied to the preview config before any user presets have been applied.
+[Addon authors](../../addons/writing-presets.mdx#babel) should use [`babelDefault`](./main-config-babel-default.mdx) instead, which is applied to the preview config before any user presets have been applied.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## `Babel.Config`
The options provided by [Babel](https://babeljs.io/docs/options) are only applicable if you've enabled the [`@storybook/addon-webpack5-compiler-babel`](https://storybook.js.org/addons/@storybook/addon-webpack5-compiler-babel) addon.
- If you have an existing Babel configuration file (e.g., `.babelrc`), it will be automatically detected and used by Storybook without any additional configuration required.
-
+If you have an existing Babel configuration file (e.g., `.babelrc`), it will be automatically detected and used by Storybook without any additional configuration required.
+
## `Options`
diff --git a/docs/api/main-config/main-config-build.mdx b/docs/api/main-config/main-config-build.mdx
index ebad98b2b0f9..4fe1c2fd50b2 100644
--- a/docs/api/main-config/main-config-build.mdx
+++ b/docs/api/main-config/main-config-build.mdx
@@ -1,8 +1,7 @@
---
-title: 'build'
+title: build
sidebar:
order: 7
- title: build
---
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -32,7 +31,7 @@ Configures Storybook's production builds for performance testing purposes by dis
- The options documented on this page are automatically enabled when the `--test` flag is provided to the [`storybook build`](../cli-options.mdx#build) command. We encourage you to override these options only if you need to disable a specific feature for your project or if you are debugging a build issue.
+The options documented on this page are automatically enabled when the `--test` flag is provided to the [`storybook build`](../cli-options.mdx#build) command. We encourage you to override these options only if you need to disable a specific feature for your project or if you are debugging a build issue.
@@ -42,80 +41,52 @@ Type: `boolean`
Excludes the `@storybook/addon-docs/blocks` module from the build, which generates automatic documentation with [Docs Blocks](../../writing-docs/doc-blocks.mdx).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### `test.disabledAddons`
Type: `string[]`
Sets the list of addons that will be disabled in the build output.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### `test.disableMDXEntries`
Type: `boolean`
Enabling this option removes user-written documentation entries in MDX format from the build.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### `test.disableAutoDocs`
Type: `boolean`
Prevents automatic documentation generated with the [autodocs](../../writing-docs/autodocs.mdx) feature from being included in the build.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### `test.disableDocgen`
Type: `boolean`
Disables [automatic argType](../arg-types.mdx#automatic-argtype-inference) and component property inference with any of the supported static analysis tools based on the framework you are using.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### `test.disableSourcemaps`
Type: `boolean`
Overrides the default behavior of generating source maps for the build.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### `test.disableTreeShaking`
Type: `boolean`
Disables [tree shaking](https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking) in the build.
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/api/main-config/main-config-core.mdx b/docs/api/main-config/main-config-core.mdx
index e2531467af84..005796834ab2 100644
--- a/docs/api/main-config/main-config-core.mdx
+++ b/docs/api/main-config/main-config-core.mdx
@@ -1,8 +1,7 @@
---
-title: 'core'
+title: core
sidebar:
order: 8
- title: core
---
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -34,12 +33,8 @@ Default: `[]`
Configures the allowed hosts for the Storybook dev server, used for Origin and Host header validation. Storybook's localhost and local network (or [`--host`](../cli-options.mdx#dev)) addresses are always allowed. Use this when accessing your local Storybook instance through a reverse proxy (e.g. your webapp dev server). Set to `true` to disable hostname validation (insecure).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## `builder`
Type:
@@ -55,16 +50,14 @@ Type:
Configures Storybook's builder, [Vite](../../builders/vite.mdx) or [Webpack](../../builders/webpack.mdx).
- With the new [Framework API](../new-frameworks.mdx), [`framework.options.builder`](./main-config-framework.mdx#optionsbuilder) is now the preferred way to configure the builder.
- You should only use `core.builder.options` if you need to configure a builder that is not part of a framework.
-
+With the new [Framework API](../new-frameworks.mdx), [`framework.options.builder`](./main-config-framework.mdx#optionsbuilder) is now the preferred way to configure the builder.
-{/* prettier-ignore-start */}
+You should only use `core.builder.options` if you need to configure a builder that is not part of a framework.
-
+
-{/* prettier-ignore-end */}
+
## `channelOptions`
@@ -85,7 +78,6 @@ Configures the channel used by Storybook to communicate between the manager and
Only two properties are likely to be used:
-
### `channelOptions.maxDepth`
Type: `number`
@@ -102,75 +94,51 @@ Enable CORS headings to run document in a "secure context". See [SharedArrayBuff
This enables these headers in development-mode:
-* `Cross-Origin-Opener-Policy: same-origin`
-* `Cross-Origin-Embedder-Policy: require-corp`
-
-{/* prettier-ignore-start */}
+- `Cross-Origin-Opener-Policy: same-origin`
+- `Cross-Origin-Embedder-Policy: require-corp`
-{/* prettier-ignore-end */}
-
## `disableProjectJson`
Type: `boolean`
Disables the generation of `project.json`, a file containing Storybook metadata
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## `disableTelemetry`
Type: `boolean`
Disables Storybook's [telemetry collection](../../configure/telemetry.mdx).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## `disableWebpackDefaults`
Type: `boolean`
Disables Storybook's default Webpack configuration.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## `disableWhatsNewNotifications`
Type: `boolean`
Disables the "What's New" notifications in the UI for new Storybook versions and ecosystem updates (e.g., [addons](https://storybook.js.org/integrations/), [content](https://storybook.js.org/blog/), etc.).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## `enableCrashReports`
Type: `boolean`
Enable crash reports to be sent to Storybook [telemetry](../../configure/telemetry.mdx).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## `renderer`
Type: `RendererName`
diff --git a/docs/api/main-config/main-config-docs.mdx b/docs/api/main-config/main-config-docs.mdx
index 7c28850020ae..a31599bb5ef3 100644
--- a/docs/api/main-config/main-config-docs.mdx
+++ b/docs/api/main-config/main-config-docs.mdx
@@ -1,8 +1,7 @@
---
-title: 'docs'
+title: docs
sidebar:
order: 9
- title: docs
---
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -26,20 +25,12 @@ Default: `'Docs'`
Name used for generated documentation pages.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## `docsMode`
Type: `boolean`
Only show documentation pages in the sidebar (usually set with the `--docs` CLI flag).
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/api/main-config/main-config-env.mdx b/docs/api/main-config/main-config-env.mdx
index 5ed5392bf429..487fe6c911f2 100644
--- a/docs/api/main-config/main-config-env.mdx
+++ b/docs/api/main-config/main-config-env.mdx
@@ -1,8 +1,7 @@
---
-title: 'env'
+title: env
sidebar:
order: 10
- title: env
---
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -11,8 +10,4 @@ Type: `(config: { [key: string]: string }) => { [key: string]: string }`
Defines custom Storybook [environment variables](../../configure/environment-variables.mdx#using-storybook-configuration).
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/api/main-config/main-config-features.mdx b/docs/api/main-config/main-config-features.mdx
index 1b9fa4e69c13..1c2c55dcd262 100644
--- a/docs/api/main-config/main-config-features.mdx
+++ b/docs/api/main-config/main-config-features.mdx
@@ -1,8 +1,7 @@
---
-title: 'features'
+title: features
sidebar:
order: 11
- title: features
---
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -32,6 +31,7 @@ Type:
viewport?: boolean;
}
```
+
@@ -55,6 +55,7 @@ Type:
viewport?: boolean;
}
```
+
@@ -77,8 +78,8 @@ Type:
viewport?: boolean;
}
```
-
+
Enables Storybook's additional features.
@@ -110,12 +111,8 @@ Default: `true`
Filter args with a "target" on the type from the render function.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## `backgrounds`
Type: `boolean`
@@ -160,12 +157,8 @@ Type: `boolean`
Set `NODE_ENV` to `'development'` in built Storybooks for better testing and debugging capabilities.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## `experimentalCodeExamples`
@@ -186,14 +179,10 @@ Unlike the current implementation, this method reads the actual stories source f
Type: `boolean`
-Enable the [experimental `.test` method with the CSF Next format](../csf/csf-next#storytest).
-
-{/* prettier-ignore-start */}
+Enable the [experimental `.test` method with the CSF Next format](../csf/csf-next.mdx#storytest).
-{/* prettier-ignore-end */}
-
## `highlight`
@@ -218,12 +207,8 @@ Type: `boolean`
Apply decorators from preview.js before decorators from addons or frameworks. [More information](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#changed-decorator-order-between-previewjs-and-addonsframeworks).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## `measure`
Type: `boolean`
diff --git a/docs/api/main-config/main-config-framework.mdx b/docs/api/main-config/main-config-framework.mdx
index 3b2a2e7b38e4..6da060baaa5b 100644
--- a/docs/api/main-config/main-config-framework.mdx
+++ b/docs/api/main-config/main-config-framework.mdx
@@ -1,8 +1,7 @@
---
-title: 'framework'
+title: framework
sidebar:
order: 2
- title: framework
---
(**Required**)
@@ -13,12 +12,8 @@ Type: `FrameworkName | { name: FrameworkName; options?: FrameworkOptions }`
Configures Storybook based on a set of [framework-specific](../../configure/integration/frameworks.mdx) settings.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## `name`
Type: `string`
diff --git a/docs/api/main-config/main-config-indexers.mdx b/docs/api/main-config/main-config-indexers.mdx
index 9fce870fcc6c..042fe1759dbc 100644
--- a/docs/api/main-config/main-config-indexers.mdx
+++ b/docs/api/main-config/main-config-indexers.mdx
@@ -1,14 +1,15 @@
---
-title: 'indexers'
+title: indexers
sidebar:
order: 12
- title: indexers
---
(⚠️ **Experimental**)
- While this feature is experimental, it must be specified by the `experimental_indexers` property of [`StorybookConfig`](./main-config.mdx).
+
+While this feature is experimental, it must be specified by the `experimental_indexers` property of [`StorybookConfig`](./main-config.mdx).
+
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -21,12 +22,8 @@ The indexers API is an advanced feature that allows you to customize Storybook's
They are defined as a function that returns the full list of indexers, including the existing ones. This allows you to add your own indexer to the list, or to replace an existing one:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Unless your indexer is doing something relatively trivial (e.g. [indexing stories with a different naming convention](../../configure/user-interface/sidebar-and-urls.mdx#story-indexers)), in addition to indexing the file, you will likely need to [transpile it to CSF](#transpiling-to-csf) so that Storybook can read them in the browser.
## `Indexer`
@@ -157,7 +154,7 @@ Default: Auto-generated from [`title`](#title)
Define the custom id for meta of the entry.
-If specified, the export default (meta) in the CSF file *must* have a corresponding `id` property, to be correctly matched.
+If specified, the export default (meta) in the CSF file _must_ have a corresponding `id` property, to be correctly matched.
##### `name`
@@ -183,12 +180,8 @@ Determines the location of the entry in the sidebar.
Most of the time, you should **not** specify a title, so that your indexer will use the default naming behavior. When specifying a title, you **must** use the [`makeTitle`](#maketitle) function provided in [`IndexerOptions`](#indexeroptions) to also use this behavior. For example, here's an indexer that merely appends a "Custom" prefix to the title derived from the file name:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
##### `__id`
Type: `string`
@@ -203,7 +196,7 @@ Only use this if you need to override the auto-generated id.
## Transpiling to CSF
-The value of [`importPath`](#importpath) in an [`IndexInput`](#indexinput) must resolve to a [CSF](../csf/index.mdx) file. Most custom indexers, however, are only necessary because the input is *not* CSF. Therefore, you will likely need to transpile the input to CSF, so that Storybook can read it in the browser and render your stories.
+The value of [`importPath`](#importpath) in an [`IndexInput`](#indexinput) must resolve to a [CSF](../csf/index.mdx) file. Most custom indexers, however, are only necessary because the input is _not_ CSF. Therefore, you will likely need to transpile the input to CSF, so that Storybook can read it in the browser and render your stories.
Transpiling the custom source format to CSF is beyond the scope of this documentation. This transpilation is often done at the builder level ([Vite](../../builders/vite.mdx) and/or [Webpack](../../builders/webpack.mdx)), and we recommend using [unplugin](https://github.com/unjs/unplugin) to create plugins for multiple builders.
@@ -270,234 +263,227 @@ export const Primary = {
};
```
-### Examples
+## Examples
Some example usages of custom indexers include:
- Generating stories dynamically from fixture data or API endpoints
-
- This indexer generates stories for components based on JSON fixture data. It looks for `*.stories.json` files in the project, adds them to the index and separately converts their content to CSF.
-
- {/* prettier-ignore-start */}
+Generating stories dynamically from fixture data or API endpoints
-
+This indexer generates stories for components based on JSON fixture data. It looks for `*.stories.json` files in the project, adds them to the index and separately converts their content to CSF.
- {/* prettier-ignore-end */}
+
- An example input JSON file could look like this:
+An example input JSON file could look like this:
- ```json
- {
- "Button": {
- "componentPath": "./button/Button.jsx",
- "stories": {
- "Primary": {
- "args": {
- "primary": true
- },
- "Secondary": {
- "args": {
- "primary": false
- }
+```json
+{
+ "Button": {
+ "componentPath": "./button/Button.jsx",
+ "stories": {
+ "Primary": {
+ "args": {
+ "primary": true
+ }
+ },
+ "Secondary": {
+ "args": {
+ "primary": false
}
}
- },
- "Dialog": {
- "componentPath": "./dialog/Dialog.jsx",
- "stories": {
- "Closed": {},
- "Open": {
- "args": {
- "isOpen": true
- }
- },
+ }
+ },
+ "Dialog": {
+ "componentPath": "./dialog/Dialog.jsx",
+ "stories": {
+ "Closed": {},
+ "Open": {
+ "args": {
+ "isOpen": true
+ }
}
}
}
- ```
+}
+```
- A builder plugin will then need to transform the JSON file into a regular CSF file. This transformation could be done with a Vite plugin similar to this:
+A builder plugin will then need to transform the JSON file into a regular CSF file. This transformation could be done with a Vite plugin similar to this:
- ```ts
- // vite-plugin-storybook-json-stories.ts
+```ts
+// vite-plugin-storybook-json-stories.ts
- import type { PluginOption } from 'vite';
- import fs from 'fs/promises';
+import type { PluginOption } from 'vite';
+import fs from 'fs/promises';
- function JsonStoriesPlugin(): PluginOption {
- return {
- name: 'vite-plugin-storybook-json-stories',
- load(id) {
- if (!id.startsWith('virtual:jsonstories')) {
- return;
- }
+function JsonStoriesPlugin(): PluginOption {
+ return {
+ name: 'vite-plugin-storybook-json-stories',
+ load(id) {
+ if (!id.startsWith('virtual:jsonstories')) {
+ return;
+ }
- const [, fileName, componentName] = id.split('--');
- const content = JSON.parse(fs.readFileSync(fileName));
+ const [, fileName, componentName] = id.split('--');
+ const content = JSON.parse(fs.readFileSync(fileName));
- const { componentPath, stories } = getComponentStoriesFromJson(content, componentName);
+ const { componentPath, stories } = getComponentStoriesFromJson(content, componentName);
- return `
- import ${componentName} from '${componentPath}';
+ return `
+ import ${componentName} from '${componentPath}';
- export default { component: ${componentName} };
+ export default { component: ${componentName} };
+
+ ${stories.map((story) => `export const ${story.name} = ${story.config};\n`)}
+ `;
+ },
+ };
+}
+```
- ${stories.map((story) => `export const ${story.name} = ${story.config};\n`)}
- `;
- },
- };
- }
- ```
- Generating stories with an alternative API
+Generating stories with an alternative API
+
+You can use a custom indexer and builder plugin to create your API to define stories extending the CSF format. To learn more, see the following [proof of concept](https://stackblitz.com/edit/github-h2rgfk?file=README.md) to set up a custom indexer to generate stories dynamically. It contains everything needed to support such a feature, including the indexer, a Vite plugin, and a Webpack loader.
- You can use a custom indexer and builder plugin to create your API to define stories extending the CSF format. To learn more, see the following [proof of concept](https://stackblitz.com/edit/github-h2rgfk?file=README.md) to set up a custom indexer to generate stories dynamically. It contains everything needed to support such a feature, including the indexer, a Vite plugin, and a Webpack loader.
- Defining stories in non-JavaScript language
+Defining stories in non-JavaScript language
- Custom indexers can be used for an advanced purpose: defining stories in any language, including template languages, and converting the files to CSF. To see examples of this in action, you can refer to [`@storybook/addon-svelte-csf`](https://github.com/storybookjs/addon-svelte-csf) for Svelte template syntax and [`storybook-vue-addon`](https://github.com/tobiasdiez/storybook-vue-addon) for Vue template syntax.
-
+Custom indexers can be used for an advanced purpose: defining stories in any language, including template languages, and converting the files to CSF. To see examples of this in action, you can refer to [`@storybook/addon-svelte-csf`](https://github.com/storybookjs/addon-svelte-csf) for Svelte template syntax and [`storybook-vue-addon`](https://github.com/tobiasdiez/storybook-vue-addon) for Vue template syntax.
+
- Adding sidebar links from a URL collection
-
- The indexer API is flexible enough to let you process arbitrary content, so long as your framework tooling can transform the exports in that content into actual stories it can run. This advanced example demonstrates how you can create a custom indexer to process a collection of URLs, extract the title and URL from each page, and render them as sidebar links in the UI. Implemented with Svelte, it can be adapted to any framework.
-
- Start by creating the URL collection file (i.e., `src/MyLinks.url.js`) with a list of URLs listed as named exports. The indexer will use the export name as the story title and the value as the unique identifier.
-
- ```js title="MyLinks.url.js"
- export default {};
-
- export const DesignTokens = 'https://www.designtokens.org/';
- export const CobaltUI = 'https://cobalt-ui.pages.dev/';
- export const MiseEnMode = 'https://mode.place/';
- export const IndexerAPI = 'https://github.com/storybookjs/storybook/discussions/23176';
- ```
-
- Adjust your Vite configuration file to include a custom plugin complementing the indexer. This will allow Storybook to process and import the URL collection file as stories.
-
- ```ts title="vite.config.ts"
- import * as acorn from 'acorn';
- import * as walk from 'acorn-walk';
- import { defineConfig, type Plugin } from 'vite';
- import { svelte } from '@sveltejs/vite-plugin-svelte';
-
- function StorybookUrlLinksPlugin(): Plugin {
- return {
- name: 'storybook-url-links',
- async transform(code: string, id: string) {
- if (id.endsWith('.url.js')) {
- const ast = acorn.parse(code, {
- ecmaVersion: 2020,
- sourceType: 'module',
- });
-
- const namedExports: string[] = [];
- let defaultExport = 'export default {};';
-
- walk.simple(ast, {
- // Extracts the named exports, those represent our stories, and for each of them, we'll return a valid Svelte component.
- ExportNamedDeclaration(node: acorn.ExportNamedDeclaration) {
- if (
- node.declaration &&
- node.declaration.type === 'VariableDeclaration'
- ) {
- node.declaration.declarations.forEach((declaration) => {
- if ('name' in declaration.id) {
- namedExports.push(declaration.id.name);
- }
- });
- }
- },
- // Preserve our default export.
- ExportDefaultDeclaration(node: acorn.ExportDefaultDeclaration) {
- defaultExport = code.slice(node.start, node.end);
- },
- });
-
- return {
- code: `
- import RedirectBack from '../../.storybook/components/RedirectBack.svelte';
- ${namedExports
- .map(
- (name) =>
- `export const ${name} = () => new RedirectBack();`
- )
- .join('\n')}
- ${defaultExport}
- `,
- map: null,
- };
- }
- },
- };
- }
+Adding sidebar links from a URL collection
- export default defineConfig({
- plugins: [StorybookUrlLinksPlugin(), svelte()],
- })
- ```
-
- Update your Storybook configuration (i.e., `.storybook/main.js|ts`) to include the custom indexer.
-
- ```ts title=".storybook/main.js|ts"
- // Replace your-framework with the framework you are using, e.g. sveltekit or svelte-vite
- import type { StorybookConfig } from '@storybook/your-framework';
- import type { Indexer } from 'storybook/internal/types';
-
- const urlIndexer: Indexer = {
- test: /\.url\.js$/,
- createIndex: async (fileName, { makeTitle }) => {
- const fileData = await import(fileName);
-
- return Object.entries(fileData)
- .filter(([key]) => key != 'default')
- .map(([name, url]) => {
- return {
- type: 'docs',
- importPath: fileName,
- exportName: name,
- title: makeTitle(name)
- .replace(/([a-z])([A-Z])/g, '$1 $2')
- .trim(),
- __id: `url--${name}--${encodeURIComponent(url as string)}`,
- tags: ['!autodocs', 'url']
- };
+The indexer API is flexible enough to let you process arbitrary content, so long as your framework tooling can transform the exports in that content into actual stories it can run. This advanced example demonstrates how you can create a custom indexer to process a collection of URLs, extract the title and URL from each page, and render them as sidebar links in the UI. Implemented with Svelte, it can be adapted to any framework.
+
+Start by creating the URL collection file (i.e., `src/MyLinks.url.js`) with a list of URLs listed as named exports. The indexer will use the export name as the story title and the value as the unique identifier.
+
+```js title="MyLinks.url.js"
+export default {};
+
+export const DesignTokens = 'https://www.designtokens.org/';
+export const CobaltUI = 'https://cobalt-ui.pages.dev/';
+export const MiseEnMode = 'https://mode.place/';
+export const IndexerAPI = 'https://github.com/storybookjs/storybook/discussions/23176';
+```
+
+Adjust your Vite configuration file to include a custom plugin complementing the indexer. This will allow Storybook to process and import the URL collection file as stories.
+
+```ts title="vite.config.ts"
+import * as acorn from 'acorn';
+import * as walk from 'acorn-walk';
+import { defineConfig, type Plugin } from 'vite';
+import { svelte } from '@sveltejs/vite-plugin-svelte';
+
+function StorybookUrlLinksPlugin(): Plugin {
+ return {
+ name: 'storybook-url-links',
+ async transform(code: string, id: string) {
+ if (id.endsWith('.url.js')) {
+ const ast = acorn.parse(code, {
+ ecmaVersion: 2020,
+ sourceType: 'module',
+ });
+
+ const namedExports: string[] = [];
+ let defaultExport = 'export default {};';
+
+ walk.simple(ast, {
+ // Extracts the named exports, those represent our stories, and for each of them, we'll return a valid Svelte component.
+ ExportNamedDeclaration(node: acorn.ExportNamedDeclaration) {
+ if (node.declaration && node.declaration.type === 'VariableDeclaration') {
+ node.declaration.declarations.forEach((declaration) => {
+ if ('name' in declaration.id) {
+ namedExports.push(declaration.id.name);
+ }
+ });
+ }
+ },
+ // Preserve our default export.
+ ExportDefaultDeclaration(node: acorn.ExportDefaultDeclaration) {
+ defaultExport = code.slice(node.start, node.end);
+ },
});
- }
- };
- const config: StorybookConfig = {
- stories: ['../src/**/*.stories.@(js|ts|svelte)', '../src/**/*.url.js'],
- framework: {
- name: '@storybook/svelte-vite',
- options: {},
+ return {
+ code: `
+ import RedirectBack from '../../.storybook/components/RedirectBack.svelte';
+ ${namedExports
+ .map((name) => `export const ${name} = () => new RedirectBack();`)
+ .join('\n')}
+ ${defaultExport}
+ `,
+ map: null,
+ };
+ }
},
- experimental_indexers: async (existingIndexers) => [urlIndexer, ...existingIndexers]
};
- export default config;
- ```
+}
+
+export default defineConfig({
+ plugins: [StorybookUrlLinksPlugin(), svelte()],
+});
+```
+
+Update your Storybook configuration (i.e., `.storybook/main.js|ts`) to include the custom indexer.
+
+```ts title=".storybook/main.js|ts"
+// Replace your-framework with the framework you are using, e.g. sveltekit or svelte-vite
+import type { StorybookConfig } from '@storybook/your-framework';
+import type { Indexer } from 'storybook/internal/types';
+
+const urlIndexer: Indexer = {
+ test: /\.url\.js$/,
+ createIndex: async (fileName, { makeTitle }) => {
+ const fileData = await import(fileName);
+
+ return Object.entries(fileData)
+ .filter(([key]) => key != 'default')
+ .map(([name, url]) => {
+ return {
+ type: 'docs',
+ importPath: fileName,
+ exportName: name,
+ title: makeTitle(name)
+ .replace(/([a-z])([A-Z])/g, '$1 $2')
+ .trim(),
+ __id: `url--${name}--${encodeURIComponent(url as string)}`,
+ tags: ['!autodocs', 'url'],
+ };
+ });
+ },
+};
- Add a Storybook UI configuration file (i.e., `.storybook/manager.js|ts`) to render the indexed URLs as sidebar links in the UI:
+const config: StorybookConfig = {
+ stories: ['../src/**/*.stories.@(js|ts|svelte)', '../src/**/*.url.js'],
+ framework: {
+ name: '@storybook/svelte-vite',
+ options: {},
+ },
+ experimental_indexers: async (existingIndexers) => [urlIndexer, ...existingIndexers],
+};
+export default config;
+```
- ```ts title=".storybook/manager.ts"
- import { addons } from 'storybook/manager-api';
+Add a Storybook UI configuration file (i.e., `.storybook/manager.js|ts`) to render the indexed URLs as sidebar links in the UI:
- import SidebarLabelWrapper from './components/SidebarLabelWrapper.tsx';
+```ts title=".storybook/manager.ts"
+import { addons } from 'storybook/manager-api';
- addons.setConfig({
- sidebar: {
- renderLabel: (item) => SidebarLabelWrapper({ item }),
- },
- });
- ```
+import SidebarLabelWrapper from './components/SidebarLabelWrapper.tsx';
+
+addons.setConfig({
+ sidebar: {
+ renderLabel: (item) => SidebarLabelWrapper({ item }),
+ },
+});
+```
- This example's code and live demo are available on [StackBlitz](https://stackblitz.com/~/github.com/Sidnioulz/storybook-sidebar-urls).
+This example's code and live demo are available on [StackBlitz](https://stackblitz.com/~/github.com/Sidnioulz/storybook-sidebar-urls).
diff --git a/docs/api/main-config/main-config-log-level.mdx b/docs/api/main-config/main-config-log-level.mdx
index 064be3953f3f..aa8bc52c69a5 100644
--- a/docs/api/main-config/main-config-log-level.mdx
+++ b/docs/api/main-config/main-config-log-level.mdx
@@ -1,8 +1,7 @@
---
-title: 'logLevel'
+title: logLevel
sidebar:
order: 13
- title: logLevel
---
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -13,8 +12,4 @@ Default: `'info'`
Configures Storybook's logs in the browser terminal. Useful for debugging.
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/api/main-config/main-config-manager-head.mdx b/docs/api/main-config/main-config-manager-head.mdx
index 8af2641db0c1..29a1a47302e5 100644
--- a/docs/api/main-config/main-config-manager-head.mdx
+++ b/docs/api/main-config/main-config-manager-head.mdx
@@ -1,8 +1,7 @@
---
-title: 'managerHead'
+title: managerHead
sidebar:
order: 14
- title: managerHead
---
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -13,14 +12,10 @@ Programmatically adjust the manager's `` of your Storybook. For example, l
- If you don't need to programmatically adjust the manager head, you can add scripts and styles to `manager-head.html` instead.
-
+If you don't need to programmatically adjust the manager head, you can add scripts and styles to `manager-head.html` instead.
+
For example, you can conditionally add scripts or styles, depending on the environment:
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/api/main-config/main-config-preview-annotations.mdx b/docs/api/main-config/main-config-preview-annotations.mdx
index cf5a1bea2419..d2d66b889d9e 100644
--- a/docs/api/main-config/main-config-preview-annotations.mdx
+++ b/docs/api/main-config/main-config-preview-annotations.mdx
@@ -1,8 +1,7 @@
---
-title: 'previewAnnotations'
+title: previewAnnotations
sidebar:
order: 15
- title: previewAnnotations
---
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -12,7 +11,9 @@ Type: `string[] | ((config: string[], options: Options) => string[] | Promise
- Mostly used by [frameworks](../../contribute/framework.mdx#previewjs-example). Storybook users and [addon authors](../../addons/writing-presets.mdx) should add scripts to [`preview.js`](../../configure/index.mdx#configure-story-rendering) instead.
+
+Mostly used by [frameworks](../../contribute/framework.mdx#previewjs-example). Storybook users and [addon authors](../../addons/writing-presets.mdx) should add scripts to [`preview.js`](../../configure/index.mdx#configure-story-rendering) instead.
+
```ts
diff --git a/docs/api/main-config/main-config-preview-body.mdx b/docs/api/main-config/main-config-preview-body.mdx
index 0777c1a35904..e904ffe2523f 100644
--- a/docs/api/main-config/main-config-preview-body.mdx
+++ b/docs/api/main-config/main-config-preview-body.mdx
@@ -1,8 +1,7 @@
---
-title: 'previewBody'
+title: previewBody
sidebar:
order: 16
- title: previewBody
---
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -13,14 +12,10 @@ Programmatically adjust the [preview ``](../../configure/story-rendering.m
- If you don't need to programmatically adjust the preview body, you can add scripts and styles to [`preview-body.html`](../../configure/story-rendering.mdx#adding-to-body) instead.
-
+If you don't need to programmatically adjust the preview body, you can add scripts and styles to [`preview-body.html`](../../configure/story-rendering.mdx#adding-to-body) instead.
+
For example, you can conditionally add scripts or styles, depending on the environment:
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/api/main-config/main-config-preview-head.mdx b/docs/api/main-config/main-config-preview-head.mdx
index 8745bc524edb..5bf40ecb9321 100644
--- a/docs/api/main-config/main-config-preview-head.mdx
+++ b/docs/api/main-config/main-config-preview-head.mdx
@@ -1,8 +1,7 @@
---
-title: 'previewHead'
+title: previewHead
sidebar:
order: 17
- title: previewHead
---
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -12,13 +11,11 @@ Type: `(head: string) => string`
Programmatically adjust the [preview ``](../../configure/story-rendering.mdx#adding-to-head) of your Storybook. Most often used by [addon authors](../../addons/writing-presets.mdx#ui-configuration).
- If you don't need to programmatically adjust the preview head, you can add scripts and styles to [`preview-head.html`](../../configure/story-rendering.mdx#adding-to-head) instead.
+
+If you don't need to programmatically adjust the preview head, you can add scripts and styles to [`preview-head.html`](../../configure/story-rendering.mdx#adding-to-head) instead.
+
For example, you can conditionally add scripts or styles, depending on the environment:
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/api/main-config/main-config-refs.mdx b/docs/api/main-config/main-config-refs.mdx
index 33f7c69c5803..581f23503f80 100644
--- a/docs/api/main-config/main-config-refs.mdx
+++ b/docs/api/main-config/main-config-refs.mdx
@@ -1,8 +1,7 @@
---
-title: 'refs'
+title: refs
sidebar:
order: 18
- title: refs
---
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -19,28 +18,16 @@ Type:
Configures [Storybook composition](../../sharing/storybook-composition.mdx).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Using a function
You can use a function to dynamically configure refs:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Disable a ref
Some package dependencies automatically [compose their Storybook in yours](../../sharing/package-composition.mdx). You can disable this behavior by setting `disable` to `true` for the package name:
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/api/main-config/main-config-static-dirs.mdx b/docs/api/main-config/main-config-static-dirs.mdx
index 0207e0b5e67d..f33305cd3d09 100644
--- a/docs/api/main-config/main-config-static-dirs.mdx
+++ b/docs/api/main-config/main-config-static-dirs.mdx
@@ -1,8 +1,7 @@
---
-title: 'staticDirs'
+title: staticDirs
sidebar:
order: 19
- title: staticDirs
---
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -11,22 +10,16 @@ Type: `(string | { from: string; to: string })[]`
Sets a list of directories of [static files](../../configure/integration/images-and-assets.mdx#serving-static-files-via-storybook-configuration) to be loaded by Storybook.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
+
When using Vite-based frameworks, additional directories may be copied to your build directory because of Vite's own [static asset handling](https://vite.dev/guide/assets#the-public-directory). You can set Vite's `publicDir` option to `false` to disable this behavior.
+
## With configuration objects
You can also use a configuration object to define the directories:
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
\ No newline at end of file
diff --git a/docs/api/main-config/main-config-stories.mdx b/docs/api/main-config/main-config-stories.mdx
index 9555cc1e356e..ef50a26d0f06 100644
--- a/docs/api/main-config/main-config-stories.mdx
+++ b/docs/api/main-config/main-config-stories.mdx
@@ -1,8 +1,7 @@
---
-title: 'stories'
+title: stories
sidebar:
order: 3
- title: stories
---
(**Required**)
@@ -25,16 +24,14 @@ Configures Storybook to load stories from the specified locations. The intention
└── Button.stories.ts
```
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- If you want to use a different naming convention, you can alter the glob using the syntax supported by [picomatch](https://github.com/micromatch/picomatch#globbing-features).
- Keep in mind that some addons may assume Storybook's default naming convention.
+If you want to use a different naming convention, you can alter the glob using the syntax supported by [picomatch](https://github.com/micromatch/picomatch#globbing-features).
+
+Keep in mind that some addons may assume Storybook's default naming convention.
+
## With an array of globs
@@ -43,24 +40,16 @@ Storybook will load stories from your project as found by this array of globs (p
Stories are loaded in the order they are defined in the array. This allows you to control the order in which stories are displayed in the sidebar:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## With a configuration object
Additionally, you can customize your Storybook configuration to load your stories based on a configuration object. This object is of the type `StoriesSpecifier`, defined below.
For example, if you wanted to load your stories from a `packages/components` directory, you could adjust your `stories` configuration field into the following:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
When Storybook starts, it will look for any file containing the `stories` extension inside the `packages/components` directory and generate the titles for your stories.
### `StoriesSpecifier`
@@ -102,13 +91,11 @@ When [auto-titling](../../configure/user-interface/sidebar-and-urls.mdx#csf-30-a
## With a custom implementation
- 💡 Storybook now statically analyzes the configuration file to improve performance. Loading stories with a custom implementation may de-optimize or break this ability.
+
+Storybook now statically analyzes the configuration file to improve performance. Loading stories with a custom implementation may de-optimize or break this ability.
+
You can also adjust your Storybook configuration and implement custom logic to load your stories. For example, suppose you were working on a project that includes a particular pattern that the conventional ways of loading stories could not solve. In that case, you could adjust your configuration as follows:
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/api/main-config/main-config-swc.mdx b/docs/api/main-config/main-config-swc.mdx
index a896e63079f3..16d245866077 100644
--- a/docs/api/main-config/main-config-swc.mdx
+++ b/docs/api/main-config/main-config-swc.mdx
@@ -1,8 +1,7 @@
---
-title: 'swc'
+title: swc
sidebar:
order: 20
- title: swc
---
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -11,12 +10,8 @@ Type: `(config: swc.Options, options: Options) => swc.Options | Promise
-{/* prettier-ignore-end */}
-
## `SWC.Options`
The options provided by [SWC](https://swc.rs/) are only applicable if you've enabled the [`@storybook/addon-webpack5-compiler-swc`](https://storybook.js.org/addons/@storybook/addon-webpack5-compiler-swc) addon.
diff --git a/docs/api/main-config/main-config-tags.mdx b/docs/api/main-config/main-config-tags.mdx
index d0cc7613bb4a..96bd848ddff5 100644
--- a/docs/api/main-config/main-config-tags.mdx
+++ b/docs/api/main-config/main-config-tags.mdx
@@ -1,8 +1,7 @@
---
-title: 'tags'
+title: tags
sidebar:
order: 21
- title: tags
---
Parent: [main.js|ts configuration](./main-config.mdx)
diff --git a/docs/api/main-config/main-config-typescript.mdx b/docs/api/main-config/main-config-typescript.mdx
index c23f8e693a77..af07b03a457d 100644
--- a/docs/api/main-config/main-config-typescript.mdx
+++ b/docs/api/main-config/main-config-typescript.mdx
@@ -1,35 +1,38 @@
---
-title: 'typescript'
+title: typescript
sidebar:
order: 22
- title: typescript
---
Parent: [main.js|ts configuration](./main-config.mdx)
Type:
-
- ```ts
- {
- check?: boolean;
- checkOptions?: CheckOptions;
- reactDocgen?: 'react-docgen' | 'react-docgen-typescript' | false;
- reactDocgenTypescriptOptions?: ReactDocgenTypescriptOptions;
- skipCompiler?: boolean;
- }
- ```
-
-
-
- ```ts
- {
- check?: boolean;
- checkOptions?: CheckOptions;
- skipCompiler?: boolean;
- }
- ```
-
+
+
+```ts
+{
+ check?: boolean;
+ checkOptions?: CheckOptions;
+ reactDocgen?: 'react-docgen' | 'react-docgen-typescript' | false;
+ reactDocgenTypescriptOptions?: ReactDocgenTypescriptOptions;
+ skipCompiler?: boolean;
+}
+```
+
+
+
+
+
+```ts
+{
+ check?: boolean;
+ checkOptions?: CheckOptions;
+ skipCompiler?: boolean;
+}
+```
+
+
Configures how Storybook handles [TypeScript files](../../configure/integration/typescript.mdx).
@@ -39,54 +42,40 @@ Type: `boolean`
Optionally run [fork-ts-checker-webpack-plugin](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin). Note that because this uses a Webpack plugin, it is only available when using the [Webpack builder](../../builders/webpack.mdx).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## `checkOptions`
Type: `CheckOptions`
Options to pass to `fork-ts-checker-webpack-plugin`, if [enabled](#check). See [docs for available options](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/blob/v4.1.6/README.md#options).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
-
- ## `reactDocgen`
-
- Type: `'react-docgen' | 'react-docgen-typescript' | false`
+
- Default:
+## `reactDocgen`
- * `false`: if `@storybook/react` is not installed
- * `'react-docgen'`: if `@storybook/react` is installed
+Type: `'react-docgen' | 'react-docgen-typescript' | false`
- Configures which library, if any, Storybook uses to parse React components, [react-docgen](https://github.com/reactjs/react-docgen) or [react-docgen-typescript](https://github.com/styleguidist/react-docgen-typescript). Set to `false` to disable parsing React components. `react-docgen-typescript` invokes the TypeScript compiler, which makes it slow but generally accurate. `react-docgen` performs its own analysis, which is much faster but incomplete.
+Default:
- {/* prettier-ignore-start */}
+- `false`: if `@storybook/react` is not installed
+- `'react-docgen'`: if `@storybook/react` is installed
-
+Configures which library, if any, Storybook uses to parse React components, [react-docgen](https://github.com/reactjs/react-docgen) or [react-docgen-typescript](https://github.com/styleguidist/react-docgen-typescript). Set to `false` to disable parsing React components. `react-docgen-typescript` invokes the TypeScript compiler, which makes it slow but generally accurate. `react-docgen` performs its own analysis, which is much faster but incomplete.
- {/* prettier-ignore-end */}
+
- ## `reactDocgenTypescriptOptions`
+## `reactDocgenTypescriptOptions`
- Type: `ReactDocgenTypescriptOptions`
+Type: `ReactDocgenTypescriptOptions`
- Configures the options to pass to `react-docgen-typescript-plugin` if `react-docgen-typescript` is enabled. See docs for available options [for Webpack projects](https://github.com/hipstersmoothie/react-docgen-typescript-plugin) or [for Vite projects](https://github.com/joshwooding/vite-plugin-react-docgen-typescript).
+Configures the options to pass to `react-docgen-typescript-plugin` if `react-docgen-typescript` is enabled. See docs for available options [for Webpack projects](https://github.com/hipstersmoothie/react-docgen-typescript-plugin) or [for Vite projects](https://github.com/joshwooding/vite-plugin-react-docgen-typescript).
- {/* prettier-ignore-start */}
+
-
-
- {/* prettier-ignore-end */}
-
+
## `skipCompiler`
@@ -94,8 +83,4 @@ Type: `boolean`
Disable parsing of TypeScript files through the compiler, which is used for Webpack5.
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/api/main-config/main-config-vite-final.mdx b/docs/api/main-config/main-config-vite-final.mdx
index c0761375db83..1169f59e895d 100644
--- a/docs/api/main-config/main-config-vite-final.mdx
+++ b/docs/api/main-config/main-config-vite-final.mdx
@@ -1,8 +1,7 @@
---
-title: 'viteFinal'
+title: viteFinal
sidebar:
order: 23
- title: viteFinal
---
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -11,12 +10,8 @@ Type: `(config: Vite.InlineConfig, options: Options) => Vite.InlineConfig | Prom
Customize Storybook's Vite setup when using the [Vite builder](../../builders/vite.mdx).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## `Options`
Type: `{ configType?: 'DEVELOPMENT' | 'PRODUCTION' }`
diff --git a/docs/api/main-config/main-config-webpack-final.mdx b/docs/api/main-config/main-config-webpack-final.mdx
index 07139fbd8dc9..360f90afd0b1 100644
--- a/docs/api/main-config/main-config-webpack-final.mdx
+++ b/docs/api/main-config/main-config-webpack-final.mdx
@@ -1,8 +1,7 @@
---
-title: 'webpackFinal'
+title: webpackFinal
sidebar:
order: 24
- title: webpackFinal
---
Parent: [main.js|ts configuration](./main-config.mdx)
@@ -11,12 +10,8 @@ Type: `async (config: Config, options: WebpackOptions) => Config`
Customize Storybook's Webpack setup when using the [webpack builder](../../builders/webpack.mdx).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## `Options`
Type: `{ configType?: 'DEVELOPMENT' | 'PRODUCTION' }`
diff --git a/docs/api/main-config/main-config.mdx b/docs/api/main-config/main-config.mdx
index bdcd243df931..a6e550a7ebf9 100644
--- a/docs/api/main-config/main-config.mdx
+++ b/docs/api/main-config/main-config.mdx
@@ -1,5 +1,5 @@
---
-title: 'Main configuration'
+title: Main configuration
sidebar:
order: 1
title: Overview
@@ -7,7 +7,6 @@ sidebar:
The main configuration defines a Storybook project's behavior, including the location of stories, addons to use, feature flags, and other project-specific settings.
-
## The main configuration file: `main.js` or `main.ts`
@@ -20,36 +19,32 @@ This configuration is defined in `.storybook/main.js|ts`, which is located relat
A typical Storybook configuration file looks like this:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## config
An object to configure Storybook containing the following properties:
-* [`framework`](./main-config-framework.mdx) (Required)
-* [`stories`](./main-config-stories.mdx) (Required)
-* [`addons`](./main-config-addons.mdx)
-* [`babel`](./main-config-babel.mdx)
-* [`babelDefault`](./main-config-babel-default.mdx)
-* [`build`](./main-config-build.mdx)
-* [`core`](./main-config-core.mdx)
-* [`docs`](./main-config-docs.mdx)
-* [`env`](./main-config-env.mdx)
-* [`features`](./main-config-features.mdx)
-* [`indexers`](./main-config-indexers.mdx) (⚠️ Experimental)
-* [`logLevel`](./main-config-log-level.mdx)
-* [`managerHead`](./main-config-manager-head.mdx)
-* [`previewAnnotations`](./main-config-preview-annotations.mdx)
-* [`previewBody`](./main-config-preview-body.mdx)
-* [`previewHead`](./main-config-preview-head.mdx)
-* [`refs`](./main-config-refs.mdx)
-* [`staticDirs`](./main-config-static-dirs.mdx)
-* [`swc`](./main-config-swc.mdx)
-* [`tags`](./main-config-tags.mdx)
-* [`typescript`](./main-config-typescript.mdx)
-* [`viteFinal`](./main-config-vite-final.mdx)
-* [`webpackFinal`](./main-config-webpack-final.mdx)
+- [`framework`](./main-config-framework.mdx) (Required)
+- [`stories`](./main-config-stories.mdx) (Required)
+- [`addons`](./main-config-addons.mdx)
+- [`babel`](./main-config-babel.mdx)
+- [`babelDefault`](./main-config-babel-default.mdx)
+- [`build`](./main-config-build.mdx)
+- [`core`](./main-config-core.mdx)
+- [`docs`](./main-config-docs.mdx)
+- [`env`](./main-config-env.mdx)
+- [`features`](./main-config-features.mdx)
+- [`indexers`](./main-config-indexers.mdx) (⚠️ Experimental)
+- [`logLevel`](./main-config-log-level.mdx)
+- [`managerHead`](./main-config-manager-head.mdx)
+- [`previewAnnotations`](./main-config-preview-annotations.mdx)
+- [`previewBody`](./main-config-preview-body.mdx)
+- [`previewHead`](./main-config-preview-head.mdx)
+- [`refs`](./main-config-refs.mdx)
+- [`staticDirs`](./main-config-static-dirs.mdx)
+- [`swc`](./main-config-swc.mdx)
+- [`tags`](./main-config-tags.mdx)
+- [`typescript`](./main-config-typescript.mdx)
+- [`viteFinal`](./main-config-vite-final.mdx)
+- [`webpackFinal`](./main-config-webpack-final.mdx)
diff --git a/docs/api/new-frameworks.mdx b/docs/api/new-frameworks.mdx
index 25809dd92f35..2f6ecf8c039c 100644
--- a/docs/api/new-frameworks.mdx
+++ b/docs/api/new-frameworks.mdx
@@ -1,8 +1,7 @@
---
-title: 'Frameworks'
+title: Frameworks
sidebar:
order: 7
- title: Frameworks
---
Storybook is architected to support diverse web frameworks, including React, Vue, Angular, Web Components, Svelte, and over a dozen others. This guide helps you get started on adding new framework support for Storybook.
@@ -46,12 +45,8 @@ These scripts pass an `options` object to `storybook/internal/server`, a library
For example, here’s the boilerplate to start the dev server with `storybook dev`:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Thus the essence of adding framework presets is just filling in that options object.
### Server options
@@ -60,24 +55,16 @@ As described above, the server `options` object does the heavy lifting of config
Let’s look at the `@storybook/vue`’s options definition:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
The value of the `framework` option (i.e., ‘vue’) is something that gets passed to addons and allows them to do specific tasks related to your framework.
The essence of this file is the framework presets, and these are standard [Storybook presets](../addons/writing-presets.mdx) -- you can look at framework packages in the Storybook monorepo (e.g. [React](https://github.com/storybookjs/storybook/blob/next/code/frameworks/react-vite/src/preset.ts), [Vue](https://github.com/storybookjs/storybook/blob/next/code/frameworks/vue3-vite/src/preset.ts), [Web Components](https://github.com/storybookjs/storybook/blob/next/code/frameworks/web-components-vite/src/preset.ts)) to see examples of framework-specific customizations.
While developing your custom framework, not maintained by Storybook, you can specify the path to the location file with the `frameworkPath` key:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
You can add a relative path to `frameworkPath`. Don't forget that they resolve from the Storybook configuration directory (i.e., `.storybook`) by default.
Make sure the `frameworkPath` ends up at the `dist/client/index.js` file within your framework app.
@@ -92,52 +79,32 @@ Storybook stories are ES6 objects that return a “renderable object.”
Consider the following React story:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
In this case, the renderable object is the React element, ``.
In most other frameworks, the renderable object is actually a plain JavaScript object.
Consider the following hypothetical example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
The design of this “renderable object” is framework-specific and should ideally match the idioms of that framework.
### Render function
The framework's render function is the entity responsible for converting the renderable object into DOM nodes. It is typically of the form:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Package structure
On the client side, the key file is [`src/client/preview.js`](../configure/index.mdx#configure-story-rendering):
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
The globals file typically sets up a single global variable that client-side code (such as addon-provided decorators) can refer to if needed to understand which framework it's running in:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
The `start` function abstracts all of Storybook’s framework-independent client-side (browser) code, and it takes the render function we defined above. For examples of render functions, see [React](https://github.com/storybookjs/storybook/blob/next/code/renderers/react/src/render.tsx), [Vue](https://github.com/storybookjs/storybook/blob/next/code/renderers/vue3/src/render.ts), [Angular](https://github.com/storybookjs/storybook/blob/next/code/frameworks/angular/src/client/render.ts), and [Web Components](https://github.com/storybookjs/storybook/blob/next/code/renderers/web-components/src/render.ts) in the Storybook monorepo.
diff --git a/docs/api/parameters.mdx b/docs/api/parameters.mdx
index 1af361bc580c..57f0619c8c42 100644
--- a/docs/api/parameters.mdx
+++ b/docs/api/parameters.mdx
@@ -1,8 +1,7 @@
---
-title: 'Parameters'
+title: Parameters
sidebar:
order: 4
- title: Parameters
---
Parameters are static metadata used to configure your [stories](../get-started/whats-a-story.mdx) and [addons](../addons/index.mdx) in Storybook. They are specified at the story, meta (component), project (global) levels.
@@ -11,40 +10,32 @@ Parameters are static metadata used to configure your [stories](../get-started/w
Parameters specified at the story level apply to that story only. They are defined in the `parameters` property of the story (named export):
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- Parameters specified at the story level will [override](#parameter-inheritance) those specified at the project level and meta (component) level.
+
+Parameters specified at the story level will [override](#parameter-inheritance) those specified at the project level and meta (component) level.
+
## Meta parameters
-Parameter's specified in a [CSF](../writing-stories/index.mdx#component-story-format-csf) file's meta configuration apply to all stories in that file. They are defined in the `parameters` property of the meta (or default export):
-
-{/* prettier-ignore-start */}
+Parameter's specified in a [CSF](../writing-stories/index.mdx#component-story-format) file's meta configuration apply to all stories in that file. They are defined in the `parameters` property of the meta (or default export):
-{/* prettier-ignore-end */}
-
- Parameters specified at the meta (component) level will [override](#parameter-inheritance) those specified at the project level.
+
+Parameters specified at the meta (component) level will [override](#parameter-inheritance) those specified at the project level.
+
## Project parameters
Parameters specified at the project (global) level apply to **all stories** in your Storybook. They are defined in the `parameters` property of the meta (or default export) in your `.storybook/preview.*` file:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Available parameters
Storybook only accepts a few parameters directly.
@@ -57,9 +48,9 @@ Default: `'padded'`
Specifies how the canvas should [lay out the story](../configure/story-layout.mdx).
-* **centered**: Center the story within the canvas
-* **padded**: (default) Add padding to the story
-* **fullscreen**: Show the story as-is, without padding
+- **centered**: Center the story within the canvas
+- **padded**: (default) Add padding to the story
+- **fullscreen**: Show the story as-is, without padding
### `options`
@@ -72,7 +63,9 @@ Type:
```
- The `options` parameter can *only* be applied at the [project level](#project-parameters).
+
+The `options` parameter can _only_ be applied at the [project level](#project-parameters).
+
#### `options.storySort`
@@ -101,13 +94,13 @@ Specifies the order in which stories are displayed in the Storybook UI.
When specifying a configuration object, the following options are available:
-* **includeNames**: Whether to include the story name in the sorting algorithm. Defaults to `false`.
-* **locales**: The locale to use when sorting stories. Defaults to your system locale.
-* **method**: The sorting method to use. Defaults to `alphabetical`.
- * **alphabetical**: Sort stories alphabetically by name.
- * **alphabetical-by-kind**: Sort stories alphabetically by kind, then by name.
- * **custom**: Use a custom sorting function.
-* **order**: Stories in the specified order will be displayed first, in the order specified. All other stories will be displayed after, in alphabetical order. The order array can accept a nested array to sort 2nd-level story kinds, e.g. `['Intro', 'Pages', ['Home', 'Login', 'Admin'], 'Components']`.
+- **includeNames**: Whether to include the story name in the sorting algorithm. Defaults to `false`.
+- **locales**: The locale to use when sorting stories. Defaults to your system locale.
+- **method**: The sorting method to use. Defaults to `alphabetical`.
+ - **alphabetical**: Sort stories alphabetically by name.
+ - **alphabetical-by-kind**: Sort stories alphabetically by kind, then by name.
+ - **custom**: Use a custom sorting function.
+- **order**: Stories in the specified order will be displayed first, in the order specified. All other stories will be displayed after, in alphabetical order. The order array can accept a nested array to sort 2nd-level story kinds, e.g. `['Intro', 'Pages', ['Home', 'Login', 'Admin'], 'Components']`.
When specifying a custom sorting function, the function behaves like a typical JavaScript sorting function. It accepts two stories to compare and returns a number. For example:
@@ -162,18 +155,18 @@ Default: `false`
Unhandled errors might cause false positive assertions. Setting this to `true` will prevent the [play function](../writing-stories/play-function.mdx) from failing and showing a warning when unhandled errors are thrown during execution.
-***
+---
### Essentials
All other parameters are contributed by features. The [essential feature's](../essentials/index.mdx) parameters are documented on their individual pages:
-* [Actions](../essentials/actions.mdx#parameters)
-* [Backgrounds](../essentials/backgrounds.mdx#parameters)
-* [Controls](../essentials/controls.mdx#parameters)
-* [Highlight](../essentials/highlight.mdx#parameters)
-* [Measure & Outline](../essentials/measure-and-outline.mdx#parameters)
-* [Viewport](../essentials/viewport.mdx#parameters)
+- [Actions](../essentials/actions.mdx#parameters)
+- [Backgrounds](../essentials/backgrounds.mdx#parameters)
+- [Controls](../essentials/controls.mdx#parameters)
+- [Highlight](../essentials/highlight.mdx#parameters)
+- [Measure & Outline](../essentials/measure-and-outline.mdx#parameters)
+- [Viewport](../essentials/viewport.mdx#parameters)
## Parameter inheritance
@@ -186,7 +179,9 @@ When specifying parameters, they are merged together in order of increasing spec
3. Story parameters
- Parameters are **merged**, so objects are deep-merged, but arrays and other properties are overwritten.
+
+Parameters are **merged**, so objects are deep-merged, but arrays and other properties are overwritten.
+
In other words, the following specifications of parameters:
diff --git a/docs/api/portable-stories/index.mdx b/docs/api/portable-stories/index.mdx
index b31d7bce0c07..3a90845e8021 100644
--- a/docs/api/portable-stories/index.mdx
+++ b/docs/api/portable-stories/index.mdx
@@ -2,5 +2,4 @@
title: Portable Stories
sidebar:
order: 6
- title: Portable Stories
----
\ No newline at end of file
+---
diff --git a/docs/api/portable-stories/portable-stories-jest.mdx b/docs/api/portable-stories/portable-stories-jest.mdx
index 83b10d28c963..9c7c483f0cc5 100644
--- a/docs/api/portable-stories/portable-stories-jest.mdx
+++ b/docs/api/portable-stories/portable-stories-jest.mdx
@@ -1,256 +1,245 @@
---
-title: 'Portable stories in Jest'
+title: Portable stories in Jest
sidebar:
title: Jest
order: 2
---
-
- Portable stories in Jest are currently only supported in [React](?renderer=react) and [Vue](?renderer=vue) projects.
-
- {/* End non-supported renderers */}
+
+
+Portable stories in Jest are currently only supported in [React](?renderer=react) and [Vue](?renderer=vue) projects.
+
+
+
+{/* End non-supported renderers */}
-
- If you are using the [experimental CSF Factories format](../../api/csf/csf-next.mdx), you don't need to use the portable stories API. Instead, you can [import and use your stories directly](../../api/csf/csf-next.mdx#manual).
-
-
-
- Portable stories are Storybook [stories](../../writing-stories/index.mdx) which can be used in external environments, such as [Jest](https://jestjs.io).
+
- Normally, Storybook composes a story and its [annotations](#annotations) automatically, as part of the [story pipeline](#story-pipeline). When using stories in Jest tests, you must handle the story pipeline yourself, which is what the [`composeStories`](#composestories) and [`composeStory`](#composestory) functions enable.
+If you are using the [experimental CSF Factories format](../../api/csf/csf-next.mdx), you don't need to use the portable stories API. Instead, you can [import and use your stories directly](../../api/csf/csf-next.mdx#manual).
-
- The API specified here is available in Storybook `8.2.7` and up. If you're using an older version of Storybook, you can upgrade to the latest version (`npx storybook@latest upgrade`) to use this API. If you're unable to upgrade, you can use previous API, which uses the `.play()` method instead of `.run()`, but is otherwise identical.
-
+
-
-
- **Using `Next.js`?** You need to do three things differently when using portable stories in Jest with Next.js projects:
+
- * Configure the [`next/jest.js` transformer](https://nextjs.org/docs/pages/building-your-application/testing/jest#manual-setup), which will handle all of the necessary Next.js configuration for you.
- * Import [`composeStories`](#composestories) or [`composeStory`](#composestory) from the `@storybook/nextjs` package (e.g. `import { composeStories } from '@storybook/nextjs'`).
- * Set up [internal module aliases](../../get-started/frameworks/nextjs.mdx#storybooknextjsexport-mocks) to ensure the framework configuration works correctly and to be able to mock and assert on them.
-
-
+
- ## composeStories
+Portable stories are Storybook [stories](../../writing-stories/index.mdx) which can be used in external environments, such as [Jest](https://jestjs.io).
- `composeStories` will process the component's stories you specify, compose each of them with the necessary [annotations](#annotations), and return an object containing the composed stories.
+Normally, Storybook composes a story and its [annotations](#annotations) automatically, as part of the [story pipeline](#story-pipeline). When using stories in Jest tests, you must handle the story pipeline yourself, which is what the [`composeStories`](#composestories) and [`composeStory`](#composestory) functions enable.
- By default, the composed story will render the component with the [args](../../writing-stories/args.mdx) that are defined in the story. You can also pass any props to the component in your test and those props will override the values passed in the story's args.
+
- {/* prettier-ignore-start */}
+The API specified here is available in Storybook `8.2.7` and up. If you're using an older version of Storybook, you can upgrade to the latest version (`npx storybook@latest upgrade`) to use this API. If you're unable to upgrade, you can use previous API, which uses the `.play()` method instead of `.run()`, but is otherwise identical.
-
+
- {/* prettier-ignore-end */}
+
- ### Type
+
- {/* prettier-ignore-start */}
+**Using `Next.js`?** You need to do three things differently when using portable stories in Jest with Next.js projects:
- ```ts
- (
- csfExports: CSF file exports,
- projectAnnotations?: ProjectAnnotations
- ) => Record
- ```
+- Configure the [`next/jest.js` transformer](https://nextjs.org/docs/pages/building-your-application/testing/jest#manual-setup), which will handle all of the necessary Next.js configuration for you.
+- Import [`composeStories`](#composestories) or [`composeStory`](#composestory) from the `@storybook/nextjs` package (e.g. `import { composeStories } from '@storybook/nextjs'`).
+- Set up [internal module aliases](../../get-started/frameworks/nextjs.mdx#storybooknextjsexport-mocks) to ensure the framework configuration works correctly and to be able to mock and assert on them.
- {/* prettier-ignore-end */}
+
- ### Parameters
+
- #### `csfExports`
+## composeStories
- (**Required**)
+`composeStories` will process the component's stories you specify, compose each of them with the necessary [annotations](#annotations), and return an object containing the composed stories.
- Type: CSF file exports
+By default, the composed story will render the component with the [args](../../writing-stories/args.mdx) that are defined in the story. You can also pass any props to the component in your test and those props will override the values passed in the story's args.
- Specifies which component's stories you want to compose. Pass the **full set of exports** from the CSF file (not the default export!). E.g. `import * as stories from './Button.stories'`
+
- #### `projectAnnotations`
+### Type
- Type: `ProjectAnnotation | ProjectAnnotation[]`
+```ts
+(
+ csfExports: CSF file exports,
+ projectAnnotations?: ProjectAnnotations
+) => Record
+```
- Specifies the project annotations to be applied to the composed stories.
+### Parameters
- This parameter is provided for convenience. You should likely use [`setProjectAnnotations`](#setprojectannotations) instead. Details about the `ProjectAnnotation` type can be found in that function's [`projectAnnotations`](#projectannotations-2) parameter.
+#### `csfExports`
- This parameter can be used to [override](#overriding-globals) the project annotations applied via `setProjectAnnotations`.
+(**Required**)
- ### Return
+Type: CSF file exports
- Type: `Record`
+Specifies which component's stories you want to compose. Pass the **full set of exports** from the CSF file (not the default export!). E.g. `import * as stories from './Button.stories'`
- An object where the keys are the names of the stories and the values are the composed stories.
+#### `projectAnnotations`
- Additionally, the composed story will have the following properties:
+Type: `ProjectAnnotation | ProjectAnnotation[]`
- | Property | Type | Description |
- | ---------- | ----------------------------------------- | ------------------------------------------------------------------------------------- |
- | args | `Record` | The story's [args](../../writing-stories/args.mdx) |
- | argTypes | `ArgType` | The story's [argTypes](../arg-types.mdx) |
- | id | `string` | The story's id |
- | parameters | `Record` | The story's [parameters](../parameters.mdx) |
- | play | `(context) => Promise \| undefined` | Executes the play function of a given story |
- | run | `(context) => Promise \| undefined` | [Mounts and executes the play function](#3-run) of a given story |
- | storyName | `string` | The story's name |
- | tags | `string[]` | The story's [tags](../../writing-stories/tags.mdx) |
+Specifies the project annotations to be applied to the composed stories.
- ## composeStory
+This parameter is provided for convenience. You should likely use [`setProjectAnnotations`](#setprojectannotations) instead. Details about the `ProjectAnnotation` type can be found in that function's [`projectAnnotations`](#projectannotations-2) parameter.
- You can use `composeStory` if you wish to compose a single story for a component.
+This parameter can be used to [override](#overriding-globals) the project annotations applied via `setProjectAnnotations`.
- {/* prettier-ignore-start */}
+### Return
-
+Type: `Record`
- {/* prettier-ignore-end */}
+An object where the keys are the names of the stories and the values are the composed stories.
- ### Type
+Additionally, the composed story will have the following properties:
- {/* prettier-ignore-start */}
+| Property | Type | Description |
+| ---------- | ----------------------------------------- | ---------------------------------------------------------------- |
+| args | `Record` | The story's [args](../../writing-stories/args.mdx) |
+| argTypes | `ArgType` | The story's [argTypes](../arg-types.mdx) |
+| id | `string` | The story's id |
+| parameters | `Record` | The story's [parameters](../parameters.mdx) |
+| play | `(context) => Promise \| undefined` | Executes the play function of a given story |
+| run | `(context) => Promise \| undefined` | [Mounts and executes the play function](#3-run) of a given story |
+| storyName | `string` | The story's name |
+| tags | `string[]` | The story's [tags](../../writing-stories/tags.mdx) |
- ```ts
- (
- story: Story export,
- componentAnnotations: Meta,
- projectAnnotations?: ProjectAnnotations,
- exportsName?: string
- ) => ComposedStoryFn
- ```
+## composeStory
- {/* prettier-ignore-end */}
+You can use `composeStory` if you wish to compose a single story for a component.
- ### Parameters
+
- #### `story`
+### Type
- (**Required**)
+```ts
+(
+ story: Story export,
+ componentAnnotations: Meta,
+ projectAnnotations?: ProjectAnnotations,
+ exportsName?: string
+) => ComposedStoryFn
+```
- Type: `Story export`
+### Parameters
- Specifies which story you want to compose.
+#### `story`
- #### `componentAnnotations`
+(**Required**)
- (**Required**)
+Type: `Story export`
- Type: `Meta`
+Specifies which story you want to compose.
- The default export from the stories file containing the [`story`](#story).
+#### `componentAnnotations`
- #### `projectAnnotations`
+(**Required**)
- Type: `ProjectAnnotation | ProjectAnnotation[]`
+Type: `Meta`
- Specifies the project annotations to be applied to the composed story.
+The default export from the stories file containing the [`story`](#story).
- This parameter is provided for convenience. You should likely use [`setProjectAnnotations`](#setprojectannotations) instead. Details about the `ProjectAnnotation` type can be found in that function's [`projectAnnotations`](#projectannotations-2) parameter.
+#### `projectAnnotations`
- This parameter can be used to [override](#overriding-globals) the project annotations applied via `setProjectAnnotations`.
+Type: `ProjectAnnotation | ProjectAnnotation[]`
- #### `exportsName`
+Specifies the project annotations to be applied to the composed story.
- Type: `string`
+This parameter is provided for convenience. You should likely use [`setProjectAnnotations`](#setprojectannotations) instead. Details about the `ProjectAnnotation` type can be found in that function's [`projectAnnotations`](#projectannotations-2) parameter.
- You probably don't need this. Because `composeStory` accepts a single story, it does not have access to the name of that story's export in the file (like `composeStories` does). If you must ensure unique story names in your tests and you cannot use `composeStories`, you can pass the name of the story's export here.
+This parameter can be used to [override](#overriding-globals) the project annotations applied via `setProjectAnnotations`.
- ### Return
+#### `exportsName`
- Type: `ComposedStoryFn`
+Type: `string`
- A single [composed story](#return).
+You probably don't need this. Because `composeStory` accepts a single story, it does not have access to the name of that story's export in the file (like `composeStories` does). If you must ensure unique story names in your tests and you cannot use `composeStories`, you can pass the name of the story's export here.
- ## setProjectAnnotations
+### Return
- This API should be called once, before the tests run, typically in a [setup file](https://jestjs.io/docs/configuration#setupfiles-array). This will make sure that whenever `composeStories` or `composeStory` are called, the project annotations are taken into account as well.
+Type: `ComposedStoryFn`
- These are the configurations needed in the setup file:
- - preview annotations: those defined in `.storybook/preview.tsx`
- - addon annotations (optional): those exported by addons
- - beforeAll: code that runs before all tests ([more info](../../writing-tests/interaction-testing.mdx#beforeall))
+A single [composed story](#return).
- {/* prettier-ignore-start */}
+## setProjectAnnotations
-
+This API should be called once, before the tests run, typically in a [setup file](https://jestjs.io/docs/configuration#setupfiles-array). This will make sure that whenever `composeStories` or `composeStory` are called, the project annotations are taken into account as well.
- {/* prettier-ignore-end */}
+These are the configurations needed in the setup file:
- Sometimes a story can require an addon's [decorator](../../writing-stories/decorators.mdx) or [loader](../../writing-stories/loaders.mdx) to render properly. For example, an addon can apply a decorator that wraps your story in the necessary router context. In this case, you must include that addon's `preview` export in the project annotations set. See `addonAnnotations` in the example above.
+- preview annotations: those defined in `.storybook/preview.tsx`
+- addon annotations (optional): those exported by addons
+- beforeAll: code that runs before all tests ([more info](../../writing-tests/interaction-testing.mdx#beforeall))
- Note: If the addon doesn't automatically apply the decorator or loader itself, but instead exports them for you to apply manually in `.storybook/preview.*` (e.g. using `withThemeFromJSXProvider` from [@storybook/addon-themes](https://github.com/storybookjs/storybook/blob/next/code/addons/themes/docs/api.md#withthemefromjsxprovider)), then you do not need to do anything else. They are already included in the `previewAnnotations` in the example above.
+
- If you need to configure Testing Library's `render` or use a different render function, please let us know in [this discussion](https://github.com/storybookjs/storybook/discussions/28532) so we can learn more about your needs.
+Sometimes a story can require an addon's [decorator](../../writing-stories/decorators.mdx) or [loader](../../writing-stories/loaders.mdx) to render properly. For example, an addon can apply a decorator that wraps your story in the necessary router context. In this case, you must include that addon's `preview` export in the project annotations set. See `addonAnnotations` in the example above.
- ### Type
+Note: If the addon doesn't automatically apply the decorator or loader itself, but instead exports them for you to apply manually in `.storybook/preview.*` (e.g. using `withThemeFromJSXProvider` from [@storybook/addon-themes](https://github.com/storybookjs/storybook/blob/next/code/addons/themes/docs/api.md#withthemefromjsxprovider)), then you do not need to do anything else. They are already included in the `previewAnnotations` in the example above.
- ```ts
- (projectAnnotations: ProjectAnnotation | ProjectAnnotation[]) => ProjectAnnotation
- ```
+If you need to configure Testing Library's `render` or use a different render function, please let us know in [this discussion](https://github.com/storybookjs/storybook/discussions/28532) so we can learn more about your needs.
- ### Parameters
+### Type
- #### `projectAnnotations`
+```ts
+(projectAnnotations: ProjectAnnotation | ProjectAnnotation[]) => ProjectAnnotation;
+```
- (**Required**)
+### Parameters
- Type: `ProjectAnnotation | ProjectAnnotation[]`
+#### `projectAnnotations`
- A set of project [annotations](#annotations) (those defined in `.storybook/preview.*`) or an array of sets of project annotations, which will be applied to all composed stories.
+(**Required**)
- ## Annotations
+Type: `ProjectAnnotation | ProjectAnnotation[]`
- Annotations are the metadata applied to a story, like [args](../../writing-stories/args.mdx), [decorators](../../writing-stories/decorators.mdx), [loaders](../../writing-stories/loaders.mdx), and [play functions](../../writing-stories/play-function.mdx). They can be defined for a specific story, all stories for a component, or all stories in the project.
+A set of project [annotations](#annotations) (those defined in `.storybook/preview.*`) or an array of sets of project annotations, which will be applied to all composed stories.
- ## Story pipeline
+## Annotations
- To preview your stories in Storybook, Storybook runs a story pipeline, which includes applying project annotations, loading data, rendering the story, and playing interactions. This is a simplified version of the pipeline:
+Annotations are the metadata applied to a story, like [args](../../writing-stories/args.mdx), [decorators](../../writing-stories/decorators.mdx), [loaders](../../writing-stories/loaders.mdx), and [play functions](../../writing-stories/play-function.mdx). They can be defined for a specific story, all stories for a component, or all stories in the project.
- 
+## Story pipeline
- When you want to reuse a story in a different environment, however, it's crucial to understand that all these steps make a story. The portable stories API provides you with the mechanism to recreate that story pipeline in your external environment:
+To preview your stories in Storybook, Storybook runs a story pipeline, which includes applying project annotations, loading data, rendering the story, and playing interactions. This is a simplified version of the pipeline:
- ### 1. Apply project-level annotations
+
- [Annotations](#annotations) come from the story itself, that story's component, and the project. The project-level annotations are those defined in your `.storybook/preview.*` file and by addons you're using. In portable stories, these annotations are not applied automatically — you must apply them yourself.
+When you want to reuse a story in a different environment, however, it's crucial to understand that all these steps make a story. The portable stories API provides you with the mechanism to recreate that story pipeline in your external environment:
- 👉 For this, you use the [`setProjectAnnotations`](#setprojectannotations) API.
+### 1. Apply project-level annotations
- ### 2. Compose
+[Annotations](#annotations) come from the story itself, that story's component, and the project. The project-level annotations are those defined in your `.storybook/preview.*` file and by addons you're using. In portable stories, these annotations are not applied automatically — you must apply them yourself.
- The story is prepared by running [`composeStories`](#composestories) or [`composeStory`](#composestory). The outcome is a renderable component that represents the render function of the story.
+👉 For this, you use the [`setProjectAnnotations`](#setprojectannotations) API.
- ### 3. Run
+### 2. Compose
- Finally, stories can prepare data they need (e.g. setting up some mocks or fetching data) before rendering by defining [loaders](../../writing-stories/loaders.mdx), [beforeEach](../../writing-tests/interaction-testing.mdx#run-code-before-each-story) or by having all the story code in the play function when using the [mount](../../writing-tests/interaction-testing.mdx#run-code-before-the-component-gets-rendered). In portable stories, all of these steps will be executed when you call the `run` method of the composed story.
+The story is prepared by running [`composeStories`](#composestories) or [`composeStory`](#composestory). The outcome is a renderable component that represents the render function of the story.
- 👉 For this, you use the [`composeStories`](#composestories) or [`composeStory`](#composestory) API. The composed story will return a `run` method to be called.
+### 3. Run
- {/* prettier-ignore-start */}
+Finally, stories can prepare data they need (e.g. setting up some mocks or fetching data) before rendering by defining [loaders](../../writing-stories/loaders.mdx), [beforeEach](../../writing-tests/interaction-testing.mdx#run-code-before-each-story-in-a-file) or by having all the story code in the play function when using the [mount](../../writing-tests/interaction-testing.mdx#run-code-before-the-component-gets-rendered). In portable stories, all of these steps will be executed when you call the `run` method of the composed story.
-
+👉 For this, you use the [`composeStories`](#composestories) or [`composeStory`](#composestory) API. The composed story will return a `run` method to be called.
- {/* prettier-ignore-end */}
+
-
- If your play function contains assertions (e.g. `expect` calls), your test will fail when those assertions fail.
-
+
- ## Overriding globals
+If your play function contains assertions (e.g. `expect` calls), your test will fail when those assertions fail.
- If your stories behave differently based on [globals](../../essentials/toolbars-and-globals.mdx#globals) (e.g. rendering text in English or Spanish), you can define those global values in portable stories by overriding project annotations when composing a story:
+
- {/* prettier-ignore-start */}
+## Overriding globals
-
+If your stories behave differently based on [globals](../../essentials/toolbars-and-globals.mdx#globals) (e.g. rendering text in English or Spanish), you can define those global values in portable stories by overriding project annotations when composing a story:
- {/* prettier-ignore-end */}
+
- {/* End supported renderers */}
+{/* End supported renderers */}
diff --git a/docs/api/portable-stories/portable-stories-playwright.mdx b/docs/api/portable-stories/portable-stories-playwright.mdx
index 6c8efc66ce99..9044344dae01 100644
--- a/docs/api/portable-stories/portable-stories-playwright.mdx
+++ b/docs/api/portable-stories/portable-stories-playwright.mdx
@@ -1,5 +1,5 @@
---
-title: 'Portable stories in Playwright CT'
+title: Portable stories in Playwright CT
sidebar:
title: Playwright
order: 3
@@ -8,188 +8,198 @@ sidebar:
(⚠️ **Experimental**)
-
- Portable stories are currently only supported in [React](?renderer=react) and [Vue](?renderer=vue) projects.
-
- {/* End non-supported renderers */}
+
+
+Portable stories are currently only supported in [React](?renderer=react) and [Vue](?renderer=vue) projects.
+
+
+
+{/* End non-supported renderers */}
-
- The portable stories API for Playwright CT is experimental. Playwright CT itself is also experimental. Breaking changes might occur in either library in upcoming releases.
-
- Portable stories are Storybook [stories](../../writing-stories/index.mdx) which can be used in external environments, such as [Playwright Component Tests (CT)](https://playwright.dev/docs/test-components).
+
+
+The portable stories API for Playwright CT is experimental. Playwright CT itself is also experimental. Breaking changes might occur in either library in upcoming releases.
+
+
- Normally, Storybook composes a story and its [annotations](#annotations) automatically, as part of the [story pipeline](#story-pipeline). When using stories in Playwright CT, you can use the [`createTest`](#createtest) function, which extends Playwright's test functionality to add a custom `mount` mechanism, to take care of the story pipeline for you.
+Portable stories are Storybook [stories](../../writing-stories/index.mdx) which can be used in external environments, such as [Playwright Component Tests (CT)](https://playwright.dev/docs/test-components).
-
-
- Your project must be using React 18+ to use the portable stories API with Playwright CT.
+Normally, Storybook composes a story and its [annotations](#annotations) automatically, as part of the [story pipeline](#story-pipeline). When using stories in Playwright CT, you can use the [`createTest`](#createtest) function, which extends Playwright's test functionality to add a custom `mount` mechanism, to take care of the story pipeline for you.
- **Using `Next.js`?** The portable stories API is not yet supported in Next.js with Playwright CT.
-
-
+
-
-
- If your stories use template-based Vue components, you may need to [alias the `vue` module](https://vuejs.org/guide/scaling-up/tooling#note-on-in-browser-template-compilation) to resolve correctly in the Playwright CT environment. You can do this via the [`ctViteConfig` property](https://playwright.dev/docs/test-components#i-have-a-project-that-already-uses-vite-can-i-reuse-the-config):
+
+
+Your project must be using React 18+ to use the portable stories API with Playwright CT.
+
+**Using `Next.js`?** The portable stories API is not yet supported in Next.js with Playwright CT.
+
+
+
+
-
- Example Playwright configuration
+
- ```ts
- // playwright-config.ts
- import { defineConfig } from '@playwright/experimental-ct-vue';
+
- export default defineConfig({
- ctViteConfig: {
- resolve: {
- alias: {
- vue: 'vue/dist/vue.esm-bundler.js',
- },
- },
- },
- });
- ```
-
-
-
+If your stories use template-based Vue components, you may need to [alias the `vue` module](https://vuejs.org/guide/scaling-up/tooling#note-on-in-browser-template-compilation) to resolve correctly in the Playwright CT environment. You can do this via the [`ctViteConfig` property](https://playwright.dev/docs/test-components#i-have-a-project-that-already-uses-vite-can-i-reuse-the-config):
- ## createTest
+
+Example Playwright configuration
+
+```ts
+// playwright-config.ts
+import { defineConfig } from '@playwright/experimental-ct-vue';
+
+export default defineConfig({
+ ctViteConfig: {
+ resolve: {
+ alias: {
+ vue: 'vue/dist/vue.esm-bundler.js',
+ },
+ },
+ },
+});
+```
+
+
+
+
+
+
+
+## createTest
+
+(⚠️ **Experimental**)
- (⚠️ **Experimental**)
+Instead of using Playwright's own `test` function, you can use Storybook's special `createTest` function to [extend Playwright's base fixture](https://playwright.dev/docs/test-fixtures#creating-a-fixture) and override the `mount` function to load, render, and play the story. This function is experimental and is subject to changes.
- Instead of using Playwright's own `test` function, you can use Storybook's special `createTest` function to [extend Playwright's base fixture](https://playwright.dev/docs/test-fixtures#creating-a-fixture) and override the `mount` function to load, render, and play the story. This function is experimental and is subject to changes.
+
- {/* prettier-ignore-start */}
+
-
+The code which you write in your Playwright test file is transformed and orchestrated by Playwright, where part of the code executes in Node, while other parts execute in the browser.
- {/* prettier-ignore-end */}
+Because of this, you have to compose the stories _in a separate file than your own test file_:
-
- The code which you write in your Playwright test file is transformed and orchestrated by Playwright, where part of the code executes in Node, while other parts execute in the browser.
+```ts title="Button.stories.portable.ts"
+// Replace your-framework with the framework you are using, e.g. react-vite, nextjs, vue3-vite, etc.
+import { composeStories } from '@storybook/your-framework';
- Because of this, you have to compose the stories *in a separate file than your own test file*:
+import * as stories from './Button.stories';
- ```ts title="Button.stories.portable.ts"
- // Replace your-framework with the framework you are using, e.g. react-vite, nextjs, vue3-vite, etc.
- import { composeStories } from '@storybook/your-framework';
+// This function will be executed in the browser
+// and compose all stories, exporting them in a single object
+export default composeStories(stories);
+```
- import * as stories from './Button.stories';
+You can then import the composed stories in your Playwright test file, as in the example above.
- // This function will be executed in the browser
- // and compose all stories, exporting them in a single object
- export default composeStories(stories);
- ```
+
- You can then import the composed stories in your Playwright test file, as in the example above.
-
+### Type
- ### Type
+```ts
+createTest(
+ baseTest: PlaywrightFixture
+) => PlaywrightFixture
+```
- ```ts
- createTest(
- baseTest: PlaywrightFixture
- ) => PlaywrightFixture
- ```
+### Parameters
- ### Parameters
+#### `baseTest`
- #### `baseTest`
+(**Required**)
- (**Required**)
+Type: `PlaywrightFixture`
- Type: `PlaywrightFixture`
+The base test function to use, e.g. `test` from Playwright.
- The base test function to use, e.g. `test` from Playwright.
+### Return
- ### Return
+Type: `PlaywrightFixture`
- Type: `PlaywrightFixture`
+A Storybook-specific test function with the custom `mount` mechanism.
- A Storybook-specific test function with the custom `mount` mechanism.
+## setProjectAnnotations
- ## setProjectAnnotations
+This API should be called once, before the tests run, in [`playwright/index.ts`](https://playwright.dev/docs/test-components#step-1-install-playwright-test-for-components-for-your-respective-framework). This will make sure that when `mount` is called, the project annotations are taken into account as well.
- This API should be called once, before the tests run, in [`playwright/index.ts`](https://playwright.dev/docs/test-components#step-1-install-playwright-test-for-components-for-your-respective-framework). This will make sure that when `mount` is called, the project annotations are taken into account as well.
+These are the configurations needed in the setup file:
- These are the configurations needed in the setup file:
- - preview annotations: those defined in `.storybook/preview.*`
- - addon annotations (optional): those exported by addons
- - beforeAll: code that runs before all tests ([more info](../../writing-tests/interaction-testing.mdx#beforeall))
+- preview annotations: those defined in `.storybook/preview.tsx`
+- addon annotations (optional): those exported by addons
+- beforeAll: code that runs before all tests ([more info](../../writing-tests/interaction-testing.mdx#beforeall))
- {/* prettier-ignore-start */}
+
-
+Sometimes a story can require an addon's [decorator](../../writing-stories/decorators.mdx) or [loader](../../writing-stories/loaders.mdx) to render properly. For example, an addon can apply a decorator that wraps your story in the necessary router context. In this case, you must include that addon's `preview` export in the project annotations set. See `addonAnnotations` in the example above.
- {/* prettier-ignore-end */}
+Note: If the addon doesn't automatically apply the decorator or loader itself, but instead exports them for you to apply manually in `.storybook/preview.*` (e.g. using `withThemeFromJSXProvider` from [@storybook/addon-themes](https://github.com/storybookjs/storybook/blob/next/code/addons/themes/docs/api.md#withthemefromjsxprovider)), then you do not need to do anything else. They are already included in the `previewAnnotations` in the example above.
- Sometimes a story can require an addon's [decorator](../../writing-stories/decorators.mdx) or [loader](../../writing-stories/loaders.mdx) to render properly. For example, an addon can apply a decorator that wraps your story in the necessary router context. In this case, you must include that addon's `preview` export in the project annotations set. See `addonAnnotations` in the example above.
+### Type
- Note: If the addon doesn't automatically apply the decorator or loader itself, but instead exports them for you to apply manually in `.storybook/preview.*` (e.g. using `withThemeFromJSXProvider` from [@storybook/addon-themes](https://github.com/storybookjs/storybook/blob/next/code/addons/themes/docs/api.md#withthemefromjsxprovider)), then you do not need to do anything else. They are already included in the `previewAnnotations` in the example above.
+```ts
+(projectAnnotations: ProjectAnnotation | ProjectAnnotation[]) => ProjectAnnotation;
+```
- ### Type
+### Parameters
- ```ts
- (projectAnnotations: ProjectAnnotation | ProjectAnnotation[]) => ProjectAnnotation
- ```
+#### `projectAnnotations`
- ### Parameters
+(**Required**)
- #### `projectAnnotations`
+Type: `ProjectAnnotation | ProjectAnnotation[]`
- (**Required**)
+A set of project [annotations](#annotations) (those defined in `.storybook/preview.*`) or an array of sets of project annotations, which will be applied to all composed stories.
- Type: `ProjectAnnotation | ProjectAnnotation[]`
+## Annotations
- A set of project [annotations](#annotations) (those defined in `.storybook/preview.*`) or an array of sets of project annotations, which will be applied to all composed stories.
+Annotations are the metadata applied to a story, like [args](../../writing-stories/args.mdx), [decorators](../../writing-stories/decorators.mdx), [loaders](../../writing-stories/loaders.mdx), and [play functions](../../writing-stories/play-function.mdx). They can be defined for a specific story, all stories for a component, or all stories in the project.
- ## Annotations
+
- Annotations are the metadata applied to a story, like [args](../../writing-stories/args.mdx), [decorators](../../writing-stories/decorators.mdx), [loaders](../../writing-stories/loaders.mdx), and [play functions](../../writing-stories/play-function.mdx). They can be defined for a specific story, all stories for a component, or all stories in the project.
+[Read more about Playwright's component testing](https://playwright.dev/docs/test-components#test-stories).
-
- [Read more about Playwright's component testing](https://playwright.dev/docs/test-components#test-stories).
-
+
- ## Story pipeline
+## Story pipeline
- To preview your stories, Storybook runs a story pipeline, which includes applying project annotations, loading data, rendering the story, and playing interactions. This is a simplified version of the pipeline:
+To preview your stories, Storybook runs a story pipeline, which includes applying project annotations, loading data, rendering the story, and playing interactions. This is a simplified version of the pipeline:
- 
+
- When you want to reuse a story in a different environment, however, it's crucial to understand that all these steps make a story. The portable stories API provides you with the mechanism to recreate that story pipeline in your external environment:
+When you want to reuse a story in a different environment, however, it's crucial to understand that all these steps make a story. The portable stories API provides you with the mechanism to recreate that story pipeline in your external environment:
- ### 1. Apply project-level annotations
+### 1. Apply project-level annotations
- [Annotations](#annotations) come from the story itself, that story's component, and the project. The project-level annotations are those defined in your `.storybook/preview.*` file and by addons you're using. In portable stories, these annotations are not applied automatically — you must apply them yourself.
+[Annotations](#annotations) come from the story itself, that story's component, and the project. The project-level annotations are those defined in your `.storybook/preview.*` file and by addons you're using. In portable stories, these annotations are not applied automatically — you must apply them yourself.
- 👉 For this, you use the [`setProjectAnnotations`](#setprojectannotations) API.
+👉 For this, you use the [`setProjectAnnotations`](#setprojectannotations) API.
- ### 2. Prepare, load, render, and play
+### 2. Prepare, load, render, and play
- The story pipeline includes preparing the story, [loading data](../../writing-stories/loaders.mdx), rendering the story, and [playing interactions](../../writing-tests/interaction-testing.mdx#debugging-interaction-tests). In portable stories within Playwright CT, the `mount` function takes care of these steps for you.
+The story pipeline includes preparing the story, [loading data](../../writing-stories/loaders.mdx), rendering the story, and [playing interactions](../../writing-tests/interaction-testing.mdx#debugging-interaction-tests). In portable stories within Playwright CT, the `mount` function takes care of these steps for you.
- 👉 For this, you use the [`createTest`](#createtest) API.
+👉 For this, you use the [`createTest`](#createtest) API.
-
- If your play function contains assertions (e.g. `expect` calls), your test will fail when those assertions fail.
-
+
- ## Overriding globals
+If your play function contains assertions (e.g. `expect` calls), your test will fail when those assertions fail.
- If your stories behave differently based on [globals](../../essentials/toolbars-and-globals.mdx#globals) (e.g. rendering text in English or Spanish), you can define those global values in portable stories by overriding project annotations when composing a story:
+
- {/* prettier-ignore-start */}
+## Overriding globals
-
+If your stories behave differently based on [globals](../../essentials/toolbars-and-globals.mdx#globals) (e.g. rendering text in English or Spanish), you can define those global values in portable stories by overriding project annotations when composing a story:
- You can then use those composed stories in your Playwright test file using the [`createTest`](#createtest) function.
+
- {/* prettier-ignore-end */}
+You can then use those composed stories in your Playwright test file using the [`createTest`](#createtest) function.
- {/* End supported renderers */}
+{/* End supported renderers */}
diff --git a/docs/api/portable-stories/portable-stories-vitest.mdx b/docs/api/portable-stories/portable-stories-vitest.mdx
index 36cbede97878..0bfa37174a28 100644
--- a/docs/api/portable-stories/portable-stories-vitest.mdx
+++ b/docs/api/portable-stories/portable-stories-vitest.mdx
@@ -1,5 +1,5 @@
---
-title: 'Portable stories in Vitest'
+title: Portable stories in Vitest
sidebar:
title: Vitest
order: 1
@@ -7,262 +7,252 @@ sidebar:
---
-
- Portable stories in Vitest are currently only supported in [React](?renderer=react), [Vue](?renderer=vue) and [Svelte](?renderer=svelte) projects.
-
- {/* End non-supported renderers */}
+
+
+Portable stories in Vitest are currently only supported in [React](?renderer=react), [Vue](?renderer=vue) and [Svelte](?renderer=svelte) projects.
+
+
+
+{/* End non-supported renderers */}
- (⚠️ **Experimental**)
-
+(⚠️ **Experimental**)
+
+
- This feature is not supported with the Svelte CSF. To opt-in to this feature with Svelte, you must use Storybook's [Component Story Format](../csf/index.mdx).
+This feature is not supported with the Svelte CSF. To opt-in to this feature with Svelte, you must use Storybook's [Component Story Format](../csf/index.mdx).
-
+
-
- Storybook now recommends testing your stories in Vitest with the [Vitest addon](../../writing-tests/integrations/vitest-addon/index.mdx), which automatically transforms stories into real Vitest tests (using this API under the hood).
-
- This API is still available for those who prefer to use portable stories directly, but we recommend using the Vitest addon for a more streamlined testing experience.
-
- Portable stories are Storybook [stories](../../writing-stories/index.mdx) which can be used in external environments, such as [Vitest](https://vitest.dev).
+
- Normally, Storybook composes a story and its [annotations](#annotations) automatically, as part of the [story pipeline](#story-pipeline). When using stories in Vitest tests, you must handle the story pipeline yourself, which is what the [`composeStories`](#composestories) and [`composeStory`](#composestory) functions enable.
+Storybook now recommends testing your stories in Vitest with the [Vitest addon](../../writing-tests/integrations/vitest-addon/index.mdx), which automatically transforms stories into real Vitest tests (using this API under the hood).
-
-
- **Using `Next.js`?** You can test your Next.js stories with Vitest by installing and setting up the `@storybook/nextjs-vite` which re-exports [vite-plugin-storybook-nextjs](https://github.com/storybookjs/vite-plugin-storybook-nextjs) package.
-
-
+This API is still available for those who prefer to use portable stories directly, but we recommend using the Vitest addon for a more streamlined testing experience.
- ## composeStories
+
- `composeStories` will process the component's stories you specify, compose each of them with the necessary [annotations](#annotations), and return an object containing the composed stories.
+Portable stories are Storybook [stories](../../writing-stories/index.mdx) which can be used in external environments, such as [Vitest](https://vitest.dev).
-
- By default, the composed story will render the component with the [args](../../writing-stories/args.mdx) that are defined in the story. You can also pass any props to the component in your test and those props will override the values passed in the story's args.
-
+Normally, Storybook composes a story and its [annotations](#annotations) automatically, as part of the [story pipeline](#story-pipeline). When using stories in Vitest tests, you must handle the story pipeline yourself, which is what the [`composeStories`](#composestories) and [`composeStory`](#composestory) functions enable.
-
- By default, the composed story will render the component with the [args](../../writing-stories/args.mdx) that are defined in the story. If you need to override props for an individual story, you can use the [`composeStory`](#composestory) function to do so.
-
+
- {/* prettier-ignore-start */}
+
-
+**Using `Next.js`?** You can test your Next.js stories with Vitest by installing and setting up the `@storybook/nextjs-vite` which re-exports [vite-plugin-storybook-nextjs](https://github.com/storybookjs/vite-plugin-storybook-nextjs) package.
- {/* prettier-ignore-end */}
+
- ### Type
+
+
+## composeStories
- {/* prettier-ignore-start */}
+`composeStories` will process the component's stories you specify, compose each of them with the necessary [annotations](#annotations), and return an object containing the composed stories.
- ```ts
- (
- csfExports: CSF file exports,
- projectAnnotations?: ProjectAnnotations
- ) => Record
- ```
+
- {/* prettier-ignore-end */}
+By default, the composed story will render the component with the [args](../../writing-stories/args.mdx) that are defined in the story. You can also pass any props to the component in your test and those props will override the values passed in the story's args.
- ### Parameters
+
- #### `csfExports`
+
- (**Required**)
+By default, the composed story will render the component with the [args](../../writing-stories/args.mdx) that are defined in the story. If you need to override props for an individual story, you can use the [`composeStory`](#composestory) function to do so.
- Type: CSF file exports
+
- Specifies which component's stories you want to compose. Pass the **full set of exports** from the CSF file (not the default export!). E.g. `import * as stories from './Button.stories'`
+
- #### `projectAnnotations`
+### Type
- Type: `ProjectAnnotation | ProjectAnnotation[]`
+```ts
+(
+ csfExports: CSF file exports,
+ projectAnnotations?: ProjectAnnotations
+) => Record
+```
- Specifies the project annotations to be applied to the composed stories.
+### Parameters
- This parameter is provided for convenience. You should likely use [`setProjectAnnotations`](#setprojectannotations) instead. Details about the `ProjectAnnotation` type can be found in that function's [`projectAnnotations`](#projectannotations-2) parameter.
+#### `csfExports`
- This parameter can be used to [override](#overriding-globals) the project annotations applied via `setProjectAnnotations`.
+(**Required**)
- ### Return
+Type: CSF file exports
- Type: `Record`
+Specifies which component's stories you want to compose. Pass the **full set of exports** from the CSF file (not the default export!). E.g. `import * as stories from './Button.stories'`
- An object where the keys are the names of the stories and the values are the composed stories.
+#### `projectAnnotations`
- Additionally, the composed story will have the following properties:
+Type: `ProjectAnnotation | ProjectAnnotation[]`
- | Property | Type | Description |
- | ---------- | ----------------------------------------- | ------------------------------------------------------------------------------------- |
- | args | `Record` | The story's [args](../../writing-stories/args.mdx) |
- | argTypes | `ArgType` | The story's [argTypes](../arg-types.mdx) |
- | id | `string` | The story's id |
- | parameters | `Record` | The story's [parameters](../parameters.mdx) |
- | play | `(context) => Promise \| undefined` | Executes the play function of a given story |
- | run | `(context) => Promise \| undefined` | [Mounts and executes the play function](#3-run) of a given story |
- | storyName | `string` | The story's name |
- | tags | `string[]` | The story's [tags](../../writing-stories/tags.mdx) |
+Specifies the project annotations to be applied to the composed stories.
- ## composeStory
+This parameter is provided for convenience. You should likely use [`setProjectAnnotations`](#setprojectannotations) instead. Details about the `ProjectAnnotation` type can be found in that function's [`projectAnnotations`](#projectannotations-2) parameter.
- You can use `composeStory` if you wish to compose a single story for a component.
+This parameter can be used to [override](#overriding-globals) the project annotations applied via `setProjectAnnotations`.
- {/* prettier-ignore-start */}
+### Return
-
+Type: `Record`
- {/* prettier-ignore-end */}
+An object where the keys are the names of the stories and the values are the composed stories.
- ### Type
+Additionally, the composed story will have the following properties:
- {/* prettier-ignore-start */}
+| Property | Type | Description |
+| ---------- | ----------------------------------------- | ---------------------------------------------------------------- |
+| args | `Record` | The story's [args](../../writing-stories/args.mdx) |
+| argTypes | `ArgType` | The story's [argTypes](../arg-types.mdx) |
+| id | `string` | The story's id |
+| parameters | `Record` | The story's [parameters](../parameters.mdx) |
+| play | `(context) => Promise \| undefined` | Executes the play function of a given story |
+| run | `(context) => Promise \| undefined` | [Mounts and executes the play function](#3-run) of a given story |
+| storyName | `string` | The story's name |
+| tags | `string[]` | The story's [tags](../../writing-stories/tags.mdx) |
- ```ts
- (
- story: Story export,
- componentAnnotations: Meta,
- projectAnnotations?: ProjectAnnotations,
- exportsName?: string
- ) => ComposedStoryFn
- ```
+## composeStory
- {/* prettier-ignore-end */}
+You can use `composeStory` if you wish to compose a single story for a component.
- ### Parameters
+
- #### `story`
+### Type
- (**Required**)
+```ts
+(
+ story: Story export,
+ componentAnnotations: Meta,
+ projectAnnotations?: ProjectAnnotations,
+ exportsName?: string
+) => ComposedStoryFn
+```
- Type: `Story export`
+### Parameters
- Specifies which story you want to compose.
+#### `story`
- #### `componentAnnotations`
+(**Required**)
- (**Required**)
+Type: `Story export`
- Type: `Meta`
+Specifies which story you want to compose.
- The default export from the stories file containing the [`story`](#story).
+#### `componentAnnotations`
- #### `projectAnnotations`
+(**Required**)
- Type: `ProjectAnnotation | ProjectAnnotation[]`
+Type: `Meta`
- Specifies the project annotations to be applied to the composed story.
+The default export from the stories file containing the [`story`](#story).
- This parameter is provided for convenience. You should likely use [`setProjectAnnotations`](#setprojectannotations) instead. Details about the `ProjectAnnotation` type can be found in that function's [`projectAnnotations`](#projectannotations-2) parameter.
+#### `projectAnnotations`
- This parameter can be used to [override](#overriding-globals) the project annotations applied via `setProjectAnnotations`.
+Type: `ProjectAnnotation | ProjectAnnotation[]`
- #### `exportsName`
+Specifies the project annotations to be applied to the composed story.
- Type: `string`
+This parameter is provided for convenience. You should likely use [`setProjectAnnotations`](#setprojectannotations) instead. Details about the `ProjectAnnotation` type can be found in that function's [`projectAnnotations`](#projectannotations-2) parameter.
- You probably don't need this. Because `composeStory` accepts a single story, it does not have access to the name of that story's export in the file (like `composeStories` does). If you must ensure unique story names in your tests and you cannot use `composeStories`, you can pass the name of the story's export here.
+This parameter can be used to [override](#overriding-globals) the project annotations applied via `setProjectAnnotations`.
- ### Return
+#### `exportsName`
- Type: `ComposedStoryFn`
+Type: `string`
- A single [composed story](#return).
+You probably don't need this. Because `composeStory` accepts a single story, it does not have access to the name of that story's export in the file (like `composeStories` does). If you must ensure unique story names in your tests and you cannot use `composeStories`, you can pass the name of the story's export here.
- ## setProjectAnnotations
+### Return
- This API should be called once, before the tests run, typically in a [setup file](https://vitest.dev/config/#setupfiles). This will make sure that whenever `composeStories` or `composeStory` are called, the project annotations are taken into account as well.
+Type: `ComposedStoryFn`
- These are the configurations needed in the setup file:
- - preview annotations: those defined in `.storybook/preview.tsx`
- - addon annotations (optional): those exported by addons
- - beforeAll: code that runs before all tests ([more info](../../writing-tests/interaction-testing.mdx#beforeall))
+A single [composed story](#return).
- {/* prettier-ignore-start */}
+## setProjectAnnotations
-
+This API should be called once, before the tests run, typically in a [setup file](https://vitest.dev/config/#setupfiles). This will make sure that whenever `composeStories` or `composeStory` are called, the project annotations are taken into account as well.
- {/* prettier-ignore-end */}
+These are the configurations needed in the setup file:
- {/* TODO: Create issue for interest in non-Testing Library render option, with recipe, and mention here (Jest, too) */}
+- preview annotations: those defined in `.storybook/preview.tsx`
+- addon annotations (optional): those exported by addons
+- beforeAll: code that runs before all tests ([more info](../../writing-tests/interaction-testing.mdx#beforeall))
- Sometimes a story can require an addon's [decorator](../../writing-stories/decorators.mdx) or [loader](../../writing-stories/loaders.mdx) to render properly. For example, an addon can apply a decorator that wraps your story in the necessary router context. In this case, you must include that addon's `preview` export in the project annotations set. See `addonAnnotations` in the example above.
+
- Note: If the addon doesn't automatically apply the decorator or loader itself, but instead exports them for you to apply manually in `.storybook/preview.*` (e.g. using `withThemeFromJSXProvider` from [@storybook/addon-themes](https://github.com/storybookjs/storybook/blob/next/code/addons/themes/docs/api.md#withthemefromjsxprovider)), then you do not need to do anything else. They are already included in the `previewAnnotations` in the example above.
+{/* TODO: Create issue for interest in non-Testing Library render option, with recipe, and mention here (Jest, too) */}
- If you need to configure Testing Library's `render` or use a different render function, please let us know in [this discussion](https://github.com/storybookjs/storybook/discussions/28532) so we can learn more about your needs.
+Sometimes a story can require an addon's [decorator](../../writing-stories/decorators.mdx) or [loader](../../writing-stories/loaders.mdx) to render properly. For example, an addon can apply a decorator that wraps your story in the necessary router context. In this case, you must include that addon's `preview` export in the project annotations set. See `addonAnnotations` in the example above.
- ### Type
+Note: If the addon doesn't automatically apply the decorator or loader itself, but instead exports them for you to apply manually in `.storybook/preview.*` (e.g. using `withThemeFromJSXProvider` from [@storybook/addon-themes](https://github.com/storybookjs/storybook/blob/next/code/addons/themes/docs/api.md#withthemefromjsxprovider)), then you do not need to do anything else. They are already included in the `previewAnnotations` in the example above.
- ```ts
- (projectAnnotations: ProjectAnnotation | ProjectAnnotation[]) => ProjectAnnotation
- ```
+If you need to configure Testing Library's `render` or use a different render function, please let us know in [this discussion](https://github.com/storybookjs/storybook/discussions/28532) so we can learn more about your needs.
- ### Parameters
+### Type
- #### `projectAnnotations`
+```ts
+(projectAnnotations: ProjectAnnotation | ProjectAnnotation[]) => ProjectAnnotation;
+```
- (**Required**)
+### Parameters
- Type: `ProjectAnnotation | ProjectAnnotation[]`
+#### `projectAnnotations`
- A set of project [annotations](#annotations) (those defined in `.storybook/preview.*`) or an array of sets of project annotations, which will be applied to all composed stories.
+(**Required**)
- ## Annotations
+Type: `ProjectAnnotation | ProjectAnnotation[]`
- Annotations are the metadata applied to a story, like [args](../../writing-stories/args.mdx), [decorators](../../writing-stories/decorators.mdx), [loaders](../../writing-stories/loaders.mdx), and [play functions](../../writing-stories/play-function.mdx). They can be defined for a specific story, all stories for a component, or all stories in the project.
+A set of project [annotations](#annotations) (those defined in `.storybook/preview.*`) or an array of sets of project annotations, which will be applied to all composed stories.
- ## Story pipeline
+## Annotations
- To preview your stories in Storybook, Storybook runs a story pipeline, which includes applying project annotations, loading data, rendering the story, and playing interactions. This is a simplified version of the pipeline:
+Annotations are the metadata applied to a story, like [args](../../writing-stories/args.mdx), [decorators](../../writing-stories/decorators.mdx), [loaders](../../writing-stories/loaders.mdx), and [play functions](../../writing-stories/play-function.mdx). They can be defined for a specific story, all stories for a component, or all stories in the project.
- 
+## Story pipeline
- When you want to reuse a story in a different environment, however, it's crucial to understand that all these steps make a story. The portable stories API provides you with the mechanism to recreate that story pipeline in your external environment:
+To preview your stories in Storybook, Storybook runs a story pipeline, which includes applying project annotations, loading data, rendering the story, and playing interactions. This is a simplified version of the pipeline:
- ### 1. Apply project-level annotations
+
- [Annotations](#annotations) come from the story itself, that story's component, and the project. The project-level annotations are those defined in your `.storybook/preview.*` file and by addons you're using. In portable stories, these annotations are not applied automatically — you must apply them yourself.
+When you want to reuse a story in a different environment, however, it's crucial to understand that all these steps make a story. The portable stories API provides you with the mechanism to recreate that story pipeline in your external environment:
- 👉 For this, you use the [`setProjectAnnotations`](#setprojectannotations) API.
+### 1. Apply project-level annotations
- ### 2. Compose
+[Annotations](#annotations) come from the story itself, that story's component, and the project. The project-level annotations are those defined in your `.storybook/preview.*` file and by addons you're using. In portable stories, these annotations are not applied automatically — you must apply them yourself.
- The story is prepared by running [`composeStories`](#composestories) or [`composeStory`](#composestory). The outcome is a renderable component that represents the render function of the story.
+👉 For this, you use the [`setProjectAnnotations`](#setprojectannotations) API.
- ### 3. Run
+### 2. Compose
- Finally, stories can prepare data they need (e.g. setting up some mocks or fetching data) before rendering by defining [loaders](../../writing-stories/loaders.mdx), [beforeEach](../../writing-tests/interaction-testing.mdx#run-code-before-each-story) or by having all the story code in the play function when using the [mount](../../writing-tests/interaction-testing.mdx#run-code-before-the-component-gets-rendered). In portable stories, all of these steps will be executed when you call the `run` method of the composed story.
+The story is prepared by running [`composeStories`](#composestories) or [`composeStory`](#composestory). The outcome is a renderable component that represents the render function of the story.
- 👉 For this, you use the [`composeStories`](#composestories) or [`composeStory`](#composestory) API. The composed story will return a `run` method to be called.
+### 3. Run
- {/* prettier-ignore-start */}
+Finally, stories can prepare data they need (e.g. setting up some mocks or fetching data) before rendering by defining [loaders](../../writing-stories/loaders.mdx), [beforeEach](../../writing-tests/interaction-testing.mdx#run-code-before-each-story-in-a-file) or by having all the story code in the play function when using the [mount](../../writing-tests/interaction-testing.mdx#run-code-before-the-component-gets-rendered). In portable stories, all of these steps will be executed when you call the `run` method of the composed story.
-
+👉 For this, you use the [`composeStories`](#composestories) or [`composeStory`](#composestory) API. The composed story will return a `run` method to be called.
- {/* prettier-ignore-end */}
+
-
- If your play function contains assertions (e.g. `expect` calls), your test will fail when those assertions fail.
-
+
- ## Overriding globals
+If your play function contains assertions (e.g. `expect` calls), your test will fail when those assertions fail.
- If your stories behave differently based on [globals](../../essentials/toolbars-and-globals.mdx#globals) (e.g. rendering text in English or Spanish), you can define those global values in portable stories by overriding project annotations when composing a story:
+
- {/* prettier-ignore-start */}
+## Overriding globals
-
+If your stories behave differently based on [globals](../../essentials/toolbars-and-globals.mdx#globals) (e.g. rendering text in English or Spanish), you can define those global values in portable stories by overriding project annotations when composing a story:
- {/* prettier-ignore-end */}
+
- {/* End supported renderers */}
+{/* End supported renderers */}
diff --git a/docs/builders/builder-api.mdx b/docs/builders/builder-api.mdx
index 78f0e9cf2331..f80289746a51 100644
--- a/docs/builders/builder-api.mdx
+++ b/docs/builders/builder-api.mdx
@@ -1,5 +1,5 @@
---
-title: 'Builder API'
+title: Builder API
sidebar:
order: 3
title: API
@@ -15,28 +15,16 @@ In Storybook, a builder is responsible for compiling your components and stories
To opt into a builder, the user must add it as a dependency and then edit their configuration file (`.storybook/main.js`) to enable it. For example, with the Vite builder:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Builder API
In Storybook, every builder must implement the following [API](https://github.com/storybookjs/storybook/blob/next/code/core/src/types/modules/core-common.ts#L255-L275), exposing the following configuration options and entry points:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
In development mode, the `start` API call is responsible for initializing the development server to monitor the file system for changes (for example, components and stories) then execute a hot module reload in the browser.
It also provides a **bail** function to allow the running process to end gracefully, either via user input or error.
@@ -54,32 +42,20 @@ The `stories` configuration field enables story loading in Storybook. It defines
By default, Storybook's configuration is handled in a dedicated file (`storybook/main.js|ts`), giving the user the option to customize it to suit its needs. The builder should also provide its own configuration support through additional fields or some other builder-appropriate mechanism. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Handle preview.js exports
The [`preview.js`](../configure/index.mdx#configure-story-rendering) configuration file allows users to control how the story renders in the UI. This is provided via the [decorators](../writing-stories/decorators.mdx) named export. When Storybook starts, it converts these named exports into internal API calls via virtual module entry, for example, `addDecorator()`. The builder must also provide a similar implementation. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### MDX support
[Storybook's Docs](../writing-docs/index.mdx) includes the ability to author stories/documentation in MDX using a Webpack loader. The builder must also know how to interpret MDX and invoke Storybook's special extensions. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Generate source code snippets
Storybook annotates components and stories with additional metadata related to their inputs to automatically generate interactive controls and documentation. Currently, this is provided via Webpack loaders/plugins. The builder must re-implement this to support those features.
@@ -88,32 +64,20 @@ Storybook annotates components and stories with additional metadata related to t
One of Storybook's core features it's the ability to generate a static build that can be [published](../sharing/publish-storybook.mdx) to a web hosting service. The builder must also be able to provide a similar mechanism. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Development server integration
By default, when Storybook starts in development mode, it relies on its internal development server. The builder needs to be able to integrate with it. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Shutdown the development server
The builder must provide a way to stop the development server once the process terminates; this can be via user input or error. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### HMR support
While running in development mode, the builder's development server must be able to reload the page once a change happens, either in a story, component, or helper function.
@@ -124,6 +88,6 @@ This area is under rapid development, and the associated documentation is still
**Learn more about builders**
-* [Vite builder](./vite.mdx) for bundling with Vite
-* [Webpack builder](./webpack.mdx) for bundling with Webpack
-* Builder API for building a Storybook builder
+- [Vite builder](./vite.mdx) for bundling with Vite
+- [Webpack builder](./webpack.mdx) for bundling with Webpack
+- Builder API for building a Storybook builder
diff --git a/docs/builders/index.mdx b/docs/builders/index.mdx
index 3f97cce37681..4322a3482bd2 100644
--- a/docs/builders/index.mdx
+++ b/docs/builders/index.mdx
@@ -1,9 +1,8 @@
---
-title: 'Builders'
+title: Builders
hideRendererSelector: true
sidebar:
order: 11
- title: Builders
---
Storybook, at its core, is powered by builders such as Webpack and Vite. These builders spin up a development environment, compile your code—Javascript, CSS, and MDX—into an executable bundle and update the browser in real-time.
@@ -24,6 +23,6 @@ npx storybook@latest init --builder
Storybook uses the Webpack 5 builder by default if you don't specify one. If you want to use a different builder in your application, these docs detail how you can set up Storybook's supported builders.
-* [**Vite builder**](./vite.mdx) for bundling your stories with Vite with near-instant HMR.
-* [**Webpack**](./webpack.mdx) for bundling your stories with Webpack with improved performance
-* [**Rspack / Rsbuild**](https://github.com/rspack-contrib/storybook-rsbuild) for bundling your stories with blazing fast Rspack and Rsbuild.
+- [**Vite builder**](./vite.mdx) for bundling your stories with Vite with near-instant HMR.
+- [**Webpack**](./webpack.mdx) for bundling your stories with Webpack with improved performance
+- [**Rspack / Rsbuild**](https://github.com/rspack-contrib/storybook-rsbuild) for bundling your stories with blazing fast Rspack and Rsbuild.
diff --git a/docs/builders/vite.mdx b/docs/builders/vite.mdx
index cd08cde7e89c..2a6ec6b7130c 100644
--- a/docs/builders/vite.mdx
+++ b/docs/builders/vite.mdx
@@ -1,14 +1,13 @@
---
-title: 'Vite'
+title: Vite
sidebar:
order: 1
- title: Vite
---
Storybook Vite builder bundles your components and stories with [Vite](https://vitejs.dev/), a fast ESM bundler.
-* For applications built with Vite: it allows reusing the existing configuration in Storybook.
-* For applications built with Webpack: it provides faster startup and refresh times, with the disadvantage that your component's execution environment differs from your application.
+- For applications built with Vite: it allows reusing the existing configuration in Storybook.
+- For applications built with Webpack: it provides faster startup and refresh times, with the disadvantage that your component's execution environment differs from your application.
## Setup
@@ -16,69 +15,47 @@ If you ran `npx storybook@latest init` to include Storybook in your Vite applica
Run the following command to install the builder.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Update your Storybook configuration (in `.storybook/main.js|ts`) to include the builder.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Configuration
Out of the box, Storybook's Vite builder includes a set of configuration defaults for the supported frameworks, which are merged alongside your existing configuration file. For an optimal experience when using the Vite builder, we recommend applying any configuration directly inside Vite's configuration file (i.e., [`vite.config.js|ts`](https://vitejs.dev/config/)).
When Storybook loads, it automatically merges the configuration into its own. However, since different projects may have specific requirements, you may need to provide a custom configuration for Storybook. In such cases, you can modify your configuration file (`.storybook/main.js|ts`) and add the `viteFinal` configuration function as follows:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
The asynchronous function [`viteFinal`](../api/main-config/main-config-vite-final.mdx) receives a `config` object with the default builder configuration and returns the updated configuration.
### Environment-based configuration
If you need to customize the builder's configuration and apply specific options based on your environment, extend the `viteFinal` function as follows:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Override the default configuration
By default, the Vite builder in Storybook searches for the Vite configuration file in the root directory of your Storybook project. However, you can customize it to look for the configuration file in a different location. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- If you do not want Storybook to load the Vite configuration file automatically, you can use the `viteConfigPath` option to point to a non-existent file.
+
+If you do not want Storybook to load the Vite configuration file automatically, you can use the `viteConfigPath` option to point to a non-existent file.
+
### TypeScript
If you need, you can also configure Storybook's Vite builder using TypeScript. Rename your `.storybook/main.js` to `.storybook/main.ts` and adjust it as follows:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
-***
+---
## Troubleshooting
@@ -90,12 +67,8 @@ We recommend starting with no Storybook-specific Vite configuration and only add
For reference, here is a Webpack configuration to handle loading graphql queries and its equivalent, using a plugin, in Vite:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Working directory not being detected
By default, the Vite builder enables Vite's [`server.fs.strict`](https://vitejs.dev/config/#server-fs-strict) option for increased security, defining the project's `root` to Storybook's configuration directory.
@@ -105,24 +78,16 @@ If you need to override it, you can use the `viteFinal` function and adjust it.
Currently, [automatic argType inference](../api/arg-types.mdx#automatic-argtype-inference) is only available for React, Vue 3, and Svelte (JSDocs only). With React, the Vite builder defaults to `react-docgen`, a faster alternative to `react-docgen-typescript` for parsing React components. If you run into any issues, you can revert to `react-docgen-typescript` by updating your Storybook configuration file as follows:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Interaction tests not working as expected
If you are migrating from a Webpack-based project, such as [CRA](https://create-react-app.dev/), to Vite, and you are [interaction testing](../writing-tests/interaction-testing.mdx), you may run into a situation where your tests fail to execute notifying you that the `window` object is not defined. To resolve this issue, you can create a `preview-head.html` file in your Storybook configuration directory and include the following:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
**Learn more about builders**
-* Vite builder for bundling with Vite
-* [Webpack builder](./webpack.mdx) for bundling with Webpack
-* [Builder API](./builder-api.mdx) for building a Storybook builder
+- Vite builder for bundling with Vite
+- [Webpack builder](./webpack.mdx) for bundling with Webpack
+- [Builder API](./builder-api.mdx) for building a Storybook builder
diff --git a/docs/builders/webpack.mdx b/docs/builders/webpack.mdx
index 8ad9321bfed7..45467acf9546 100644
--- a/docs/builders/webpack.mdx
+++ b/docs/builders/webpack.mdx
@@ -1,8 +1,7 @@
---
-title: 'Webpack'
+title: Webpack
sidebar:
order: 2
- title: Webpack
---
Storybook Webpack builder is the default builder for Storybook. This builder enables you to create a seamless development and testing experience for your components and provides an efficient way to develop UI components in isolation allowing you to leverage your existing Webpack configuration with Storybook.
@@ -16,68 +15,46 @@ By default, Storybook provides zero-config support for Webpack and automatically
| `lazyCompilation` | Enables Webpack's experimental [`lazy compilation`](https://webpack.js.org/configuration/experiments/#experimentslazycompilation) `core: { builder: { options: { lazyCompilation: true } } }` |
| `fsCache` | Configures Webpack's filesystem [caching](https://webpack.js.org/configuration/cache/#cachetype) feature `core: { builder: { options: { fsCache: true } } }` |
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Override the default configuration
Storybook's Webpack configuration is based on [Webpack 5](https://webpack.js.org/), allowing it to be extended to fit your project's needs. If you need to add a loader or a plugin, you can provide the `webpackFinal` configuration element in your [`.storybook/main.js|ts`](../configure/index.mdx#configure-your-storybook-project) file. The configuration element should export a function that receives the baseline configuration as the first argument and Storybook's options object as the second argument. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
When Storybook starts, it automatically merges the configuration into its own. However, when providing the `webpackFinal` configuration element, you're responsible for merging the configuration yourself. We recommend that you handle the changes to the `config` object responsibly, preserving both the `entry` and `output` properties.
#### Working with Webpack plugins
Another way to customize your Storybook configuration is to add a custom plugin or loader to help with code optimization, asset management, or other tasks. Nevertheless, since Storybook relies on the `HtmlWebpackPlugin` to generate the preview page, we recommend that you append the changes to the `config.plugins` array rather than overwriting it. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Additionally, when working with Webpack loaders that don't explicitly include specific file extensions (i.e., via the `test` property), you should `exclude` the `.ejs` file extension for that loader.
### Import a custom Webpack configuration
If you already have an existing Webpack configuration file that you need to reuse with Storybook, you can import it and merge it into the default configuration. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- Projects scaffolded based on generators may require that you import their specific Webpack configuration files. We suggest reading your generator's documentation for more information.
+
+Projects scaffolded based on generators may require that you import their specific Webpack configuration files. We suggest reading your generator's documentation for more information.
+
### Debug Webpack configuration
If you intend to debug the Webpack configuration used by Storybook, you can use the Storybook CLI to help you. If you're running in [development mode](../api/cli-options.mdx#dev), you can use the following command:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Additionally, if you're generating a [static build](../api/cli-options.mdx#build) of your Storybook, you can use the following command:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Compiler support
Storybook takes a compiler-agnostic approach to bundling. This allows you to bring your own application bundler (e.g., [Babel](https://babeljs.io/), [SWC](https://swc.rs/)) and ensures compatibility within the vast ecosystem of Webpack 5-based projects.
@@ -86,14 +63,12 @@ Storybook takes a compiler-agnostic approach to bundling. This allows you to bri
If your project is built using [SWC](https://swc.rs/), use the [`@storybook/addon-webpack5-compiler-swc`](https://storybook.js.org/addons/@storybook/addon-webpack5-compiler-swc) addon. This addon increases ecosystem compatibility with Webpack 5 projects while maintaining high performance. Run the following command to set up the addon automatically:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- Additional options can be provided to customize the SWC configuration. See the [SWC API documentation](../api/main-config/main-config-swc.mdx) for more information.
+
+Additional options can be provided to customize the SWC configuration. See the [SWC API documentation](../api/main-config/main-config-swc.mdx) for more information.
+
When enabled, this addon adjusts the Webpack configuration to use the [`swc-loader`](https://swc.rs/docs/usage/swc-loader) for JavaScript and TypeScript files. Additionally, it will detect and use your project's SWC configuration.
@@ -102,14 +77,12 @@ When enabled, this addon adjusts the Webpack configuration to use the [`swc-load
If you're working with a project that relies on Babel's tooling to provide support for specific features, including TypeScript or other modern JavaScript features, you can use the [`@storybook/addon-webpack5-compiler-babel`](https://storybook.js.org/addons/@storybook/addon-webpack5-compiler-babel) addon to allow you to include them in your Storybook to ensure compatibility with your project. Run the following command to set up the addon automatically:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- Additional options can be provided to customize the Babel configuration. See the [`babel` API documentation](../api/main-config/main-config-babel.mdx) for more information, or if you're working on an addon, the [`babelDefault` documentation](../api/main-config/main-config-babel-default.mdx) for more information.
+
+Additional options can be provided to customize the Babel configuration. See the [`babel` API documentation](../api/main-config/main-config-babel.mdx) for more information, or if you're working on an addon, the [`babelDefault` documentation](../api/main-config/main-config-babel-default.mdx) for more information.
+
When enabled, the addon will adjust the Webpack configuration to use the [`babel-loader`](https://webpack.js.org/loaders/babel-loader/) as the default loader for JavaScript and TypeScript files. Additionally, it will detect and use your project's Babel configuration.
@@ -120,20 +93,12 @@ When enabled, the addon will adjust the Webpack configuration to use the [`babel
Storybook's default Webpack configuration provides support for most project setups without the need for any additional configuration. Nevertheless, depending on your project configuration, or the framework of choice, you may run into issues with TypeScript modules not being resolved within Storybook when aliased from your [`tsconfig` file](https://www.typescriptlang.org/tsconfig). If you encounter this issue, you can use [`tsconfig-paths-webpack-plugin`](https://github.com/dividab/tsconfig-paths-webpack-plugin#tsconfig-paths-webpack-plugin) while [extending Storybook's Webpack config](#override-the-default-configuration) as follows:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
However, if you're working with a framework that provides a default aliasing configuration (e.g., Next.js, Nuxt) and you want to configure Storybook to use the same aliases, you may not need to install any additional packages. Instead, you can extend the default configuration of Storybook to use the same aliases provided by the framework. For example, to set up an alias for the `@` import path, you can add the following to your `.storybook/main.js|ts` file:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Pre-bundled assets do not show in the Storybook UI
As Storybook relies on [esbuild](https://esbuild.github.io/) to build its internal manager, support for bundling assets with the `managerWebpack` will no longer have an impact on the Storybook UI. We recommend removing existing `managerWebpack` configuration elements from your Storybook configuration file and bundling assets other than images or CSS into JavaScript beforehand.
@@ -144,6 +109,6 @@ Support for Webpack 4 has been removed and is no longer being maintained. If you
**Learn more about builders**
-* [Vite builder](./vite.mdx) for bundling with Vite
-* Webpack builder for bundling with Webpack
-* [Builder API](./builder-api.mdx) for building a Storybook builder
+- [Vite builder](./vite.mdx) for bundling with Vite
+- Webpack builder for bundling with Webpack
+- [Builder API](./builder-api.mdx) for building a Storybook builder
diff --git a/docs/configure/environment-variables.mdx b/docs/configure/environment-variables.mdx
index 894c5b60e20a..b15f75ea71ed 100644
--- a/docs/configure/environment-variables.mdx
+++ b/docs/configure/environment-variables.mdx
@@ -1,8 +1,7 @@
---
-title: 'Environment variables'
+title: Environment variables
sidebar:
order: 8
- title: Environment variables
---
You can use environment variables in Storybook to change its behavior in different “modes”.
@@ -13,31 +12,31 @@ STORYBOOK_THEME=red STORYBOOK_DATA_KEY=12345 npm run storybook
```
- Do not store any secrets (e.g., private API keys) or other types of sensitive information in your Storybook. Environment variables are embedded into the build, meaning anyone can view them by inspecting your files.
+
+Do not store any secrets (e.g., private API keys) or other types of sensitive information in your Storybook. Environment variables are embedded into the build, meaning anyone can view them by inspecting your files.
+
Then we can access these environment variables anywhere inside our preview JavaScript code like below:
-
- {/* prettier-ignore-start */}
+
-
-
+
-{/* prettier-ignore-end */}
+
-
- {/* prettier-ignore-start */}
+
-
-
+
-{/* prettier-ignore-end */}
+
You can also access these variables in your custom ``/`` using the substitution `%STORYBOOK_X%`, for example: `%STORYBOOK_THEME%` will become `red`.
- If using the environment variables as attributes or values in JavaScript, you may need to add quotes, as the value will be inserted directly, for example: ``.
+
+If using the environment variables as attributes or values in JavaScript, you may need to add quotes, as the value will be inserted directly, for example: ``.
+
## Using .env files
@@ -50,26 +49,22 @@ STORYBOOK_DATA_KEY=12345
Then you can access this environment variable anywhere, even within your stories:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
-
- ### With Vite
+
- Out of the box, Storybook provides a [Vite builder](../builders/vite.mdx), which does not output Node.js globals like `process.env`. To access environment variables in Storybook (e.g., `STORYBOOK_`, `VITE_`), you can use `import.meta.env`. For example:
+### With Vite
- {/* prettier-ignore-start */}
+Out of the box, Storybook provides a [Vite builder](../builders/vite.mdx), which does not output Node.js globals like `process.env`. To access environment variables in Storybook (e.g., `STORYBOOK_`, `VITE_`), you can use `import.meta.env`. For example:
-
+
- {/* prettier-ignore-end */}
-
+
- You can also use specific files for specific modes. Add a `.env.development` or `.env.production` to apply different values to your environment variables.
+
+You can also use specific files for specific modes. Add a `.env.development` or `.env.production` to apply different values to your environment variables.
+
You can also pass these environment variables when you are [building your Storybook](../sharing/publish-storybook.mdx) with `build-storybook`.
@@ -80,20 +75,12 @@ Then they'll be hardcoded to the static version of your Storybook.
Additionally, you can extend your Storybook configuration file (i.e., [`.storybook/main.js|.ts`](../configure/index.mdx#configure-story-rendering)) and provide a configuration field that you can use to define specific variables (e.g., API URLs). For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
When Storybook loads, it will enable you to access them in your stories similar as you would do if you were working with an `env` file:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Using environment variables to choose the browser
Storybook allows you to choose the browser you want to preview your stories. Either through a `.env` file entry or directly in your `storybook` script.
@@ -107,7 +94,9 @@ The table below lists the available options:
| Chromium | `BROWSER="chromium"` |
- By default, Storybook will open a new Chrome window as part of its startup process. If you don't have Chrome installed, make sure to include one of the following options, or set your default browser accordingly.
+
+By default, Storybook will open a new Chrome window as part of its startup process. If you don't have Chrome installed, make sure to include one of the following options, or set your default browser accordingly.
+
## Troubleshooting
diff --git a/docs/configure/index.mdx b/docs/configure/index.mdx
index f0904d1190da..9e9aaf0a855b 100644
--- a/docs/configure/index.mdx
+++ b/docs/configure/index.mdx
@@ -1,5 +1,5 @@
---
-title: 'Configure Storybook'
+title: Configure Storybook
sidebar:
order: 10
title: Configure
@@ -8,32 +8,32 @@ sidebar:
Storybook is configured via a folder called `.storybook`, which contains various configuration files.
- Note that you can change the folder that Storybook uses by setting the `-c` flag to your `storybook dev` and `storybook build` [CLI commands](../api/cli-options.mdx).
+
+Note that you can change the folder that Storybook uses by setting the `-c` flag to your `storybook dev` and `storybook build` [CLI commands](../api/cli-options.mdx).
+
## Configure your Storybook project
Storybook's main configuration (i.e., the `main.js|ts`) defines your Storybook project's behavior, including the location of your stories, the addons you use, feature flags and other project-specific settings. This file should be in the `.storybook` folder in your project's root directory. You can author this file in either JavaScript or [TypeScript](./integration/typescript.mdx). Listed below are the available options and examples of how to use them.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- This configuration file is a [preset](../addons/addon-types.mdx) and, as such, has a powerful interface, which can be further customized. Read our documentation on writing [presets](../addons/writing-presets.mdx) to learn more.
+
+This configuration file is a [preset](../addons/addon-types.mdx) and, as such, has a powerful interface, which can be further customized. Read our documentation on writing [presets](../addons/writing-presets.mdx) to learn more.
+
| Configuration element | Description |
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `stories` | The array of globs that indicates the [location of your story files](#configure-story-loading), relative to `main.js` |
| `staticDirs` | Sets a list of directories of [static files](./integration/images-and-assets.mdx#serving-static-files-via-storybook-configuration) to be loaded by Storybook `staticDirs: ['../public']` |
-| `addons` | Sets the list of [addons](https://storybook.js.org/integrations) loaded by Storybook `addons: ['@storybook/addon-docs']` |
+| `addons` | Sets the list of [addons](https://storybook.js.org/integrations) loaded by Storybook `addons: ['@storybook/addon-docs']` |
| `typescript` | Configures how Storybook handles [TypeScript files](./integration/typescript.mdx) `typescript: { check: false, checkOptions: {} }` |
| `framework` | Configures Storybook based on a set of [framework-specific](./integration/frameworks.mdx) settings `framework: { name: '@storybook/svelte-vite', options:{} }` |
| `core` | Configures Storybook's [internal features](../api/main-config/main-config-core.mdx) `core: { disableTelemetry: true, }` |
-| `docs` | Configures Storybook's [auto-generated documentation](../writing-docs/autodocs.mdx) `docs: { defaultName: 'Documentation' }` |
+| `docs` | Configures Storybook's [auto-generated documentation](../writing-docs/autodocs.mdx) `docs: { defaultName: 'Documentation' }` |
| `features` | Enables Storybook's [additional features](../api/main-config/main-config-features.mdx) See table below for a list of available features |
| `refs` | Configures [Storybook composition](../sharing/storybook-composition.mdx) `refs: { example: { title: 'ExampleStorybook', url:'https://your-url.com' } }` |
| `logLevel` | Configures Storybook's logs in the browser terminal. Useful for debugging `logLevel: 'debug'` |
@@ -57,50 +57,34 @@ If you want to use a different naming convention, you can alter the glob using t
For example, if you wanted to pull both `.md` and `.js` files from the `my-project/src/components` directory, you could write:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### With a configuration object
Additionally, you can customize your Storybook configuration to load your stories based on a configuration object. For example, if you wanted to load your stories from a `packages/components` directory, you could adjust your `stories` configuration field into the following:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
When Storybook starts, it will look for any file containing the `stories` extension inside the `packages/components` directory and generate the titles for your stories.
### With a directory
You can also simplify your Storybook configuration and load the stories using a directory. For example, if you want to load all the stories inside a `packages/MyStories`, you can adjust the configuration as such:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### With a custom implementation
You can also adjust your Storybook configuration and implement custom logic to load your stories. For example, suppose you were working on a project that includes a particular pattern that the conventional ways of loading stories could not solve. In that case, you could adjust your configuration as follows:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### Known limitations
Because of the way stories are currently indexed in Storybook, loading stories on demand has a couple of minor limitations at the moment:
-* [CSF formats](../api/csf/index.mdx) from version 1 to version 3 are supported.
-* Custom `storySort` functions are allowed based on a restricted API.
+- [CSF formats](../api/csf/index.mdx) from version 1 to version 3 are supported.
+- Custom `storySort` functions are allowed based on a restricted API.
## Configure story rendering
@@ -108,9 +92,9 @@ To control the way stories are rendered and add global [decorators](../writing-s
The `preview.js` file can be an ES module and export the following keys:
-* `decorators` - an array of global [decorators](../writing-stories/decorators.mdx#global-decorators)
-* `parameters` - an object of global [parameters](../writing-stories/parameters.mdx#global-parameters)
-* `globalTypes` - definition of [globalTypes](../essentials/toolbars-and-globals.mdx#global-types-and-the-toolbar-annotation)
+- `decorators` - an array of global [decorators](../writing-stories/decorators.mdx#global-decorators)
+- `parameters` - an object of global [parameters](../writing-stories/parameters.mdx#global-parameters)
+- `globalTypes` - definition of [globalTypes](../essentials/toolbars-and-globals.mdx#global-types-and-the-toolbar-annotation)
If you’re looking to change how to order your stories, read about [sorting stories](../writing-stories/naming-components-and-hierarchy.mdx#sorting-stories).
diff --git a/docs/configure/integration/compilers.mdx b/docs/configure/integration/compilers.mdx
index 4ed33e1e7794..63a931e18e4a 100644
--- a/docs/configure/integration/compilers.mdx
+++ b/docs/configure/integration/compilers.mdx
@@ -1,5 +1,5 @@
---
-title: 'Compiler support'
+title: Compiler support
sidebar:
order: 3
title: Compilers
@@ -12,7 +12,9 @@ Javascript compilers are essential in optimizing and transforming code, enhancin
SWC is a fast, highly extensible tool for compiling and bundling modern JavaScript applications. Powered by [Rust](https://www.rust-lang.org/), it improves performance and reduces build times. Storybook includes a built-in integration with SWC, allowing zero-configuration setup and built-in types for APIs. If you've initialized Storybook in a Webpack-based project with any of the supported [frameworks](./frameworks.mdx), except Angular, Create React App, Ember.js and Next.js, it will automatically use SWC as its default, providing you with faster loading time.
- Support for the SWC builder is currently experimental for Next.js projects, and it's not enabled by default. It requires you to opt in to use it. For more information on configuring SWC with the supported frameworks, see the [SWC API](../../api/main-config/main-config-swc.mdx) documentation.
+
+Support for the SWC builder is currently experimental for Next.js projects, and it's not enabled by default. It requires you to opt in to use it. For more information on configuring SWC with the supported frameworks, see the [SWC API](../../api/main-config/main-config-swc.mdx) documentation.
+
## Babel
@@ -20,20 +22,24 @@ SWC is a fast, highly extensible tool for compiling and bundling modern JavaScri
Babel is a widely adopted JavaScript compiler providing a modular architecture and extensive plugin system to support a wide range of use cases, enabling access to the cutting-edge features of the tooling ecosystem. Storybook provides a seamless integration with Babel, allowing you to share a standard setup between your project and Storybook without any additional configuration.
- If you're not using Storybook 7, please reference the [previous documentation](../../../release-6-5/docs/configure/babel.mdx) for guidance on configuring your Babel setup.
+
+If you're not using Storybook 7, please reference the [previous documentation](../../../release-6-5/docs/configure/babel.mdx) for guidance on configuring your Babel setup.
+
### Configure
By default, Babel provides an opinionated [configuration](https://babeljs.io/docs/config-files) that works for most projects, relying on two distinct methods for configuring projects with the tool:
-* **Project-wide configuration**: Babel will look for a `babel.config.js` or equivalent file in the root of your project and use it to configure your project's Babel setup.
-* **File-relative configuration**: Babel will look for a `.babelrc.json` or equivalent file, introspecting the project structure until it finds a configuration file. This will allow you to configure Babel individually for multiple aspects of your project.
+- **Project-wide configuration**: Babel will look for a `babel.config.js` or equivalent file in the root of your project and use it to configure your project's Babel setup.
+- **File-relative configuration**: Babel will look for a `.babelrc.json` or equivalent file, introspecting the project structure until it finds a configuration file. This will allow you to configure Babel individually for multiple aspects of your project.
Storybook relies on an agnostic approach to configuring Babel, enabling you to provide the necessary configuration for your project, and it will use it. Based on the supported frameworks, builders, and addons, it may include minor adjustments to ensure compatibility with Storybook's features.
- For custom project configurations such as monorepos, where you have multiple Storybook configurations, creating a `.babelrc.json` file in your project's current working directory may not be sufficient. In those cases, you can create a `babel.config.js` file to override Babel's configuration, and Storybook will automatically detect and use it. See the Babel [documentation](https://babeljs.io/docs/config-files) for more information.
+
+For custom project configurations such as monorepos, where you have multiple Storybook configurations, creating a `.babelrc.json` file in your project's current working directory may not be sufficient. In those cases, you can create a `babel.config.js` file to override Babel's configuration, and Storybook will automatically detect and use it. See the Babel [documentation](https://babeljs.io/docs/config-files) for more information.
+
### Working with Create React App
@@ -42,17 +48,15 @@ If you're working with a project that was initialized with [Create React App](ht
## Troubleshooting
-
- ### The SWC compiler doesn't work with React
+
- If you have enabled the SWC builder option in a React-based project and you are not explicitly importing React in your `jsx|tsx` files, it can cause Storybook to fail to load. SWC does not automatically import the `jsx-runtime` module when using the SWC builder. To resolve this issue, you need to adjust your Storybook configuration file (i.e., `.storybook/main.js|ts`) and configure the `swc` option as follows:
+### The SWC compiler doesn't work with React
- {/* prettier-ignore-start */}
+If you have enabled the SWC builder option in a React-based project and you are not explicitly importing React in your `jsx|tsx` files, it can cause Storybook to fail to load. SWC does not automatically import the `jsx-runtime` module when using the SWC builder. To resolve this issue, you need to adjust your Storybook configuration file (i.e., `.storybook/main.js|ts`) and configure the `swc` option as follows:
-
+
- {/* prettier-ignore-end */}
-
+
### Babel configuration not working
diff --git a/docs/configure/integration/eslint-plugin.mdx b/docs/configure/integration/eslint-plugin.mdx
index fe1a7bd112b4..1e20b0ce2714 100644
--- a/docs/configure/integration/eslint-plugin.mdx
+++ b/docs/configure/integration/eslint-plugin.mdx
@@ -1,9 +1,8 @@
---
-title: "ESLint plugin"
+title: ESLint plugin
hideRendererSelector: true
sidebar:
order: 5
- title: ESLint plugin
---
Storybook provides a dedicated [ESLint plugin](https://github.com/storybookjs/storybook/tree/next/code/lib/eslint-plugin) to help you write stories and components aligned with the latest Storybook and frontend development best practices.
@@ -40,10 +39,10 @@ For more details on why this line is required in the `.eslintignore` file, refer
If you are using [flat config style](https://eslint.org/docs/latest/use/configure/configuration-files-new), add this to your configuration file:
```js title="eslint.config.js"
-import { defineConfig, globalIgnores } from "eslint/config";
+import { defineConfig, globalIgnores } from 'eslint/config';
export default defineConfig([
- globalIgnores(["!.storybook"], "Include Storybook Directory"),
+ globalIgnores(['!.storybook'], 'Include Storybook Directory'),
// ...
]);
```
@@ -62,7 +61,7 @@ Depending on the version of ESLint you are using, you may need to install a spec
### Configuration (`.eslintrc`)
-Use `.eslintrc.*` file to configure rules in ESLint < v9. See also: https://eslint.org/docs/latest/use/configure/.
+Use `.eslintrc.*` file to configure rules in ESLint < v9. [ESLint docs](https://eslint.org/docs/latest/use/configure/).
This plugin will only be applied to files following the `*.stories.*` (recommended) or `*.story.*` pattern. This is an automatic configuration, so no action is required.
@@ -89,15 +88,15 @@ Optionally, you can override, add to, or disable individual rules. You likely do
### Configuration (flat config format)
-Use the `eslint.config.js` file to configure rules using the [flat config style](https://eslint.org/docs/latest/use/configure/configuration-files-new). This is the default in ESLint v9, but can be used starting from ESLint v8.57.0. See also: https://eslint.org/docs/latest/use/configure/configuration-files-new.
+Use the `eslint.config.js` file to configure rules using the [flat config style](https://eslint.org/docs/latest/use/configure/configuration-files-new). This is the default in ESLint v9, but can be used starting from ESLint v8.57.0. [ESLint docs](https://eslint.org/docs/latest/use/configure/configuration-files-new).
```js title="eslint.config.js"
-import storybook from "eslint-plugin-storybook";
+import storybook from 'eslint-plugin-storybook';
// Replace the eslint/config package with @eslint/config-helpers if you're using an older version of ESLint.
-import { defineConfig } from "eslint/config";
+import { defineConfig } from 'eslint/config';
export default defineConfig([
- ...storybook.configs["flat/recommended"],
+ ...storybook.configs['flat/recommended'],
// Add more configuration options and generic rulesets here, such as js.configs.recommended
]);
```
@@ -105,13 +104,13 @@ export default defineConfig([
In case you are using utility functions from tools like `tseslint`, you might need to register the plugin a little differently:
```ts title="eslint.config.ts"
-import storybook from "eslint-plugin-storybook";
-import somePlugin from "some-plugin";
-import tseslint from "typescript-eslint";
+import storybook from 'eslint-plugin-storybook';
+import somePlugin from 'some-plugin';
+import tseslint from 'typescript-eslint';
export default tseslint.config(
somePlugin,
- storybook.configs["flat/recommended"], // notice that it is not destructured
+ storybook.configs['flat/recommended'], // notice that it is not destructured
);
```
@@ -120,19 +119,19 @@ export default tseslint.config(
Optionally, you can override, add, or disable individual rules. You likely don't want these settings to be applied to every file, so ensure that you add a flat config section in your `eslint.config.js` file that applies the overrides only to your story files.
```js title="eslint.config.js"
-import storybook from "eslint-plugin-storybook";
-import { defineConfig } from "eslint/config";
+import storybook from 'eslint-plugin-storybook';
+import { defineConfig } from 'eslint/config';
export default defineConfig([
- ...storybook.configs["flat/recommended"],
+ ...storybook.configs['flat/recommended'],
{
// 👇 This should match the `stories` property in .storybook/main.js|ts
- files: ["**/*.stories.@(ts|tsx|js|jsx|mjs|cjs)"],
+ files: ['**/*.stories.@(ts|tsx|js|jsx|mjs|cjs)'],
rules: {
// 👇 Enable this rule
- "storybook/csf-component": "error",
+ 'storybook/csf-component': 'error',
// 👇 Disable this rule
- "storybook/default-exports": "off",
+ 'storybook/default-exports': 'off',
},
},
]);
diff --git a/docs/configure/integration/frameworks-feature-support.mdx b/docs/configure/integration/frameworks-feature-support.mdx
index 635462906269..e1183e7f349f 100644
--- a/docs/configure/integration/frameworks-feature-support.mdx
+++ b/docs/configure/integration/frameworks-feature-support.mdx
@@ -1,9 +1,8 @@
---
-title: 'Feature support for frameworks'
+title: Feature support for frameworks
hideRendererSelector: true
sidebar:
order: 2
- title: Feature support for frameworks
---
Storybook integrates with many popular frontend frameworks. We do our best to keep feature parity amongst frameworks, but it’s tricky for our modest team to support every framework.
@@ -14,107 +13,107 @@ Below is a comprehensive table of what’s supported in which framework integrat
Core frameworks have dedicated maintainers or contributors who are responsible for maintaining the integration. As such, you can use most Storybook features in these frameworks.
-| | React | Vue 3 | Angular | Web Components |
-| --------------------------------------------------------------------------------------------- | ----- | ----- | ------- | -------------- |
-| **Essentials** | | | | |
-| [Actions](../../essentials/actions.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Backgrounds](../../essentials/backgrounds.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Controls](../../essentials/controls.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Interactions](../../writing-tests/interaction-testing.mdx#debugging-interaction-tests) | ✅ | ✅ | ✅ | ✅ |
-| [Measure](../../essentials/measure-and-outline.mdx#measure-addon) | ✅ | ✅ | ✅ | ✅ |
-| [Outline](../../essentials/measure-and-outline.mdx#outline-addon) | ✅ | ✅ | ✅ | ✅ |
-| [Viewport](../../essentials/viewport.mdx) | ✅ | ✅ | ✅ | ✅ |
-| **Addons** | | | | |
-| [A11y](../../writing-tests/accessibility-testing.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Docs](../../writing-docs/index.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Test runner](../../writing-tests/integrations/test-runner.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Test coverage](../../writing-tests/test-coverage.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [CSS resources](https://github.com/storybookjs/addon-cssresources) | ✅ | ✅ | ✅ | ✅ |
-| [Design assets](https://github.com/storybookjs/addon-design-assets) | ✅ | ✅ | ✅ | ✅ |
-| [Events](https://github.com/storybookjs/addon-events) | ✅ | ✅ | ✅ | ✅ |
-| [Google analytics](https://github.com/storybookjs/addon-google-analytics) | ✅ | ✅ | ✅ | ✅ |
-| [GraphQL](https://github.com/storybookjs/addon-graphql) | ✅ | | ✅ | |
-| [Jest](https://github.com/storybookjs/addon-jest) | ✅ | ✅ | ✅ | ✅ |
-| [Links](https://github.com/storybookjs/storybook/tree/next/code/addons/links) | ✅ | ✅ | ✅ | ✅ |
-| [Queryparams](https://github.com/storybookjs/addon-queryparams) | ✅ | ✅ | ✅ | ✅ |
-| **Docs** | | | | |
-| [CSF Stories](../../api/csf/index.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Autodocs](../../writing-docs/autodocs.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - ArgTypes](../../api/doc-blocks/doc-block-argtypes.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Canvas](../../api/doc-blocks/doc-block-canvas.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - ColorPalette](../../api/doc-blocks/doc-block-colorpalette.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Controls](../../api/doc-blocks/doc-block-controls.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Description](../../api/doc-blocks/doc-block-description.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - IconGallery](../../api/doc-blocks/doc-block-icongallery.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Markdown](../../api/doc-blocks/doc-block-markdown.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Meta](../../api/doc-blocks/doc-block-meta.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Primary](../../api/doc-blocks/doc-block-primary.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Source](../../api/doc-blocks/doc-block-source.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Story](../../api/doc-blocks/doc-block-story.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Stories](../../api/doc-blocks/doc-block-stories.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Subtitle](../../api/doc-blocks/doc-block-subtitle.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Title](../../api/doc-blocks/doc-block-title.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Typeset](../../api/doc-blocks/doc-block-typeset.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Unstyled](../../api/doc-blocks/doc-block-unstyled.mdx) | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - UseOf](../../api/doc-blocks/doc-block-useof.mdx) | ✅ | ✅ | ✅ | ✅ |
-| Inline stories | ✅ | ✅ | ✅ | ✅ |
+| | React | Vue 3 | Angular | Web Components |
+| --------------------------------------------------------------------------------------- | ----- | ----- | ------- | -------------- |
+| **Essentials** | | | | |
+| [Actions](../../essentials/actions.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Backgrounds](../../essentials/backgrounds.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Controls](../../essentials/controls.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Interactions](../../writing-tests/interaction-testing.mdx#debugging-interaction-tests) | ✅ | ✅ | ✅ | ✅ |
+| [Measure](../../essentials/measure-and-outline.mdx#measure) | ✅ | ✅ | ✅ | ✅ |
+| [Outline](../../essentials/measure-and-outline.mdx#outline) | ✅ | ✅ | ✅ | ✅ |
+| [Viewport](../../essentials/viewport.mdx) | ✅ | ✅ | ✅ | ✅ |
+| **Addons** | | | | |
+| [A11y](../../writing-tests/accessibility-testing.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Docs](../../writing-docs/index.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Test runner](../../writing-tests/integrations/test-runner.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Test coverage](../../writing-tests/test-coverage.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [CSS resources](https://github.com/storybookjs/addon-cssresources) | ✅ | ✅ | ✅ | ✅ |
+| [Design assets](https://github.com/storybookjs/addon-design-assets) | ✅ | ✅ | ✅ | ✅ |
+| [Events](https://github.com/storybookjs/addon-events) | ✅ | ✅ | ✅ | ✅ |
+| [Google analytics](https://github.com/storybookjs/addon-google-analytics) | ✅ | ✅ | ✅ | ✅ |
+| [GraphQL](https://github.com/storybookjs/addon-graphql) | ✅ | | ✅ | |
+| [Jest](https://github.com/storybookjs/addon-jest) | ✅ | ✅ | ✅ | ✅ |
+| [Links](https://github.com/storybookjs/storybook/tree/next/code/addons/links) | ✅ | ✅ | ✅ | ✅ |
+| [Queryparams](https://github.com/storybookjs/addon-queryparams) | ✅ | ✅ | ✅ | ✅ |
+| **Docs** | | | | |
+| [CSF Stories](../../api/csf/index.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Autodocs](../../writing-docs/autodocs.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - ArgTypes](../../api/doc-blocks/doc-block-argtypes.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Canvas](../../api/doc-blocks/doc-block-canvas.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - ColorPalette](../../api/doc-blocks/doc-block-colorpalette.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Controls](../../api/doc-blocks/doc-block-controls.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Description](../../api/doc-blocks/doc-block-description.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - IconGallery](../../api/doc-blocks/doc-block-icongallery.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Markdown](../../api/doc-blocks/doc-block-markdown.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Meta](../../api/doc-blocks/doc-block-meta.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Primary](../../api/doc-blocks/doc-block-primary.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Source](../../api/doc-blocks/doc-block-source.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Story](../../api/doc-blocks/doc-block-story.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Stories](../../api/doc-blocks/doc-block-stories.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Subtitle](../../api/doc-blocks/doc-block-subtitle.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Title](../../api/doc-blocks/doc-block-title.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Typeset](../../api/doc-blocks/doc-block-typeset.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Unstyled](../../api/doc-blocks/doc-block-unstyled.mdx) | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - UseOf](../../api/doc-blocks/doc-block-useof.mdx) | ✅ | ✅ | ✅ | ✅ |
+| Inline stories | ✅ | ✅ | ✅ | ✅ |
## Community frameworks
Community frameworks have fewer contributors which means they may not be as up to date as core frameworks. If you use one of these frameworks for your job, please consider contributing to its integration with Storybook.
-| | Ember | HTML | Svelte | Preact | Qwik | SolidJS |
-| --------------------------------------------------------------------------------------------- | ----- | ---- | ------ | ------ | ---- | ------- |
-| **Essentials** | | | | | | |
-| [Actions](../../essentials/actions.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Backgrounds](../../essentials/backgrounds.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Controls](../../essentials/controls.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Interactions](../../writing-tests/interaction-testing.mdx#debugging-interaction-tests) | | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Measure](../../essentials/measure-and-outline.mdx#measure-addon) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Outline](../../essentials/measure-and-outline.mdx#outline-addon) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Viewport](../../essentials/viewport.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| **Addons** | | | | | | |
-| [A11y](../../writing-tests/accessibility-testing.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Docs](../../writing-docs/index.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Test runner](../../writing-tests/integrations/test-runner.mdx) | | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Test coverage](../../writing-tests/test-coverage.mdx) | | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [CSS resources](https://github.com/storybookjs/addon-cssresources) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Design assets](https://github.com/storybookjs/addon-design-assets) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Events](https://github.com/storybookjs/addon-events) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Google analytics](https://github.com/storybookjs/addon-google-analytics) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [GraphQL](https://github.com/storybookjs/addon-graphql) | | | | | | |
-| [Jest](https://github.com/storybookjs/addon-jest) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Links](https://github.com/storybookjs/storybook/tree/next/code/addons/links) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Queryparams](https://github.com/storybookjs/addon-queryparams) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| **Docs** | | | | | | |
-| [CSF Stories](../../api/csf/index.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Autodocs](../../writing-docs/autodocs.mdx) | | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - ArgTypes](../../api/doc-blocks/doc-block-argtypes.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Canvas](../../api/doc-blocks/doc-block-canvas.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - ColorPalette](../../api/doc-blocks/doc-block-colorpalette.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Controls](../../api/doc-blocks/doc-block-controls.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Description](../../api/doc-blocks/doc-block-description.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - IconGallery](../../api/doc-blocks/doc-block-icongallery.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Markdown](../../api/doc-blocks/doc-block-markdown.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Meta](../../api/doc-blocks/doc-block-meta.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Primary](../../api/doc-blocks/doc-block-primary.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Source](../../api/doc-blocks/doc-block-source.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Story](../../api/doc-blocks/doc-block-story.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Stories](../../api/doc-blocks/doc-block-stories.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Subtitle](../../api/doc-blocks/doc-block-subtitle.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Title](../../api/doc-blocks/doc-block-title.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Typeset](../../api/doc-blocks/doc-block-typeset.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - Unstyled](../../api/doc-blocks/doc-block-unstyled.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| [Doc Blocks - UseOf](../../api/doc-blocks/doc-block-useof.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
-| Inline stories | | ✅ | ✅ | | | |
+| | Ember | HTML | Svelte | Preact | Qwik | SolidJS |
+| --------------------------------------------------------------------------------------- | ----- | ---- | ------ | ------ | ---- | ------- |
+| **Essentials** | | | | | | |
+| [Actions](../../essentials/actions.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Backgrounds](../../essentials/backgrounds.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Controls](../../essentials/controls.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Interactions](../../writing-tests/interaction-testing.mdx#debugging-interaction-tests) | | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Measure](../../essentials/measure-and-outline.mdx#measure) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Outline](../../essentials/measure-and-outline.mdx#outline) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Viewport](../../essentials/viewport.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| **Addons** | | | | | | |
+| [A11y](../../writing-tests/accessibility-testing.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Docs](../../writing-docs/index.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Test runner](../../writing-tests/integrations/test-runner.mdx) | | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Test coverage](../../writing-tests/test-coverage.mdx) | | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [CSS resources](https://github.com/storybookjs/addon-cssresources) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Design assets](https://github.com/storybookjs/addon-design-assets) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Events](https://github.com/storybookjs/addon-events) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Google analytics](https://github.com/storybookjs/addon-google-analytics) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [GraphQL](https://github.com/storybookjs/addon-graphql) | | | | | | |
+| [Jest](https://github.com/storybookjs/addon-jest) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Links](https://github.com/storybookjs/storybook/tree/next/code/addons/links) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Queryparams](https://github.com/storybookjs/addon-queryparams) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| **Docs** | | | | | | |
+| [CSF Stories](../../api/csf/index.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Autodocs](../../writing-docs/autodocs.mdx) | | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - ArgTypes](../../api/doc-blocks/doc-block-argtypes.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Canvas](../../api/doc-blocks/doc-block-canvas.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - ColorPalette](../../api/doc-blocks/doc-block-colorpalette.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Controls](../../api/doc-blocks/doc-block-controls.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Description](../../api/doc-blocks/doc-block-description.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - IconGallery](../../api/doc-blocks/doc-block-icongallery.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Markdown](../../api/doc-blocks/doc-block-markdown.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Meta](../../api/doc-blocks/doc-block-meta.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Primary](../../api/doc-blocks/doc-block-primary.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Source](../../api/doc-blocks/doc-block-source.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Story](../../api/doc-blocks/doc-block-story.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Stories](../../api/doc-blocks/doc-block-stories.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Subtitle](../../api/doc-blocks/doc-block-subtitle.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Title](../../api/doc-blocks/doc-block-title.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Typeset](../../api/doc-blocks/doc-block-typeset.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - Unstyled](../../api/doc-blocks/doc-block-unstyled.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| [Doc Blocks - UseOf](../../api/doc-blocks/doc-block-useof.mdx) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
+| Inline stories | | ✅ | ✅ | | | |
## Deprecated
To align the Storybook ecosystem with the current state of frontend development, the following features and addons are now deprecated, no longer maintained, and will be removed in future versions of Storybook
-| Feature | Status |
-| ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
-| [Knobs](https://github.com/storybookjs/addon-knobs) | The Knobs addon was officially deprecated with the release of Storybook 6.3 and is no longer actively maintained. We recommend using the [controls](../../essentials/controls.mdx) instead. |
-| Storyshots | The Storyshots addon was officially deprecated with the release of Storybook 7.6, is no longer actively maintained and was removed in Storybook 8. See the [migration guide](../../../release-8-6/docs/writing-tests/snapshot-testing/storyshots-migration-guide.mdx) for the available alternatives. |
-| StoriesOf | The `storiesOf` API was officially removed with the release of Storybook 8 and is no longer maintained. We recommend using the [CSF API](../../api/csf/index.mdx) instead for writing stories. See the [migration guide](../../releases/migration-guide-from-older-version.mdx#major-breaking-changes) for more information. |
-| Storysource | The Storysource addon was officially removed with the release of Storybook 9 and is no longer maintained. To display your stories' source code, we recommend using the [`codePanel`](../../writing-docs/code-panel.mdx) parameter instead. |
+| Feature | Status |
+| --------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| [Knobs](https://github.com/storybookjs/addon-knobs) | The Knobs addon was officially deprecated with the release of Storybook 6.3 and is no longer actively maintained. We recommend using the [controls](../../essentials/controls.mdx) instead. |
+| Storyshots | The Storyshots addon was officially deprecated with the release of Storybook 7.6, is no longer actively maintained and was removed in Storybook 8. See the [migration guide](../../../release-8-6/docs/writing-tests/snapshot-testing/storyshots-migration-guide.mdx) for the available alternatives. |
+| StoriesOf | The `storiesOf` API was officially removed with the release of Storybook 8 and is no longer maintained. We recommend using the [CSF API](../../api/csf/index.mdx) instead for writing stories. See the [migration guide](../../releases/migration-guide-from-older-version.mdx#major-breaking-changes) for more information. |
+| Storysource | The Storysource addon was officially removed with the release of Storybook 9 and is no longer maintained. To display your stories' source code, we recommend using the [`codePanel`](../../writing-docs/code-panel.mdx) parameter instead. |
diff --git a/docs/configure/integration/frameworks.mdx b/docs/configure/integration/frameworks.mdx
index 665efee35e24..7f0e43b55a31 100644
--- a/docs/configure/integration/frameworks.mdx
+++ b/docs/configure/integration/frameworks.mdx
@@ -1,5 +1,5 @@
---
-title: 'Framework support'
+title: Framework support
sidebar:
order: 1
title: Frameworks
@@ -28,22 +28,18 @@ In addition to supporting the most popular frameworks in the industry, Storybook
Every modern web application has unique requirements and relies on various tools and frameworks. By default, with Storybook, you get an out-of-the-box configuration generated to work with most frameworks. However, you can extend your existing configuration file (i.e., `./storybook/main.js|ts|cjs`) and provide additional options. Below is an abridged table with available options and examples of configuring Storybook for your framework.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
-| Option | Description | Framework |
-| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
-| `nextConfigPath` | Sets the default path for the NextJS configuration file `framework: { name: '@storybook/nextjs', options: { nextConfigPath: '../next.config.js'} }` | NextJS |
-| `builder` | Configures [Webpack 5](../../builders/webpack.mdx) builder options for NextJS `core: { builder: { name:'webpack5', options: { lazyCompilation: true} }}` | NextJS |
-| `strictMode` | Enables React's [strict mode](https://reactjs.org/docs/strict-mode.html) `framework: { name: '@storybook/react-webpack5', options: { strictMode: false } }` | React |
-| `legacyRootApi` | Requires React 18. Toggles support for React's [legacy root API](https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html#updates-to-client-rendering-apis) `framework: { name: '@storybook/react-webpack5', options: { legacyRootApi: true } }` | React |
-| `enableIvy` | Enabled by default with Angular 9+. Replaces the default compiler with the [Ivy compiler](https://docs.angular.lat/guide/ivy) `framework: { name: '@storybook/angular', options: { enableIvy: true } }` | Angular |
-| `enableNgcc` | Enabled by default with Angular 9+. Adds support for ngcc for backwards compatibility `framework: { name: '@storybook/angular', options: { enableNgcc: false } }` | Angular |
+| Option | Description | Framework |
+| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------- |
+| `nextConfigPath` | Sets the default path for the NextJS configuration file `framework: { name: '@storybook/nextjs', options: { nextConfigPath: '../next.config.js'} }` | NextJS |
+| `builder` | Configures [Webpack 5](../../builders/webpack.mdx) builder options for NextJS `core: { builder: { name:'webpack5', options: { lazyCompilation: true} }}` | NextJS |
+| `strictMode` | Enables React's [strict mode](https://reactjs.org/docs/strict-mode.html) `framework: { name: '@storybook/react-webpack5', options: { strictMode: false } }` | React |
+| `legacyRootApi` | Requires React 18. Toggles support for React's [legacy root API](https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html#updates-to-client-rendering-apis) `framework: { name: '@storybook/react-webpack5', options: { legacyRootApi: true } }` | React |
+| `enableIvy` | Enabled by default with Angular 9+. Replaces the default compiler with the [Ivy compiler](https://docs.angular.lat/guide/ivy) `framework: { name: '@storybook/angular', options: { enableIvy: true } }` | Angular |
+| `enableNgcc` | Enabled by default with Angular 9+. Adds support for ngcc for backwards compatibility `framework: { name: '@storybook/angular', options: { enableNgcc: false } }` | Angular |
-***
+---
## Troubleshooting
@@ -65,7 +61,7 @@ We're deprecating support for several frameworks, including [Aurelia](https://gi
### Learn about configuring Storybook
-* [Theming](../user-interface/theming.mdx) to customize the look and feel of Storybook's UI
-* [CSS](../styling-and-css.mdx) to configure CSS support
-* [Images & assets](./images-and-assets.mdx) for static asset handling
-* [Environment variables](../environment-variables.mdx) to configure environment variables
+- [Theming](../user-interface/theming.mdx) to customize the look and feel of Storybook's UI
+- [CSS](../styling-and-css.mdx) to configure CSS support
+- [Images & assets](./images-and-assets.mdx) for static asset handling
+- [Environment variables](../environment-variables.mdx) to configure environment variables
diff --git a/docs/configure/integration/images-and-assets.mdx b/docs/configure/integration/images-and-assets.mdx
index 757d858c68ae..cf7968df11b9 100644
--- a/docs/configure/integration/images-and-assets.mdx
+++ b/docs/configure/integration/images-and-assets.mdx
@@ -13,62 +13,40 @@ You can import any media assets by importing (or requiring) them. It works out o
Afterward, you can use any asset in your stories:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Serving static files via Storybook Configuration
We recommend serving static files via Storybook to ensure that your components always have the assets they need to load. We recommend this technique for assets that your components often use, like logos, fonts, and icons.
Configure a directory (or a list of directories) where your assets live when starting Storybook. Use the `staticDirs` configuration element in your main Storybook configuration file (i.e., `.storybook/main.js|ts`) to specify the directories:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Here `../public` is your static directory. Now use it in a component or story like this.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
You can also pass a list of directories separated by commas without spaces instead of a single directory.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Or even use a configuration object to define the directories:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
+
When using Vite-based frameworks, additional directories may be copied to your build directory because of Vite's own [static asset handling](https://vite.dev/guide/assets#the-public-directory). You can set Vite's `publicDir` option to `false` to disable this behavior.
+
## Reference assets from a CDN
Upload your files to an online CDN and reference them. In this example, we’re using a placeholder image service.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Absolute versus relative paths
Sometimes, you may want to deploy your Storybook into a subpath, like `https://example.com/storybook`.
@@ -83,8 +61,4 @@ Suppose you are serving assets in a [static directory](#serving-static-files-via
After configuring Storybook to serve assets from your static folder, you can reference those assets in Storybook. For example, you can reference and apply a custom font to your stories. To do this, create a [`preview-head.html`](../story-rendering.mdx) file inside the configuration directory (i.e., `.storybook`) and add a `` tag to reference your font.
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/configure/integration/index.mdx b/docs/configure/integration/index.mdx
index b0a23488940b..5e958897b88f 100644
--- a/docs/configure/integration/index.mdx
+++ b/docs/configure/integration/index.mdx
@@ -2,5 +2,4 @@
title: Integration
sidebar:
order: 4
- title: Integration
----
\ No newline at end of file
+---
diff --git a/docs/configure/integration/typescript.mdx b/docs/configure/integration/typescript.mdx
index ae0a3abf9f4d..65249d739091 100644
--- a/docs/configure/integration/typescript.mdx
+++ b/docs/configure/integration/typescript.mdx
@@ -1,8 +1,7 @@
---
-title: 'TypeScript'
+title: TypeScript
sidebar:
order: 4
- title: Typescript
---
Storybook provides an integrated [TypeScript](https://www.typescriptlang.org/) experience, including zero-configuration setup and built-in types for APIs, addons, and stories.
@@ -11,130 +10,110 @@ Storybook provides an integrated [TypeScript](https://www.typescriptlang.org/) e
Storybook's configuration file (i.e., `main.ts`) is defined as an ESM module written in TypeScript, providing you with the baseline configuration to support your existing framework while enabling you stricter type-checking and autocompletion in your editor. Below is an abridged configuration file.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
See the [main configuration API reference](../../api/main-config/main-config.mdx) for more details and additional properties.
- See the Vite builder [TypeScript documentation](https://github.com/storybookjs/builder-vite#typescript) if using `@storybook/builder-vite`.
+
+See the Vite builder [TypeScript documentation](https://github.com/storybookjs/builder-vite#typescript) if using `@storybook/builder-vite`.
+
### Extending the default configuration
-
- Out of the box, Storybook is built to work with a wide range of third-party libraries, enabling you to safely access and document metadata (e.g., props, inputs) from your components without any additional configuration. Since Storybook supports multiple frameworks, it also includes a set of third-party packages to support each framework (e.g., `ts-loader`, `vue-docgen-api` for Vue). If you need to customize the default configuration for a specific use case scenario, you can adjust your Storybook configuration file and provide the required options. Listed below are the available options and examples of how to use them.
+
- | Option | Description |
- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
- | `check` | Available for Webpack-based projects. Enables type checking within Storybook `typescript: { check: true },` |
- | `checkOptions` | Requires the `check` option to be enabled. Configures the [`fork-ts-checker-webpack-plugin`](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin) plugin `typescript: { checkOptions:{},},` |
- | `skipCompiler` | Disables parsing Typescript files through the compiler `typescript: { skipCompiler:false,},` |
-
+Out of the box, Storybook is built to work with a wide range of third-party libraries, enabling you to safely access and document metadata (e.g., props, inputs) from your components without any additional configuration. Since Storybook supports multiple frameworks, it also includes a set of third-party packages to support each framework (e.g., `ts-loader`, `vue-docgen-api` for Vue). If you need to customize the default configuration for a specific use case scenario, you can adjust your Storybook configuration file and provide the required options. Listed below are the available options and examples of how to use them.
-
- Out of the box, Storybook is built to work with a wide range of third-party libraries, enabling you to safely access and document metadata (e.g., props) for your components without any additional configuration. It relies on [`react-docgen`](https://github.com/reactjs/react-docgen), a fast and highly customizable parser to process TypeScript files to infer the component's metadata and generate types automatically for improved performance and type safety. If you need to customize the default configuration for a specific use case scenario, you can adjust your Storybook configuration file and provide the required options. Listed below are the available options and examples of how to use them.
+| Option | Description |
+| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `check` | Available for Webpack-based projects. Enables type checking within Storybook `typescript: { check: true },` |
+| `checkOptions` | Requires the `check` option to be enabled. Configures the [`fork-ts-checker-webpack-plugin`](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin) plugin `typescript: { checkOptions:{},},` |
+| `skipCompiler` | Disables parsing Typescript files through the compiler `typescript: { skipCompiler:false,},` |
- | Option | Description |
- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
- | `check` | Available for Webpack-based projects. Enables type checking within Storybook `typescript: { check: true },` |
- | `checkOptions` | Requires the `check` option to be enabled. Configures the [`fork-ts-checker-webpack-plugin`](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin) plugin `typescript: { checkOptions: {},},` |
- | `reactDocgen` | Configures the TypeScript parser used by Storybook. Available options: `react-docgen` (default), `react-docgen-typescript`,` false` `typescript: { reactDocgen: 'react-docgen'},` |
- | `reactDocgenTypescriptOptions` | Requires the `reactDocgen`option to be `react-docgen-typescript`. Configures the `react-docgen-typescript-plugin` plugin per builder `typescript: { reactDocgen: 'react-docgen-typescript', reactDocgenTypescriptOptions: {},},` |
- | `skipCompiler` | Disables parsing Typescript files through the compiler `typescript: { skipCompiler:false,},` |
-
+
-{/* prettier-ignore-start */}
+
+
+Out of the box, Storybook is built to work with a wide range of third-party libraries, enabling you to safely access and document metadata (e.g., props) for your components without any additional configuration. It relies on [`react-docgen`](https://github.com/reactjs/react-docgen), a fast and highly customizable parser to process TypeScript files to infer the component's metadata and generate types automatically for improved performance and type safety. If you need to customize the default configuration for a specific use case scenario, you can adjust your Storybook configuration file and provide the required options. Listed below are the available options and examples of how to use them.
+
+| Option | Description |
+| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `check` | Available for Webpack-based projects. Enables type checking within Storybook `typescript: { check: true },` |
+| `checkOptions` | Requires the `check` option to be enabled. Configures the [`fork-ts-checker-webpack-plugin`](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin) plugin `typescript: { checkOptions: {},},` |
+| `reactDocgen` | Configures the TypeScript parser used by Storybook. Available options: `react-docgen` (default), `react-docgen-typescript`,` false` `typescript: { reactDocgen: 'react-docgen'},` |
+| `reactDocgenTypescriptOptions` | Requires the `reactDocgen`option to be `react-docgen-typescript`. Configures the `react-docgen-typescript-plugin` plugin per builder `typescript: { reactDocgen: 'react-docgen-typescript', reactDocgenTypescriptOptions: {},},` |
+| `skipCompiler` | Disables parsing Typescript files through the compiler `typescript: { skipCompiler:false,},` |
+
+
-{/* prettier-ignore-end */}
+
+
+Additional options are available for the `typescript` configuration option. See the [`config.typescript` API reference](../../api/main-config/main-config-typescript.mdx) for more information.
-
- Additional options are available for the `typescript` configuration option. See the [`config.typescript` API reference](../../api/main-config/main-config-typescript.mdx) for more information.
## Write stories with TypeScript
Storybook provides zero-config TypeScript support, allowing you to write stories using this language without additional configuration. You can use this format for improved type safety and code completion. For example, if you're testing a `Button` component, you could do the following in your story file:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
The example above uses the power of TypeScript in combination with the exported generic types (`Meta` and `StoryObj`) to tell Storybook how to infer the component's metadata and the type of the component's inputs (e.g., props). This can greatly improve the developer experience by letting your IDE show you what properties are injected by Storybook.
### TypeScript 4.9 support
Assuming that you're working on a project that uses TypeScript 4.9+, you can update your component stories to use the new [`satisfies`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-9.html) operator to ensure stricter type checking for your component stories. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Now, when you define a story or update an existing one, you'll automatically get notified that you're missing a required [`arg`](../../writing-stories/args.mdx). However, you're not limited to using the `satisfies` operator at the component level. If you need, you can also use it at the story level. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Troubleshooting
### The `satisfies` operator is not working as expected
Out of the box, Storybook supports the `satisfies` operator for almost every framework already using TypeScript version 4.9 or higher. However, due to the constraints of the Angular and Web Components framework, you might run into issues when applying this operator for additional type safety. This is primarily due to how both frameworks are currently implemented, making it almost impossible for Storybook to determine if the component property is required. If you encounter this issue, please open up a support request on [GitHub Discussions](https://github.com/storybookjs/storybook/discussions/new?category=help).
-
- ### The TypeScript auto-completion is not working on my editor
-
- If you're using Vue single file components and TypeScript, you can add the official [Vue](https://marketplace.visualstudio.com/items?itemName=Vue.volar) extension for editor support, additional type safety and auto-completion. Nevertheless, if you're working with Svelte, you can add the [Svelte for VSCode extension](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) for similar benefits.
-
-
-
- ### Storybook doesn't create the required types for external packages
+
- If your project relies on a third-party library and the expected types are not being generated, preventing you from accurately documenting your components, you can adjust the `reactDocgen` configuration option in your Storybook configuration file to use `react-docgen-typescript` instead and include the required options. For example:
+### The TypeScript auto-completion is not working on my editor
- {/* prettier-ignore-start */}
+If you're using Vue single file components and TypeScript, you can add the official [Vue](https://marketplace.visualstudio.com/items?itemName=Vue.volar) extension for editor support, additional type safety and auto-completion. Nevertheless, if you're working with Svelte, you can add the [Svelte for VSCode extension](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) for similar benefits.
-
+
- {/* prettier-ignore-end */}
+
- ### Inherited args are missing for components from workspace packages
+### Storybook doesn't create the required types for external packages
- If you're using `react-docgen-typescript` in a monorepo with npm/yarn/pnpm workspaces, you may find that components imported from a workspace package are missing inherited args (e.g., MUI's `ButtonProps`), while the same component imported locally works fine.
+If your project relies on a third-party library and the expected types are not being generated, preventing you from accurately documenting your components, you can adjust the `reactDocgen` configuration option in your Storybook configuration file to use `react-docgen-typescript` instead and include the required options. For example:
- This happens because the underlying Vite plugin creates a TypeScript program from files matching its `include` glob (default: `**/**.tsx`), resolved from the Storybook project's directory. Workspace package files are outside that directory and aren't included in the program, so inherited types can't be resolved.
+
- To fix this, add your workspace package source files to the `include` option:
+### Inherited args are missing for components from workspace packages
- {/* prettier-ignore-start */}
+If you're using `react-docgen-typescript` in a monorepo with npm/yarn/pnpm workspaces, you may find that components imported from a workspace package are missing inherited args (e.g., MUI's `ButtonProps`), while the same component imported locally works fine.
-
+This happens because the underlying Vite plugin creates a TypeScript program from files matching its `include` glob (default: `**/**.tsx`), resolved from the Storybook project's directory. Workspace package files are outside that directory and aren't included in the program, so inherited types can't be resolved.
- {/* prettier-ignore-end */}
+To fix this, add your workspace package source files to the `include` option:
- Adjust the path (`../../packages/ui/src/**/*.tsx`) to match your monorepo layout. You might expect that pointing `tsconfigPath` to a tsconfig that includes your workspace packages would solve this, but `tsconfigPath` only affects which compiler options are used. It does not change which files are included in the TypeScript program.
+
- ### The types are not being generated for my component
+Adjust the path (`../../packages/ui/src/**/*.tsx`) to match your monorepo layout. You might expect that pointing `tsconfigPath` to a tsconfig that includes your workspace packages would solve this, but `tsconfigPath` only affects which compiler options are used. It does not change which files are included in the TypeScript program.
- If you're working with a React project, type inference is automatically enabled for your components using the `react-docgen` library for improved build times and type safety. However, you may run into a situation where some options may not work as expected (e.g., [`Enums`](https://www.typescriptlang.org/docs/handbook/enums.html), React's [`forwardRef`](https://react.dev/reference/react/forwardRef)). This is primarily due to how the `react-docgen` package is implemented, making it difficult for Storybook to infer the component's metadata and generate types automatically. To solve this, you can update the `typescript` configuration option in your Storybook configuration file to use `react-docgen-typescript` instead. For example:
+### The types are not being generated for my component
- {/* prettier-ignore-start */}
+If you're working with a React project, type inference is automatically enabled for your components using the `react-docgen` library for improved build times and type safety. However, you may run into a situation where some options may not work as expected (e.g., [`Enums`](https://www.typescriptlang.org/docs/handbook/enums.html), React's [`forwardRef`](https://react.dev/reference/react/forwardRef)). This is primarily due to how the `react-docgen` package is implemented, making it difficult for Storybook to infer the component's metadata and generate types automatically. To solve this, you can update the `typescript` configuration option in your Storybook configuration file to use `react-docgen-typescript` instead. For example:
-
+
- {/* prettier-ignore-end */}
+If you're still encountering issues, we recommend reaching out to the community using the default communication channels (e.g., [GitHub discussions](https://github.com/storybookjs/storybook/discussions/new?category=help)).
- If you're still encountering issues, we recommend reaching out to the community using the default communication channels (e.g., [GitHub discussions](https://github.com/storybookjs/storybook/discussions/new?category=help)).
-
+
diff --git a/docs/configure/story-layout.mdx b/docs/configure/story-layout.mdx
index deac6de3b8e7..5c42ecc0670f 100644
--- a/docs/configure/story-layout.mdx
+++ b/docs/configure/story-layout.mdx
@@ -1,8 +1,7 @@
---
-title: 'Story layout'
+title: Story layout
sidebar:
order: 6
- title: Story layout
---
The `layout` [parameter](../writing-stories/parameters.mdx) allows you to configure how stories are positioned in Storybook's Canvas tab.
@@ -11,36 +10,24 @@ The `layout` [parameter](../writing-stories/parameters.mdx) allows you to config
You can add the parameter to your [`./storybook/preview.js`](./index.mdx#configure-story-rendering), like so:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-

In the example above, Storybook will center all stories in the UI. `layout` accepts these options:
-* `centered`: center the component horizontally and vertically in the Canvas
-* `fullscreen`: allow the component to expand to the full width and height of the Canvas
-* `padded`: *(default)* Add extra padding around the component
+- `centered`: center the component horizontally and vertically in the Canvas
+- `fullscreen`: allow the component to expand to the full width and height of the Canvas
+- `padded`: _(default)_ Add extra padding around the component
## Component layout
You can also set it at a component level like so:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Story layout
Or even apply it to specific stories like so:
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/configure/story-rendering.mdx b/docs/configure/story-rendering.mdx
index 95cb1886ccc1..f22ddedb3581 100644
--- a/docs/configure/story-rendering.mdx
+++ b/docs/configure/story-rendering.mdx
@@ -1,8 +1,7 @@
---
-title: 'Story rendering'
+title: Story rendering
sidebar:
order: 5
- title: Story rendering
---
In Storybook, your stories render in a particular “preview” iframe (also called the Canvas) inside the larger Storybook web application. The JavaScript build configuration of the preview is controlled by a [builder](../builders/index.mdx) config, but you also may want to run some code for every story or directly control the rendered HTML to help your stories render correctly.
@@ -12,33 +11,31 @@ In Storybook, your stories render in a particular “preview” iframe (also cal
Code executed in the preview file (`.storybook/preview.ts|tsx`) runs for every story in your Storybook. This is useful for setting up global styles, initializing libraries, or anything else required to render your components.
- Here's an example of how you might use the preview file to initialize a library that must run before your components render:
-
+Here's an example of how you might use the preview file to initialize a library that must run before your components render:
+
+
+
- For example, with Vue, you can extend Storybook's application and register your library (e.g., [Fontawesome](https://github.com/FortAwesome/vue-fontawesome)). Or with Angular, add the package ([localize](https://angular.io/api/localize)) into your `polyfills.ts` and import it:
- {/* prettier-ignore-start */}
+For example, with Vue, you can extend Storybook's application and register your library (e.g., [Fontawesome](https://github.com/FortAwesome/vue-fontawesome)). Or with Angular, add the package ([localize](https://angular.io/api/localize)) into your `polyfills.ts` and import it:
-
+
- {/* prettier-ignore-end */}
## Adding to \
If you need to add extra elements to the `head` of the preview iframe, for instance, to load static stylesheets, font files, or similar, you can create a file called [`.storybook/preview-head.html`](./index.mdx#configure-story-rendering) and add tags like this:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- Storybook will inject these tags into the *preview iframe* where your components render, not the Storybook application UI.
+
+Storybook will inject these tags into the _preview iframe_ where your components render, not the Storybook application UI.
+
However, it's also possible to modify the preview head HTML programmatically using a preset defined in the `main.js` file. Read the [presets documentation](../addons/writing-presets.mdx#ui-configuration) for more information.
@@ -49,22 +46,16 @@ Sometimes, you may need to add different tags to the ``. Helpful for addin
You can accomplish this by creating a file called `preview-body.html` inside your `.storybook` directory and adding tags like this:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
If using relative sizing in your project (like `rem` or `em`), you may update the base `font-size` by adding a `style` tag to `preview-body.html`:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- Storybook will inject these tags into the *preview iframe* where your components render, not the Storybook application UI.
+
+Storybook will inject these tags into the _preview iframe_ where your components render, not the Storybook application UI.
+
Just like how you have the ability to customize the preview `head` HTML tag, you can also follow the same steps to customize the preview `body` with a preset. To obtain more information on how to do this, refer to the [presets documentation](../addons/writing-presets.mdx#ui-configuration).
diff --git a/docs/configure/styling-and-css.mdx b/docs/configure/styling-and-css.mdx
index 735b0b832ece..7476ae884b38 100644
--- a/docs/configure/styling-and-css.mdx
+++ b/docs/configure/styling-and-css.mdx
@@ -1,213 +1,218 @@
---
-title: 'Styling and CSS'
+title: Styling and CSS
sidebar:
order: 1
- title: Styling and CSS
---
{/* Not Angular */}
- There are many ways to include CSS in a web application, and correspondingly there are many ways to include CSS in Storybook. Usually, it is best to try and replicate what your application does with styling in Storybook’s configuration.
- ## CSS
+There are many ways to include CSS in a web application, and correspondingly there are many ways to include CSS in Storybook. Usually, it is best to try and replicate what your application does with styling in Storybook’s configuration.
- Storybook supports importing CSS files in a few different ways. Storybook will inject these tags into the preview iframe where your components render, not the Storybook Manager UI. The best way to import CSS depends on your project's configuration and your preferences.
+## CSS
- ### Import bundled CSS (Recommended)
+Storybook supports importing CSS files in a few different ways. Storybook will inject these tags into the preview iframe where your components render, not the Storybook Manager UI. The best way to import CSS depends on your project's configuration and your preferences.
- All Storybooks are pre-configured to recognize imports for CSS files. To add global CSS for all your stories, import it in [`.storybook/preview.ts|tsx`](./index.mdx#configure-story-rendering). These files will be subject to HMR, so you can see your changes without restarting your Storybook server.
+### Import bundled CSS (recommended)
- {/* prettier-ignore-start */}
+All Storybooks are pre-configured to recognize imports for CSS files. To add global CSS for all your stories, import it in [`.storybook/preview.ts|tsx`](./index.mdx#configure-story-rendering). These files will be subject to HMR, so you can see your changes without restarting your Storybook server.
-
+
- {/* prettier-ignore-end */}
+If your component files import their CSS files, this will work too. However, if you're using CSS processor tools like Sass or Postcss, you may need some more configuration.
- If your component files import their CSS files, this will work too. However, if you're using CSS processor tools like Sass or Postcss, you may need some more configuration.
+### Include static CSS
- ### Include static CSS
+If you have a global CSS file that you want to include in all your stories, you can import it in [`.storybook/preview-head.html`](./story-rendering.mdx#adding-to-head).
+However, these files will not be subject to HMR, so you'll need to restart your Storybook server to see your changes.
- If you have a global CSS file that you want to include in all your stories, you can import it in [`.storybook/preview-head.html`](./story-rendering.mdx#adding-to-head).
- However, these files will not be subject to HMR, so you'll need to restart your Storybook server to see your changes.
+
- {/* prettier-ignore-start */}
+## CSS modules
-
+### Vite
- {/* prettier-ignore-end */}
+Vite comes with CSS modules support out-of-the-box. If you have customized the CSS modules configuration in your `vite.config.js` this will automatically be applied to your Storybook as well. Read more about [Vite's CSS modules support](https://vitejs.dev/guide/features.html#css-modules).
- ## CSS modules
+### Webpack
- ### Vite
+
- Vite comes with CSS modules support out-of-the-box. If you have customized the CSS modules configuration in your `vite.config.js` this will automatically be applied to your Storybook as well. Read more about [Vite's CSS modules support](https://vitejs.dev/guide/features.html#css-modules).
+
- ### Webpack
+Storybook recreates your Next.js configuration, so you can use CSS modules in your stories without any extra configuration.
-
-
- Storybook recreates your Next.js configuration, so you can use CSS modules in your stories without any extra configuration.
-
-
+
- If you're using Webpack and want to use CSS modules, you'll need some extra configuration. We recommend installing [`@storybook/addon-styling-webpack`](https://storybook.js.org/addons/@storybook/addon-styling-webpack/) to help you configure these tools.
+
+
+If you're using Webpack and want to use CSS modules, you'll need some extra configuration. We recommend installing [`@storybook/addon-styling-webpack`](https://storybook.js.org/addons/@storybook/addon-styling-webpack/) to help you configure these tools.
+
+## PostCSS
+
+### Vite
- ## PostCSS
+Vite comes with PostCSS support out-of-the-box. If you have customized the PostCSS configuration in your `vite.config.js` this will automatically be applied to your Storybook as well. Read more about [Vite's PostCSS support](https://vitejs.dev/guide/features.html#postcss).
- ### Vite
+### Webpack
- Vite comes with PostCSS support out-of-the-box. If you have customized the PostCSS configuration in your `vite.config.js` this will automatically be applied to your Storybook as well. Read more about [Vite's PostCSS support](https://vitejs.dev/guide/features.html#postcss).
+
- ### Webpack
+
-
-
- Storybook recreates your Next.js configuration, so you can use PostCSS in your stories without any extra configuration.
-
-
+Storybook recreates your Next.js configuration, so you can use PostCSS in your stories without any extra configuration.
+
+
+
+
- If you're using Webpack and want to use PostCSS, you'll need some extra configuration. We recommend installing [`@storybook/addon-styling-webpack`](https://storybook.js.org/addons/@storybook/addon-styling-webpack/) to help you configure these tools.
+If you're using Webpack and want to use PostCSS, you'll need some extra configuration. We recommend installing [`@storybook/addon-styling-webpack`](https://storybook.js.org/addons/@storybook/addon-styling-webpack/) to help you configure these tools.
- ## CSS pre-processors
+## CSS pre-processors
- ### Vite
+### Vite
- Vite comes with Sass, Less, and Stylus support out-of-the-box. Read more about [Vite's CSS Pre-processor support](https://vitejs.dev/guide/features.html#css-pre-processors).
+Vite comes with Sass, Less, and Stylus support out-of-the-box. Read more about [Vite's CSS Pre-processor support](https://vitejs.dev/guide/features.html#css-pre-processors).
- ### Webpack
+### Webpack
+
+
+
+
+
+Storybook recreates your Next.js configuration, so you can use Sass in your stories without any extra configuration.
+
+
+
+
-
-
- Storybook recreates your Next.js configuration, so you can use Sass in your stories without any extra configuration.
-
-
+If you're using Webpack and want to use Sass or Less, you'll need some extra configuration. We recommend installing [`@storybook/addon-styling-webpack`](https://storybook.js.org/addons/@storybook/addon-styling-webpack/) to help you configure these tools. Or if you'd prefer, you can customize [Storybook's webpack configuration yourself](../builders/webpack.mdx#override-the-default-configuration) to include the appropriate loader(s).
- If you're using Webpack and want to use Sass or less, you'll need some extra configuration. We recommend installing [`@storybook/addon-styling-webpack`](https://storybook.js.org/addons/@storybook/addon-styling-webpack/) to help you configure these tools. Or if you'd prefer, you can customize [Storybook's webpack configuration yourself](../builders/webpack.mdx#override-the-default-configuration) to include the appropriate loader(s).
+## CSS-in-JS
- ## CSS-in-JS
+CSS-in-JS libraries are designed to use basic JavaScript, and they often work in Storybook without any extra configuration. Some libraries expect components to render in a specific rendering “context” (for example, to provide themes), which can be accomplished with `@storybook/addon-themes`'s [`withThemeFromJSXProvider` decorator](https://github.com/storybookjs/storybook/blob/next/code/addons/themes/docs/api.md#withthemefromjsxprovider).
- CSS-in-JS libraries are designed to use basic JavaScript, and they often work in Storybook without any extra configuration. Some libraries expect components to render in a specific rendering “context” (for example, to provide themes), which can be accomplished with `@storybook/addon-themes`'s [`withThemeFromJSXProvider` decorator](https://github.com/storybookjs/storybook/blob/next/code/addons/themes/docs/api.md#withthemefromjsxprovider).
+## Adding webfonts
- ## Adding webfonts
+### `.storybook/preview-head.html`
- ### `.storybook/preview-head.html`
+If you need webfonts to be available, you may need to add some code to the [`.storybook/preview-head.html`](./story-rendering.mdx#adding-to-head) file. We recommend including any assets with your Storybook if possible, in which case you likely want to configure the [static file location](./integration/images-and-assets.mdx#serving-static-files-via-storybook-configuration).
- If you need webfonts to be available, you may need to add some code to the [`.storybook/preview-head.html`](./story-rendering.mdx#adding-to-head) file. We recommend including any assets with your Storybook if possible, in which case you likely want to configure the [static file location](./integration/images-and-assets.mdx#serving-static-files-via-storybook-configuration).
+### `.storybook/preview.ts|tsx`
- ### `.storybook/preview.ts|tsx`
+If you're using something like [`fontsource`](https://fontsource.org/) for your fonts, you can import the needed css files in your [`.storybook/preview.ts|tsx`](./index.mdx#configure-story-rendering) file.
- If you're using something like [`fontsource`](https://fontsource.org/) for your fonts, you can import the needed css files in your [`.storybook/preview.ts|tsx`](./index.mdx#configure-story-rendering) file.
{/* Angular only */}
-
- Storybook for Angular relies on the Angular CLI to build your stories. This means that you can use any CSS preprocessor that the Angular CLI supports. You can read more about this in the [Angular CLI documentation](https://angular.io/guide/workspace-config#style-script-config).
-
- ## Global styles
-
- To add global styles to your Storybook, you can add them to the `styles` array in your `angular.json` file. This will add the styles to the preview iframe where your components render, not the Storybook Manager UI.
-
- Don't forget to also add your global styles to your `build-storybook` target in your `angular.json` file. This will ensure that your global styles are included in the static build of your Storybook as well.
-
- ```json title="angular.json"
- {
- "storybook": {
- "builder": "@storybook/angular:start-storybook",
- "options": {
- "configDir": ".storybook",
- "browserTarget": "angular-latest:build",
- "compodoc": true,
- "compodocArgs": ["-e", "json", "-d", "."],
- "port": 6006,
- "styles": [
- // Add your global styles here
- "@angular/material/prebuilt-themes/indigo-pink.css",
- "@fontsource/roboto/300.css",
- "@fontsource/roboto/400.css",
- "@fontsource/roboto/500.css",
- "@fontsource/roboto/700.css",
- "@fontsource/material-icons",
- "src/styles.scss"
- ]
- }
- },
- "build-storybook": {
- "builder": "@storybook/angular:build-storybook",
- "options": {
- "configDir": ".storybook",
- "browserTarget": "angular-latest:build",
- "compodoc": true,
- "compodocArgs": ["-e", "json", "-d", "."],
- "styles": [
- // Add your global styles here
- "@angular/material/prebuilt-themes/indigo-pink.css",
- "@fontsource/roboto/300.css",
- "@fontsource/roboto/400.css",
- "@fontsource/roboto/500.css",
- "@fontsource/roboto/700.css",
- "@fontsource/material-icons",
- "src/styles.scss"
- ],
- "outputDir": "storybook-static"
- }
+
+
+Storybook for Angular relies on the Angular CLI to build your stories. This means that you can use any CSS preprocessor that the Angular CLI supports. You can read more about this in the [Angular CLI documentation](https://angular.io/guide/workspace-config#style-script-config).
+
+## Global styles
+
+To add global styles to your Storybook, you can add them to the `styles` array in your `angular.json` file. This will add the styles to the preview iframe where your components render, not the Storybook Manager UI.
+
+Don't forget to also add your global styles to your `build-storybook` target in your `angular.json` file. This will ensure that your global styles are included in the static build of your Storybook as well.
+
+```json title="angular.json"
+{
+ "storybook": {
+ "builder": "@storybook/angular:start-storybook",
+ "options": {
+ "configDir": ".storybook",
+ "browserTarget": "angular-latest:build",
+ "compodoc": true,
+ "compodocArgs": ["-e", "json", "-d", "."],
+ "port": 6006,
+ "styles": [
+ // Add your global styles here
+ "@angular/material/prebuilt-themes/indigo-pink.css",
+ "@fontsource/roboto/300.css",
+ "@fontsource/roboto/400.css",
+ "@fontsource/roboto/500.css",
+ "@fontsource/roboto/700.css",
+ "@fontsource/material-icons",
+ "src/styles.scss"
+ ]
+ }
+ },
+ "build-storybook": {
+ "builder": "@storybook/angular:build-storybook",
+ "options": {
+ "configDir": ".storybook",
+ "browserTarget": "angular-latest:build",
+ "compodoc": true,
+ "compodocArgs": ["-e", "json", "-d", "."],
+ "styles": [
+ // Add your global styles here
+ "@angular/material/prebuilt-themes/indigo-pink.css",
+ "@fontsource/roboto/300.css",
+ "@fontsource/roboto/400.css",
+ "@fontsource/roboto/500.css",
+ "@fontsource/roboto/700.css",
+ "@fontsource/material-icons",
+ "src/styles.scss"
+ ],
+ "outputDir": "storybook-static"
}
}
- ```
-
- ## Troubleshooting
-
- If you're working with Storybook and [Nx libraries](https://nx.dev/structure/library-types), you can extend your project's configuration (i.e., project.json) and provide the application's styles.
-
- For earlier Nx versions (before 14.1.8), your configuration would look like this:
-
- ```json title="project.json"
- {
- "build-storybook": {
- "executor": "@nrwl/storybook:build",
- "outputs": ["{options.outputPath}"],
- "options": {
- "uiFramework": "@storybook/angular",
- "outputPath": "dist/storybook/example-lib",
- "config": {
- "configFolder": "libs/example-lib/storybook/.storybook"
- },
- "projectBuildConfig": "example-lib:build-storybook",
- "styles": ["apps/example-app/src/styles.scss"]
- }
- },
- }
- ```
+}
+```
+
+## Troubleshooting
+
+If you're working with Storybook and [Nx libraries](https://nx.dev/structure/library-types), you can extend your project's configuration (i.e., project.json) and provide the application's styles.
- Starting with version 14.1.8, Nx uses the Storybook builder directly, which means any configuration supplied to the builder also applies to the NX setup. If you're working with a library, you'll need to configure the styling options ( e.g., preprocessors) inside the `build-storybook` options configuration object. For example:
+For earlier Nx versions (before 14.1.8), your configuration would look like this:
- ```json title="workspace.json"
- {
- "storybook": {
- "executor": "@storybook/angular:start-storybook",
- "options": {
- "configDir": "apps/example-lib/.storybook",
- "browserTarget": "example-lib:build-storybook",
+```json title="project.json"
+{
+ "build-storybook": {
+ "executor": "@nrwl/storybook:build",
+ "outputs": ["{options.outputPath}"],
+ "options": {
+ "uiFramework": "@storybook/angular",
+ "outputPath": "dist/storybook/example-lib",
+ "config": {
+ "configFolder": "libs/example-lib/storybook/.storybook"
},
- },
- "build-storybook": {
- "executor": "@storybook/angular:build-storybook",
- "outputs": ["{options.outputPath}"],
- "options": {
- "outputDir": "dist/storybook/example-lib",
- "configDir": "apps/example-lib/.storybook",
- "browserTarget": "example-lib:build-storybook",
- "styles": [".storybook/custom-styles.scss"],
- "stylePreprocessorOptions": {
- "includePaths": [
- "libs/design-system/src/lib"
- ]
- }
+ "projectBuildConfig": "example-lib:build-storybook",
+ "styles": ["apps/example-app/src/styles.scss"]
+ }
+ }
+}
+```
+
+Starting with version 14.1.8, Nx uses the Storybook builder directly, which means any configuration supplied to the builder also applies to the NX setup. If you're working with a library, you'll need to configure the styling options (e.g., preprocessors) inside the `build-storybook` options configuration object. For example:
+
+```json title="workspace.json"
+{
+ "storybook": {
+ "executor": "@storybook/angular:start-storybook",
+ "options": {
+ "configDir": "apps/example-lib/.storybook",
+ "browserTarget": "example-lib:build-storybook"
+ }
+ },
+ "build-storybook": {
+ "executor": "@storybook/angular:build-storybook",
+ "outputs": ["{options.outputPath}"],
+ "options": {
+ "outputDir": "dist/storybook/example-lib",
+ "configDir": "apps/example-lib/.storybook",
+ "browserTarget": "example-lib:build-storybook",
+ "styles": [".storybook/custom-styles.scss"],
+ "stylePreprocessorOptions": {
+ "includePaths": ["libs/design-system/src/lib"]
}
- },
+ }
}
- ```
+}
+```
+
+When Nx runs, it will load Storybook's configuration and styling based on [`storybook.browserTarget`](https://nx.dev/storybook/extra-topics-for-angular-projects#setting-up-browsertarget).
- When Nx runs, it will load Storybook's configuration and styling based on [`storybook.browserTarget`](https://nx.dev/storybook/extra-topics-for-angular-projects#setting-up-browsertarget).
-
+
diff --git a/docs/configure/telemetry.mdx b/docs/configure/telemetry.mdx
index 4aacc45029e7..9149afdb792c 100644
--- a/docs/configure/telemetry.mdx
+++ b/docs/configure/telemetry.mdx
@@ -1,9 +1,8 @@
---
-title: 'Telemetry'
+title: Telemetry
hideRendererSelector: true
sidebar:
order: 3
- title: Telemetry
---
Storybook collects completely anonymous data to help us improve user experience. Participation in this anonymous program is optional, and you may opt-out if you'd not like to share any information.
@@ -12,10 +11,10 @@ Storybook collects completely anonymous data to help us improve user experience.
Hundreds of thousands of developers use Storybook daily to build, test, and document components. Storybook is framework agnostic and integrates with the front-end ecosystem:
-* **JavaScript frameworks** such as [React](https://reactjs.org/), [Vue 3](https://vuejs.org/), [Svelte](https://svelte.dev/) and [Solid](https://www.solidjs.com/)
-* **Libraries** such as [Styled-Components](https://styled-components.com/), [Tailwind](https://tailwindcss.com/), [Redux](https://redux.js.org/)
-* **Design tools** such as [Figma](https://figma.com/), [Sketch](https://www.sketch.com/), [Zeplin](https://zeplin.io/) and [InVision](https://www.invisionapp.com/)
-* **Workflow tools** such as [Notion](https://www.notion.so/product), [Confluence](https://www.atlassian.com/software/confluence), and [Jira](https://www.atlassian.com/software/jira)
+- **JavaScript frameworks** such as [React](https://reactjs.org/), [Vue 3](https://vuejs.org/), [Svelte](https://svelte.dev/) and [Solid](https://www.solidjs.com/)
+- **Libraries** such as [Styled-Components](https://styled-components.com/), [Tailwind](https://tailwindcss.com/), [Redux](https://redux.js.org/)
+- **Design tools** such as [Figma](https://figma.com/), [Sketch](https://www.sketch.com/), [Zeplin](https://zeplin.io/) and [InVision](https://www.invisionapp.com/)
+- **Workflow tools** such as [Notion](https://www.notion.so/product), [Confluence](https://www.atlassian.com/software/confluence), and [Jira](https://www.atlassian.com/software/jira)
In the past, our improvement process relied on manually gathering feedback. But with a growing userbase and the need to support a wide variety of integrations, we need a more accurate method for gauging Storybook usage and pain points.
@@ -27,22 +26,22 @@ We collect general usage details, including command invocation, Storybook versio
Specifically, we track the following information in our telemetry events:
-* Timestamp of the occurrence.
-* Command invoked (e.g., `init`, `upgrade`, `dev`, `build`).
-* Storybook unique identifier: One-way hash generated during Storybook installation process.
-* One way hash of the IP address where the event occurred for spam detection.
-* Story count.
-* Storybook version.
-* Storybook metadata:
- * Language (e.g., TypeScript, JavaScript).
- * Supported view layers (e.g., React, Vue 3, Angular, Svelte).
- * Builder (e.g., Webpack5, Vite).
- * Meta framework (e.g., [Next](https://nextjs.org/), [Gatsby](https://www.gatsbyjs.com/), [CRA](https://create-react-app.dev/)).
- * [Addons](https://storybook.js.org/integrations) (e.g., [Accessibility](https://storybook.js.org/addons/@storybook/addon-a11y/)).
- * Testing tools (e.g. [Jest](https://jestjs.io/), [Vitest](https://vitest.dev/), [Playwright](https://playwright.dev/)).
-* Package manager information (e.g., `npm`, `yarn`).
-* Monorepo information (e.g., [NX](https://nx.dev/), [Turborepo](https://turborepo.org/)).
-* In-app events (e.g., [Storybook guided tour](https://github.com/storybookjs/addon-onboarding), [UI test run](../writing-tests/integrations/vitest-addon/index.mdx#storybook-ui)).
+- Timestamp of the occurrence.
+- Command invoked (e.g., `init`, `upgrade`, `dev`, `build`).
+- Storybook unique identifier: One-way hash generated during Storybook installation process.
+- One way hash of the IP address where the event occurred for spam detection.
+- Story count.
+- Storybook version.
+- Storybook metadata:
+ - Language (e.g., TypeScript, JavaScript).
+ - Supported view layers (e.g., React, Vue 3, Angular, Svelte).
+ - Builder (e.g., Webpack5, Vite).
+ - Meta framework (e.g., [Next](https://nextjs.org/), [Gatsby](https://www.gatsbyjs.com/), [CRA](https://create-react-app.dev/)).
+ - [Addons](https://storybook.js.org/integrations) (e.g., [Accessibility](https://storybook.js.org/addons/@storybook/addon-a11y/)).
+ - Testing tools (e.g. [Jest](https://jestjs.io/), [Vitest](https://vitest.dev/), [Playwright](https://playwright.dev/)).
+- Package manager information (e.g., `npm`, `yarn`).
+- Monorepo information (e.g., [NX](https://nx.dev/), [Turborepo](https://turborepo.org/)).
+- In-app events (e.g., [Storybook guided tour](https://github.com/storybookjs/addon-onboarding), [UI test run](../writing-tests/integrations/vitest-addon/index.mdx#storybook-ui)).
Access to the raw data is highly controlled, limited to select members of Storybook's core team who maintain the telemetry. We cannot identify individual users from the dataset: it is anonymized and untraceable back to the user.
@@ -50,12 +49,8 @@ Access to the raw data is highly controlled, limited to select members of Storyb
We take your privacy and our security very seriously. We perform additional steps to ensure that secure data (e.g., environment variables or other forms of sensitive data) **do not** make their way into our analytics. You can view all the information we collect by setting the `STORYBOOK_TELEMETRY_DEBUG` to `1` to print out the information gathered. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Will generate the following output:
```json
@@ -168,62 +163,36 @@ In the future, we plan to share relevant data with the community through public
You may opt out of the telemetry within your Storybook configuration by setting the `disableTelemetry` configuration element to `true`.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
If necessary, you can also turn off telemetry via the command line with the `--disable-telemetry` flag.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Or via the `STORYBOOK_DISABLE_TELEMETRY` environment variable.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- There is a `boot` event containing no metadata (used to ensure the telemetry is working). It is sent prior to evaluating your [Storybook configuration file](../api/main-config/main-config.mdx) (i.e., `main.js|ts`), so it is unaffected by the `disableTelemetry` option. If you want to ensure that the event is not sent, use the `STORYBOOK_DISABLE_TELEMETRY` environment variable.
+
+There is a `boot` event containing no metadata (used to ensure the telemetry is working). It is sent prior to evaluating your [Storybook configuration file](../api/main-config/main-config.mdx) (i.e., `main.js|ts`), so it is unaffected by the `disableTelemetry` option. If you want to ensure that the event is not sent, use the `STORYBOOK_DISABLE_TELEMETRY` environment variable.
+
## Crash reports (disabled by default)
In addition to general usage telemetry, you may also choose to share crash reports. Storybook will then sanitize the error object (removing all user paths) and append it to the telemetry event. To enable crash reporting, you can set the `enableCrashReports` configuration element to `true`.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
You can also enable crash reporting via the command line with the `--enable-crash-reports` flag.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Or by setting the `STORYBOOK_ENABLE_CRASH_REPORTS` environment variable to `1`.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Enabling any of the options will generate the following item in the telemetry event:
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/configure/user-interface/features-and-behavior.mdx b/docs/configure/user-interface/features-and-behavior.mdx
index c6cf86c75cad..bb014684149b 100644
--- a/docs/configure/user-interface/features-and-behavior.mdx
+++ b/docs/configure/user-interface/features-and-behavior.mdx
@@ -1,18 +1,13 @@
---
-title: 'Features and behavior'
+title: Features and behavior
sidebar:
order: 1
- title: Features and behavior
---
To control the layout of Storybook’s UI you can use `addons.setConfig` in your `.storybook/manager.js`:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
The following table details how to use the API values:
| Name | Type | Description | Example Value |
@@ -40,9 +35,9 @@ The following options are configurable under the `sidebar` namespace:
The following options are configurable under the `toolbar` namespace:
-| Name | Type | Description | Example Value |
-| ---------| ------ | -------------------------------------------------------------------- | -------------------- |
-| **[id]** | String | Toggle visibility for a specific toolbar item (e.g. `title`, `zoom`) | `{ hidden: false }` |
+| Name | Type | Description | Example Value |
+| -------- | ------ | -------------------------------------------------------------------- | ------------------- |
+| **[id]** | String | Toggle visibility for a specific toolbar item (e.g. `title`, `zoom`) | `{ hidden: false }` |
The following options are configurable under the `layoutCustomisations` namespace:
@@ -52,7 +47,9 @@ The following options are configurable under the `layoutCustomisations` namespac
| **showToolbar** | Function | Toggle visibility for the toolbar | `({ viewMode }, defaultValue) => viewMode === 'docs' ? false : defaultValue` |
- The `showSidebar` and `showToolbar` functions let you hide parts of the UI that are essential to Storybook's functionality. If misused, they can make navigation impossible. When hiding the sidebar, ensure the displayed page provides an alternative means of navigation.
+
+The `showSidebar` and `showToolbar` functions let you hide parts of the UI that are essential to Storybook's functionality. If misused, they can make navigation impossible. When hiding the sidebar, ensure the displayed page provides an alternative means of navigation.
+
## Customize the UI
@@ -63,79 +60,67 @@ Storybook's UI is highly customizable. Its API and configuration options, availa
The sidebar, present on the left of the screen, contains the search function and navigation menu. Users may show or hide it with a keyboard shortcut. If you want to force the sidebar to be visible or hidden in certain places, you can define a `showSidebar` function in `layoutCustomisations`. Below are the available parameters passed to this function and an overview of how to use them.
-| Name | Type | Description | Example Value |
-| ------------------------ | -------- | -------------------------------------------------------------- | ------------------------------------- |
-| **path** | String | Path to the page being displayed | `'/story/components-button--default'` |
-| **viewMode** | String | Whether the current page is a story or docs | `'docs'` or `'story'` |
-| **singleStory** | Boolean | Whether the current page is the only story for a component | `true` or `false` |
-| **storyId** | String | The id of the current story or docs page | `'blocks-unstyled--docs'` |
-| **index** | Object | The index containing statically analysed metadata for every story | `{ 'blocks-unstyled--docs': { tags: ['autodocs'] } }` |
-| **layout** | Object | The current layout state | *see below* |
-| **layout.isFullscreen** | Boolean | Whether the preview canvas is in fullscreen mode | `true` or `false` |
-| **layout.panelPosition** | String | Whether the panel is shown below or on the side of the preview | `'bottom'` or `'right'` |
-| **layout.showNav** | Boolean | The setting for whether the end user wants to see the sidebar | `true` or `false` |
-| **layout.showPanel** | Boolean | The setting for whether the end user wants to see the panel | `true` or `false` |
-| **layout.showToolbar** | Boolean | The setting for whether the end user wants to see the toolbar | `true` or `false` |
-
-{/* prettier-ignore-start */}
-
-
-
-{/* prettier-ignore-end */}
+| Name | Type | Description | Example Value |
+| ------------------------ | ------- | ----------------------------------------------------------------- | ----------------------------------------------------- |
+| **path** | String | Path to the page being displayed | `'/story/components-button--default'` |
+| **viewMode** | String | Whether the current page is a story or docs | `'docs'` or `'story'` |
+| **singleStory** | Boolean | Whether the current page is the only story for a component | `true` or `false` |
+| **storyId** | String | The id of the current story or docs page | `'blocks-unstyled--docs'` |
+| **index** | Object | The index containing statically analysed metadata for every story | `{ 'blocks-unstyled--docs': { tags: ['autodocs'] } }` |
+| **layout** | Object | The current layout state | _see below_ |
+| **layout.isFullscreen** | Boolean | Whether the preview canvas is in fullscreen mode | `true` or `false` |
+| **layout.panelPosition** | String | Whether the panel is shown below or on the side of the preview | `'bottom'` or `'right'` |
+| **layout.showNav** | Boolean | The setting for whether the end user wants to see the sidebar | `true` or `false` |
+| **layout.showPanel** | Boolean | The setting for whether the end user wants to see the panel | `true` or `false` |
+| **layout.showToolbar** | Boolean | The setting for whether the end user wants to see the toolbar | `true` or `false` |
+
+
- If you're hiding the sidebar through `showSidebar`, ensure the displayed page provides an alternative means of navigation.
+If you're hiding the sidebar through `showSidebar`, ensure the displayed page provides an alternative means of navigation.
### Configure the addon panel
-When viewing a story, Storybook displays the addon panel on the bottom or right of the UI. The panel shows UIs for available addons (e.g., the [interactions panel](../../writing-tests/interaction-testing#debugging-interaction-tests), [accessibility tests panel](../../writing-tests/accessibility-testing) or [controls panel](../../essentials/controls)). If you want to customize when the addon panel appears, you can use the `showPanel` function. Listed below are the available options and an overview of how to use them.
-
-| Name | Type | Description | Example Value |
-| ------------------------ | -------- | -------------------------------------------------------------- | ------------------------------------- |
-| **path** | String | Path to the page being displayed | `'/story/components-button--default'` |
-| **viewMode** | String | Whether the current page is a story or docs | `'docs'` or `'story'` |
-| **singleStory** | Boolean | Whether the current page is the only story for a component | `true` or `false` |
-| **storyId** | String | The id of the current story or docs page | `'blocks-unstyled--docs'` |
-| **index** | Object | The index containing statically analysed metadata for every story | `{ 'blocks-unstyled--docs': { tags: ['autodocs'] } }` |
-| **layout** | Object | The current layout state | *see below* |
-| **layout.isFullscreen** | Boolean | Whether the preview canvas is in fullscreen mode | `true` or `false` |
-| **layout.panelPosition** | String | Whether the panel is shown below or on the side of the preview | `'bottom'` or `'right'` |
-| **layout.showNav** | Boolean | The setting for whether the end user wants to see the sidebar | `true` or `false` |
-| **layout.showPanel** | Boolean | The setting for whether the end user wants to see the panel | `true` or `false` |
-| **layout.showToolbar** | Boolean | The setting for whether the end user wants to see the toolbar | `true` or `false` |
-
-{/* prettier-ignore-start */}
+When viewing a story, Storybook displays the addon panel on the bottom or right of the UI. The panel shows UIs for available addons (e.g., the [interactions panel](../../writing-tests/interaction-testing.mdx#debugging-interaction-tests), [accessibility tests panel](../../writing-tests/accessibility-testing.mdx) or [controls panel](../../essentials/controls.mdx)). If you want to customize when the addon panel appears, you can use the `showPanel` function. Listed below are the available options and an overview of how to use them.
-
+| Name | Type | Description | Example Value |
+| ------------------------ | ------- | ----------------------------------------------------------------- | ----------------------------------------------------- |
+| **path** | String | Path to the page being displayed | `'/story/components-button--default'` |
+| **viewMode** | String | Whether the current page is a story or docs | `'docs'` or `'story'` |
+| **singleStory** | Boolean | Whether the current page is the only story for a component | `true` or `false` |
+| **storyId** | String | The id of the current story or docs page | `'blocks-unstyled--docs'` |
+| **index** | Object | The index containing statically analysed metadata for every story | `{ 'blocks-unstyled--docs': { tags: ['autodocs'] } }` |
+| **layout** | Object | The current layout state | _see below_ |
+| **layout.isFullscreen** | Boolean | Whether the preview canvas is in fullscreen mode | `true` or `false` |
+| **layout.panelPosition** | String | Whether the panel is shown below or on the side of the preview | `'bottom'` or `'right'` |
+| **layout.showNav** | Boolean | The setting for whether the end user wants to see the sidebar | `true` or `false` |
+| **layout.showPanel** | Boolean | The setting for whether the end user wants to see the panel | `true` or `false` |
+| **layout.showToolbar** | Boolean | The setting for whether the end user wants to see the toolbar | `true` or `false` |
-{/* prettier-ignore-end */}
+
### Configure the toolbar
By default, Storybook displays a toolbar at the top of the UI, allowing you to access menus from addons (e.g., [viewport](../../essentials/viewport.mdx), [background](../../essentials/backgrounds.mdx)), or custom defined [menus](../../essentials/toolbars-and-globals.mdx#global-types-and-the-toolbar-annotation). However, if you want to customize the toolbar's behavior, you can use the `showToolbar` function. Listed below are the available options and an overview of how to use them.
-| Name | Type | Description | Example Value |
-| ------------------------ | -------- | -------------------------------------------------------------- | ------------------------------------- |
-| **path** | String | Path to the page being displayed | `'/story/components-button--default'` |
-| **viewMode** | String | Whether the current page is a story or docs | `'docs'` or `'story'` |
-| **singleStory** | Boolean | Whether the current page is the only story for a component | `true` or `false` |
-| **storyId** | String | The id of the current story or docs page | `'blocks-unstyled--docs'` |
-| **index** | Object | The index containing statically analysed metadata for every story | `{ 'blocks-unstyled--docs': { tags: ['autodocs'] } }` |
-| **layout** | Object | The current layout state | *see below* |
-| **layout.isFullscreen** | Boolean | Whether the preview canvas is in fullscreen mode | `true` or `false` |
-| **layout.panelPosition** | String | Whether the panel is shown below or on the side of the preview | `'bottom'` or `'right'` |
-| **layout.showNav** | Boolean | The setting for whether the end user wants to see the sidebar | `true` or `false` |
-| **layout.showPanel** | Boolean | The setting for whether the end user wants to see the panel | `true` or `false` |
-| **layout.showToolbar** | Boolean | The setting for whether the end user wants to see the toolbar | `true` or `false` |
-
-{/* prettier-ignore-start */}
-
-
-
-{/* prettier-ignore-end */}
+| Name | Type | Description | Example Value |
+| ------------------------ | ------- | ----------------------------------------------------------------- | ----------------------------------------------------- |
+| **path** | String | Path to the page being displayed | `'/story/components-button--default'` |
+| **viewMode** | String | Whether the current page is a story or docs | `'docs'` or `'story'` |
+| **singleStory** | Boolean | Whether the current page is the only story for a component | `true` or `false` |
+| **storyId** | String | The id of the current story or docs page | `'blocks-unstyled--docs'` |
+| **index** | Object | The index containing statically analysed metadata for every story | `{ 'blocks-unstyled--docs': { tags: ['autodocs'] } }` |
+| **layout** | Object | The current layout state | _see below_ |
+| **layout.isFullscreen** | Boolean | Whether the preview canvas is in fullscreen mode | `true` or `false` |
+| **layout.panelPosition** | String | Whether the panel is shown below or on the side of the preview | `'bottom'` or `'right'` |
+| **layout.showNav** | Boolean | The setting for whether the end user wants to see the sidebar | `true` or `false` |
+| **layout.showPanel** | Boolean | The setting for whether the end user wants to see the panel | `true` or `false` |
+| **layout.showToolbar** | Boolean | The setting for whether the end user wants to see the toolbar | `true` or `false` |
+
+
## Configuring through URL parameters
diff --git a/docs/configure/user-interface/index.mdx b/docs/configure/user-interface/index.mdx
index ede942a212a4..1b9a7cd6c65c 100644
--- a/docs/configure/user-interface/index.mdx
+++ b/docs/configure/user-interface/index.mdx
@@ -2,5 +2,4 @@
title: User Interface
sidebar:
order: 7
- title: User Interface
----
\ No newline at end of file
+---
diff --git a/docs/configure/user-interface/sidebar-and-urls.mdx b/docs/configure/user-interface/sidebar-and-urls.mdx
index 67646779e5b6..e9cba792c098 100644
--- a/docs/configure/user-interface/sidebar-and-urls.mdx
+++ b/docs/configure/user-interface/sidebar-and-urls.mdx
@@ -2,7 +2,6 @@
title: 'Sidebar & URLS'
sidebar:
order: 3
- title: Sidebar & URLS
---
@@ -21,56 +20,36 @@ By default, Storybook will treat your top-level nodes as “roots”. Roots are
If you’d prefer to show top-level nodes as folders rather than roots, you can set the `sidebar.showRoots` option to `false` in [`./storybook/manager.js`](./features-and-behavior.mdx):
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Permalink to stories
By default, Storybook generates an `id` for each story based on the component title and the story name. This `id` in particular is used in the URL for each story, and that URL can serve as a permalink (primarily when you [publish](../../sharing/publish-storybook.mdx) your Storybook).
Consider the following story:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Storybook's ID-generation logic will give this the `id` `foo-bar--baz`, so the link would be `?path=/story/foo-bar--baz`.
It is possible to manually set the story's id, which is helpful if you want to rename stories without breaking permalinks. Suppose you want to change the position in the hierarchy to `OtherFoo/Bar` and the story name to `Moo`. Here's how to do that:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Storybook will prioritize the `id` over the title for ID generation if provided and prioritize the `story.name` over the export key for display.
## CSF 3.0 auto-titles
Storybook 6.4 introduced [CSF 3.0](https://storybook.js.org/blog/component-story-format-3-0/) as an experimental feature, allowing you to write stories more compactly. Suppose you're already using this format to write your stories. In that case, you can omit the `title` element from the meta (or default export) and allow Storybook automatically infer it based on the file's physical location. For example, given the following configuration and story:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
When Storybook loads, the story can show up in the sidebar as `components/My Component`.
Auto-titles work with explicit titling options like the component's `title` and the story's `name`:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Auto-title filename case
Starting with Storybook 6.5, story titles generated automatically no longer rely on Lodash's [startCase](https://lodash.com/docs/#startCase).
@@ -78,34 +57,22 @@ Instead, the file name casing is preserved, allowing additional control over the
If you need, you can revert to the previous pattern by adding the following configuration:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Auto-title redundant filenames
In addition to improvements to the story file name casing, a new heuristic was introduced, removing redundant names in case the filename has the same name as the directory name, or if it's called `index.stories.js|ts`. For example, before `components/MyComponent/MyComponent.stories.js` was defined as `Components/MyComponent/MyComponent` in the sidebar. Now it will be defined as `Components/MyComponent`.
If you need to preserve the naming scheme, you can add the `title` element to the meta (or default export). For example:
-{/* prettier-ignore-start */}
-
-
-
-{/* prettier-ignore-end */}
+
### Auto-title prefixes
Additionally, if you customize your Storybook to load your stories based on a [configuration object](../index.mdx#with-a-configuration-object), including a `titlePrefix`, Storybook automatically prefixes all titles to matching stories. For example, assuming you have the following configuration:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
When Storybook generates the titles for all matching stories, they'll retain the `Custom` prefix.
### Story Indexers
diff --git a/docs/configure/user-interface/storybook-addons.mdx b/docs/configure/user-interface/storybook-addons.mdx
index 6b7bc1cfef0f..a5989a585042 100644
--- a/docs/configure/user-interface/storybook-addons.mdx
+++ b/docs/configure/user-interface/storybook-addons.mdx
@@ -1,8 +1,7 @@
---
-title: 'Storybook Addons'
+title: Storybook Addons
sidebar:
order: 4
- title: Storybook Addons
---
A key strength of Storybook is its extensibility. Use addons to extend and customize Storybook to fit your team’s development workflow.
@@ -23,5 +22,5 @@ Finally, addons can affect the build setup of Storybook by injecting their own w
There are many, many Storybook addons, but they can be roughly categorized into two areas:
-* **Core** addons are developed by the core team. They are kept in sync with the development of Storybook itself and written in idiomatic ways as templates for other addons. They can be found within the [Storybook monorepo](https://github.com/storybookjs/storybook/tree/next/code/addons).
-* **Community** addons are addons written by the massive Storybook community. They can be found on our [website](https://storybook.js.org/addons/), [GitHub](https://github.com/), and [npm](https://www.npmjs.com/).
+- **Core** addons are developed by the core team. They are kept in sync with the development of Storybook itself and written in idiomatic ways as templates for other addons. They can be found within the [Storybook monorepo](https://github.com/storybookjs/storybook/tree/next/code/addons).
+- **Community** addons are addons written by the massive Storybook community. They can be found on our [website](https://storybook.js.org/addons/), [GitHub](https://github.com/), and [npm](https://www.npmjs.com/).
diff --git a/docs/configure/user-interface/theming.mdx b/docs/configure/user-interface/theming.mdx
index 4af2f214d2fd..3d0d33cb845c 100644
--- a/docs/configure/user-interface/theming.mdx
+++ b/docs/configure/user-interface/theming.mdx
@@ -1,8 +1,7 @@
---
-title: 'Theming'
+title: Theming
sidebar:
order: 2
- title: Theming
---
Storybook is theme-able using a lightweight theming API.
@@ -15,12 +14,8 @@ Storybook includes a set of built-in themes that you can use to customize the ap
As an example, you can tell Storybook to use the "dark" theme by modifying [`.storybook/manager.js`](./features-and-behavior.mdx):
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
When setting a theme, set a complete theme object. The theme is replaced, not combined.
## Theming docs
@@ -29,20 +24,12 @@ When setting a theme, set a complete theme object. The theme is replaced, not co
Supposing you have a Storybook theme defined for the main UI in [`.storybook/manager.js`](./features-and-behavior.mdx):
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Here's how you'd specify the same theme for docs in [`.storybook/preview.js`](../index.mdx#configure-story-rendering):
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Continue to read if you want to learn how to create your theme.
## Create a theme quickstart
@@ -51,56 +38,46 @@ The easiest way to customize Storybook is to generate a new theme using the `cre
Inside your `.storybook` directory, create a new file called `YourTheme.js` and add the following:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- If you're using `brandImage` to add your custom logo, you can use any of the most common image formats.
-
+If you're using `brandImage` to add your custom logo, you can use any of the most common image formats.
+
Above, we're creating a new theme that will:
-* Use Storybook's `light` theme as a baseline.
-* Replace Storybook's logo in the sidebar with our own (defined in the brandImage variable).
-* Add custom branding information.
-* Set the brand link to open in the same window (as opposed to a new one), via the `target` attribute.
+- Use Storybook's `light` theme as a baseline.
+- Replace Storybook's logo in the sidebar with our own (defined in the brandImage variable).
+- Add custom branding information.
+- Set the brand link to open in the same window (as opposed to a new one), via the `target` attribute.
Finally, we'll need to import the theme into Storybook. Create a new file called `manager.js` in your `.storybook` directory and add the following:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Now your custom theme will replace Storybook's default theme, and you'll see a similar set of changes in the UI.

Let's take a look at a more complex example. Copy the code below and paste it in `.storybook/YourTheme.js`.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Above, we're updating the theme with the following changes:
-* A custom color palette (defined in the `app` and `color` variables).
-* Custom fonts (defined in the `font` and `text` variables).
+- A custom color palette (defined in the `app` and `color` variables).
+- Custom fonts (defined in the `font` and `text` variables).
With the new changes introduced, the custom theme should yield a similar result.

- Many theme variables are optional, the base property is **NOT**.
+
+Many theme variables are optional, the base property is **NOT**.
+
The `storybook/theming` module is built using TypeScript, which should help create a valid theme for TypeScript users. The types are part of the package itself.
@@ -111,11 +88,13 @@ The Storybook theme API is narrow by design. If you want to have fine-grained co
To style these elements, insert style tags into:
-* For Storybook’s UI, use `.storybook/manager-head.html`
-* For Storybook Docs, use `.storybook/preview-head.html`
+- For Storybook’s UI, use `.storybook/manager-head.html`
+- For Storybook Docs, use `.storybook/preview-head.html`
- The same way as you can adjust your [preview’s head tag](../story-rendering.mdx#adding-to-head), Storybook allows you to modify the code on the manager's side, through `.storybook/manager-head.html`. It can be helpful when adding theme styles that target Storybook's HTML, but it comes with a cost as Storybook's inner HTML can change at any time through the release cycle.
+
+The same way as you can adjust your [preview’s head tag](../story-rendering.mdx#adding-to-head), Storybook allows you to modify the code on the manager's side, through `.storybook/manager-head.html`. It can be helpful when adding theme styles that target Storybook's HTML, but it comes with a cost as Storybook's inner HTML can change at any time through the release cycle.
+
## MDX component overrides
@@ -124,56 +103,32 @@ If you're using MDX for docs, there's one more level of "themability". MDX allow
Here's how you might insert a custom code renderer for `code` blocks on the page, in [`.storybook/preview.js`](../index.mdx#configure-story-rendering):
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
You can even override a Storybook block component.
Here's how you might insert a custom `` block:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Addons and theme creation
Some addons require specific theme variables that a Storybook user must add. If you share your theme with the community, make sure to support the official API and other popular addons, so your users have a consistent experience.
For example, the popular Actions feature uses [react-inspector](https://github.com/storybookjs/react-inspector/blob/master/src/styles/themes/chromeLight.tsx), which has themes of its own. Supply additional theme variables to style it like so:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Using the theme for addon authors
Reuse the theme variables above for a native Storybook developer experience. The theming engine relies on [emotion](https://emotion.sh/), a CSS-in-JS library.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Use the theme variables in object notation:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Or with template literals:
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/configure/webpack.mdx b/docs/configure/webpack.mdx
index d5fc8b716d19..706cada5aaaf 100644
--- a/docs/configure/webpack.mdx
+++ b/docs/configure/webpack.mdx
@@ -1,5 +1,5 @@
---
-title: 'Webpack'
+title: Webpack
draft: true
---
@@ -9,30 +9,22 @@ You can customize Storybook's webpack setup by providing a `webpackFinal` field
The value should be an async function that receives a webpack config and eventually returns a webpack config.
-### Default configuration
+## Default configuration
By default, Storybook's webpack configuration will allow you to:
-#### Import images and other static files
+### Import images and other static files
You can import images and other local files and have them built into the Storybook:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
-#### Import JSON as JavaScript
+### Import JSON as JavaScript
You can import `.json` files and have them expanded to a JavaScript object:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
If you want to know the exact details of the webpack config, the best way is to run either of the following:
```shell
@@ -44,42 +36,30 @@ yarn storybook dev --debug-webpack
yarn storybook build --debug-webpack
```
-When you start your Storybook, you'll see an improvement in loading times. Read more about it in the [announcement post](https://storybook.js.org/blog/storybook-on-demand-architecture/) and the [configuration documentation](./index.mdx#on-demand-story-loading).
+When you start your Storybook, you'll see an improvement in loading times. Read more about it in the [announcement post](https://storybook.js.org/blog/storybook-on-demand-architecture/) and the [configuration documentation](./index.mdx#configure-story-loading).
### Webpack 5
Storybook builds your project with Webpack 4 by default. If your project uses Webpack 5, you can opt into the Webpack 5 builder by installing the required dependencies (i.e., `@storybook/builder-webpack5`, `@storybook/manager-webpack5`) and update your Storybook configuration as follows:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Once you are using Webpack 5, you can further opt into some features to optimize your build:
#### Lazy Compilation
Storybook supports Webpack's experimental [lazy compilation](https://webpack.js.org/configuration/experiments/#experimentslazycompilation) feature, via the `lazyCompilation` builder flag:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
This feature applies in development mode, and will mean your Storybook will start up faster, at the cost of slightly slower browsing time when you change stories.
#### Filesystem Caching
Storybook supports Webpack's [filesystem caching](https://webpack.js.org/configuration/cache/#cachetype) feature, via the `fsCache` builder flag:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
This feature will mean build output is cached between runs of Storybook, speeding up subsequent startup times.
### Extending Storybook’s webpack config
@@ -90,27 +70,19 @@ The value should export a `function`, which will receive the default config as i
For example, if you need to adjust the config for a specific environment, you can do so like this:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Storybook uses the config returned from the above function to render your components in Storybook's "preview" iframe. Note that Storybook has an entirely separate webpack config for its UI (also referred to as the "manager"), so the customizations you make only apply to the rendering of your stories, i.e., you can completely replace `config.module.rules` if you want.
Nevertheless, edit `config` with care. Make sure to preserve the following config options:
-* **entry**
-* **output**
+- **entry**
+- **output**
Furthermore, `config` requires the `HtmlWebpackplugin` to generate the preview page, so rather than overwriting `config.plugins` you should probably append to it (or overwrite it with care), see [the following issue](https://github.com/storybookjs/storybook/issues/6020) for examples on how to handle this:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Finally, if your custom webpack config uses a loader that does not explicitly include specific file extensions via the `test` property, in that case, it is necessary to `exclude` the `.ejs` file extension from that loader.
If you're using a non-standard Storybook config directory, you should put `main.js` there instead of `.storybook` and update the `include` path to ensure it resolves to your project root.
@@ -121,26 +93,22 @@ Suppose you have an existing webpack config for your project and want to reuse t
The following code snippet shows how you can replace the loaders from Storybook with the ones from your app's `webpack.config.js`:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- Projects initialized via generators (e.g, Vue CLI) may require that you import their own webpack config file (i.e., /projectRoot/node\_modules/@vue/cli-service/webpack.config.js) to use a certain feature with Storybook. For other generators, make sure to check the documentation for instructions.
+
+Projects initialized via generators (e.g, Vue CLI) may require that you import their own webpack config file (i.e., /projectRoot/node_modules/@vue/cli-service/webpack.config.js) to use a certain feature with Storybook. For other generators, make sure to check the documentation for instructions.
+
### TypeScript Module Resolution
When working with TypeScript projects, the default Webpack configuration may fail to resolve module aliases defined in your [`tsconfig` file](https://www.typescriptlang.org/tsconfig). To work around this issue you may use [`tsconfig-paths-webpack-plugin`](https://github.com/dividab/tsconfig-paths-webpack-plugin#tsconfig-paths-webpack-plugin) while [extending Storybook's Webpack config](#extending-storybooks-webpack-config) like:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- Learn more about Storybook's built-in TypeScript support or see this issue for more information.
+
+Learn more about Storybook's built-in TypeScript support or see this issue for more information.
+
diff --git a/docs/contribute/RFC.mdx b/docs/contribute/RFC.mdx
index d67f71e9a179..5bec103ad896 100644
--- a/docs/contribute/RFC.mdx
+++ b/docs/contribute/RFC.mdx
@@ -1,9 +1,8 @@
---
-title: 'RFC process'
+title: RFC process
hideRendererSelector: true
sidebar:
order: 1
- title: RFC process
---
The RFC (Request for Comment) process is intended to provide a consistent and controlled path for new features to enter the project. It helps ensure that new features are well-designed, well-implemented, and well-tested, and they do not conflict with the project's overall direction and scope.
@@ -14,15 +13,15 @@ Many changes, such as bug fixes and documentation improvements, can be implement
The purpose of the RFC (Request for Comment) process is to:
-* Provide a transparent system for proposing new feature ideas.
-* Establish a reliable and well-regulated process for introducing new features into the project.
-* Provide a way for the community to participate in developing new features.
+- Provide a transparent system for proposing new feature ideas.
+- Establish a reliable and well-regulated process for introducing new features into the project.
+- Provide a way for the community to participate in developing new features.
### “Feature Request” vs. “RFC”
-A *feature request* is a straightforward and relatively informal way for Storybook users to suggest a new feature or enhancement to the project. While feature requests can provide valuable insights and ideas, they typically do not involve an in-depth design process or require consensus among the core team. Feature requests are usually open to discussion and may or may not be implemented based on factors like popularity, feasibility, and alignment with the project's goals.
+A _feature request_ is a straightforward and relatively informal way for Storybook users to suggest a new feature or enhancement to the project. While feature requests can provide valuable insights and ideas, they typically do not involve an in-depth design process or require consensus among the core team. Feature requests are usually open to discussion and may or may not be implemented based on factors like popularity, feasibility, and alignment with the project's goals.
-On the other hand, an *RFC* is a more formalized and structured process for proposing substantial changes or additions to the project. It involves following a defined set of steps to ensure that the proposed feature or modification receives proper consideration, design, and feedback. RFCs are typically used for changes that significantly impact the project, such as introducing new API functionality, removing existing features, or establishing new usage conventions. The RFC process aims to foster discussions, gather feedback from a wider audience, and reach consensus among the core team before integrating the proposed change into the project. Accepted RFCs are more likely to be implemented than regular feature requests.
+On the other hand, an _RFC_ is a more formalized and structured process for proposing substantial changes or additions to the project. It involves following a defined set of steps to ensure that the proposed feature or modification receives proper consideration, design, and feedback. RFCs are typically used for changes that significantly impact the project, such as introducing new API functionality, removing existing features, or establishing new usage conventions. The RFC process aims to foster discussions, gather feedback from a wider audience, and reach consensus among the core team before integrating the proposed change into the project. Accepted RFCs are more likely to be implemented than regular feature requests.
## The RFC lifecycle
@@ -30,7 +29,7 @@ On the other hand, an *RFC* is a more formalized and structured process for prop
Open a new GitHub discussion in the [“RFC” category](https://github.com/storybookjs/storybook/discussions/new?category=rfc). Fill out the form as instructed.
-*Details matter*: RFCs that do not present convincing motivation, demonstrate a lack of understanding of the design's impact, or are disingenuous about the drawbacks or alternatives tend to be poorly received.
+_Details matter_: RFCs that do not present convincing motivation, demonstrate a lack of understanding of the design's impact, or are disingenuous about the drawbacks or alternatives tend to be poorly received.
### 2. `Status: In review`
@@ -52,8 +51,8 @@ This RFC process took heavy inspiration from the RFC processes from [Rust](https
**Learn more about contributing to Storybook**
-* RFC process for authoring feature requests
-* [Code](./code.mdx) for features and bug fixes
-* [Frameworks](./framework.mdx) to get started with a new framework
-* [Documentation](./documentation/documentation-updates.mdx) for documentation improvements, typos, and clarifications
-* [Examples](./documentation/new-snippets.mdx) for new snippets
+- RFC process for authoring feature requests
+- [Code](./code.mdx) for features and bug fixes
+- [Frameworks](./framework.mdx) to get started with a new framework
+- [Documentation](./documentation/documentation-updates.mdx) for documentation improvements, typos, and clarifications
+- [Examples](./documentation/new-snippets.mdx) for new snippets
diff --git a/docs/contribute/code.mdx b/docs/contribute/code.mdx
index fe23efbcb59a..f35b9993cfab 100644
--- a/docs/contribute/code.mdx
+++ b/docs/contribute/code.mdx
@@ -1,5 +1,5 @@
---
-title: 'Code contributions'
+title: Code contributions
hideRendererSelector: true
sidebar:
order: 2
@@ -10,8 +10,8 @@ Contribute a new feature or bug fix to [Storybook's monorepo](https://github.com
## Prerequisites
-* Ensure you have Node version 18 installed (suggestion: v18.16.0).
-* If you're working with Windows, all commands should be run in a terminal with administrator privileges.
+- Ensure you have Node version 18 installed (suggestion: v18.16.0).
+- If you're working with Windows, all commands should be run in a terminal with administrator privileges.
## Initial setup
@@ -30,7 +30,7 @@ corepack enable
## Run your first sandbox
-Storybook development happens in a set of *sandboxes* which are templated Storybook environments corresponding to different user setups. Within each sandbox, we inject a set of generalized stories that allow us to test core features and addons in all such environments.
+Storybook development happens in a set of _sandboxes_ which are templated Storybook environments corresponding to different user setups. Within each sandbox, we inject a set of generalized stories that allow us to test core features and addons in all such environments.
To run a sandbox locally, you can use the `start` command:
@@ -56,7 +56,7 @@ When prompted, answer the questions as accurately as possible to allow Storybook
- The `yarn task` command takes a few development shortcuts that can catch you off guard when switching branches and may require you to re-run both the `install` and `compile` tasks. You can speed up the process by running the command with the `start-from=install` flag.
+The `yarn task` command takes a few development shortcuts that can catch you off guard when switching branches and may require you to re-run both the `install` and `compile` tasks. You can speed up the process by running the command with the `start-from=install` flag.
@@ -90,7 +90,7 @@ When prompted to start the build process in `watch` mode, answer **yes** to deve
- Build's `watch` mode is great for interactive development. However, for performance reasons, it only transpiles your code and doesn't execute the TypeScript compiler. If something isn't working as expected, try running the `build` command **WITHOUT** enabling watch mode: it will re-generate TypeScript types and perform automatic type checking for you.
+Build's `watch` mode is great for interactive development. However, for performance reasons, it only transpiles your code and doesn't execute the TypeScript compiler. If something isn't working as expected, try running the `build` command **WITHOUT** enabling watch mode: it will re-generate TypeScript types and perform automatic type checking for you.
@@ -103,10 +103,11 @@ Otherwise, if it affects the `Manager` (the outermost Storybook `iframe` where t

The `yarn build` commands accepts arguments to help speed up your development workflow:
-* `--all` will cause all packages to be built
-* `--watch` will enable watch mode (and skip the watch mode prompt)
-* `--prod` will build for production (and skip the production mode prompt)
-* individual package names can be passed, without the `@storybook/` prefix, e.g. `storybook`, `addon-docs`, etc.
+
+- `--all` will cause all packages to be built
+- `--watch` will enable watch mode (and skip the watch mode prompt)
+- `--prod` will build for production (and skip the production mode prompt)
+- individual package names can be passed, without the `@storybook/` prefix, e.g. `storybook`, `addon-docs`, etc.
For example, to build Storybook and the docs addon in watch mode, run:
@@ -114,7 +115,6 @@ For example, to build Storybook and the docs addon in watch mode, run:
yarn build --watch storybook addon-docs
```
-
## Check your work
When you're done coding, add documentation and tests as appropriate. That simplifies the PR review process, which means your code will get merged faster.
@@ -163,8 +163,8 @@ yarn test
- Storybook relies on [Vitest](https://vitest.dev/) as part of it's testing suite. During the test run, if you spot that snapshot tests are failing, re-run the command with the `-u` flag to update them.
-
+Storybook relies on [Vitest](https://vitest.dev/) as part of it's testing suite. During the test run, if you spot that snapshot tests are failing, re-run the command with the `-u` flag to update them.
+
Doing this prevents last-minute bugs and is a great way to merge your contribution faster once you submit your pull request. Failing to do so will lead to one of the maintainers mark the pull request with the **Work in Progress** label until all tests pass.
@@ -177,8 +177,8 @@ If your contribution focuses on a bugfix and you want it featured in the next st
#### Useful resources when working with forks
-* [Sync a fork](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/working-with-forks/syncing-a-fork)
-* [Merge an upstream repository into your fork](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/working-with-forks/merging-an-upstream-repository-into-your-fork)
+- [Sync a fork](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/working-with-forks/syncing-a-fork)
+- [Merge an upstream repository into your fork](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/working-with-forks/merging-an-upstream-repository-into-your-fork)
### Reproducing job failures
@@ -191,9 +191,11 @@ yarn task --task e2e-tests --template=react-vite/default-ts --start-from=install
Typically it is a good idea to start from the `install` task to ensure your local code is completely up to date. If you reproduce the failure, you can try and make fixes, [compile them](#start-developing) with `build`, then rerun the task with `--start-from=auto`.
- The default instructions run the code in "linked" mode, meaning built changes to Storybook library code will be reflected in the sandbox immediately (the next time you run the task). However, CI runs in "unlinked" mode, which in rare cases, will behave differently.
- If you are having trouble reproducing, try rerunning the command with the `--no-link` flag. If you need to do that, you'll need to run it with `--start-from=compile` after each code change.
+The default instructions run the code in "linked" mode, meaning built changes to Storybook library code will be reflected in the sandbox immediately (the next time you run the task). However, CI runs in "unlinked" mode, which in rare cases, will behave differently.
+
+If you are having trouble reproducing, try rerunning the command with the `--no-link` flag. If you need to do that, you'll need to run it with `--start-from=compile` after each code change.
+
## How to work with reproductions
@@ -215,7 +217,9 @@ npx storybook@next link --local /path/to/local-repro-directory
```
- The `storybook link` command relies on [Yarn linking](https://yarnpkg.com/cli/link/) under the hood. It requires your local reproduction to be using [Yarn 2 or higher](https://yarnpkg.com/) as well, which is the case if you've already enabled it with the [`storybook sandbox`](./how-to-reproduce.mdx) command per our contribution guidelines. The process will fail if you're trying to link a non-Yarn 2 project.
+
+The `storybook link` command relies on [Yarn linking](https://yarnpkg.com/cli/link/) under the hood. It requires your local reproduction to be using [Yarn 2 or higher](https://yarnpkg.com/) as well, which is the case if you've already enabled it with the [`storybook sandbox`](./how-to-reproduce.mdx) command per our contribution guidelines. The process will fail if you're trying to link a non-Yarn 2 project.
+
## Developing a template
@@ -239,8 +243,8 @@ Add the `inDevelopment` flag until the PR is merged (you can fast-follow it with
The **`key`** `cra/default-js` consists of two parts:
-* The prefix is the tool that was used to generate the repro app
-* The suffix is options that modify the default install, e.g. a specific version or options
+- The prefix is the tool that was used to generate the repro app
+- The suffix is options that modify the default install, e.g. a specific version or options
The **`script`** field is what generates the application environment. The `.` argument is “the current working directory” which is auto-generated based on the key (e.g. `repros/cra/default-js/before-storybook`). The `{{beforeDir}}` key can also be used, which will be replaced by the path of that directory.
@@ -267,15 +271,16 @@ Once the PR is merged, the template will be generated on a nightly cadence and y
## Troubleshooting
- yarn build --all --watch watches everything but is resource-intensive
+yarn build --all --watch watches everything but is resource-intensive
+
+It's troublesome to know which packages you'll change ahead of time, and watching them can be highly demanding, even on modern machines. If you're working on a powerful enough machine, you can use `yarn build --all --watch` instead of `yarn build`.
- It's troublesome to know which packages you'll change ahead of time, and watching them can be highly demanding, even on modern machines. If you're working on a powerful enough machine, you can use `yarn build --all --watch` instead of `yarn build`.
**Learn more about contributing to Storybook**
-* [RFC process](./RFC.mdx) for authoring feature requests
-* Code for features and bug fixes
-* [Frameworks](./framework.mdx) to get started with a new framework
-* [Documentation](./documentation/documentation-updates.mdx) for documentation improvements, typos, and clarifications
-* [Examples](./documentation/new-snippets.mdx) for new snippets
+- [RFC process](./RFC.mdx) for authoring feature requests
+- Code for features and bug fixes
+- [Frameworks](./framework.mdx) to get started with a new framework
+- [Documentation](./documentation/documentation-updates.mdx) for documentation improvements, typos, and clarifications
+- [Examples](./documentation/new-snippets.mdx) for new snippets
diff --git a/docs/contribute/documentation/documentation-updates.mdx b/docs/contribute/documentation/documentation-updates.mdx
index 51e38f8a523a..fad0710b249c 100644
--- a/docs/contribute/documentation/documentation-updates.mdx
+++ b/docs/contribute/documentation/documentation-updates.mdx
@@ -1,5 +1,5 @@
---
-title: 'Documentation updates'
+title: Documentation updates
hideRendererSelector: true
sidebar:
order: 1
@@ -28,8 +28,8 @@ In the Storybook repository, create a pull request that describes changes and in
**Learn more about contributing to Storybook**
-* [RFC process](../RFC.mdx) for authoring feature requests
-* [Code](../code.mdx) for features and bug fixes
-* [Frameworks](../framework.mdx) to get started with a new framework
-* Documentation for documentation improvements, typos, and clarifications
-* [Examples](./new-snippets.mdx) for new snippets
+- [RFC process](../RFC.mdx) for authoring feature requests
+- [Code](../code.mdx) for features and bug fixes
+- [Frameworks](../framework.mdx) to get started with a new framework
+- Documentation for documentation improvements, typos, and clarifications
+- [Examples](./new-snippets.mdx) for new snippets
diff --git a/docs/contribute/documentation/index.mdx b/docs/contribute/documentation/index.mdx
index eec3822713e0..f875ea70ae76 100644
--- a/docs/contribute/documentation/index.mdx
+++ b/docs/contribute/documentation/index.mdx
@@ -2,5 +2,4 @@
title: Documentation
sidebar:
order: 3
- title: Documentation
----
\ No newline at end of file
+---
diff --git a/docs/contribute/documentation/new-snippets.mdx b/docs/contribute/documentation/new-snippets.mdx
index 0f0a85bba8a1..582e4a1450ad 100644
--- a/docs/contribute/documentation/new-snippets.mdx
+++ b/docs/contribute/documentation/new-snippets.mdx
@@ -1,5 +1,5 @@
---
-title: 'Code snippets contributions'
+title: Code snippets contributions
hideRendererSelector: true
sidebar:
order: 2
@@ -14,11 +14,9 @@ Storybook maintains code snippets for a [variety of frameworks](../../configure/
We welcome community contributions to the code snippets. Here's a matrix of the frameworks for which we have snippets. Help us add snippets for your favorite framework.
-
-| React | Vue 3 | Angular | Web Components | Svelte | Solid | Ember | HTML | Preact | Qwik |
-| ------ | ----- | --------- | ---------------|--------|--------|-------|------| -------|------|
-| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
-
+| React | Vue 3 | Angular | Web Components | Svelte | Solid | Ember | HTML | Preact | Qwik |
+| ----- | ----- | ------- | -------------- | ------ | ----- | ----- | ---- | ------ | ---- |
+| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
## Snippet syntax
@@ -28,8 +26,6 @@ The code snippets referenced throughout the Storybook documentation are located
The following code block demonstrates how to structure a code snippet in the Storybook documentation and the attributes you can use to provide additional context to the code snippet.
-{/* prettier-ignore-start */}
-
````md title="docs/_snippets/button-group-story.md"
```ts filename="ButtonGroup.stories.ts" renderer="vue" language="ts" tabTitle="3"
import type { Meta, StoryObj } from '@storybook/vue3-vite';
@@ -59,12 +55,9 @@ export const Pair: Story = {
orientation: 'horizontal',
},
};
-```
+```
````
-{/* prettier-ignore-end */}
-
-
## Common attributes for code snippets
Following are the attributes you'll use most often in the Storybook documentation code snippets, as well as a brief explanation of each to help you understand the context in which they are used.
@@ -73,114 +66,82 @@ Following are the attributes you'll use most often in the Storybook documentatio
Most code examples should include a file name so readers can understand which file they relate to and where to paste it into their project. For code examples, include the `filename` attribute wrapped with quotation marks to indicate the file name. This is not required if the example relates to a terminal command.
-{/* prettier-ignore-start */}
-
````md title="docs/_snippets/button-stories.md"
```ts filename="Button.stories.ts"
+
```
````
-{/* prettier-ignore-end */}
-
### Language configuration
Use the `language` attribute to define the language to which the code snippet applies. The documentation uses this attribute to determine which variant to display (e.g., JavaScript, TypeScript, MDX).
-{/* prettier-ignore-start */}
-
````md title="docs/_snippets/button-stories.md"
```ts filename="Button.stories.ts" language="js|ts|mdx"
+
```
````
-{/* prettier-ignore-end */}
-
### Framework-specific code
Use the `renderer` attribute to indicate which of the [supported frameworks](../../configure/integration/frameworks-feature-support.mdx) the code snippet belongs to.
-{/* prettier-ignore-start */}
-
````md title="docs/_snippets/button-stories.md"
```ts filename="Button.stories.ts" language="ts" renderer="react|vue|angular|web-components|ember|html|svelte|preact|qwik|solid"
+
```
````
-{/* prettier-ignore-end */}
-
Alternatively, if you're documenting examples that apply to multiple frameworks, use the `renderer` attribute with the `common` value to indicate that the code snippet is framework-agnostic.
-{/* prettier-ignore-start */}
-
````md title="docs/_snippets/button-stories.md"
```ts filename="Button.stories.ts" language="ts" renderer="common"
+
```
````
-{/* prettier-ignore-end */}
-
### Package manager configuration
Use the `packageManager` attribute to configure the package manager used in the example from the following options: `npm`, `yarn`, or `pnpm`.
-
-{/* prettier-ignore-start */}
-
````md title="docs/_snippets/storybook-run-dev.md"
```shell renderer="common" language="js" packageManager="npm|yarn|pnpm"
+
```
````
-{/* prettier-ignore-end */}
-
### Working with multiple snippets
Use the `tabTitle` attribute to indicate the tab title in which the code snippet will be displayed. This attribute should only be used when multiple examples are in a single code snippet file.
-
-{/* prettier-ignore-start */}
````md title="docs/_snippets/component-decorator.md"
```ts filename="YourComponent.stories.ts" language="ts" renderer="common" tabTitle="Story"
+
```
+
```ts filename=".storybook/preview.ts|tsx" language="ts" renderer="common" tabTitle="Storybook configuration"
+
```
````
-{/* prettier-ignore-end */}
-
## Contributing code snippets
You can start contributing to the Storybook documentation by now that you're familiar with how the documentation is organized, the code snippet's structure, and available options. Assuming that you have already set up your [local development environment](../code.mdx#initial-setup) and are ready to contribute, the following steps will guide you through contributing code snippets to the Storybook documentation.
Start by creating a new branch on your local Storybook monorepo with the following command:
-{/* prettier-ignore-start */}
-
```shell
git checkout -b code-snippets-for-framework
```
-
-{/* prettier-ignore-end */}
Browse the documentation and look for the code snippets you want to contribute. For example, on the [setup page](https://github.com/storybookjs/storybook/blob/next/docs/get-started/setup.mdx) you should see the following:
-{/* prettier-ignore-start */}
-
- ```jsx title="docs/get-started/setup.mdx"
-{/* prettier-ignore-start */}
-
-
-
-{/* prettier-ignore-end */}
+```mdx title="docs/get-started/setup.mdx"
+
```
-{/* prettier-ignore-end */}
-
-
Open the file inside the `docs/_snippets` directory and adjust the content to match the code snippet you're willing to contribute. For example:
-{/* prettier-ignore-start */}
-
````md title="docs/_snippets/your-component.md"
```ts filename="YourComponent.stories.ts" renderer="qwik" language="ts"
import type { Meta, StoryObj } from 'storybook-framework-qwik';
@@ -199,14 +160,12 @@ type Story = StoryObj;
export const FirstStory: Story = {
args: {
- //👇 The args you need here will depend on your component
+ //👇 The args you need here will depend on your component
},
};
```
````
-{/* prettier-ignore-end */}
-
Go through the rest of the documentation and repeat the process.
## Preview your work
@@ -215,34 +174,22 @@ Before submitting your contribution, we encourage you to check your work against
Start by forking the Storybook [website repository](https://github.com/storybookjs/web) and cloning it locally.
-{/* prettier-ignore-start */}
-
```shell
git clone https://github.com/your-username/web.git
```
-
-{/* prettier-ignore-end */}
Navigate to the `web` directory and install the required dependencies.
-{/* prettier-ignore-start */}
-
```shell
npm install
```
-{/* prettier-ignore-end */}
-
We recommend that you generate a website build first to ensure you can preview your changes locally and verify that everything is working as expected. To do so, run the following command:
-{/* prettier-ignore-start */}
-
```shell
npm run build:frontpage
```
-{/* prettier-ignore-end */}
-
When executed, this command will retrieve the required files needed to successfully build the Storybook website, including current documentation versions (e.g., `6.5`, `7.6`, `8.x`), and copy them to the `apps/frontpage/docs/` directory, organized by version number.
@@ -251,24 +198,16 @@ When executed, this command will retrieve the required files needed to successfu
Run the `sync-docs` command to connect the documentation from the Storybook monorepo to the Storybook website. When prompted, provide the path to your local fork of the Storybook monorepo and the documentation version you're working on.
-{/* prettier-ignore-start */}
-
```shell
npm run sync-docs
```
-{/* prettier-ignore-end */}
-
Finally, open a new terminal window and run the `dev` command to start the Storybook website.
-{/* prettier-ignore-start */}
-
```shell
npm run dev
```
-{/* prettier-ignore-end */}
-
If all goes well, you should see the Storybook website running. Open a browser window to `http://localhost:3000`, click the Docs link to open the documentation, and select your framework from the dropdown.
@@ -279,7 +218,6 @@ Go through the documentation and check your work.
Once you have verified that your changes are working as expected, you're ready to create a "Pull Request". This will let the Storybook maintainers know you have some changes to propose. At this point, we can give you feedback and request changes. To help with the review process, we encourage you to add a clear title and description of your work.
-
## Troubleshooting
### Code snippets not displaying
@@ -288,8 +226,8 @@ If you're documenting an example that includes the `packageManager` attribute co
## Learn more about contributing to Storybook
-* [RFC process](../RFC.mdx) for authoring feature requests
-* [Code](../code.mdx) for features and bug fixes
-* [Frameworks](../framework.mdx) to get started with a new framework
-* [Documentation](./documentation-updates.mdx) for documentation improvements, typos, and clarifications
-* Examples for new snippets
\ No newline at end of file
+- [RFC process](../RFC.mdx) for authoring feature requests
+- [Code](../code.mdx) for features and bug fixes
+- [Frameworks](../framework.mdx) to get started with a new framework
+- [Documentation](./documentation-updates.mdx) for documentation improvements, typos, and clarifications
+- Examples for new snippets
diff --git a/docs/contribute/framework.mdx b/docs/contribute/framework.mdx
index 684ed5e707d1..6db61e0c56a8 100644
--- a/docs/contribute/framework.mdx
+++ b/docs/contribute/framework.mdx
@@ -1,5 +1,5 @@
---
-title: 'Contributing a Storybook framework'
+title: Contributing a Storybook framework
hideRendererSelector: true
sidebar:
order: 4
@@ -39,88 +39,89 @@ A framework can contain the following parts:
Because a framework is a node package, it must contain a `package.json` file. Here’s a template you can use to start:
- package.json template
-
- ```json title="package.json"
- {
- "name": "",
- "version": "1.0.0",
- "description": "Storybook for or & ",
- "keywords": [
- "Storybook",
- "",
- "",
- "",
- "",
- "",
- ""
- ],
- "homepage": "",
- "bugs": {
- "url": "https://github.com///issues"
+package.json template
+
+```json title="package.json"
+{
+ "name": "",
+ "version": "1.0.0",
+ "description": "Storybook for or & ",
+ "keywords": [
+ "Storybook",
+ "",
+ "",
+ "",
+ "",
+ "",
+ ""
+ ],
+ "homepage": "",
+ "bugs": {
+ "url": "https://github.com///issues"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com//.git",
+ "directory": ""
+ },
+ "license": "MIT",
+ "exports": {
+ ".": {
+ "types": "./dist/index.d.ts",
+ "require": "./dist/index.js",
+ "import": "./dist/index.mjs"
},
- "repository": {
- "type": "git",
- "url": "https://github.com//.git",
- "directory": ""
+ "./preset": {
+ "types": "./dist/preset.d.ts",
+ "require": "./dist/preset.js",
+ "import": "./dist/preset.mjs"
},
- "license": "MIT",
- "exports": {
- ".": {
- "types": "./dist/index.d.ts",
- "require": "./dist/index.js",
- "import": "./dist/index.mjs"
- },
- "./preset": {
- "types": "./dist/preset.d.ts",
- "require": "./dist/preset.js",
- "import": "./dist/preset.mjs"
- },
- "./preview.js": {
- "types": "./dist/preview.d.ts",
- "require": "./dist/preview.js",
- "import": "./dist/preview.mjs"
- },
- "./package.json": "./package.json"
+ "./preview.js": {
+ "types": "./dist/preview.d.ts",
+ "require": "./dist/preview.js",
+ "import": "./dist/preview.mjs"
},
- "main": "dist/index.js",
- "module": "dist/index.mjs",
- "types": "dist/index.d.ts",
- "files": ["dist/**/*", "types/**/*", "README.md", "*.js", "*.d.ts"],
- "scripts": {
- "check": "tsc --noEmit",
- "test": "..."
- },
- "dependencies": {
- "storybook": "^9.0.0",
- "@storybook/": "^9.0.0",
- "@storybook/": "^9.0.0"
- },
- "devDependencies": {
- "typescript": "x.x.x",
- "": "^x.x.x",
- "": "^x.x.x"
- },
- "peerDependencies": {
- "": "^x.x.x || ^x.x.x",
- "": "^x.x.x || ^x.x.x",
- "": "^x.x.x"
- },
- "engines": {
- "node": ">=20.0.0"
- },
- "publishConfig": {
- "access": "public"
- }
+ "./package.json": "./package.json"
+ },
+ "main": "dist/index.js",
+ "module": "dist/index.mjs",
+ "types": "dist/index.d.ts",
+ "files": ["dist/**/*", "types/**/*", "README.md", "*.js", "*.d.ts"],
+ "scripts": {
+ "check": "tsc --noEmit",
+ "test": "..."
+ },
+ "dependencies": {
+ "storybook": "^9.0.0",
+ "@storybook/": "^9.0.0",
+ "@storybook/": "^9.0.0"
+ },
+ "devDependencies": {
+ "typescript": "x.x.x",
+ "": "^x.x.x",
+ "": "^x.x.x"
+ },
+ "peerDependencies": {
+ "": "^x.x.x || ^x.x.x",
+ "": "^x.x.x || ^x.x.x",
+ "": "^x.x.x"
+ },
+ "engines": {
+ "node": ">=20.0.0"
+ },
+ "publishConfig": {
+ "access": "public"
}
- ```
+}
+```
+
+A few notes on some of those properties:
- A few notes on some of those properties:
+- `exports`: The root, `./preset`, and `package.json` exports are required. If your framework has a `preview.js`, then that is required as well.
+- `types`: We strongly encourage you to author your framework in TypeScript and distribute the types.
+- `dependencies` and `devDependencies`: These are just examples. Yours may look quite different.
+- `peerDependencies`: If your framework provides support for multiple versions of the libraries you’re targeting, be sure that is represented here.
- * `exports`: The root, `./preset`, and `package.json` exports are required. If your framework has a `preview.js`, then that is required as well.
- * `types`: We strongly encourage you to author your framework in TypeScript and distribute the types.
- * `dependencies` and `devDependencies`: These are just examples. Yours may look quite different.
- * `peerDependencies`: If your framework provides support for multiple versions of the libraries you’re targeting, be sure that is represented here.
#### `preset.js` ([example](https://github.com/storybookjs/storybook/blob/next/code/frameworks/nextjs/src/preset.ts))
@@ -145,8 +146,8 @@ Once it's fully tested and released, please let us know about your framework by
**Learn more about contributing to Storybook**
-* [RFC process](./RFC.mdx) for authoring feature requests
-* [Code](./code.mdx) for features and bug fixes
-* Frameworks to get started with a new framework
-* [Documentation](./documentation/documentation-updates.mdx) for documentation improvements, typos, and clarifications
-* [Examples](./documentation/new-snippets.mdx) for new snippets
+- [RFC process](./RFC.mdx) for authoring feature requests
+- [Code](./code.mdx) for features and bug fixes
+- Frameworks to get started with a new framework
+- [Documentation](./documentation/documentation-updates.mdx) for documentation improvements, typos, and clarifications
+- [Examples](./documentation/new-snippets.mdx) for new snippets
diff --git a/docs/contribute/how-to-reproduce.mdx b/docs/contribute/how-to-reproduce.mdx
index 7f846a5e8a6a..a1f2f71eea6c 100644
--- a/docs/contribute/how-to-reproduce.mdx
+++ b/docs/contribute/how-to-reproduce.mdx
@@ -1,5 +1,5 @@
---
-title: 'Create a reproduction'
+title: Create a reproduction
hideRendererSelector: true
sidebar:
order: 5
@@ -16,9 +16,9 @@ A reproducible test case is a great way to share a specific set of conditions th
Make sure you have:
-* Installed [`Yarn`](https://yarnpkg.com/) on your local development machine.
-* A [GitHub account](https://github.com/signup) for hosting the reproduction's code.
-* A [Chromatic account](https://www.chromatic.com/start/?utm_source=storybook_website\&utm_medium=link\&utm_campaign=storybook) for publishing your Storybook.
+- Installed [`Yarn`](https://yarnpkg.com/) on your local development machine.
+- A [GitHub account](https://github.com/signup) for hosting the reproduction's code.
+- A [Chromatic account](https://www.chromatic.com/start/?utm_source=storybook_website&utm_medium=link&utm_campaign=storybook) for publishing your Storybook.
## Initial setup
@@ -29,7 +29,9 @@ npx storybook@next sandbox
```
- You can append a template name in the command to get filtered results (e.g., `npx storybook@next sandbox react`).
+
+You can append a template name in the command to get filtered results (e.g., `npx storybook@next sandbox react`).
+
Next, choose the template you want to work with:
@@ -41,7 +43,9 @@ Finally, enter a location for your reproduction:

- If you don't provide a full path for the reproduction it will be generated in the current directory.
+
+If you don't provide a full path for the reproduction it will be generated in the current directory.
+
If everything worked as it should, you should have a fully functional Storybook set up in your local environment.
@@ -67,19 +71,21 @@ Then, follow GitHub's instructions to set up the repository.

- Don't forget to replace `your-username` with your own account name.
+
+Don't forget to replace `your-username` with your own account name.
+
## Publish
-An excellent way to check your reproduction is to have it deployed online. We recommend [Chromatic](https://www.chromatic.com/?utm_source=storybook_website\&utm_medium=link\&utm_campaign=storybook), a free publishing service created by the Storybook maintainers. It allows you to deploy and host your reproduction safely and securely in the cloud.
+An excellent way to check your reproduction is to have it deployed online. We recommend [Chromatic](https://www.chromatic.com/?utm_source=storybook_website&utm_medium=link&utm_campaign=storybook), a free publishing service created by the Storybook maintainers. It allows you to deploy and host your reproduction safely and securely in the cloud.
### Helpful resources when working with Chromatic
-* [Publish Storybook](../sharing/publish-storybook.mdx)
-* [Setup Chromatic](https://www.chromatic.com/docs/setup?utm_source=storybook_website\&utm_medium=link\&utm_campaign=storybook)
-* [Automate Chromatic with continuous integration](https://www.chromatic.com/docs/ci?utm_source=storybook_website\&utm_medium=link\&utm_campaign=storybook)
+- [Publish Storybook](../sharing/publish-storybook.mdx)
+- [Setup Chromatic](https://www.chromatic.com/docs/setup?utm_source=storybook_website&utm_medium=link&utm_campaign=storybook)
+- [Automate Chromatic with continuous integration](https://www.chromatic.com/docs/ci?utm_source=storybook_website&utm_medium=link&utm_campaign=storybook)
## Submit the issue
-Finally, create your issue in the [Storybook issue tracker](https://github.com/storybookjs/storybook/issues/new/choose), go through the required steps, and provide a detailed description of the problem. Add the GitHub repository and [deployed reproduction](https://www.chromatic.com/docs/setup?utm_source=storybook_website\&utm_medium=link\&utm_campaign=storybook#view-published-storybook) to help with the triage process.
+Finally, create your issue in the [Storybook issue tracker](https://github.com/storybookjs/storybook/issues/new/choose), go through the required steps, and provide a detailed description of the problem. Add the GitHub repository and [deployed reproduction](https://www.chromatic.com/docs/setup?utm_source=storybook_website&utm_medium=link&utm_campaign=storybook#view-published-storybook) to help with the triage process.
diff --git a/docs/contribute/index.mdx b/docs/contribute/index.mdx
index ea42c33515b6..439eb010cb0b 100644
--- a/docs/contribute/index.mdx
+++ b/docs/contribute/index.mdx
@@ -1,5 +1,5 @@
---
-title: 'How to contribute'
+title: How to contribute
hideRendererSelector: true
sidebar:
order: 14
@@ -14,18 +14,18 @@ In the interest of fostering an open and welcoming environment, we as contributo
## Ways to contribute
-* [**RFC process**](./RFC.mdx) for authoring feature requests
-* [**Code**](./code.mdx) for features and bug fixes
-* [**Frameworks**](./framework.mdx) to get started with a new framework
-* [**Documentation**](./documentation/documentation-updates.mdx) for documentation improvements, typos, and clarifications
-* [**Examples**](./documentation/new-snippets.mdx) for new snippets and examples
-* [**Addons**](../addons/index.mdx) for new addons
+- [**RFC process**](./RFC.mdx) for authoring feature requests
+- [**Code**](./code.mdx) for features and bug fixes
+- [**Frameworks**](./framework.mdx) to get started with a new framework
+- [**Documentation**](./documentation/documentation-updates.mdx) for documentation improvements, typos, and clarifications
+- [**Examples**](./documentation/new-snippets.mdx) for new snippets and examples
+- [**Addons**](../addons/index.mdx) for new addons
## Not sure how to get started?
-* [Chat in Discord `#contributing`](https://discord.com/channels/486522875931656193/839297503446695956)
-* [Browse "good first issues" to fix](https://github.com/storybookjs/storybook/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
-* [Submit a bug report or feature request](https://github.com/storybookjs/storybook/issues)
+- [Chat in Discord `#contributing`](https://discord.com/channels/486522875931656193/839297503446695956)
+- [Browse "good first issues" to fix](https://github.com/storybookjs/storybook/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
+- [Submit a bug report or feature request](https://github.com/storybookjs/storybook/issues)
## AI contributions
diff --git a/docs/essentials/actions.mdx b/docs/essentials/actions.mdx
index 3c7398a4e27d..f23acd7d3cc5 100644
--- a/docs/essentials/actions.mdx
+++ b/docs/essentials/actions.mdx
@@ -1,8 +1,7 @@
---
-title: "Actions"
+title: Actions
sidebar:
order: 1
- title: Actions
---
Actions are used to show that an event handler (callback) has been called, and to display its arguments. The actions panel can show both story args and other function calls.
@@ -17,12 +16,8 @@ Actions work via supplying special Storybook-generated mock functions to your st
The recommended way to write actions is to use the `fn` utility from `storybook/test` to mock and spy args. This is very useful for writing [interaction tests](../writing-tests/interaction-testing.mdx). You can mock your component's methods by assigning them to the `fn()` function:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
If your component calls an arg (because of either the user's interaction or the `play` function) and that arg is spied on, the event will show up in the action panel:

@@ -33,20 +28,12 @@ Another option is to use a global parameter to match all [argTypes](../api/arg-t
This is quite useful when your component has dozens (or hundreds) of methods and you do not want to manually apply the `fn` utility for each of those methods. However, **this is not the recommended** way of writing actions. That's because automatically inferred args **are not available as spies in your play function**. If you use `argTypesRegex` and your stories have play functions, you will need to also define args with the `fn` utility to test them in your play function.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
If you need more granular control over which `argTypes` are matched, you can adjust your stories and include the `argTypesRegex` parameter. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
This will bind a standard HTML event handler to the outermost HTML element rendered by your component and trigger an action when the event is called for a given selector. The format is ``. The selector is optional; it defaults to all elements.
## Non-story function calls
@@ -96,7 +83,7 @@ Controls how many levels deep the action tree is initially expanded. Useful when
### Exports
```js
-import { action } from "storybook/actions";
+import { action } from 'storybook/actions';
```
#### `action`
@@ -105,16 +92,12 @@ Type: `(name?: string) => void`
Allows you to create an action that appears in the actions panel of the Storybook UI when clicked. The action function takes an optional name parameter, which is used to identify the action in the UI.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### `configureActions`
```js
-import { configureActions } from "storybook/actions";
+import { configureActions } from 'storybook/actions';
```
Type: `(options?: ActionOptions) => void`
@@ -125,9 +108,8 @@ Configures the global behavior of the actions addon. Call this in your `.storybo
- **`clearOnStoryChange`** (`boolean`, default: `true`): Clear the actions panel when navigating to a different story.
- **`depth`** (`number`, default: `10`): Serialization depth for action arguments.
-```js
-// .storybook/preview.js
-import { configureActions } from "storybook/actions";
+```js title=".storybook/preview.ts|tsx"
+import { configureActions } from 'storybook/actions';
configureActions({
limit: 20,
diff --git a/docs/essentials/backgrounds.mdx b/docs/essentials/backgrounds.mdx
index 730f635d3bab..effc8876b75d 100644
--- a/docs/essentials/backgrounds.mdx
+++ b/docs/essentials/backgrounds.mdx
@@ -1,8 +1,7 @@
---
-title: 'Backgrounds'
+title: Backgrounds
sidebar:
order: 2
- title: Backgrounds
---
The backgrounds feature allows you to set the background color on which the story renders in the UI:
@@ -17,26 +16,17 @@ But you're not restricted to these backgrounds. You can configure your own set o
You can define the available background colors using the [`options` property](#options) and set the initial background color using the `initialGlobals` property:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Defining the background for a story
The backgrounds feature enables you to change the background color applied to a story by selecting from the list of predefined background colors in the toolbar. If needed, you can set a story to default to a specific background color, by using the `globals` option:
-{/* prettier-ignore-start */}
-
-
-
-{/* prettier-ignore-end */}
-
+
- When you specify a background color for a story (or a component's stories) using `globals`, the color is applied and cannot be changed using the toolbar. This is useful to ensure a story is always rendered on a specific background color.
+When you specify a background color for a story (or a component's stories) using `globals`, the color is applied and cannot be changed using the toolbar. This is useful to ensure a story is always rendered on a specific background color.
@@ -46,22 +36,13 @@ You can also configure backgrounds on a per-component or per-story basis through
To set the available background colors, use the [`options` property](#options). In this example, we'll adjust the colors for all of the Button component's stories:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
-
## Disable backgrounds
If you want to turn off backgrounds in a story, you can do so by configuring the `backgrounds` parameter like so:
-{/* prettier-ignore-start */}
-
-
-
-{/* prettier-ignore-end */}
+
## Grid
@@ -69,12 +50,8 @@ The backgrounds feature also includes a Grid selector, which allows you to quick
You don't need additional configuration to get started. But its properties are fully customizable; if you don't supply any value to any of its properties, they'll default to the following values:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## API
### Globals
diff --git a/docs/essentials/controls.mdx b/docs/essentials/controls.mdx
index e79e3a9f8c0a..6f95316faff5 100644
--- a/docs/essentials/controls.mdx
+++ b/docs/essentials/controls.mdx
@@ -1,8 +1,7 @@
---
-title: 'Controls'
+title: Controls
sidebar:
order: 3
- title: Controls
---
Storybook Controls gives you a graphical UI to interact with a component's arguments dynamically without needing to code. Use the Controls panel to edit the inputs to your stories and see the results in real-time. It's a great way to explore your components and test different states.
@@ -11,146 +10,112 @@ Storybook Controls gives you a graphical UI to interact with a component's argum
Controls do not require any modification to your components. Stories for controls are:
-* Convenient. Auto-generate controls based on React/Vue/Angular/etc. components.
-* Portable. Reuse your interactive stories in documentation, tests, and even in designs.
-* Rich. Customize the controls and interactive data to suit your exact needs.
+- Convenient. Auto-generate controls based on React/Vue/Angular/etc. components.
+- Portable. Reuse your interactive stories in documentation, tests, and even in designs.
+- Rich. Customize the controls and interactive data to suit your exact needs.
To use Controls, you need to write your stories using [args](../writing-stories/args.mdx). Storybook will automatically generate UI controls based on your args and what it can infer about your component. Still, you can configure the controls further using [argTypes](../api/arg-types.mdx), see below.
- If you have stories in the older pre-Storybook 6 style, check the [args & controls migration guide](https://medium.com/storybookjs/storybook-6-migration-guide-200346241bb5) to learn how to convert your existing stories for args.
-
-
-## Choosing the control type
-
-
- By default, Storybook will try to infer the required argTypes and associated controls for your stories based on the component's definition and initial value of the args using [Compodoc](https://compodoc.app/), a documentation generator for Angular applications that can extract the metadata of your components, including first-class support for Angular's `inputs`, `outputs`, `properties`, `methods`, and `view/content child/children`. If you opt-in to use it, you must take additional steps to set it up properly.
-
- Run the following command to install the tooling.
- {/* prettier-ignore-start */}
+If you have stories in the older pre-Storybook 6 style, check the [args & controls migration guide](https://medium.com/storybookjs/storybook-6-migration-guide-200346241bb5) to learn how to convert your existing stories for args.
-
-
- {/* prettier-ignore-end */}
-
- Update your `angular.json` file to include the following configuration to include it in the Storybook's inbuilt builder configuration.
-
- {/* prettier-ignore-start */}
+
-
+## Choosing the control type
- {/* prettier-ignore-end */}
+
- Finally, update your `.storybook/preview.ts|tsx` file to include the following configuration to import the metadata generated by Compodoc and use it to generate the controls and argTypes for your stories.
+By default, Storybook will try to infer the required argTypes and associated controls for your stories based on the component's definition and initial value of the args using [Compodoc](https://compodoc.app/), a documentation generator for Angular applications that can extract the metadata of your components, including first-class support for Angular's `inputs`, `outputs`, `properties`, `methods`, and `view/content child/children`. If you opt-in to use it, you must take additional steps to set it up properly.
- {/* prettier-ignore-start */}
+Run the following command to install the tooling.
-
+
- {/* prettier-ignore-end */}
+Update your `angular.json` file to include the following configuration to include it in the Storybook's inbuilt builder configuration.
- When you set the `component` annotation of the meta (or default export) of your story file, it will be used to infer the controls and auto-generate the matching [`argTypes`](../api/arg-types.mdx) for your component.
+
- {/* prettier-ignore-start */}
+Finally, update your `.storybook/preview.ts|tsx` file to include the following configuration to import the metadata generated by Compodoc and use it to generate the controls and argTypes for your stories.
-
+
- {/* prettier-ignore-end */}
-
+When you set the `component` annotation of the meta (or default export) of your story file, it will be used to infer the controls and auto-generate the matching [`argTypes`](../api/arg-types.mdx) for your component.
-
- By default, Storybook will try to infer the required argTypes and associated controls for your stories based on the metadata provided by the [`@storybook/ember-cli-storybook`](https://github.com/storybookjs/ember-cli-storybook) adapter. You'll need to take some additional steps to set it up properly.
+
- Update your `ember-cli-build.js` configuration file to include the adapter.
+
- {/* prettier-ignore-start */}
+
-
+By default, Storybook will try to infer the required argTypes and associated controls for your stories based on the metadata provided by the [`@storybook/ember-cli-storybook`](https://github.com/storybookjs/ember-cli-storybook) adapter. You'll need to take some additional steps to set it up properly.
- {/* prettier-ignore-end */}
+Update your `ember-cli-build.js` configuration file to include the adapter.
- Restart your application to generate the metadata file (i.e., `storybook-docgen/index.json`) and update your `.storybook/preview.js` file to include it, which will be used to create the controls and argTypes for your stories.
+
- {/* prettier-ignore-start */}
+Restart your application to generate the metadata file (i.e., `storybook-docgen/index.json`) and update your `.storybook/preview.js` file to include it, which will be used to create the controls and argTypes for your stories.
-
+
- {/* prettier-ignore-end */}
+
-
- Enabling this feature will generate a `storybook-docgen/index.json` automatically with each build. For more information on how the metadata is generated, refer to [documentation](https://github.com/storybookjs/storybook/tree/next/code/frameworks/ember) for the Ember framework.
-
+Enabling this feature will generate a `storybook-docgen/index.json` automatically with each build. For more information on how the metadata is generated, refer to [documentation](https://github.com/storybookjs/storybook/tree/next/code/frameworks/ember) for the Ember framework.
- When you set the `component` annotation of the meta (or default export) of your story file, it will be used to infer the controls and auto-generate the matching [`argTypes`](../api/arg-types.mdx) for your component.
+
- {/* prettier-ignore-start */}
+When you set the `component` annotation of the meta (or default export) of your story file, it will be used to infer the controls and auto-generate the matching [`argTypes`](../api/arg-types.mdx) for your component.
-
+
- {/* prettier-ignore-end */}
-
+
-
- By default, Storybook will choose a control for each arg based on its initial value. This will work well with specific arg types (e.g., `boolean` or `string`). To enable them, add the `component` annotation to the meta (or default export) of your story file, and it will be used to infer the controls and auto-generate the matching [`argTypes`](../api/arg-types.mdx) for your component using [`react-docgen`](https://github.com/reactjs/react-docgen), a documentation generator for React components that also includes first-class support for TypeScript.
+
- {/* prettier-ignore-start */}
+By default, Storybook will choose a control for each arg based on its initial value. This will work well with specific arg types (e.g., `boolean` or `string`). To enable them, add the `component` annotation to the meta (or default export) of your story file, and it will be used to infer the controls and auto-generate the matching [`argTypes`](../api/arg-types.mdx) for your component using [`react-docgen`](https://github.com/reactjs/react-docgen), a documentation generator for React components that also includes first-class support for TypeScript.
-
+
- {/* prettier-ignore-end */}
-
+
-
- By default, Storybook will choose a control for each arg based on its initial value. This will work well with specific arg types (e.g., `boolean` or `string`). To enable them, add the `component` annotation to the meta (or default export) of your story file, and it will be used to infer the controls and auto-generate the matching [`argTypes`](../api/arg-types.mdx) for your component using [`vue-docgen-api`](https://github.com/vue-styleguidist/vue-styleguidist/tree/dev/packages/vue-docgen-api), including first-class support for Vue's `props`, `events`, and `slots`.
+
- {/* prettier-ignore-start */}
+By default, Storybook will choose a control for each arg based on its initial value. This will work well with specific arg types (e.g., `boolean` or `string`). To enable them, add the `component` annotation to the meta (or default export) of your story file, and it will be used to infer the controls and auto-generate the matching [`argTypes`](../api/arg-types.mdx) for your component using [`vue-docgen-api`](https://github.com/vue-styleguidist/vue-styleguidist/tree/dev/packages/vue-docgen-api), including first-class support for Vue's `props`, `events`, and `slots`.
-
+
- {/* prettier-ignore-end */}
-
+
-
- By default, Storybook will try to infer the required argTypes and associated controls for your stories based on the component's definition and the initial value of the args. You'll need to take some additional steps to set it up properly. You can opt to generate a [`custom-elements.json`](https://github.com/webcomponents/custom-elements-json) file with [`@custom-elements-manifest/analyzer`](https://github.com/open-wc/custom-elements-manifest) if you're using the `pre-v1.0.0` version of the elements file or [`@custom-elements-manifest/analyzer`](https://github.com/open-wc/custom-elements-manifest/tree/master/packages/analyzer) for newer versions and configure it in your Storybook UI configuration file (i.e., `.storybook/preview.ts|tsx`) to enable it.
+
- {/* prettier-ignore-start */}
+By default, Storybook will try to infer the required argTypes and associated controls for your stories based on the component's definition and the initial value of the args. You'll need to take some additional steps to set it up properly. You can opt to generate a [`custom-elements.json`](https://github.com/webcomponents/custom-elements-json) file with [`@custom-elements-manifest/analyzer`](https://github.com/open-wc/custom-elements-manifest) if you're using the `pre-v1.0.0` version of the elements file or [`@custom-elements-manifest/analyzer`](https://github.com/open-wc/custom-elements-manifest/tree/master/packages/analyzer) for newer versions and configure it in your Storybook UI configuration file (i.e., `.storybook/preview.ts|tsx`) to enable it.
-
+
- {/* prettier-ignore-end */}
+When you set the `component` annotation of the meta (or default export) of your story file, it will be used to infer the controls and auto-generate the matching [`argTypes`](../api/arg-types.mdx) for your component.
- When you set the `component` annotation of the meta (or default export) of your story file, it will be used to infer the controls and auto-generate the matching [`argTypes`](../api/arg-types.mdx) for your component.
+
- {/* prettier-ignore-start */}
+
-
+
- {/* prettier-ignore-end */}
-
+By default, Storybook will choose a control for each arg based on its initial value. This will work well with specific arg types (e.g., `boolean` or `string`). To enable them, add the `component` annotation to the meta (or default export) of your story file, and it will be used to infer the controls and auto-generate the matching [`argTypes`](../api/arg-types.mdx) for your component provided by the framework you've chosen to use.
-
- By default, Storybook will choose a control for each arg based on its initial value. This will work well with specific arg types (e.g., `boolean` or `string`). To enable them, add the `component` annotation to the meta (or default export) of your story file, and it will be used to infer the controls and auto-generate the matching [`argTypes`](../api/arg-types.mdx) for your component provided by the framework you've chosen to use.
+
- {/* prettier-ignore-start */}
+
-
+If you're using a framework that doesn't support this feature, you'll need to define the `argTypes` for your component [manually](#fully-custom-args).
- {/* prettier-ignore-end */}
+
-
- If you're using a framework that doesn't support this feature, you'll need to define the `argTypes` for your component [manually](#fully-custom-args).
-
-
+
For instance, suppose you have a `variant` arg on your story that should be `primary` or `secondary`:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
By default, Storybook will render a free text input for the `variant` arg:

@@ -159,26 +124,24 @@ It works as long as you type a valid string into the auto-generated text control
We can specify which controls get used by declaring a custom [argType](../api/arg-types.mdx) for the `variant` property. ArgTypes encode basic metadata for args, such as name, description, and defaultValue for an arg. These get automatically filled in by Storybook Docs.
-
+
- `ArgTypes` can also contain arbitrary annotations, which the user can override. Since `variant` is a component property, let's put that annotation on the `defineMeta` function, or the default export if you're using standard CSF.
+`ArgTypes` can also contain arbitrary annotations, which the user can override. Since `variant` is a component property, let's put that annotation on the `defineMeta` function, or the default export if you're using standard CSF.
-
+
- `ArgTypes` can also contain arbitrary annotations, which the user can override. Since `variant` is a component property, let's put that annotation on the meta (or default export).
+`ArgTypes` can also contain arbitrary annotations, which the user can override. Since `variant` is a component property, let's put that annotation on the meta (or default export).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- ArgTypes are a powerful feature that can be used to customize the controls for your stories. For more information, see the documentation about [customizing controls](#annotation) with `argTypes` annotation.
+
+ArgTypes are a powerful feature that can be used to customize the controls for your stories. For more information, see the documentation about [customizing controls](#annotation) with `argTypes` annotation.
+
This replaces the input with a radio group for a more intuitive experience.
@@ -196,63 +159,46 @@ Controls can automatically be inferred from arg's name with [regex](https://deve
If you haven't used the CLI to set the configuration, or if you want to define your patterns, use the `matchers` property in the `controls` parameter:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Fully custom args
Until now, we only used auto-generated controls based on the component for which we're writing stories. If we are writing [complex stories](../writing-stories/stories-for-multiple-components.mdx), we may want to add controls for args that aren’t part of the component. For example, here's how you could use a `footer` arg to populate a child component:
-{/* prettier-ignore-start */}
-
-
-
-{/* prettier-ignore-end */}
+
By default, Storybook will add controls for all args that:
- * It infers from the component definition [if your framework supports it](../configure/integration/frameworks-feature-support.mdx).
+- It infers from the component definition [if your framework supports it](../configure/integration/frameworks-feature-support.mdx).
- * Appear in the list of args for your story.
+- Appear in the list of args for your story.
Using `argTypes`, you can change the display and behavior of each control.
-
### Dealing with complex values
When dealing with non-primitive values, you'll notice that you'll run into some limitations. The most obvious issue is that not every value can be represented as part of the `args` param in the URL, losing the ability to share and deep link to such a state. Beyond that, complex values such as JSX cannot be synchronized between the manager (e.g., the Controls panel) and the preview (your story).
One way to deal with this is to use primitive values (e.g., strings) as arg values and add a custom `render` function to convert them to their complex counterpart before rendering. It isn't the nicest way to do it (see below), but certainly the most flexible.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Unless you need the flexibility of a function, an easier way to map primitives to complex values before rendering is to define a `mapping`; additionally, you can specify `control.labels` to configure custom labels for your checkbox, radio, or select input.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Note that both `mapping` and `control.labels` don't have to be exhaustive. If the currently selected option is not listed, it's used verbatim.
## Creating and editing stories from controls
-
+
+
+This feature is not supported with the Svelte CSF. To opt-in to this feature with Svelte, you must use Storybook's [Component Story Format](../api/csf/index.mdx).
+
+
- This feature is not supported with the Svelte CSF. To opt-in to this feature with Svelte, you must use Storybook's [Component Story Format](../api/csf/index.mdx).
-
-
-
You can create or edit stories, directly from the Controls panel.
@@ -264,9 +210,11 @@ Open the Controls panel for a story and adjust the value of a control. Then save
- If you're working on a component that does not yet have any stories, you can click the ➕ button in the sidebar to search for your component and have a basic story created for you.
-
+If you're working on a component that does not yet have any stories, you can click the ➕ button in the sidebar to search for your component and have a basic story created for you.
+
+
+
### Edit a story
@@ -283,8 +231,8 @@ If you don't want to allow the creation or editing of stories from the Controls
Controls can be configured in two ways:
-* Individual controls can be configured via control annotations.
-* The panel's appearance can be configured via parameters.
+- Individual controls can be configured via control annotations.
+- The panel's appearance can be configured via parameters.
### Annotation
@@ -309,17 +257,17 @@ As shown above, you can configure individual controls with the “control" annot
| | `date` | Provides a datepicker component to handle date selection. `argTypes: { startDate: { control: 'date' }}` |
- The `date` control will convert the date into a UNIX timestamp when the value changes. It's a known limitation that will be fixed in a future release. If you need to represent the actual date, you'll need to update the story's implementation and convert the value into a date object.
-
-{/* prettier-ignore-start */}
+The `date` control will convert the date into a UNIX timestamp when the value changes. It's a known limitation that will be fixed in a future release. If you need to represent the actual date, you'll need to update the story's implementation and convert the value into a date object.
-
+
-{/* prettier-ignore-end */}
+
- Numeric data types will default to a `number` control unless additional configuration is provided.
+
+Numeric data types will default to a `number` control unless additional configuration is provided.
+
### Parameters
@@ -332,12 +280,8 @@ Since Controls is built on the same engine as Storybook Docs, it can also show p
To enable expanded mode globally, add the following to [`.storybook/preview.ts|tsx`](../configure/index.mdx#configure-story-rendering):
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Here's what the resulting UI looks like:

@@ -346,12 +290,8 @@ Here's what the resulting UI looks like:
For `color` controls, you can specify an array of `presetColors`, either on the `control` in `argTypes`, or as a parameter under the `controls` namespace:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Color presets can be defined as an object with `color` and `title` or a simple CSS color string. These will then be available as swatches in the color picker. When you hover over the color swatch, you'll be able to see its title. It will default to the nearest CSS color name if none is specified.
#### Filtering controls
@@ -362,50 +302,36 @@ To make this possible, you can use optional `include` and `exclude` configuratio
Consider the following story snippets:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### Sorting controls
By default, controls are unsorted and use whatever order the args data is processed in (`none`). Additionally, you can sort them alphabetically by the arg's name (`alpha`) or with the required args first (`requiredFirst`).
Consider the following snippet to force required args first:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Disable controls for specific properties
Aside from the features already documented here, Controls can also be disabled for individual properties.
Suppose you want to turn off Controls for a property called `foo` in a component's story. The following example illustrates how:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Resulting in the following change in Storybook UI:
The previous example also removed the prop documentation from the table. In some cases, this is fine. However, sometimes you might want to render the prop documentation without a control. The following example illustrates how:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- As with other Storybook properties, such as [decorators](../writing-stories/decorators.mdx), you can apply the same pattern at a story level for more granular cases.
+
+As with other Storybook properties, such as [decorators](../writing-stories/decorators.mdx), you can apply the same pattern at a story level for more granular cases.
+
### Conditional controls
@@ -414,20 +340,12 @@ In some cases, it's useful to be able to conditionally exclude a control based o
Consider a collection of "advanced" settings only visible when the user toggles an "advanced" toggle.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Or consider a constraint where if the user sets one control value, it doesn't make sense for the user to be able to set another value.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
The query object must contain either an `arg` or `global` target:
| field | type | meaning |
@@ -448,11 +366,13 @@ If no operator is provided, that is equivalent to `{ truthy: true }`.
## Troubleshooting
-
- ### Controls are not automatically generated for my component
+
+
+### Controls are not automatically generated for my component
- If you're working with Angular, Ember, or Web Components, automatic argTypes and controls inference will not work out of the box and requires you to provide [additional configuration](#choosing-the-control-type) to allow Storybook to retrieve the necessary metadata and generate the needed argTypes and controls for your stories. However, if you need additional customization, you can always [define them manually](#fully-custom-args).
-
+If you're working with Angular, Ember, or Web Components, automatic argTypes and controls inference will not work out of the box and requires you to provide [additional configuration](#choosing-the-control-type) to allow Storybook to retrieve the necessary metadata and generate the needed argTypes and controls for your stories. However, if you need additional customization, you can always [define them manually](#fully-custom-args).
+
+
### The controls are not updating the story within the auto-generated documentation
@@ -504,9 +424,9 @@ Default: `'none'`
Specifies how the controls are sorted.
-* **none**: Unsorted, displayed in the same order the arg types are processed in
-* **alpha**: Sorted alphabetically, by the arg type's name
-* **requiredFirst**: Same as `alpha`, with any required arg types displayed first
+- **none**: Unsorted, displayed in the same order the arg types are processed in
+- **alpha**: Sorted alphabetically, by the arg type's name
+- **requiredFirst**: Same as `alpha`, with any required arg types displayed first
#### `disableSaveFromUI`
diff --git a/docs/essentials/highlight.mdx b/docs/essentials/highlight.mdx
index f0b9fbba4fd9..14e86dba4a81 100644
--- a/docs/essentials/highlight.mdx
+++ b/docs/essentials/highlight.mdx
@@ -1,8 +1,7 @@
---
-title: 'Highlight'
+title: Highlight
sidebar:
order: 4
- title: Highlight
---
Storybook's Highlight feature is a helpful tool for visually debugging your components. It allows you to highlight specific DOM nodes within your story when used directly or enhancing addons such as the [Accessibility addon](../writing-tests/accessibility-testing.mdx) to inform you of accessibility issues within your components.
@@ -13,28 +12,24 @@ Storybook's Highlight feature is a helpful tool for visually debugging your comp
To highlight DOM elements with the feature, you'll need to emit the `HIGHLIGHT` event from within a story or an addon. The event payload must contain a `selectors` property assigned to an array of selectors matching the elements you want to highlight. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- We recommend choosing the most specific selector possible to avoid highlighting elements other addons use. This is because the feature tries to match selectors against the entire DOM tree.
+
+We recommend choosing the most specific selector possible to avoid highlighting elements other addons use. This is because the feature tries to match selectors against the entire DOM tree.
+
### Customize style
By default, highlighted elements contain a standard outline style applied to the selected elements. However, you can enable your custom style by extending the payload object with additional properties to customize the appearance of the highlighted elements. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- These properties are optional, and you can use them to customize the appearance of the highlighted elements. The `hoverStyles` and `focusStyles` properties are recommended for use with the `menu` property. Pseudo-classes and pseudo-elements are not supported.
+
+These properties are optional, and you can use them to customize the appearance of the highlighted elements. The `hoverStyles` and `focusStyles` properties are recommended for use with the `menu` property. Pseudo-classes and pseudo-elements are not supported.
+
### Highlight menu
@@ -43,12 +38,8 @@ The Highlight feature includes a built-in debugging option, allowing you to sele

-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */ }
-
When enabled, the menu will be displayed when you click on the selected element matching your provided selectors. However, if you don't want to show any information, you can omit the items or set the `menu` property to an empty array to show the default menu.

@@ -57,36 +48,26 @@ When enabled, the menu will be displayed when you click on the selected element
If you need to remove a highlight from a specific element, you can do so by emitting the `REMOVE_HIGHLIGHT` event and providing the `id` of the highlight you want to remove. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- The `emit` function derived from the `useChannel` API hook creates a communication channel in Storybook's UI to listen for events and update the UI accordingly. The Highlight feature uses this channel to listen to custom events and update the highlighted elements (if any) accordingly.
+
+The `emit` function derived from the `useChannel` API hook creates a communication channel in Storybook's UI to listen for events and update the UI accordingly. The Highlight feature uses this channel to listen to custom events and update the highlighted elements (if any) accordingly.
+
## Reset highlighted elements
Out of the box, Storybook automatically removes highlighted elements when transitioning between stories. However, if you need to clear them manually, you can emit the `RESET_HIGHLIGHT` event from within a story or an addon. This removes all highlights, even ones created by other addons. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Scroll element into view
The Highlight feature allows you to scroll an element into view and highlight it. To enable it, emit the `SCROLL_INTO_VIEW` event from within a story or an addon. The event payload must contain a `selector` property to target the element you want to scroll into view. When the element is visible, it will be highlighted for a brief moment.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## API
### Parameters
@@ -106,7 +87,12 @@ This parameter is most useful to allow overriding at more specific levels. For e
This feature contributes the following exports to Storybook:
```js
-import { HIGHLIGHT, REMOVE_HIGHLIGHT, RESET_HIGHLIGHT, SCROLL_INTO_VIEW } from 'storybook/highlight';
+import {
+ HIGHLIGHT,
+ REMOVE_HIGHLIGHT,
+ RESET_HIGHLIGHT,
+ SCROLL_INTO_VIEW,
+} from 'storybook/highlight';
```
#### `HIGHLIGHT`
@@ -118,7 +104,7 @@ import { HIGHLIGHT, type HighlightOptions } from 'storybook/highlight';
channel.emit(
HIGHLIGHT,
- options // The available configuration options inheriting from the HighlightOptions API
+ options, // The available configuration options inheriting from the HighlightOptions API
);
```
@@ -152,9 +138,9 @@ interface HighlightMenuItem {
/** Description of the menu item */
description?: string;
/** Icon for the menu item, left side */
- iconLeft?: "chevronLeft" | "chevronRight" | "info" | "shareAlt";
+ iconLeft?: 'chevronLeft' | 'chevronRight' | 'info' | 'shareAlt';
/** Icon for the menu item, right side */
- iconRight?: "chevronLeft" | "chevronRight" | "info" | "shareAlt";
+ iconRight?: 'chevronLeft' | 'chevronRight' | 'info' | 'shareAlt';
/** Name for a channel event to trigger when the menu item is clicked */
clickEvent?: string;
/** HTML selectors for which this menu item should show (subset of HighlightOptions['selectors']) */
@@ -190,15 +176,18 @@ import type { ClickEventDetails } from 'storybook/highlight';
const handleClickEvent = (itemId: string, details: ClickEventDetails) => {
// Handle the menu item click event
-}
+};
// When you have a channel instance:
-channel.on('MY_CLICK_EVENT', handleClickEvent)
+channel.on('MY_CLICK_EVENT', handleClickEvent);
// Or from a decorator:
-useChannel({
- MY_CLICK_EVENT: handleClickEvent,
-}, [handleClickEvent])
+useChannel(
+ {
+ MY_CLICK_EVENT: handleClickEvent,
+ },
+ [handleClickEvent],
+);
```
#### `REMOVE_HIGHLIGHT`
@@ -210,7 +199,7 @@ import { REMOVE_HIGHLIGHT } from 'storybook/highlight';
channel.emit(
REMOVE_HIGHLIGHT,
- id // The id of the previously created highlight to be removed
+ id, // The id of the previously created highlight to be removed
);
```
diff --git a/docs/essentials/index.mdx b/docs/essentials/index.mdx
index 2eeddd0c4b1e..a4efcfc84965 100644
--- a/docs/essentials/index.mdx
+++ b/docs/essentials/index.mdx
@@ -3,37 +3,34 @@ title: Essentials
hideRendererSelector: true
sidebar:
order: 8
- title: Essentials
---
Storybook essentials is a set of tools that help you build, test, and document your components within Storybook. It includes the following:
-* [Actions](./actions.mdx)
-* [Backgrounds](./backgrounds.mdx)
-* [Controls](./controls.mdx)
-* [Highlight](./highlight.mdx)
-* [Measure & outline](./measure-and-outline.mdx)
-* [Toolbars & globals](./toolbars-and-globals.mdx)
-* [Viewport](./viewport.mdx)
+- [Actions](./actions.mdx)
+- [Backgrounds](./backgrounds.mdx)
+- [Controls](./controls.mdx)
+- [Highlight](./highlight.mdx)
+- [Measure & outline](./measure-and-outline.mdx)
+- [Toolbars & globals](./toolbars-and-globals.mdx)
+- [Viewport](./viewport.mdx)
-### Configuration
+## Configuration
-Essentials is "zero-config”. It comes with a recommended configuration out of the box.
+Essentials is “zero-config”. It comes with a recommended configuration out of the box.
Many of the features above can be configured via [parameters](../writing-stories/parameters.mdx). See each feature's documentation (linked above) for more details.
-### Disabling features
+## Disabling features
If you need to disable any of the essential features, you can do it by changing your [`.storybook/main.js|ts`](../configure/index.mdx#configure-your-storybook-project) file.
For example, if you wanted to disable the [backgrounds feature](./backgrounds.mdx), you would apply the following change to your Storybook configuration:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- You can use the following keys for each individual feature: `actions`, `backgrounds`, `controls`, `highlight`, `measure`, `outline`, `toolbars`, and `viewport`.
+
+You can use the following keys for each individual feature: `actions`, `backgrounds`, `controls`, `highlight`, `measure`, `outline`, `toolbars`, and `viewport`.
+
diff --git a/docs/essentials/measure-and-outline.mdx b/docs/essentials/measure-and-outline.mdx
index f8fdf8629f76..a56a0236d281 100644
--- a/docs/essentials/measure-and-outline.mdx
+++ b/docs/essentials/measure-and-outline.mdx
@@ -2,7 +2,6 @@
title: 'Measure & outline'
sidebar:
order: 6
- title: Measure & outline
---
Storybook's measure and outline features give you the necessary tooling to inspect and visually debug CSS layout and alignment issues within your stories. It makes it easy to catch UI bugs early in development.
@@ -16,7 +15,9 @@ Instead, you can quickly visualize each component's measurements by clicking the

- Alternatively you can press the `m` key on your keyboard to toggle measure on and off.
+
+Alternatively you can press the `m` key on your keyboard to toggle measure on and off.
+
## Outline
diff --git a/docs/essentials/themes.mdx b/docs/essentials/themes.mdx
index 372095ddea8a..03cbe6da955a 100644
--- a/docs/essentials/themes.mdx
+++ b/docs/essentials/themes.mdx
@@ -3,7 +3,6 @@ title: Themes
draft: true
sidebar:
order: 9
- title: Themes
---
Storybook's [Themes](https://github.com/storybookjs/storybook/tree/next/code/addons/themes) addon allows you to switch between multiple themes for your components inside of the preview in [Storybook](https://storybook.js.org).
@@ -18,28 +17,16 @@ To make your themes accessible to your stories, `@storybook/addon-themes` expose
For libraries that expose themes to components through providers, such as [Material UI](https://storybook.js.org/recipes/@mui/material/), [Styled-components](https://storybook.js.org/recipes/styled-components/), and [Emotion](https://storybook.js.org/recipes/@emotion/styled/), use the `withThemeFromJSXProvider`.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### CSS classes
For libraries that rely on CSS classes on a parent element to determine the theme, you can use the `withThemeByClassName` decorator.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Data attributes
For libraries that rely on data attributes on a parent element to determine the theme, you can use the `withThemeByDataAttribute` decorator.
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/essentials/toolbars-and-globals.mdx b/docs/essentials/toolbars-and-globals.mdx
index c4de484fe50c..15d2ad2f9c59 100644
--- a/docs/essentials/toolbars-and-globals.mdx
+++ b/docs/essentials/toolbars-and-globals.mdx
@@ -2,7 +2,6 @@
title: 'Toolbars & globals'
sidebar:
order: 7
- title: Toolbars & globals
---
Storybook ships with features to control the [viewport](./viewport.mdx) and [background](./backgrounds.mdx) the story renders in. Similarly, you can use built-in features to create toolbar items which control special “globals”. You can then read the global values to create [decorators](../writing-stories/decorators.mdx) to control story rendering.
@@ -19,15 +18,11 @@ When the globals change, the story re-renders and the decorators rerun with the
Storybook has a simple, declarative syntax for configuring toolbar menus. In your [`.storybook/preview.*`](../configure/index.mdx#configure-story-rendering), you can add your own toolbars by creating `globalTypes` with a `toolbar` annotation:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- As globals are *global* you can *only* set `globalTypes` and `initialGlobals` in [`.storybook/preview.*`](../configure/index.mdx#configure-story-rendering).
+As globals are _global_ you can _only_ set `globalTypes` and `initialGlobals` in [`.storybook/preview.*`](../configure/index.mdx#configure-story-rendering).
@@ -37,45 +32,37 @@ When you start your Storybook, your toolbar should have a new dropdown menu with
We have a `global` implemented. Let's wire it up! We can consume our new `theme` global in a decorator using the `context.globals.theme` value.
-
- For example, suppose you are using [`styled-components`](https://styled-components.com/). You can add a theme provider decorator to your [`.storybook/preview.*`](../configure/index.mdx#configure-story-rendering) config:
+
- {/* prettier-ignore-start */}
+For example, suppose you are using [`styled-components`](https://styled-components.com/). You can add a theme provider decorator to your [`.storybook/preview.*`](../configure/index.mdx#configure-story-rendering) config:
-
+
- {/* prettier-ignore-end */}
-
+
-
- For example, suppose you are using [`Vuetify`](https://vuetifyjs.com/en/). You can add a theme provider decorator to your [`.storybook/preview.*`](../configure/index.mdx#configure-story-rendering) config:
+
- {/* prettier-ignore-start */}
+For example, suppose you are using [`Vuetify`](https://vuetifyjs.com/en/). You can add a theme provider decorator to your [`.storybook/preview.*`](../configure/index.mdx#configure-story-rendering) config:
-
+
- {/* prettier-ignore-end */}
-
+
-
- For example, suppose you are using [`Angular Material`](https://material.angular.io/). You can add a theme provider decorator to your [`.storybook/preview.*`](../configure/index.mdx#configure-story-rendering) config:
+
- {/* prettier-ignore-start */}
+For example, suppose you are using [`Angular Material`](https://material.angular.io/). You can add a theme provider decorator to your [`.storybook/preview.*`](../configure/index.mdx#configure-story-rendering) config:
-
+
- {/* prettier-ignore-end */}
-
+
-
- Depending on your framework and theming library, you can extend your [`.storybook/preview.*`](../configure/index.mdx#configure-story-rendering) and provide a decorator to load the theme. For example:
+
- {/* prettier-ignore-start */}
+Depending on your framework and theming library, you can extend your [`.storybook/preview.*`](../configure/index.mdx#configure-story-rendering) and provide a decorator to load the theme. For example:
-
+
- {/* prettier-ignore-end */}
-
+
## Setting globals on a story
@@ -83,12 +70,8 @@ When a global value is changed with a toolbar menu in Storybook, that value cont
To ensure that a story always uses a specific global value, regardless of what has been chosen in the toolbar, you can set the `globals` annotation on a story or component. This overrides the global value for those stories and disables the toolbar menu for that global when viewing the stories.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
In the example above, Storybook will force all Button stories to use a gray background color, except the `OnDark` story, which will use the dark background. For all Button stories, the toolbar menu will be disabled for the `backgrounds` global, with a tooltip explaining that the global is set at the story level.
@@ -105,16 +88,12 @@ Now, let's take a look at a more complex example. Suppose we wanted to implement
In your [`.storybook/preview.*`](../configure/index.mdx#configure-story-rendering), add the following:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
The `icon` element used in the examples loads the icons from the `@storybook/icons` package. See [here](../faq.mdx#what-icons-are-available-for-my-toolbar-or-my-addon) for the list of available icons that you can use.
-
+
Adding the configuration element `right` will display the text on the right side in the toolbar menu once you connect it to a decorator.
@@ -136,32 +115,20 @@ But we're aware that sometimes it's more beneficial to use toolbar options on a
Using the example above, you can modify any story to retrieve the **Locale** `global` from the story context:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Consuming globals from within an addon
If you're working on a Storybook addon and need to retrieve globals, you can do so. The `storybook/manager-api` module provides a hook for this scenario. You can use the [`useGlobals()`](../addons/addons-api.mdx#useglobals) hook to retrieve any globals you want.
Using the ThemeProvider example above, you could expand it to display which theme is active inside a panel as such:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Updating globals from within an addon
If you're working on a Storybook addon that needs to update the global and refresh the UI, you can do so. As mentioned previously, the `storybook/manager-api` module provides the necessary hook for this scenario. You can use the `updateGlobals` function to update any global values you need.
For example, if you were working on a [toolbar addon](../addons/addon-types.mdx#toolbars), and you want to refresh the UI and update the global once the user clicks on a button:
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
diff --git a/docs/essentials/viewport.mdx b/docs/essentials/viewport.mdx
index bcd37bf53864..fe9097c45aa3 100644
--- a/docs/essentials/viewport.mdx
+++ b/docs/essentials/viewport.mdx
@@ -1,8 +1,7 @@
---
-title: 'Viewport'
+title: Viewport
sidebar:
order: 8
- title: Viewport
---
The viewport feature allows you to adjust the dimensions of the iframe your story is rendered in. It makes it easy to develop responsive UIs.
@@ -15,18 +14,14 @@ Out of the box, the viewport feature offers you a standard set of viewports that
You can define the available viewports using the [`options` property](#options) and set the initial viewport using the `initialGlobals` property:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Use a detailed set of devices
By default, the viewport feature will use a minimal set of viewports, which enables you to test your UI in common responsive scenarios. These are also available in the [`MINIMAL_VIEWPORTS` export](#minimal_viewports) and include the following devices:
| Key | Description | Dimensions (w×h, px) |
-| ----------|------------- | -------------------------------------------------------------------------------- |
+| --------- | ------------ | -------------------------------------------------------------------------------- |
| `mobile1` | Small mobile | 320 × 568 |
| `mobile2` | Large mobile | 414 × 896 |
| `tablet` | Tablet | 834 × 1112 |
@@ -34,76 +29,60 @@ By default, the viewport feature will use a minimal set of viewports, which enab
If you need a more detailed set of devices, you can use the [`INITIAL_VIEWPORTS` export](#initial_viewports), which includes the following devices:
-| Key | Description | Dimensions (w×h, px) |
-| -----------------| ----------------------------------------------- | -------------------------------------------------------------------------------- |
-| `iphone5` | iPhone 5 | 320 × 568 |
-| `iphone6` | iPhone 6 | 375 × 667 |
-| `iphone6p` | iPhone 6 Plus | 414 × 736 |
-| `iphone8p` | iPhone 8 Plus | 414 × 736 |
-| `iphonex` | iPhone X | 375 × 812 |
-| `iphonexr` | iPhone XR | 414 × 896 |
-| `iphonexsmax` | iPhone XS Max | 414 × 896 |
-| `iphonese2` | iPhone SE (2nd generation) | 375 × 667 |
-| `iphone12mini` | iPhone 12 mini | 375 × 812 |
-| `iphone12` | iPhone 12 | 390 × 844 |
-| `iphone12promax` | iPhone 12 Pro Max | 428 × 926 |
-| `iphoneSE3` | iPhone SE 3rd generation | 375 × 667 |
-| `iphone13` | iPhone 13 | 390 × 844 |
-| `iphone13pro` | iPhone 13 Pro | 390 × 844 |
-| `iphone13promax` | iPhone 13 Pro Max | 428 × 926 |
-| `iphone14` | iPhone 14 | 390 × 844 |
-| `iphone14pro` | iPhone 14 Pro | 393 × 852 |
-| `iphone14promax` | iPhone 14 Pro Max | 430 × 932 |
-| `galaxys5` | Galaxy S5 | 360 × 640 |
-| `galaxys9` | Galaxy S9 | 360 × 740 |
-| `nexus5x` | Nexus 5X | 412 × 668 |
-| `nexus6p` | Nexus 6P | 412 × 732 |
-| `pixel` | Pixel | 540 × 960 |
-| `pixelxl` | Pixel XL | 720 × 1280 |
-| `ipad` | iPad | 768 × 1024 |
-| `ipad10p` | iPad Pro 10.5-in | 834 × 1112 |
-| `ipad11p` | iPad Pro 11-in | 834 × 1194 |
-| `ipad12p` | iPad Pro 12.9-in | 1024 × 1366 |
+| Key | Description | Dimensions (w×h, px) |
+| ---------------- | -------------------------- | -------------------------------------------------------------------------------- |
+| `iphone5` | iPhone 5 | 320 × 568 |
+| `iphone6` | iPhone 6 | 375 × 667 |
+| `iphone6p` | iPhone 6 Plus | 414 × 736 |
+| `iphone8p` | iPhone 8 Plus | 414 × 736 |
+| `iphonex` | iPhone X | 375 × 812 |
+| `iphonexr` | iPhone XR | 414 × 896 |
+| `iphonexsmax` | iPhone XS Max | 414 × 896 |
+| `iphonese2` | iPhone SE (2nd generation) | 375 × 667 |
+| `iphone12mini` | iPhone 12 mini | 375 × 812 |
+| `iphone12` | iPhone 12 | 390 × 844 |
+| `iphone12promax` | iPhone 12 Pro Max | 428 × 926 |
+| `iphoneSE3` | iPhone SE 3rd generation | 375 × 667 |
+| `iphone13` | iPhone 13 | 390 × 844 |
+| `iphone13pro` | iPhone 13 Pro | 390 × 844 |
+| `iphone13promax` | iPhone 13 Pro Max | 428 × 926 |
+| `iphone14` | iPhone 14 | 390 × 844 |
+| `iphone14pro` | iPhone 14 Pro | 393 × 852 |
+| `iphone14promax` | iPhone 14 Pro Max | 430 × 932 |
+| `galaxys5` | Galaxy S5 | 360 × 640 |
+| `galaxys9` | Galaxy S9 | 360 × 740 |
+| `nexus5x` | Nexus 5X | 412 × 668 |
+| `nexus6p` | Nexus 6P | 412 × 732 |
+| `pixel` | Pixel | 540 × 960 |
+| `pixelxl` | Pixel XL | 720 × 1280 |
+| `ipad` | iPad | 768 × 1024 |
+| `ipad10p` | iPad Pro 10.5-in | 834 × 1112 |
+| `ipad11p` | iPad Pro 11-in | 834 × 1194 |
+| `ipad12p` | iPad Pro 12.9-in | 1024 × 1366 |
To use the detailed set of devices, you can adjust the `options` property in your configuration to include the `INITIAL_VIEWPORTS` export:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Add new devices
If the predefined viewports don't meet your needs, you can add new devices to the list of viewports. For example, let's add two Kindle devices to the default set of minimal viewports:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Configuring per component or story
In some cases, it's not practical for you to use a specific visual viewport on a global scale, and you need to adjust it to an individual story or set of stories for a component.
[Parameters](../writing-stories/parameters.mdx) can be applied at the project, component, and story levels, which allows you to specify the configuration where needed. For example, you can set the available viewports for all of the stories for a component like so:
-{/* prettier-ignore-start */}
-
-
-
-{/* prettier-ignore-end */}
+
## Defining the viewport for a story
The Viewport module enables you to change the viewport applied to a story by selecting from the list of predefined viewports in the toolbar. If needed, you can set a story to default to a specific viewport by using the `globals` option:
-{/* prettier-ignore-start */}
-
-
-
-{/* prettier-ignore-end */}
+
@@ -117,9 +96,9 @@ When you specify a viewport for a story (or a component's stories) using `global
If you need, you can edit these on the shortcuts page.
-* Next viewport: alt + v
-* Previous viewport: alt + shift + v
-* Reset viewport: alt + control + v
+- Next viewport: alt + v
+- Previous viewport: alt + shift + v
+- Reset viewport: alt + control + v
### Globals
@@ -163,7 +142,6 @@ Type:
Specify the available viewports. See [usage example](#add-new-devices) above. The `width` and `height` values must include the unit, e.g. `'320px'`.
-
### Exports
This module contributes the following exports to Storybook:
@@ -183,4 +161,3 @@ The full set of initial viewports provided by the Viewport module [listed above]
Type: `object`
A minimal set of viewports provided by the Viewport module [listed above](#use-a-detailed-set-of-devices). These are used by default.
-
diff --git a/docs/faq.mdx b/docs/faq.mdx
index 1740ffeaac70..e55172aa984e 100644
--- a/docs/faq.mdx
+++ b/docs/faq.mdx
@@ -1,5 +1,5 @@
---
-title: 'Frequently Asked Questions'
+title: Frequently Asked Questions
sidebar:
order: 15
title: FAQ
@@ -9,7 +9,7 @@ Here are some answers to frequently asked questions. If you have a question, you
## Error: No angular.json file found
-Storybook can be set up for both single-project and multi-project Angular workspaces. To set up Storybook for a project, run [the install command](./get-started/install) at the root of the workspace where the `angular.json` file is located. During initialization, the `.storybook` folder will be created and the `angular.json` file will be edited to add the Storybook configuration for the selected project. It's important to run the command at the root level to ensure that Storybook detects all projects correctly.
+Storybook can be set up for both single-project and multi-project Angular workspaces. To set up Storybook for a project, run [the install command](./get-started/install.mdx) at the root of the workspace where the `angular.json` file is located. During initialization, the `.storybook` folder will be created and the `angular.json` file will be edited to add the Storybook configuration for the selected project. It's important to run the command at the root level to ensure that Storybook detects all projects correctly.
## How can I opt-out of Angular Ivy?
@@ -35,7 +35,7 @@ npm test -- --coverage --collectCoverageFrom='["src/**/*.{js,jsx}","!src/**/stor
- If you're using [`Yarn`](https://yarnpkg.com/) as a package manager, you'll need to adjust the command accordingly.
+If you're using [`Yarn`](https://yarnpkg.com/) as a package manager, you'll need to adjust the command accordingly.
@@ -56,15 +56,11 @@ Required package: @storybook/react-webpack5 (via "@storybook/react-webpack5/pres
To fix this, you can wrap the package name inside your Storybook configuration file (i.e., `.storybook/main.js|ts`) as follows:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Extensionless imports in Storybook main config
-When upgrading or running Storybook, you may see warnings about extensionless relative imports in `.storybook/main.` (for example: `import sharedMain from '../main'`).
+When upgrading or running Storybook, you may see warnings about extensionless relative imports in `.storybook/main.` (for example: `import sharedMain from '../main'`).
Storybook requires explicit extensions in config imports to avoid this deprecation warning.
To fix the issue, just make sure to include the extension of the file (TypeScript or Javascript) you're importing:
@@ -78,6 +74,7 @@ import sharedMain from '../main.js'; // or .ts
```
### For TypeScript users (`.storybook/main.ts`)
+
You will also need to configure TypeScript so these imports type-check without emitting JavaScript:
```json title=".storybook/tsconfig.json"
@@ -92,7 +89,9 @@ You will also need to configure TypeScript so these imports type-check without e
```
- It is advisable to add a `.storybook/tsconfig.json` file so that you apply changes only to Storybook config files, and not your entire project.
+
+It is advisable to add a `.storybook/tsconfig.json` file so that you apply changes only to Storybook config files, and not your entire project.
+
## How do I setup the new React Context Root API with Storybook?
@@ -157,109 +156,111 @@ With the release of version 6.0, we updated our documentation as well. That does
We're only covering versions 5.3 and 5.0 as they were important milestones for Storybook. If you want to go back in time a little more, you'll have to check the specific release in the monorepo.
-| Section | Page | Current Location | Version 5.3 location | Version 5.0 location |
-| ---------------- | ----------------------------------------------- | ---------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| N/A | Why Storybook | [See current documentation](./get-started/why-storybook.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| Get started | Install | [See current documentation](./get-started/install.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/guides/quick-start-guide) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/guides/quick-start-guide) |
-| | What's a story | [See current documentation](./get-started/whats-a-story.mdx) | [See versioned documentation for your framework](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/guides) | [See versioned documentation for your framework](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/guides) |
-| | Browse Stories | [See current documentation](./get-started/browse-stories.mdx) | [See versioned documentation for your framework](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/guides) | [See versioned documentation for your framework](https://github.com/storybookjs/storybook/blob/release/5.0/docs/src/pages/guides) |
-| | Setup | [See current documentation](./get-started/setup.mdx) | [See versioned documentation for your framework](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/guides) | [See versioned documentation for your framework](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/guides) |
-| Write stories | Introduction | [See current documentation](./writing-stories/index.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/basics/writing-stories) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/basics/writing-stories) |
-| | Parameters | [See current documentation](./writing-stories/parameters.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/basics/writing-stories/index.md#parameters) | Non existing feature or undocumented |
-| | Decorators | [See current documentation](./writing-stories/decorators.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/basics/writing-stories/index.md#decorators) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/basics/writing-stories/index.md#using-decorators) |
-| | Naming components and hierarchy | [See current documentation](./writing-stories/naming-components-and-hierarchy.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/basics/writing-stories) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/basics/writing-stories) |
-| | Build pages and screens | [See current documentation](./writing-stories/build-pages-with-storybook.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | Stories for multiple components | [See current documentation](./writing-stories/stories-for-multiple-components.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| Write docs | Autodocs | [See current documentation](./writing-docs/autodocs.mdx) | See versioned addon documentation | Non existing feature or undocumented |
-| | MDX | [See current documentation](./writing-docs/mdx.mdx) | See versioned addon documentation | Non existing feature or undocumented |
-| | Doc Blocks | [See current documentation](./writing-docs/doc-blocks.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | Preview and build docs | [See current documentation](./writing-docs/build-documentation.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| Testing | Visual tests | [See current documentation](./writing-tests/visual-testing.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/testing/automated-visual-testing) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/testing/automated-visual-testing) |
-| | Accessibility tests | [See current documentation](./writing-tests/accessibility-testing.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | Interaction tests | [See current documentation](./writing-tests/interaction-testing.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/testing/interaction-testing) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/testing/interaction-testing) |
-| | Snapshot tests | [See current documentation](./writing-tests/snapshot-testing.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/testing/structural-testing) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/testing/structural-testing) |
-| | Import stories in tests/Unit tests | [See current documentation](./writing-tests/integrations/stories-in-unit-tests.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/testing/react-ui-testing) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/testing/react-ui-testing) |
-| | Import stories in tests/End-to-end testing | [See current documentation](./writing-tests/integrations/stories-in-end-to-end-tests.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/testing/react-ui-testing) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/testing/react-ui-testing) |
-| Sharing | Publish Storybook | [See current documentation](./sharing/publish-storybook.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/basics/exporting-storybook) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/basics/exporting-storybook) |
-| | Embed | [See current documentation](./sharing/embed.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | Composition | [See current documentation](./sharing/storybook-composition.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | Package Composition | [See current documentation](./sharing/package-composition.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| Essentials | Controls | [See current documentation](./essentials/controls.mdx) | Controls are specific to version 6.0 see [Knobs versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/addons/knobs) | Controls are specific to version 6.0 see [Knobs versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/addons/knobs) |
-| | Actions | [See current documentation](./essentials/actions.mdx) | [See addon versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/addons/actions) | [See addon versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/addons/actions) |
-| | Viewport | [See current documentation](./essentials/viewport.mdx) | [See addon versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/addons/viewport) | [See addon versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/addons/viewport) |
-| | Backgrounds | [See current documentation](./essentials/backgrounds.mdx) | [See addon versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/addons/backgrounds) | [See addon versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/addons/backgrounds) |
-| | Toolbars and globals | [See current documentation](./essentials/toolbars-and-globals.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/basics/toolbar-guide) | Non existing feature or undocumented |
-| Configure | Overview | [See current documentation](./configure/index.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/overview) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/basics/writing-stories) |
-| | Integration/Frameworks | [See current documentation](./configure/integration/frameworks.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | Integration/Framework support for frameworks | [See current documentation](./configure/integration/frameworks-feature-support.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | Integration/Compilers | [See current documentation](./configure/integration/compilers.mdx) | See versioned documentation [here](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/custom-babel-config) | See versioned documentation [here](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/custom-babel-config) |
-| | Integration/Typescript | [See current documentation](./configure/integration/typescript.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/typescript-config) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/typescript-config) |
-| | Integration/Styling and CSS | [See current documentation](./configure/styling-and-css.mdx) | See versioned documentation | See versioned documentation |
-| | Integration/Images and assets | [See current documentation](./configure/integration/images-and-assets.mdx) | See versioned documentation | See versioned documentation |
-| | Story rendering | [See current documentation](./configure/story-rendering.mdx) | See versioned documentation [here](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/add-custom-head-tags) and [here](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/add-custom-body) | See versioned documentation [here](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/add-custom-head-tags) |
-| | Story Layout | [See current documentation](./configure/story-layout.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | User Interface/Features and behavior | [See current documentation](./configure/user-interface/features-and-behavior.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/options-parameter) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/options-parameter) |
-| | User Interface/Theming | [See current documentation](./configure/user-interface/theming.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/theming) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/theming) |
-| | User Interface/Sidebar & URLS | [See current documentation](./configure/user-interface/sidebar-and-urls.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/options-parameter) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/options-parameter) |
-| | Environment variables | [See current documentation](./configure/environment-variables.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/env-vars) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/env-vars) |
-| Builders | Introduction | [See current documentation](./builders/index.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | Vite | [See current documentation](./builders/vite.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | Webpack | [See current documentation](./builders/webpack.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/custom-webpack-config/index.md) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/custom-webpack-config/index.md) |
-| | Builder API | [See current documentation](./builders/builder-api.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| Addons | Introduction | [See current documentation](./addons/index.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/addons/writing-addons) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/addons/writing-addons) |
-| | Install addons | [See current documentation](./addons/install-addons.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/addons/using-addons/) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/addons/using-addons/) |
-| | Writing Addons | [See current documentation](./addons/writing-addons.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/addons/writing-addons) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/addons/writing-addons) |
-| | Writing Presets | [See current documentation](./addons/writing-presets.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/presets/writing-presets) | Non existing feature or undocumented |
-| | Addons Knowledge Base | [See current documentation](./addons/addon-knowledge-base.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/addons/writing-addons) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/addons/writing-addons) |
-| | Types of addons | [See current documentation](./addons/addon-types.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | Addons API | [See current documentation](./addons/addons-api.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/addons/api) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/addons/api) |
-| API | @storybook/addon-docs/blocks/ArgTypes | [See current documentation](./api/doc-blocks/doc-block-argtypes.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | @storybook/addon-docs/blocks/Canvas | [See current documentation](./api/doc-blocks/doc-block-canvas.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | @storybook/addon-docs/blocks/ColorPalette | [See current documentation](./api/doc-blocks/doc-block-colorpalette.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | @storybook/addon-docs/blocks/Controls | [See current documentation](./api/doc-blocks/doc-block-controls.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | @storybook/addon-docs/blocks/Description | [See current documentation](./api/doc-blocks/doc-block-description.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | @storybook/addon-docs/blocks/IconGallery | [See current documentation](./api/doc-blocks/doc-block-icongallery.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | @storybook/addon-docs/blocks/Markdown | [See current documentation](./api/doc-blocks/doc-block-markdown.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | @storybook/addon-docs/blocks/Meta | [See current documentation](./api/doc-blocks/doc-block-meta.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | @storybook/addon-docs/blocks/Primary | [See current documentation](./api/doc-blocks/doc-block-primary.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | @storybook/addon-docs/blocks/Source | [See current documentation](./api/doc-blocks/doc-block-source.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | @storybook/addon-docs/blocks/Stories | [See current documentation](./api/doc-blocks/doc-block-stories.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | @storybook/addon-docs/blocks/Story | [See current documentation](./api/doc-blocks/doc-block-story.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | @storybook/addon-docs/blocks/Subtitle | [See current documentation](./api/doc-blocks/doc-block-subtitle.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | @storybook/addon-docs/blocks/Title | [See current documentation](./api/doc-blocks/doc-block-title.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | @storybook/addon-docs/blocks/Typeset | [See current documentation](./api/doc-blocks/doc-block-typeset.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | @storybook/addon-docs/blocks/Unstyled | [See current documentation](./api/doc-blocks/doc-block-unstyled.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | @storybook/addon-docs/blocks/useOf | [See current documentation](./api/doc-blocks/doc-block-useof.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | Stories/Component Story Format (see note below) | [See current documentation](./api/csf/index.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/formats/component-story-format) | Non existing feature or undocumented |
-| | ArgTypes | [See current documentation](./api/arg-types.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/Overview | [See current documentation](./api/main-config/main-config.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/framework | [See current documentation](./api/main-config/main-config-framework.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/stories | [See current documentation](./api/main-config/main-config-stories.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/addons | [See current documentation](./api/main-config/main-config-addons.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/babel | [See current documentation](./api/main-config/main-config-babel.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/babelDefault | [See current documentation](./api/main-config/main-config-babel-default.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/build | [See current documentation](./api/main-config/main-config-build.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/core | [See current documentation](./api/main-config/main-config-core.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/docs | [See current documentation](./api/main-config/main-config-docs.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/env | [See current documentation](./api/main-config/main-config-env.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/features | [See current documentation](./api/main-config/main-config-features.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/indexers | [See current documentation](./api/main-config/main-config-indexers.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/logLevel | [See current documentation](./api/main-config/main-config-log-level.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/managerHead | [See current documentation](./api/main-config/main-config-manager-head.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/previewAnnotations | [See current documentation](./api/main-config/main-config-preview-annotations.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/previewBody | [See current documentation](./api/main-config/main-config-preview-body.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/previewHead | [See current documentation](./api/main-config/main-config-preview-head.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/refs | [See current documentation](./api/main-config/main-config-refs.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/staticDirs | [See current documentation](./api/main-config/main-config-static-dirs.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/swc | [See current documentation](./api/main-config/main-config-swc.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/typescript | [See current documentation](./api/main-config/main-config-typescript.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/viteFinal | [See current documentation](./api/main-config/main-config-vite-final.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | `main.js` configuration/webpackFinal | [See current documentation](./api/main-config/main-config-webpack-final.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | Frameworks | [See current documentation](./api/new-frameworks.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
-| | CLI options | [See current documentation](./api/cli-options.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/cli-options) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/cli-options) |
+| Section | Page | Current Location | Version 5.3 location | Version 5.0 location |
+| ------------- | ----------------------------------------------- | ----------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| N/A | Why Storybook | [See current documentation](./get-started/why-storybook.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| Get started | Install | [See current documentation](./get-started/install.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/guides/quick-start-guide) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/guides/quick-start-guide) |
+| | What's a story | [See current documentation](./get-started/whats-a-story.mdx) | [See versioned documentation for your framework](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/guides) | [See versioned documentation for your framework](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/guides) |
+| | Browse Stories | [See current documentation](./get-started/browse-stories.mdx) | [See versioned documentation for your framework](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/guides) | [See versioned documentation for your framework](https://github.com/storybookjs/storybook/blob/release/5.0/docs/src/pages/guides) |
+| | Setup | [See current documentation](./get-started/setup.mdx) | [See versioned documentation for your framework](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/guides) | [See versioned documentation for your framework](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/guides) |
+| Write stories | Introduction | [See current documentation](./writing-stories/index.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/basics/writing-stories) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/basics/writing-stories) |
+| | Parameters | [See current documentation](./writing-stories/parameters.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/basics/writing-stories/index.md#parameters) | Non existing feature or undocumented |
+| | Decorators | [See current documentation](./writing-stories/decorators.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/basics/writing-stories/index.md#decorators) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/basics/writing-stories/index.md#using-decorators) |
+| | Naming components and hierarchy | [See current documentation](./writing-stories/naming-components-and-hierarchy.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/basics/writing-stories) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/basics/writing-stories) |
+| | Build pages and screens | [See current documentation](./writing-stories/build-pages-with-storybook.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | Stories for multiple components | [See current documentation](./writing-stories/stories-for-multiple-components.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| Write docs | Autodocs | [See current documentation](./writing-docs/autodocs.mdx) | See versioned addon documentation | Non existing feature or undocumented |
+| | MDX | [See current documentation](./writing-docs/mdx.mdx) | See versioned addon documentation | Non existing feature or undocumented |
+| | Doc Blocks | [See current documentation](./writing-docs/doc-blocks.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | Preview and build docs | [See current documentation](./writing-docs/build-documentation.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| Testing | Visual tests | [See current documentation](./writing-tests/visual-testing.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/testing/automated-visual-testing) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/testing/automated-visual-testing) |
+| | Accessibility tests | [See current documentation](./writing-tests/accessibility-testing.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | Interaction tests | [See current documentation](./writing-tests/interaction-testing.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/testing/interaction-testing) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/testing/interaction-testing) |
+| | Snapshot tests | [See current documentation](./writing-tests/snapshot-testing.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/testing/structural-testing) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/testing/structural-testing) |
+| | Import stories in tests/Unit tests | [See current documentation](./writing-tests/integrations/stories-in-unit-tests.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/testing/react-ui-testing) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/testing/react-ui-testing) |
+| | Import stories in tests/End-to-end testing | [See current documentation](./writing-tests/integrations/stories-in-end-to-end-tests.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/testing/react-ui-testing) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/testing/react-ui-testing) |
+| Sharing | Publish Storybook | [See current documentation](./sharing/publish-storybook.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/basics/exporting-storybook) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/basics/exporting-storybook) |
+| | Embed | [See current documentation](./sharing/embed.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | Composition | [See current documentation](./sharing/storybook-composition.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | Package Composition | [See current documentation](./sharing/package-composition.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| Essentials | Controls | [See current documentation](./essentials/controls.mdx) | Controls are specific to version 6.0 see [Knobs versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/addons/knobs) | Controls are specific to version 6.0 see [Knobs versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/addons/knobs) |
+| | Actions | [See current documentation](./essentials/actions.mdx) | [See addon versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/addons/actions) | [See addon versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/addons/actions) |
+| | Viewport | [See current documentation](./essentials/viewport.mdx) | [See addon versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/addons/viewport) | [See addon versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/addons/viewport) |
+| | Backgrounds | [See current documentation](./essentials/backgrounds.mdx) | [See addon versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/addons/backgrounds) | [See addon versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/addons/backgrounds) |
+| | Toolbars and globals | [See current documentation](./essentials/toolbars-and-globals.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/basics/toolbar-guide) | Non existing feature or undocumented |
+| Configure | Overview | [See current documentation](./configure/index.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/overview) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/basics/writing-stories) |
+| | Integration/Frameworks | [See current documentation](./configure/integration/frameworks.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | Integration/Framework support for frameworks | [See current documentation](./configure/integration/frameworks-feature-support.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | Integration/Compilers | [See current documentation](./configure/integration/compilers.mdx) | See versioned documentation [here](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/custom-babel-config) | See versioned documentation [here](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/custom-babel-config) |
+| | Integration/Typescript | [See current documentation](./configure/integration/typescript.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/typescript-config) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/typescript-config) |
+| | Integration/Styling and CSS | [See current documentation](./configure/styling-and-css.mdx) | See versioned documentation | See versioned documentation |
+| | Integration/Images and assets | [See current documentation](./configure/integration/images-and-assets.mdx) | See versioned documentation | See versioned documentation |
+| | Story rendering | [See current documentation](./configure/story-rendering.mdx) | See versioned documentation [here](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/add-custom-head-tags) and [here](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/add-custom-body) | See versioned documentation [here](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/add-custom-head-tags) |
+| | Story Layout | [See current documentation](./configure/story-layout.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | User Interface/Features and behavior | [See current documentation](./configure/user-interface/features-and-behavior.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/options-parameter) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/options-parameter) |
+| | User Interface/Theming | [See current documentation](./configure/user-interface/theming.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/theming) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/theming) |
+| | User Interface/Sidebar & URLS | [See current documentation](./configure/user-interface/sidebar-and-urls.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/options-parameter) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/options-parameter) |
+| | Environment variables | [See current documentation](./configure/environment-variables.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/env-vars) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/env-vars) |
+| Builders | Introduction | [See current documentation](./builders/index.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | Vite | [See current documentation](./builders/vite.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | Webpack | [See current documentation](./builders/webpack.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/custom-webpack-config/index.md) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/custom-webpack-config/index.md) |
+| | Builder API | [See current documentation](./builders/builder-api.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| Addons | Introduction | [See current documentation](./addons/index.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/addons/writing-addons) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/addons/writing-addons) |
+| | Install addons | [See current documentation](./addons/install-addons.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/addons/using-addons/) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/addons/using-addons/) |
+| | Writing Addons | [See current documentation](./addons/writing-addons.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/addons/writing-addons) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/addons/writing-addons) |
+| | Writing Presets | [See current documentation](./addons/writing-presets.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/presets/writing-presets) | Non existing feature or undocumented |
+| | Addons Knowledge Base | [See current documentation](./addons/addon-knowledge-base.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/addons/writing-addons) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/addons/writing-addons) |
+| | Types of addons | [See current documentation](./addons/addon-types.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | Addons API | [See current documentation](./addons/addons-api.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/addons/api) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/addons/api) |
+| API | @storybook/addon-docs/blocks/ArgTypes | [See current documentation](./api/doc-blocks/doc-block-argtypes.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | @storybook/addon-docs/blocks/Canvas | [See current documentation](./api/doc-blocks/doc-block-canvas.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | @storybook/addon-docs/blocks/ColorPalette | [See current documentation](./api/doc-blocks/doc-block-colorpalette.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | @storybook/addon-docs/blocks/Controls | [See current documentation](./api/doc-blocks/doc-block-controls.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | @storybook/addon-docs/blocks/Description | [See current documentation](./api/doc-blocks/doc-block-description.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | @storybook/addon-docs/blocks/IconGallery | [See current documentation](./api/doc-blocks/doc-block-icongallery.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | @storybook/addon-docs/blocks/Markdown | [See current documentation](./api/doc-blocks/doc-block-markdown.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | @storybook/addon-docs/blocks/Meta | [See current documentation](./api/doc-blocks/doc-block-meta.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | @storybook/addon-docs/blocks/Primary | [See current documentation](./api/doc-blocks/doc-block-primary.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | @storybook/addon-docs/blocks/Source | [See current documentation](./api/doc-blocks/doc-block-source.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | @storybook/addon-docs/blocks/Stories | [See current documentation](./api/doc-blocks/doc-block-stories.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | @storybook/addon-docs/blocks/Story | [See current documentation](./api/doc-blocks/doc-block-story.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | @storybook/addon-docs/blocks/Subtitle | [See current documentation](./api/doc-blocks/doc-block-subtitle.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | @storybook/addon-docs/blocks/Title | [See current documentation](./api/doc-blocks/doc-block-title.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | @storybook/addon-docs/blocks/Typeset | [See current documentation](./api/doc-blocks/doc-block-typeset.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | @storybook/addon-docs/blocks/Unstyled | [See current documentation](./api/doc-blocks/doc-block-unstyled.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | @storybook/addon-docs/blocks/useOf | [See current documentation](./api/doc-blocks/doc-block-useof.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | Stories/Component Story Format (see note below) | [See current documentation](./api/csf/index.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/formats/component-story-format) | Non existing feature or undocumented |
+| | ArgTypes | [See current documentation](./api/arg-types.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/Overview | [See current documentation](./api/main-config/main-config.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/framework | [See current documentation](./api/main-config/main-config-framework.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/stories | [See current documentation](./api/main-config/main-config-stories.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/addons | [See current documentation](./api/main-config/main-config-addons.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/babel | [See current documentation](./api/main-config/main-config-babel.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/babelDefault | [See current documentation](./api/main-config/main-config-babel-default.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/build | [See current documentation](./api/main-config/main-config-build.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/core | [See current documentation](./api/main-config/main-config-core.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/docs | [See current documentation](./api/main-config/main-config-docs.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/env | [See current documentation](./api/main-config/main-config-env.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/features | [See current documentation](./api/main-config/main-config-features.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/indexers | [See current documentation](./api/main-config/main-config-indexers.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/logLevel | [See current documentation](./api/main-config/main-config-log-level.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/managerHead | [See current documentation](./api/main-config/main-config-manager-head.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/previewAnnotations | [See current documentation](./api/main-config/main-config-preview-annotations.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/previewBody | [See current documentation](./api/main-config/main-config-preview-body.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/previewHead | [See current documentation](./api/main-config/main-config-preview-head.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/refs | [See current documentation](./api/main-config/main-config-refs.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/staticDirs | [See current documentation](./api/main-config/main-config-static-dirs.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/swc | [See current documentation](./api/main-config/main-config-swc.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/typescript | [See current documentation](./api/main-config/main-config-typescript.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/viteFinal | [See current documentation](./api/main-config/main-config-vite-final.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | `main.js` configuration/webpackFinal | [See current documentation](./api/main-config/main-config-webpack-final.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | Frameworks | [See current documentation](./api/new-frameworks.mdx) | Non existing feature or undocumented | Non existing feature or undocumented |
+| | CLI options | [See current documentation](./api/cli-options.mdx) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.3/docs/src/pages/configurations/cli-options) | [See versioned documentation](https://github.com/storybookjs/storybook/tree/release/5.0/docs/src/pages/configurations/cli-options) |
- If you have stories written with the older `storiesOf` format, it was removed in Storybook 8.0 and is no longer maintained. We recommend that you migrate your stories to CSF. See the [migration guide](./releases/migration-guide.mdx#major-breaking-changes) for more information. However, if you need, you can still access the old `storiesOf` [documentation](https://github.com/storybookjs/storybook/blob/release/5.3/docs/src/pages/formats/storiesof-api/index.md) for reference.
+
+If you have stories written with the older `storiesOf` format, it was removed in Storybook 8.0 and is no longer maintained. We recommend that you migrate your stories to CSF. See the [migration guide](./releases/migration-guide.mdx#major-breaking-changes) for more information. However, if you need, you can still access the old `storiesOf` [documentation](https://github.com/storybookjs/storybook/blob/release/5.3/docs/src/pages/formats/storiesof-api/index.md) for reference.
+
## What icons are available for my toolbar or my addon?
@@ -277,19 +278,17 @@ npx http-server storybook-static
```
- Suppose you don't want to run the command above frequently. Add `http-server` as a development dependency and create a new script to preview your production build of Storybook.
+
+Suppose you don't want to run the command above frequently. Add `http-server` as a development dependency and create a new script to preview your production build of Storybook.
+
## Can I use Storybook with Vue 2?
Vue 2 entered [End of Life](https://v2.vuejs.org/lts/) (EOL) on December 31, 2023, and is no longer supported by the Vue team. As a result, we've stopped supporting Vue 2 in Storybook 8 and above and will not be releasing any new versions that support it. We recommend upgrading your project to Vue 3, which Storybook fully supports. If that's not an option, you can still use Storybook with Vue 2 by installing the latest version of Storybook 7 with the following command:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Why aren't my code blocks highlighted with Storybook MDX?
Out of the box, Storybook provides syntax highlighting for a set of languages (e.g., Javascript, Markdown, CSS, HTML, Typescript, GraphQL) you can use with your code blocks. Currently, there's a known limitation when you try to register a custom language to get syntax highlighting. We're working on a fix for this and will update this section once it's available.
@@ -298,8 +297,6 @@ Out of the box, Storybook provides syntax highlighting for a set of languages (e
Writing documentation with MDX can be troublesome, especially regarding how your code is formatted when using line breaks with code blocks. For example, this will break:
-{/* prettier-ignore-start */}
-
```mdx title="Example.mdx"
```
-{/* prettier-ignore-end */}
-
But this will work:
-{/* prettier-ignore-start */}
-
```mdx title="Example.mdx"
```
-{/* prettier-ignore-end */}
-
See the following [issue](https://github.com/mdx-js/mdx/issues/1945) for more information.
## Why are my mocked GraphQL queries failing with Storybook's MSW addon?
@@ -365,7 +356,7 @@ export default {
replace({
'process.env.NODE_ENV': JSON.stringify('development'),
}),
- ]
+ ],
};
```
diff --git a/docs/get-started/browse-stories.mdx b/docs/get-started/browse-stories.mdx
index 302166b68d34..83b46f89fbc5 100644
--- a/docs/get-started/browse-stories.mdx
+++ b/docs/get-started/browse-stories.mdx
@@ -21,19 +21,21 @@ Or use keyboard shortcuts. Click on the Storybook menu to see a list of availabl

- Storybook supports fast keyboard navigation between landmark regions. Press F6 and Shift+F6 to navigate between the sidebar, toolbar, preview, and addons panel.
+
+Storybook supports fast keyboard navigation between landmark regions. Press F6 and Shift+F6 to navigate between the sidebar, toolbar, preview, and addons panel.
+
## Toolbar
Storybook ships with time-saving tools built-in. The toolbar contains tools that allow you to adjust how the story renders in the Canvas:
-* 🔍 Zooming visually scales the component so you can check the details.
-* 🖼 Background changes the rendered background behind your component so you can verify how your component renders in different visual contexts.
-* 📐 Grid renders your component on top of a grid layout so you can verify if your component is aligned correctly.
-* 📏 Measure toggles a measurement overlay to help you inspect the dimensions of components.
-* 🎚️ Outline displays the component's bounding box so you can verify if your component is positioned correctly.
-* 📱 Viewport renders the component in a variety of dimensions and orientations. It’s ideal for checking the responsiveness of components.
+- 🔍 Zooming visually scales the component so you can check the details.
+- 🖼 Background changes the rendered background behind your component so you can verify how your component renders in different visual contexts.
+- 📐 Grid renders your component on top of a grid layout so you can verify if your component is aligned correctly.
+- 📏 Measure toggles a measurement overlay to help you inspect the dimensions of components.
+- 🎚️ Outline displays the component's bounding box so you can verify if your component is positioned correctly.
+- 📱 Viewport renders the component in a variety of dimensions and orientations. It’s ideal for checking the responsiveness of components.
@@ -49,11 +51,11 @@ Addons are plugins that extend Storybook's core functionality. You can find them

-* **Controls** allows you to interact with a component’s args (inputs) dynamically. Experiment with alternate configurations of the component to discover edge cases.
-* **Actions** help you verify interactions produce the correct outputs via callbacks. For instance, if you view the “Logged In” story of the `Header` component, we can verify that clicking the “Log out” button triggers the `onLogout` callback, which would be provided by the component that made use of the Header.
-* **Interactions** provides a helpful user interface for debugging [interaction tests](../writing-tests/interaction-testing.mdx) with the `play` function.
-* **Accessibility** helps you identify [accessibility violations](../writing-tests/accessibility-testing.mdx) in your components.
-* **Visual Tests** lets you pinpoint UI bugs in your local development environment by providing instant feedback directly in Storybook.
+- **Controls** allows you to interact with a component’s args (inputs) dynamically. Experiment with alternate configurations of the component to discover edge cases.
+- **Actions** help you verify interactions produce the correct outputs via callbacks. For instance, if you view the “Logged In” story of the `Header` component, we can verify that clicking the “Log out” button triggers the `onLogout` callback, which would be provided by the component that made use of the Header.
+- **Interactions** provides a helpful user interface for debugging [interaction tests](../writing-tests/interaction-testing.mdx) with the `play` function.
+- **Accessibility** helps you identify [accessibility violations](../writing-tests/accessibility-testing.mdx) in your components.
+- **Visual Tests** lets you pinpoint UI bugs in your local development environment by providing instant feedback directly in Storybook.
@@ -69,9 +71,9 @@ Storybook catalogues all your components and their use cases. Therefore, you can
Here's what the workflow looks like:
-* 🗃 Use the sidebar to find a suitable component
-* 👀 Review its stories to pick a variant that suits your needs
-* 📝 Copy/paste the story definition into your app code and wire it up to data
+- 🗃 Use the sidebar to find a suitable component
+- 👀 Review its stories to pick a variant that suits your needs
+- 📝 Copy/paste the story definition into your app code and wire it up to data
You can access the story definition from the stories file or make it available in your published Storybook using the [Docs addon](../api/doc-blocks/doc-block-source.mdx).
diff --git a/docs/get-started/conclusion.mdx b/docs/get-started/conclusion.mdx
index 218c43e0a10c..59704f4cdfe1 100644
--- a/docs/get-started/conclusion.mdx
+++ b/docs/get-started/conclusion.mdx
@@ -3,13 +3,12 @@ title: Conclusion
hideRendererSelector: true
sidebar:
order: 7
- title: Conclusion
---
Congratulations! You learned the basics. Storybook is the most popular tool for UI component development and documentation. You’ll be able to transfer these skills to thousands of companies that use Storybook to build UIs including GitHub, Airbnb, and Stripe.
If you’d like to learn workflows for building app UIs with Storybook, check out our in-depth guides over at the [tutorials](https://storybook.js.org/tutorials/) page. Continue reading for detailed information on how to use Storybook APIs.
-* [How to write stories](../writing-stories/index.mdx)
-* [How to document components and design systems](../writing-docs/index.mdx)
-* [View example Storybooks from leading companies](https://storybook.js.org/showcase)
+- [How to write stories](../writing-stories/index.mdx)
+- [How to document components and design systems](../writing-docs/index.mdx)
+- [View example Storybooks from leading companies](https://storybook.js.org/showcase)
diff --git a/docs/get-started/frameworks/angular.mdx b/docs/get-started/frameworks/angular.mdx
index c0bc4d30dd77..0ea685a0408d 100644
--- a/docs/get-started/frameworks/angular.mdx
+++ b/docs/get-started/frameworks/angular.mdx
@@ -12,21 +12,31 @@ Storybook for Angular is a [framework](../../contribute/framework.mdx) that make
To install Storybook in an existing Angular project, run this command in your project's root directory:
-
+
You can then get started [writing stories](../whats-a-story.mdx), [running tests](../../writing-tests/index.mdx) and [documenting your components](../../writing-docs/index.mdx). For more control over the installation process, refer to the [installation guide](../install.mdx).
### Requirements
-
+
## Run Storybook
@@ -83,26 +93,21 @@ Add the following option to your Storybook Builder:
"json",
"-d",
// Where to store the generated documentation. It's usually the root of your Angular project. It's not necessarily the root of your Angular Workspace!
- "."
+ ".",
],
- }
+ },
},
"build-storybook": {
"builder": "@storybook/angular:build-storybook",
"options": {
// 👇 Add these
"compodoc": true,
- "compodocArgs": [
- "-e",
- "json",
- "-d",
- "."
- ],
- }
- }
- }
- }
- }
+ "compodocArgs": ["-e", "json", "-d", "."],
+ },
+ },
+ },
+ },
+ },
}
```
@@ -162,20 +167,12 @@ export const WithCustomProvider: Story = {
The easiest way to install the Angular framework is to run the upgrade command, but you can also set it up manually. First, install the framework:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Then, update your `.storybook/main.js|ts` to change the framework property:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Finally, update your `angular.json` to include the Storybook builder:
```jsonc title="angular.json"
@@ -191,24 +188,24 @@ Finally, update your `angular.json` to include the Storybook builder:
// The build target of your project
"browserTarget": "your-project:build",
// The port you want to start Storybook on
- "port": 6006
+ "port": 6006,
// More options available, documented here:
// https://github.com/storybookjs/storybook/tree/next/code/frameworks/angular/src/builders/start-storybook/schema.json
- }
+ },
},
"build-storybook": {
"builder": "@storybook/angular:build-storybook",
"options": {
"configDir": ".storybook",
"browserTarget": "your-project:build",
- "outputDir": "dist/storybook/your-project"
+ "outputDir": "dist/storybook/your-project",
// More options available, documented here:
// https://github.com/storybookjs/storybook/tree/next/code/frameworks/angular/src/builders/build-storybook/schema.json
- }
- }
- }
- }
- }
+ },
+ },
+ },
+ },
+ },
}
```
@@ -249,7 +246,6 @@ Note that `compodoc` is now built into `@storybook/angular`; you don't have to c
}
```
-
#### With multiple projects in your Angular workspace
In case you have multiple projects, you will have to adjust your `angular.json` and `package.json` as described above for each project you want to use Storybook with. Please note that each project should have a dedicated `.storybook` folder placed at the project's root directory.
@@ -262,41 +258,41 @@ You can then combine multiple Storybooks with [Storybook composition](../../shar
These are common options you may need for the Angular builder:
-| Configuration element | Description |
-| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `"browserTarget"` | Build target to be served using the following format. `"example-project:builder:config"` |
-| `"debugWebpack"` | Debug the Webpack configuration `"debugWebpack": true` |
-| `"tsConfig"` | Location of the TypeScript configuration file relative to the current workspace. `"tsConfig": "./tsconfig.json"`. |
-| `"preserveSymlinks"` | Do not use the real path when resolving modules. If true, symlinks are resolved to their real path; otherwise, they are resolved to their symlinked path. `"preserveSymlinks": true` |
-| `"port"` | Port used by Storybook. `"port": 6006` |
-| `"host"` | Set up a custom host for Storybook. `"host": "http://my-custom-host"` |
-| `"configDir"` | Storybook configuration directory location. `"configDir": ".storybook"` |
-| `"https"` | Starts Storybook with HTTPS enabled. `"https": true` Requires custom certificate information. |
-| `"sslCa"` | Provides an SSL certificate authority. `"sslCa": "your-custom-certificate-authority"` Optional usage with `"https"` |
-| `"sslCert"` | Provides an SSL certificate. `"sslCert": "your-custom-certificate"` Required for `https` |
-| `"sslKey"` | Provides an SSL key to serve Storybook. `"sslKey": "your-ssl-key"` |
-| `"smokeTest"` | Exit Storybook after successful start. `"smokeTest": true` |
-| `"ci"` | Starts Storybook in CI mode (skips interactive prompts and will not open browser window). `"ci": true` |
-| `"open"` | Whether to open Storybook automatically in the browser. `"open": true` |
-| `"quiet"` | Filters Storybook verbose build output. `"quiet": true` |
-| `"enableProdMode"` | Disable Angular's development mode, which turns off assertions and other checks within the framework. `"enableProdMode": true` |
-| `"docs"` | Starts Storybook in [documentation mode](../../writing-docs/build-documentation.mdx#preview-storybooks-documentation). `"docs": true` |
-| `"compodoc"` | Execute compodoc before. `"compodoc": true` |
-| `"compodocArgs"` | Compodoc [options](https://compodoc.app/guides/options.html). Options `-p` with tsconfig path and `-d` with workspace root is always given. `"compodocArgs": ["-e", "json"]` |
-| `"styles"` | Provide the location of the [application's styles](../../configure/styling-and-css.mdx#global-styles) to be used with Storybook. `"styles": ["src/styles.css", "src/styles.scss"]` |
-| `"stylePreprocessorOptions"` | Provides further customization for style preprocessors resolved to the workspace root. `"stylePreprocessorOptions": { "includePaths": ["src/styles"] }` |
-| `"assets"` | List of static application assets. `"assets": ["src/assets"]` |
-| `"initialPath"` | URL path to be appended when visiting Storybook for the first time. `"initialPath": "docs/configure-your-project--docs"` |
-| `"webpackStatsJson"` | Write Webpack Stats JSON to disk. `"webpackStatsJson": true` |
-| `"previewUrl"` | Disables the default storybook preview and lets you use your own. `"previewUrl": "iframe.html"` |
-| `"loglevel"` | Controls level of logging during build. Can be one of: [trace, debug, info (default), warn, error, silent]. `"loglevel": "info"` |
-| `"sourceMap"` | Configure [sourcemaps](https://angular.dev/reference/configs/workspace-config#source-map-configuration.). `"sourceMap": true` |
-| `"experimentalZoneless"` | Configure [zoneless change detection](https://angular.dev/guide/zoneless). `"experimentalZoneless": true` |
+| Configuration element | Description |
+| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `"browserTarget"` | Build target to be served using the following format. `"example-project:builder:config"` |
+| `"debugWebpack"` | Debug the Webpack configuration `"debugWebpack": true` |
+| `"tsConfig"` | Location of the TypeScript configuration file relative to the current workspace. `"tsConfig": "./tsconfig.json"`. |
+| `"preserveSymlinks"` | Do not use the real path when resolving modules. If true, symlinks are resolved to their real path; otherwise, they are resolved to their symlinked path. `"preserveSymlinks": true` |
+| `"port"` | Port used by Storybook. `"port": 6006` |
+| `"host"` | Set up a custom host for Storybook. `"host": "http://my-custom-host"` |
+| `"configDir"` | Storybook configuration directory location. `"configDir": ".storybook"` |
+| `"https"` | Starts Storybook with HTTPS enabled. `"https": true` Requires custom certificate information. |
+| `"sslCa"` | Provides an SSL certificate authority. `"sslCa": "your-custom-certificate-authority"` Optional usage with `"https"` |
+| `"sslCert"` | Provides an SSL certificate. `"sslCert": "your-custom-certificate"` Required for `https` |
+| `"sslKey"` | Provides an SSL key to serve Storybook. `"sslKey": "your-ssl-key"` |
+| `"smokeTest"` | Exit Storybook after successful start. `"smokeTest": true` |
+| `"ci"` | Starts Storybook in CI mode (skips interactive prompts and will not open browser window). `"ci": true` |
+| `"open"` | Whether to open Storybook automatically in the browser. `"open": true` |
+| `"quiet"` | Filters Storybook verbose build output. `"quiet": true` |
+| `"enableProdMode"` | Disable Angular's development mode, which turns off assertions and other checks within the framework. `"enableProdMode": true` |
+| `"docs"` | Starts Storybook in [documentation mode](../../writing-docs/build-documentation.mdx#preview-storybooks-documentation). `"docs": true` |
+| `"compodoc"` | Execute compodoc before. `"compodoc": true` |
+| `"compodocArgs"` | Compodoc [options](https://compodoc.app/guides/options.html). Options `-p` with tsconfig path and `-d` with workspace root is always given. `"compodocArgs": ["-e", "json"]` |
+| `"styles"` | Provide the location of the [application's styles](../../configure/styling-and-css.mdx#global-styles) to be used with Storybook. `"styles": ["src/styles.css", "src/styles.scss"]` |
+| `"stylePreprocessorOptions"` | Provides further customization for style preprocessors resolved to the workspace root. `"stylePreprocessorOptions": { "includePaths": ["src/styles"] }` |
+| `"assets"` | List of static application assets. `"assets": ["src/assets"]` |
+| `"initialPath"` | URL path to be appended when visiting Storybook for the first time. `"initialPath": "docs/configure-your-project--docs"` |
+| `"webpackStatsJson"` | Write Webpack Stats JSON to disk. `"webpackStatsJson": true` |
+| `"previewUrl"` | Disables the default storybook preview and lets you use your own. `"previewUrl": "iframe.html"` |
+| `"loglevel"` | Controls level of logging during build. Can be one of: [trace, debug, info (default), warn, error, silent]. `"loglevel": "info"` |
+| `"sourceMap"` | Configure [sourcemaps](https://angular.dev/reference/configs/workspace-config#source-map-configuration.). `"sourceMap": true` |
+| `"experimentalZoneless"` | Configure [zoneless change detection](https://angular.dev/guide/zoneless). `"experimentalZoneless": true` |
The full list of options can be found in the Angular builder schemas:
-* [Build Storybook](https://github.com/storybookjs/storybook/blob/next/code/frameworks/angular/build-schema.json)
-* [Start Storybook](https://github.com/storybookjs/storybook/blob/next/code/frameworks/angular/start-schema.json)
+- [Build Storybook](https://github.com/storybookjs/storybook/blob/next/code/frameworks/angular/build-schema.json)
+- [Start Storybook](https://github.com/storybookjs/storybook/blob/next/code/frameworks/angular/start-schema.json)
## API
diff --git a/docs/get-started/frameworks/index.mdx b/docs/get-started/frameworks/index.mdx
index 950f5632d36c..078524996091 100644
--- a/docs/get-started/frameworks/index.mdx
+++ b/docs/get-started/frameworks/index.mdx
@@ -2,10 +2,8 @@
title: Frameworks
sidebar:
order: 3
- title: Frameworks
---
-
## Supported frameworks
@@ -14,4 +12,4 @@ sidebar:
Storybook includes an active community that supports additional frameworks and libraries. These community-maintained frameworks are actively developed and maintained by community contributors.
-
\ No newline at end of file
+
diff --git a/docs/get-started/frameworks/nextjs-vite.mdx b/docs/get-started/frameworks/nextjs-vite.mdx
index db766a676e0b..c28892d5f9c0 100644
--- a/docs/get-started/frameworks/nextjs-vite.mdx
+++ b/docs/get-started/frameworks/nextjs-vite.mdx
@@ -18,31 +18,35 @@ You can then get started [writing stories](../whats-a-story.mdx), [running tests
### Requirements
-
+
## Choose between Vite and Webpack
This Vite-based framework offers several advantages over the Webpack-based [`@storybook/nextjs`](./nextjs.mdx) framework, and is the recommended option:
-* ⚡ **Faster builds** - Vite's build system is significantly faster than Webpack
-* 🔧 **Modern tooling** - Uses the latest build tools and optimizations
-* 🧪 **Better test support** - Full support for the [Vitest addon](../../writing-tests/integrations/vitest-addon/index.mdx) and other testing features
-* 📦 **Simpler configuration** - No need for Babel or complex Webpack configurations
-* 🎯 **Better development experience** - Faster Hot Module Replacement and dev server startup
+- ⚡ **Faster builds** - Vite's build system is significantly faster than Webpack
+- 🔧 **Modern tooling** - Uses the latest build tools and optimizations
+- 🧪 **Better test support** - Full support for the [Vitest addon](../../writing-tests/integrations/vitest-addon/index.mdx) and other testing features
+- 📦 **Simpler configuration** - No need for Babel or complex Webpack configurations
+- 🎯 **Better development experience** - Faster Hot Module Replacement and dev server startup
Storybook will automatically detect your project and select the `nextjs-vite` framework **unless** your project has custom Webpack or Babel configurations. If you have custom configurations, Storybook will ask you which framework to install.
Choose `nextjs-vite` if you're willing to migrate existing Babel or Webpack configurations to Vite. Choose `nextjs` (Webpack 5) if you need to keep your existing Webpack/Babel setup.
-
## Run Storybook
To run Storybook for a particular project, run the following:
@@ -59,14 +63,14 @@ You will find the output in the configured `outputDir` (default is `storybook-st
Storybook for Next.js with Vite supports many Next.js features including:
-* 🖼 [Image optimization](#nextjss-image-component)
-* 🔤 [Font optimization](#nextjs-font-optimization)
-* 🔀 [Routing and navigation](#nextjs-routing)
-* 🌐 [`next/head`](#nextjs-head)
-* ⤵️ [Absolute imports](#imports)
-* 🎨 [Styling](#styling)
-* 🎭 [Module mocking](#mocking-modules)
-* ☁️ [React Server Component (experimental)](#react-server-components-rsc)
+- 🖼 [Image optimization](#nextjss-image-component)
+- 🔤 [Font optimization](#nextjs-font-optimization)
+- 🔀 [Routing and navigation](#nextjs-routing)
+- 🌐 [`next/head`](#nextjs-head)
+- ⤵️ [Absolute imports](#imports)
+- 🎨 [Styling](#styling)
+- 🎭 [Module mocking](#mocking-modules)
+- ☁️ [React Server Component (experimental)](#react-server-components-rsc)
### Next.js's Image component
@@ -143,11 +147,11 @@ The Vite-based framework automatically handles font path mapping, so you don't n
The following features are not supported (yet). Support for these features might be planned for the future:
-* [Support font loaders configuration in next.config.js](https://nextjs.org/docs/pages/building-your-application/optimizing/fonts#local-fonts)
-* [fallback](https://nextjs.org/docs/pages/api-reference/components/font#fallback) option
-* [adjustFontFallback](https://nextjs.org/docs/pages/api-reference/components/font#adjustfontfallback) option
-* [preload](https://nextjs.org/docs/pages/api-reference/components/font#preload) option gets ignored. Storybook handles Font loading its own way.
-* [display](https://nextjs.org/docs/pages/api-reference/components/font#display) option gets ignored. All fonts are loaded with display set to "block" to make Storybook load the font properly.
+- [Support font loaders configuration in next.config.js](https://nextjs.org/docs/pages/building-your-application/optimizing/fonts#local-fonts)
+- [fallback](https://nextjs.org/docs/pages/api-reference/components/font#fallback) option
+- [adjustFontFallback](https://nextjs.org/docs/pages/api-reference/components/font#adjustfontfallback) option
+- [preload](https://nextjs.org/docs/pages/api-reference/components/font#preload) option gets ignored. Storybook handles Font loading its own way.
+- [display](https://nextjs.org/docs/pages/api-reference/components/font#display) option gets ignored. All fonts are loaded with display set to "block" to make Storybook load the font properly.
#### Mocking fonts during testing
@@ -197,7 +201,7 @@ module.exports = {
[Next.js's router](https://nextjs.org/docs/pages/building-your-application/routing) is automatically stubbed for you so that when the router is interacted with, all of its interactions are automatically logged to the [Actions panel](../../essentials/actions.mdx).
-
+
You should only use `next/router` in the `pages` directory. In the `app` directory, it is necessary to use `next/navigation`.
@@ -207,13 +211,9 @@ You should only use `next/router` in the `pages` directory. In the `app` directo
Per-story overrides can be done by adding a `nextjs.router` property onto the story [parameters](../../writing-stories/parameters.mdx). The framework will shallowly merge whatever you put here into the router.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
-
+
These overrides can also be applied to [all stories for a component](../../api/parameters.mdx#meta-parameters) or [all stories in your project](../../api/parameters.mdx#project-parameters). Standard [parameter inheritance](../../api/parameters.mdx#parameter-inheritance) rules apply.
@@ -248,7 +248,7 @@ To override these defaults, you can use [parameters](../../writing-stories/param
### Next.js navigation
-
+
Please note that [`next/navigation`](https://nextjs.org/docs/app/building-your-application/routing) can only be used in components/pages in the `app` directory.
@@ -258,31 +258,19 @@ Please note that [`next/navigation`](https://nextjs.org/docs/app/building-your-a
If your story imports components that use `next/navigation`, you need to set the parameter `nextjs.appDirectory` to `true` in for that component's stories:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
If your Next.js project uses the `app` directory for every page (in other words, it does not have a `pages` directory), you can set the parameter `nextjs.appDirectory` to `true` in the [`.storybook/preview.tsx`](../../configure/index.mdx#configure-story-rendering) file to apply it to all stories.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### Overriding defaults
Per-story overrides can be done by adding a `nextjs.navigation` property onto the story [parameters](../../writing-stories/parameters.mdx). The framework will shallowly merge whatever you put here into the router.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
-
+
These overrides can also be applied to [all stories for a component](../../api/parameters.mdx#meta-parameters) or [all stories in your project](../../api/parameters.mdx#project-parameters). Standard [parameter inheritance](../../api/parameters.mdx#parameter-inheritance) rules apply.
@@ -292,8 +280,6 @@ These overrides can also be applied to [all stories for a component](../../api/p
The `useSelectedLayoutSegment`, `useSelectedLayoutSegments`, and `useParams` hooks are supported in Storybook. You have to set the `nextjs.navigation.segments` parameter to return the segments or the params you want to use.
-{/* prettier-ignore-start */}
-
With the above configuration, the component rendered in the stories would receive the following values from the hooks:
@@ -309,16 +295,10 @@ export default function NavigationBasedComponent() {
}
```
-{/* prettier-ignore-end */}
-
To use `useParams`, you have to use a segments array where each element is an array containing two strings. The first string is the param key and the second string is the param value.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
With the above configuration, the component rendered in the stories would receive the following values from the hooks:
```js title="ParamsBasedComponent.js"
@@ -332,7 +312,7 @@ export default function ParamsBasedComponent() {
}
```
-
+
These overrides can also be applied to [a single story](../../api/parameters.mdx#story-parameters) or [all stories in your project](../../api/parameters.mdx#project-parameters). Standard [parameter inheritance](../../api/parameters.mdx#parameter-inheritance) rules apply.
@@ -362,67 +342,47 @@ To override these defaults, you can use [parameters](../../writing-stories/param
[`next/head`](https://nextjs.org/docs/pages/api-reference/components/head) is supported out of the box. You can use it in your stories like you would in your Next.js application. Please keep in mind, that the Head `children` are placed into the head element of the iframe that Storybook uses to render your stories.
-
## Next.js styling
### Sass/Scss
[Global Sass/SCSS stylesheets](https://nextjs.org/docs/pages/building-your-application/styling/sass) are also supported without any additional configuration. Just import them into [the preview config file](../../configure/index.mdx#configure-story-rendering).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
This will automatically include any of your [custom Sass configurations](https://nextjs.org/docs/pages/building-your-application/styling/sass#customizing-sass-options) in your Next.js config file.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### CSS/Sass/Scss Modules
[CSS modules](https://nextjs.org/docs/pages/building-your-application/styling/css-modules) work as expected.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Styled JSX
The built-in CSS-in-JS solution for Next.js is [styled-jsx](https://nextjs.org/docs/pages/building-your-application/styling/css-in-js), and this framework supports that out of the box, too, with zero config.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Tailwind
Tailwind in Next.js [is supported via PostCSS](https://nextjs.org/docs/app/getting-started/css#tailwind-css). Storybook will automatically handle the PostCSS config for you, including any custom PostCSS configuration, so that you can import your global CSS directly into [the preview config file](../../configure/index.mdx#configure-story-rendering):
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### PostCSS
Next.js lets you [customize PostCSS config](https://nextjs.org/docs/pages/building-your-application/configuring/post-css). Thus this framework will automatically handle your PostCSS config for you.
### Imports
+
#### Absolute imports
[Absolute imports](https://nextjs.org/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases#absolute-imports) from the root directory are supported.
-```jsx title="index.*"
+```jsx title="index.tsx"
// All good!
import Button from 'components/button';
// Also good!
@@ -456,7 +416,7 @@ Absolute imports **cannot** be mocked in stories/tests. See the [Mocking modules
[Module aliases](https://nextjs.org/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases#module-aliases) are also supported.
-```jsx title="index.*"
+```jsx title="index.tsx"
// All good!
import Button from '@/components/button';
// Also good!
@@ -494,7 +454,7 @@ Because subpath imports replace module aliases, you can remove the path aliases
Which can then be used like this:
-```jsx title="index.*"
+```jsx title="index.tsx"
import Button from '#components/button';
import styles from '#styles/HomePage.module.css';
@@ -554,8 +514,8 @@ Calls to `getConfig` would return the following object when called within Storyb
{
"serverRuntimeConfig": {},
"publicRuntimeConfig": {
- "staticFolder": "/static"
- }
+ "staticFolder": "/static",
+ },
}
```
@@ -588,22 +548,14 @@ If your app uses [React Server Components (RSC)](https://nextjs.org/docs/app/bui
To enable this set the `experimentalRSC` feature flag in your `.storybook/main.js|ts` config:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Setting this flag automatically wraps your story in a [Suspense](https://react.dev/reference/react/Suspense) wrapper, which is able to render asynchronous components in NextJS's version of React.
If this wrapper causes problems in any of your existing stories, you can selectively disable it using the `react.rsc` [parameter](../../writing-stories/parameters.mdx) at the global/component/story level:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Note that wrapping your server components in Suspense does not help if your server components access server-side resources like the file system or Node-specific libraries. To work around this, you'll need to mock out your data access layer using [Vite aliases](https://vitejs.dev/config/shared-options.html#resolve-alias) or an addon like [storybook-addon-module-mock](https://storybook.js.org/addons/storybook-addon-module-mock).
If your server components access data via the network, we recommend using the [MSW Storybook Addon](https://storybook.js.org/addons/msw-storybook-addon) to mock network requests.
@@ -638,20 +590,12 @@ If your project has custom Webpack configurations in `.storybook/main.js|ts` (vi
First, install the framework:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Then, update your `.storybook/main.js|ts` to change the framework property:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
If your Storybook configuration contains custom Webpack operations in [`webpackFinal`](../../api/main-config/main-config-webpack-final.mdx), you will likely need to create equivalents in [`viteFinal`](../../api/main-config/main-config-vite-final.mdx).
@@ -662,12 +606,8 @@ For more information, see the [Vite builder documentation](../../builders/vite.m
Finally, if you were using Storybook plugins to integrate with Next.js, those are no longer necessary when using this framework and can be removed:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Stories for pages/components which fetch data
Next.js pages can fetch data directly within server components in the `app` directory, which often include module imports that only run in a node environment. This does not (currently) work within Storybook, because if you import from a Next.js page file containing those node module imports in your stories, your Storybook's Vite build will crash because those modules will not run in a browser. To get around this, you can extract the component in your page file into a separate file and import that pure component in your stories. Or, if that's not feasible for some reason, you can [configure Vite to handle those modules](https://vitejs.dev/config/dep-optimization-options.html#optimizedeps-exclude) in your Storybook's [`viteFinal` configuration](../../builders/vite.mdx#configuration).
@@ -718,7 +658,7 @@ Before using this framework, image imports would import the raw path to the imag
"src": "static/media/stories/assets/logo.svg",
"height": 48,
"width": 48,
- "blurDataURL": "static/media/stories/assets/logo.svg"
+ "blurDataURL": "static/media/stories/assets/logo.svg",
}
```
@@ -748,10 +688,10 @@ You can refer to the [Install `sharp` to Use Built-In Image Optimization](https:
We recommend using `@storybook/nextjs-vite` (this framework) for most projects because it offers:
-* Faster builds and development server startup
-* Better support for modern testing features like the [Vitest addon](../../writing-tests/integrations/vitest-addon/index.mdx)
-* Simpler configuration without Babel
-* Better developer experience with faster HMR
+- Faster builds and development server startup
+- Better support for modern testing features like the [Vitest addon](../../writing-tests/integrations/vitest-addon/index.mdx)
+- Simpler configuration without Babel
+- Better developer experience with faster HMR
However, if your project has custom Webpack configurations that are incompatible with Vite, or you need specific Webpack features, you should use [`@storybook/nextjs`](./nextjs.mdx) (Webpack 5) instead.
@@ -767,58 +707,42 @@ Type: `typeof import('next/cache')`
This module exports mocked implementations of the `next/cache` module's exports. You can use it to create your own mock implementations or assert on mock calls in a story's [play function](../../writing-stories/play-function.mdx).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### `@storybook/nextjs-vite/headers.mock`
Type: [`cookies`](https://nextjs.org/docs/app/api-reference/functions/cookies#cookiessetname-value-options), [`headers`](https://nextjs.org/docs/app/api-reference/functions/headers) and [`draftMode`](https://nextjs.org/docs/app/api-reference/functions/draft-mode) from Next.js
-This module exports *writable* mocked implementations of the `next/headers` module's exports. You can use it to set up cookies or headers that are read in your story, and to later assert that they have been called.
+This module exports _writable_ mocked implementations of the `next/headers` module's exports. You can use it to set up cookies or headers that are read in your story, and to later assert that they have been called.
Next.js's default [`headers()`](https://nextjs.org/docs/app/api-reference/functions/headers) export is read-only, but this module exposes methods allowing you to write to the headers:
-* **`headers().append(name: string, value: string)`**: Appends the value to the header if it exists already.
-* **`headers().delete(name: string)`**: Deletes the header
-* **`headers().set(name: string, value: string)`**: Sets the header to the value provided.
+- **`headers().append(name: string, value: string)`**: Appends the value to the header if it exists already.
+- **`headers().delete(name: string)`**: Deletes the header
+- **`headers().set(name: string, value: string)`**: Sets the header to the value provided.
For cookies, you can use the existing API to write them. E.g., `cookies().set('firstName', 'Jane')`.
Because `headers()`, `cookies()` and their sub-functions are all mocks you can use any [mock utilities](https://vitest.dev/api/mock.html) in your stories, like `headers().getAll.mock.calls`.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### `@storybook/nextjs-vite/navigation.mock`
Type: `typeof import('next/navigation') & getRouter: () => ReturnType`
This module exports mocked implementations of the `next/navigation` module's exports. It also exports a `getRouter` function that returns a mocked version of [Next.js's `router` object from `useRouter`](https://nextjs.org/docs/app/api-reference/functions/use-router#userouter), allowing the properties to be manipulated and asserted on. You can use it mock implementations or assert on mock calls in a story's [play function](../../writing-stories/play-function.mdx).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### `@storybook/nextjs-vite/router.mock`
Type: `typeof import('next/router') & getRouter: () => ReturnType`
This module exports mocked implementations of the `next/router` module's exports. It also exports a `getRouter` function that returns a mocked version of [Next.js's `router` object from `useRouter`](https://nextjs.org/docs/pages/api-reference/functions/use-router#router-object), allowing the properties to be manipulated and asserted on. You can use it mock implementations or assert on mock calls in a story's [play function](../../writing-stories/play-function.mdx).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Options
You can pass an options object for additional configuration if needed:
@@ -893,4 +817,3 @@ Type:
```
The router object that is passed to the `next/router` context. See [Next.js's router docs](https://nextjs.org/docs/pages/building-your-application/routing) for more details.
-
diff --git a/docs/get-started/frameworks/nextjs.mdx b/docs/get-started/frameworks/nextjs.mdx
index 301f6a0b25f7..cd8f6b327270 100644
--- a/docs/get-started/frameworks/nextjs.mdx
+++ b/docs/get-started/frameworks/nextjs.mdx
@@ -13,9 +13,11 @@ Storybook for Next.js (Webpack) is a [framework](../../contribute/framework.mdx)
**We recommend using [`@storybook/nextjs-vite`](./nextjs-vite.mdx)** for most Next.js projects. The Vite-based framework is faster, more modern, and offers better support for testing features.
Use this Webpack-based framework (`@storybook/nextjs`) only if:
+
- Your project has custom Webpack configurations that are incompatible with Vite
- Your project has custom Babel configurations that require Webpack
- You need specific Webpack features not available in Vite
+
## Install
@@ -30,15 +32,20 @@ You can then get started [writing stories](../whats-a-story.mdx), [running tests
### Requirements
-
+
## Run Storybook
@@ -54,16 +61,16 @@ You will find the output in the configured `outputDir` (default is `storybook-st
## Configure
-Storybook for Next.js with Vite supports many Next.js features including:
+Storybook for Next.js supports many Next.js features including:
-* 🖼 [Image optimization](#nextjss-image-component)
-* 🔤 [Font optimization](#nextjs-font-optimization)
-* 🔀 [Routing and navigation](#nextjs-routing)
-* 🌐 [`next/head`](#nextjs-head)
-* ⤵️ [Absolute imports](#imports)
-* 🎨 [Styling](#styling)
-* 🎭 [Module mocking](#mocking-modules)
-* ☁️ [React Server Component (experimental)](#react-server-components-rsc)
+- 🖼 [Image optimization](#nextjss-image-component)
+- 🔤 [Font optimization](#nextjs-font-optimization)
+- 🔀 [Routing and navigation](#nextjs-routing)
+- 🌐 [`next/head`](#nextjs-head)
+- ⤵️ [Absolute imports](#imports)
+- 🎨 [Styling](#styling)
+- 🎭 [Module mocking](#mocking-modules)
+- ☁️ [React Server Component (experimental)](#react-server-components-rsc)
### Next.js's Image component
@@ -138,21 +145,17 @@ const localRubikStorm = localFont({ src: './fonts/RubikStorm-Regular.ttf' });
You have to tell Storybook where the `fonts` directory is located, via the [`staticDirs` configuration](../../api/main-config/main-config-static-dirs.mdx#with-configuration-objects). The `from` value is relative to the `.storybook` directory. The `to` value is relative to the execution context of Storybook. Very likely it is the root of your project.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### Not supported features of `next/font`
The following features are not supported (yet). Support for these features might be planned for the future:
-* [Support font loaders configuration in next.config.js](https://nextjs.org/docs/pages/building-your-application/optimizing/fonts#local-fonts)
-* [fallback](https://nextjs.org/docs/pages/api-reference/components/font#fallback) option
-* [adjustFontFallback](https://nextjs.org/docs/pages/api-reference/components/font#adjustfontfallback) option
-* [preload](https://nextjs.org/docs/pages/api-reference/components/font#preload) option gets ignored. Storybook handles Font loading its own way.
-* [display](https://nextjs.org/docs/pages/api-reference/components/font#display) option gets ignored. All fonts are loaded with display set to "block" to make Storybook load the font properly.
+- [Support font loaders configuration in next.config.js](https://nextjs.org/docs/pages/building-your-application/optimizing/fonts#local-fonts)
+- [fallback](https://nextjs.org/docs/pages/api-reference/components/font#fallback) option
+- [adjustFontFallback](https://nextjs.org/docs/pages/api-reference/components/font#adjustfontfallback) option
+- [preload](https://nextjs.org/docs/pages/api-reference/components/font#preload) option gets ignored. Storybook handles Font loading its own way.
+- [display](https://nextjs.org/docs/pages/api-reference/components/font#display) option gets ignored. All fonts are loaded with display set to "block" to make Storybook load the font properly.
#### Mocking fonts during testing
@@ -202,22 +205,22 @@ module.exports = {
[Next.js's router](https://nextjs.org/docs/pages/building-your-application/routing) is automatically stubbed for you so that when the router is interacted with, all of its interactions are automatically logged to the [Actions panel](../../essentials/actions.mdx).
-
- You should only use `next/router` in the `pages` directory. In the `app` directory, it is necessary to use `next/navigation`.
+
+
+You should only use `next/router` in the `pages` directory. In the `app` directory, it is necessary to use `next/navigation`.
+
#### Overriding defaults
Per-story overrides can be done by adding a `nextjs.router` property onto the story [parameters](../../writing-stories/parameters.mdx). The framework will shallowly merge whatever you put here into the router.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
+
+
+These overrides can also be applied to [all stories for a component](../../api/parameters.mdx#meta-parameters) or [all stories in your project](../../api/parameters.mdx#project-parameters). Standard [parameter inheritance](../../api/parameters.mdx#parameter-inheritance) rules apply.
-
- These overrides can also be applied to [all stories for a component](../../api/parameters.mdx#meta-parameters) or [all stories in your project](../../api/parameters.mdx#project-parameters). Standard [parameter inheritance](../../api/parameters.mdx#parameter-inheritance) rules apply.
#### Default router
@@ -249,48 +252,38 @@ To override these defaults, you can use [parameters](../../writing-stories/param
### Next.js navigation
-
- Please note that [`next/navigation`](https://nextjs.org/docs/app/building-your-application/routing) can only be used in components/pages in the `app` directory.
+
+
+Please note that [`next/navigation`](https://nextjs.org/docs/app/building-your-application/routing) can only be used in components/pages in the `app` directory.
+
#### Set `nextjs.appDirectory` to `true`
If your story imports components that use `next/navigation`, you need to set the parameter `nextjs.appDirectory` to `true` in for that component's stories:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
If your Next.js project uses the `app` directory for every page (in other words, it does not have a `pages` directory), you can set the parameter `nextjs.appDirectory` to `true` in the [`.storybook/preview.tsx`](../../configure/index.mdx#configure-story-rendering) file to apply it to all stories.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### Overriding defaults
Per-story overrides can be done by adding a `nextjs.navigation` property onto the story [parameters](../../writing-stories/parameters.mdx). The framework will shallowly merge whatever you put here into the router.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
+
+
+These overrides can also be applied to [all stories for a component](../../api/parameters.mdx#meta-parameters) or [all stories in your project](../../api/parameters.mdx#project-parameters). Standard [parameter inheritance](../../api/parameters.mdx#parameter-inheritance) rules apply.
-
- These overrides can also be applied to [all stories for a component](../../api/parameters.mdx#meta-parameters) or [all stories in your project](../../api/parameters.mdx#project-parameters). Standard [parameter inheritance](../../api/parameters.mdx#parameter-inheritance) rules apply.
#### `useSelectedLayoutSegment`, `useSelectedLayoutSegments`, and `useParams` hooks
The `useSelectedLayoutSegment`, `useSelectedLayoutSegments`, and `useParams` hooks are supported in Storybook. You have to set the `nextjs.navigation.segments` parameter to return the segments or the params you want to use.
-{/* prettier-ignore-start */}
-
With the above configuration, the component rendered in the stories would receive the following values from the hooks:
@@ -306,16 +299,10 @@ export default function NavigationBasedComponent() {
}
```
-{/* prettier-ignore-end */}
-
To use `useParams`, you have to use a segments array where each element is an array containing two strings. The first string is the param key and the second string is the param value.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
With the above configuration, the component rendered in the stories would receive the following values from the hooks:
```js title="ParamsBasedComponent.js"
@@ -329,8 +316,10 @@ export default function ParamsBasedComponent() {
}
```
-
- These overrides can also be applied to [a single story](../../api/parameters.mdx#story-parameters) or [all stories in your project](../../api/parameters.mdx#project-parameters). Standard [parameter inheritance](../../api/parameters.mdx#parameter-inheritance) rules apply.
+
+
+These overrides can also be applied to [a single story](../../api/parameters.mdx#story-parameters) or [all stories in your project](../../api/parameters.mdx#project-parameters). Standard [parameter inheritance](../../api/parameters.mdx#parameter-inheritance) rules apply.
+
The default value of `nextjs.navigation.segments` is `[]` if not set.
@@ -363,40 +352,24 @@ To override these defaults, you can use [parameters](../../writing-stories/param
[Global Sass/SCSS stylesheets](https://nextjs.org/docs/pages/building-your-application/styling/sass) are also supported without any additional configuration. Just import them into [the preview config file](../../configure/index.mdx#configure-story-rendering).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
This will automatically include any of your [custom Sass configurations](https://nextjs.org/docs/pages/building-your-application/styling/sass#customizing-sass-options) in your Next.js config file.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### CSS/Sass/Scss Modules
[CSS modules](https://nextjs.org/docs/pages/building-your-application/styling/css-modules) work as expected.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Styled JSX
The built-in CSS-in-JS solution for Next.js is [styled-jsx](https://nextjs.org/docs/pages/building-your-application/styling/css-in-js), and this framework supports that out of the box, too, with zero config.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
You can use your own Babel config, too. This is an example of how you can customize styled-jsx.
```jsonc
@@ -407,11 +380,11 @@ You can use your own Babel config, too. This is an example of how you can custom
"next/babel",
{
"styled-jsx": {
- "plugins": ["@styled-jsx/plugin-sass"]
- }
- }
- ]
- ]
+ "plugins": ["@styled-jsx/plugin-sass"],
+ },
+ },
+ ],
+ ],
}
```
@@ -419,17 +392,14 @@ You can use your own Babel config, too. This is an example of how you can custom
Tailwind in Next.js [is supported via PostCSS](https://nextjs.org/docs/app/getting-started/css#tailwind-css). Storybook will automatically handle the PostCSS config for you, including any custom PostCSS configuration, so that you can import your global CSS directly into [the preview config file](../../configure/index.mdx#configure-story-rendering):
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### PostCSS
Next.js lets you [customize PostCSS config](https://nextjs.org/docs/pages/building-your-application/configuring/post-css). Thus this framework will automatically handle your PostCSS config for you.
### Imports
+
#### Absolute imports
[Absolute imports](https://nextjs.org/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases#absolute-imports) from the root directory are supported.
@@ -459,7 +429,9 @@ import 'styles/globals.scss';
```
- Absolute imports **cannot** be mocked in stories/tests. See the [Mocking modules](#mocking-modules) section for more information.
+
+Absolute imports **cannot** be mocked in stories/tests. See the [Mocking modules](#mocking-modules) section for more information.
+
#### Module aliases
@@ -497,7 +469,9 @@ To configure subpath imports, you define the `imports` property in your project'
```
- Because subpath imports replace module aliases, you can remove the path aliases from your TypeScript configuration.
+
+Because subpath imports replace module aliases, you can remove the path aliases from your TypeScript configuration.
+
Which can then be used like this:
@@ -562,8 +536,8 @@ Calls to `getConfig` would return the following object when called within Storyb
{
"serverRuntimeConfig": {},
"publicRuntimeConfig": {
- "staticFolder": "/static"
- }
+ "staticFolder": "/static",
+ },
}
```
@@ -571,18 +545,14 @@ Calls to `getConfig` would return the following object when called within Storyb
Next.js comes with a lot of things for free out of the box like Sass support, but sometimes you add [custom Webpack config modifications to Next.js](https://nextjs.org/docs/pages/api-reference/next-config-js/webpack). This framework takes care of most of the Webpack modifications you would want to add. If Next.js supports a feature out of the box, then that feature will work out of the box in Storybook. If Next.js doesn't support something out of the box, but makes it easy to configure, then this framework will do the same for that thing for Storybook.
-Any Webpack modifications desired for Storybook should be made in [`.storybook/main.js|ts`](../../builders/webpack.mdx#extending-storybooks-webpack-config).
+Any Webpack modifications desired for Storybook should be made in [`.storybook/main.js|ts`](../../builders/webpack.mdx#override-the-default-configuration).
Note: Not all Webpack modifications are copy/paste-able between `next.config.js` and `.storybook/main.js|ts`. It is recommended to do your research on how to properly make your modification to Storybook's Webpack config and on how [Webpack works](https://webpack.js.org/concepts/).
Below is an example of how to add SVGR support to Storybook with this framework.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Typescript
Storybook handles most [Typescript](https://www.typescriptlang.org/) configurations, but this framework adds additional support for Next.js's support for [Absolute Imports and Module path aliases](https://nextjs.org/docs/pages/building-your-application/configuring/absolute-imports-and-module-aliases). In short, it takes into account your `tsconfig.json`'s [baseUrl](https://www.typescriptlang.org/tsconfig#baseUrl) and [paths](https://www.typescriptlang.org/tsconfig#paths). Thus, a `tsconfig.json` like the one below would work out of the box.
@@ -606,34 +576,20 @@ If your app uses [React Server Components (RSC)](https://nextjs.org/docs/app/bui
To enable this set the `experimentalRSC` feature flag in your `.storybook/main.js|ts` config:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Setting this flag automatically wraps your story in a [Suspense](https://react.dev/reference/react/Suspense) wrapper, which is able to render asynchronous components in NextJS's version of React.
If this wrapper causes problems in any of your existing stories, you can selectively disable it using the `react.rsc` [parameter](../../writing-stories/parameters.mdx) at the global/component/story level:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Note that wrapping your server components in Suspense does not help if your server components access server-side resources like the file system or Node-specific libraries. To work around this, you'll need to mock out your data access layer using [Webpack aliases](https://webpack.js.org/configuration/resolve/#resolvealias) or an addon like [storybook-addon-module-mock](https://storybook.js.org/addons/storybook-addon-module-mock).
If your server components access data via the network, we recommend using the [MSW Storybook Addon](https://storybook.js.org/addons/msw-storybook-addon) to mock network requests.
In the future we will provide better mocking support in Storybook and support for [Server Actions](https://nextjs.org/docs/app/api-reference/functions/server-actions).
-{/* ## Portable stories
-
-You can test your stories in a Jest environment by using the [portable stories](../../api/portable-stories/portable-stories-jest.mdx) API.
-
-When using portable stories with Next.js, you need to mock the Next.js modules on which your components depend. You can use the [`@storybook/nextjs/export-mocks` module](#storybooknextjsexport-mocks) to generate the aliases needed to set up portable stories in a Jest environment. This is needed because, to replicate Next.js configuration, Storybook sets up aliases in Webpack to make testing and developing your components easier. If you make use of the advanced functionality like the built-in mocks for common Next.js modules, you need to set up this aliasing in your Jest environment as well. */}
-
## Notes for Yarn v2 and v3 users
If you're using [Yarn](https://yarnpkg.com/) v2 or v3, you may run into issues where Storybook can't resolve `style-loader` or `css-loader`. For example, you might get errors like:
@@ -651,35 +607,23 @@ This is because those versions of Yarn have different package resolution rules t
First, install the framework:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Then, update your `.storybook/main.js|ts` to change the framework property:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Finally, if you were using Storybook plugins to integrate with Next.js, those are no longer necessary when using this framework and can be removed:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### How do I migrate to the Next.js Vite framework?
Please refer to the [migration instructions for `@storybook/nextjs-vite`](./nextjs-vite.mdx#how-do-i-migrate-from-the-nextjs-webpack-5-addon).
### Stories for pages/components which fetch data
-Next.js pages can fetch data directly within server components in the `app` directory, which often include module imports that only run in a node environment. This does not (currently) work within Storybook, because if you import from a Next.js page file containing those node module imports in your stories, your Storybook's Webpack will crash because those modules will not run in a browser. To get around this, you can extract the component in your page file into a separate file and import that pure component in your stories. Or, if that's not feasible for some reason, you can [polyfill those modules](https://webpack.js.org/configuration/node/) in your Storybook's [`webpackFinal` configuration](../../builders/webpack.mdx#extending-storybooks-webpack-config).
+Next.js pages can fetch data directly within server components in the `app` directory, which often include module imports that only run in a Node.js environment. This does not (currently) work within Storybook, because if you import from a Next.js page file containing those node module imports in your stories, your Storybook's Webpack will crash because those modules will not run in a browser. To get around this, you can extract the component in your page file into a separate file and import that pure component in your stories. Or, if that's not feasible for some reason, you can [polyfill those modules](https://webpack.js.org/configuration/node/) in your Storybook's [`webpackFinal` configuration](../../builders/webpack.mdx#override-the-default-configuration).
**Before**
@@ -727,7 +671,7 @@ Before using this framework, image imports would import the raw path to the imag
"src": "static/media/stories/assets/logo.svg",
"height": 48,
"width": 48,
- "blurDataURL": "static/media/stories/assets/logo.svg"
+ "blurDataURL": "static/media/stories/assets/logo.svg",
}
```
@@ -801,58 +745,42 @@ Type: `typeof import('next/cache')`
This module exports mocked implementations of the `next/cache` module's exports. You can use it to create your own mock implementations or assert on mock calls in a story's [play function](../../writing-stories/play-function.mdx).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### `@storybook/nextjs/headers.mock`
Type: [`cookies`](https://nextjs.org/docs/app/api-reference/functions/cookies#cookiessetname-value-options), [`headers`](https://nextjs.org/docs/app/api-reference/functions/headers) and [`draftMode`](https://nextjs.org/docs/app/api-reference/functions/draft-mode) from Next.js
-This module exports *writable* mocked implementations of the `next/headers` module's exports. You can use it to set up cookies or headers that are read in your story, and to later assert that they have been called.
+This module exports _writable_ mocked implementations of the `next/headers` module's exports. You can use it to set up cookies or headers that are read in your story, and to later assert that they have been called.
Next.js's default [`headers()`](https://nextjs.org/docs/app/api-reference/functions/headers) export is read-only, but this module exposes methods allowing you to write to the headers:
-* **`headers().append(name: string, value: string)`**: Appends the value to the header if it exists already.
-* **`headers().delete(name: string)`**: Deletes the header
-* **`headers().set(name: string, value: string)`**: Sets the header to the value provided.
+- **`headers().append(name: string, value: string)`**: Appends the value to the header if it exists already.
+- **`headers().delete(name: string)`**: Deletes the header
+- **`headers().set(name: string, value: string)`**: Sets the header to the value provided.
For cookies, you can use the existing API to write them. E.g., `cookies().set('firstName', 'Jane')`.
Because `headers()`, `cookies()` and their sub-functions are all mocks you can use any [mock utilities](https://vitest.dev/api/mock.html) in your stories, like `headers().getAll.mock.calls`.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### `@storybook/nextjs/navigation.mock`
Type: `typeof import('next/navigation') & getRouter: () => ReturnType`
This module exports mocked implementations of the `next/navigation` module's exports. It also exports a `getRouter` function that returns a mocked version of [Next.js's `router` object from `useRouter`](https://nextjs.org/docs/app/api-reference/functions/use-router#userouter), allowing the properties to be manipulated and asserted on. You can use it mock implementations or assert on mock calls in a story's [play function](../../writing-stories/play-function.mdx).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### `@storybook/nextjs/router.mock`
Type: `typeof import('next/router') & getRouter: () => ReturnType`
This module exports mocked implementations of the `next/router` module's exports. It also exports a `getRouter` function that returns a mocked version of [Next.js's `router` object from `useRouter`](https://nextjs.org/docs/pages/api-reference/functions/use-router#router-object), allowing the properties to be manipulated and asserted on. You can use it mock implementations or assert on mock calls in a story's [play function](../../writing-stories/play-function.mdx).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Options
You can pass an options object for additional configuration if needed:
diff --git a/docs/get-started/frameworks/preact-vite.mdx b/docs/get-started/frameworks/preact-vite.mdx
index a316186defd2..0c6690fe6791 100644
--- a/docs/get-started/frameworks/preact-vite.mdx
+++ b/docs/get-started/frameworks/preact-vite.mdx
@@ -18,16 +18,20 @@ You can then get started [writing stories](../whats-a-story.mdx), [running tests
### Requirements
-
-
+
## Run Storybook
@@ -42,36 +46,25 @@ To build Storybook, run:
You will find the output in the configured `outputDir` (default is `storybook-static`).
## FAQ
+
### How do I manually install the Preact framework?
First, install the framework:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Then, update your `.storybook/main.js|ts` to change the framework property:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## API
### Options
You can pass an options object for additional configuration if needed:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### `builder`
Type: `Record`
diff --git a/docs/get-started/frameworks/react-native-web-vite.mdx b/docs/get-started/frameworks/react-native-web-vite.mdx
index 9806207aff08..d375f0ce8bfc 100644
--- a/docs/get-started/frameworks/react-native-web-vite.mdx
+++ b/docs/get-started/frameworks/react-native-web-vite.mdx
@@ -9,7 +9,9 @@ sidebar:
Storybook for React Native Web is a [framework](../../contribute/framework.mdx) that makes it easy to develop and test UI components in isolation for [React Native](https://reactnative.dev/). It uses [Vite](https://vitejs.dev/) to build your components for web browsers.
- In addition to React Native Web, Storybook supports on-device [React Native](https://github.com/storybookjs/react-native) development. If you're unsure what's right for you, read our [comparison](#react-native-vs-react-native-web).
+
+In addition to React Native Web, Storybook supports on-device [React Native](https://github.com/storybookjs/react-native) development. If you're unsure what's right for you, read our [comparison](#react-native-vs-react-native-web).
+
## Install
@@ -22,19 +24,25 @@ You can then get started [writing stories](../whats-a-story.mdx), [running tests
### Requirements
-
+
## Run Storybook
@@ -84,11 +92,13 @@ So, which option is right for you?
The easiest way to use React Native and React Native Web is to select the **"Both"** option when installing Storybook. This will install and create configurations for both environments, allowing you to run Storybook for both in the same project.
When you select "Both", the installation will:
+
1. Install and configure React Native Storybook (on-device)
2. Install and configure React Native Web Storybook (web-based)
3. Set up both configurations in your project
After installation, you'll see instructions for both environments:
+
- React Native Storybook will require additional manual configuration steps (replacing app entry, wrapping metro config)
- React Native Web Storybook can be started immediately using the `storybook` command
@@ -102,32 +112,22 @@ The [React Native Web addon](https://github.com/storybookjs/addon-react-native-w
Run the following command to upgrade Storybook to the latest version:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- This framework is designed to work with Storybook 8.5 and above for the best experience. We won't be able to provide support if you're using an older Storybook version.
+
+This framework is designed to work with Storybook 8.5 and above for the best experience. We won't be able to provide support if you're using an older Storybook version.
+
Install the framework and its peer dependencies:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Update your `.storybook/main.js|ts` to change the framework property and remove the `@storybook/addon-react-native-web` addon:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Finally, remove the addon and similar packages (i.e., `@storybook/react-webpack5` and `@storybook/addon-react-native-web`) from your project.
## API
@@ -156,7 +156,7 @@ const config: StorybookConfig = {
presets: Array,
// ... other compatible babel options
}
- include: Array,
+ include: Array,
exclude: Array,
// ... other compatible @vitejs/plugin-react options
}
@@ -166,6 +166,7 @@ const config: StorybookConfig = {
export default config;
```
+
#### Example configuration for reanimated
```ts title=".storybook/main.ts"
@@ -173,13 +174,13 @@ const config: StorybookConfig = {
// ... rest of config
framework: {
- name: "@storybook/react-native-web-vite",
+ name: '@storybook/react-native-web-vite',
options: {
pluginReactOptions: {
babel: {
plugins: [
- "@babel/plugin-proposal-export-namespace-from",
- "react-native-reanimated/plugin",
+ '@babel/plugin-proposal-export-namespace-from',
+ 'react-native-reanimated/plugin',
],
},
},
@@ -187,25 +188,24 @@ const config: StorybookConfig = {
},
// ... rest of config
-}
+};
```
#### Example configuration for nativewind
```ts title=".storybook/main.ts"
-
const config: StorybookConfig = {
// ... rest of config
framework: {
- name: "@storybook/react-native-web-vite",
+ name: '@storybook/react-native-web-vite',
options: {
pluginReactOptions: {
- jsxImportSource: "nativewind",
+ jsxImportSource: 'nativewind',
},
},
},
-}
+};
```
#### Example configuration to transpile additional node_modules
@@ -218,12 +218,12 @@ const config: StorybookConfig = {
// ... rest of config
framework: {
- name: "@storybook/react-native-web-vite",
+ name: '@storybook/react-native-web-vite',
options: {
modulesToTranspile: ['my-library'],
},
},
-}
+};
```
#### `builder`
diff --git a/docs/get-started/frameworks/react-vite.mdx b/docs/get-started/frameworks/react-vite.mdx
index c04f4e4ffcba..310aa514364c 100644
--- a/docs/get-started/frameworks/react-vite.mdx
+++ b/docs/get-started/frameworks/react-vite.mdx
@@ -18,15 +18,20 @@ You can then get started [writing stories](../whats-a-story.mdx), [running tests
### Requirements
-
+
## Run Storybook
@@ -41,48 +46,33 @@ To build Storybook, run:
You will find the output in the configured `outputDir` (default is `storybook-static`).
## FAQ
+
### How do I migrate from the React Webpack framework?
The `upgrade` command should prompt you to migrate to `@storybook/react-vite` when you run it:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
In case that auto-migration does not work for your project, refer to the manual installation instructions below.
### How do I manually install the React framework?
First, install the framework:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Then, update your `.storybook/main.js|ts` to change the framework property:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## API
### Options
You can pass an options object for additional configuration if needed:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### `builder`
Type: `Record`
diff --git a/docs/get-started/frameworks/react-webpack5.mdx b/docs/get-started/frameworks/react-webpack5.mdx
index c37cf6bdec7f..67f11ecdc3dc 100644
--- a/docs/get-started/frameworks/react-webpack5.mdx
+++ b/docs/get-started/frameworks/react-webpack5.mdx
@@ -13,6 +13,7 @@ Storybook for React & Webpack is a [framework](../../contribute/framework.mdx) t
**We recommend using [`@storybook/react-vite`](./react-vite.mdx)** for most React projects. The Vite-based framework is faster, more modern, and offers better support for testing features.
Use this Webpack-based framework (`@storybook/react-webpack5`) only if you need specific Webpack features not available in Vite.
+
## Install
@@ -25,15 +26,20 @@ You can then get started [writing stories](../whats-a-story.mdx), [running tests
### Requirements
-
+
## Run Storybook
@@ -65,42 +71,28 @@ If you're working on an app that was initialized manually (i.e., without the use
First, install the framework:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Next, install and register your appropriate compiler addon, depending on whether you're using SWC (recommended) or Babel:
- If your project is using [Create React App](#create-react-app-cra), you can skip this step.
-
-{/* prettier-ignore-start */}
+If your project is using [Create React App](#create-react-app-cra), you can skip this step.
-
+
-{/* prettier-ignore-end */}
+
or
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
More details can be found in the [Webpack builder docs](../../builders/webpack.mdx#compiler-support).
Finally, update your `.storybook/main.js|ts` to change the framework property:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### How do I migrate to the React Vite framework?
Please refer to the [migration instructions for `@storybook/react-vite`](./react-vite.mdx#how-do-i-migrate-from-the-react-webpack-framework).
@@ -111,12 +103,8 @@ Please refer to the [migration instructions for `@storybook/react-vite`](./react
You can pass an options object for additional configuration if needed:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### `builder`
Type: `Record`
diff --git a/docs/get-started/frameworks/svelte-vite.mdx b/docs/get-started/frameworks/svelte-vite.mdx
index f5d8408e815c..8d1ddbfcdd2b 100644
--- a/docs/get-started/frameworks/svelte-vite.mdx
+++ b/docs/get-started/frameworks/svelte-vite.mdx
@@ -18,15 +18,20 @@ You can then get started [writing stories](../whats-a-story.mdx), [running tests
### Requirements
-
+
## Run Storybook
@@ -45,7 +50,9 @@ You will find the output in the configured `outputDir` (default is `storybook-st
Storybook provides a Svelte [addon](https://storybook.js.org/addons/@storybook/addon-svelte-csf) maintained by the community, enabling you to write stories for your Svelte components using the template syntax.
- The community actively maintains the Svelte CSF addon but still lacks some features currently available in the official Storybook Svelte framework support. For more information, see the [addon's documentation](https://github.com/storybookjs/addon-svelte-csf).
+
+The community actively maintains the Svelte CSF addon but still lacks some features currently available in the official Storybook Svelte framework support. For more information, see the [addon's documentation](https://github.com/storybookjs/addon-svelte-csf).
+
### Setup
@@ -54,43 +61,31 @@ If you initialized your project with the Svelte framework, the addon has already
Run the following command to install the addon.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- The CLI's [`add`](../../api/cli-options.mdx#add) command automates the addon's installation and setup. To install it manually, see our [documentation](../../addons/install-addons.mdx#manual-installation) on how to install addons.
+The CLI's [`add`](../../api/cli-options.mdx#add) command automates the addon's installation and setup. To install it manually, see our [documentation](../../addons/install-addons.mdx#manual-installation) on how to install addons.
Update your Storybook configuration file (i.e., `.storybook/main.js|ts`) to enable support for this format.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Configure
By default, the Svelte [addon](https://storybook.js.org/addons/@storybook/addon-svelte-csf) offers zero-config support for Storybook's Svelte framework. However, you can extend your Storybook configuration file (i.e., `.storybook/main.js|ts`) and provide additional addon options. Listed below are the available options and examples of how to use them.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
-| Options | Description |
+| Options | Description |
| ---------------- | ------------------------------------------------------------------------------------------------------------------ |
| `legacyTemplate` | Enables support for the `Template` component for backward compatibility. `options: { legacyTemplate: true }` |
- Enabling the `legacyTemplate` option can introduce a performance overhead and should be used cautiously. For more information, refer to the [addon's documentation](https://github.com/storybookjs/addon-svelte-csf/blob/next/README.md#legacy-api).
+Enabling the `legacyTemplate` option can introduce a performance overhead and should be used cautiously. For more information, refer to the [addon's documentation](https://github.com/storybookjs/addon-svelte-csf/blob/next/README.md#legacy-api).
@@ -102,25 +97,17 @@ With the Svelte 5 release, Storybook's Svelte CSF addon has been updated to supp
If you are using the `Meta` component or the `meta` named export to define the story's metadata (e.g., [parameters](../../writing-stories/parameters.mdx)), you'll need to update your stories to use the new `defineMeta` function. This function returns an object with the required information, including a `Story` component that you must use to define your component stories.
-{/* prettier-ignore-start */ }
-
-{/* prettier-ignore-end */}
-
#### Story templates
If you used the `Template` component to control how the component renders in the Storybook, this feature was replaced with built-in children support in the `Story` component, enabling you to compose components and define the UI structure directly in the story.
-{/* prettier-ignore-start */ }
-
-{/* prettier-ignore-end */}
-
- If you need support for the `Template` component, the addon provides a feature flag for backward compatibility. For more information, see the [configuration options](#configure).
+If you need support for the `Template` component, the addon provides a feature flag for backward compatibility. For more information, see the [configuration options](#configure).
@@ -150,43 +137,28 @@ With Svelte's slot deprecation and the introduction of reusable [`snippets`](htt
If you enabled automatic documentation generation with the `autodocs` story property, you must replace it with [`tags`](../../writing-stories/tags.mdx). This property allows you to categorize and filter stories based on specific criteria and generate documentation based on the tags applied to the stories.
-{/* prettier-ignore-start */ }
-
-{/* prettier-ignore-end */}
+## FAQ
-## FAQ
### How do I manually install the Svelte framework?
First, install the framework:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Then, update your `.storybook/main.js|ts` to change the framework property:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## API
### Options
You can pass an options object for additional configuration if needed:
-{/* prettier-ignore-start */ }
-
-{/* prettier-ignore-end */}
-
The available options are:
#### `builder`
@@ -203,12 +175,8 @@ Default: `true`
Enables or disables automatic documentation generation for component properties. When disabled, Storybook will skip the docgen processing step during build, which can improve build performance.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### When to disable docgen
Disabling docgen can improve build performance for large projects, but [argTypes won't be inferred automatically](../../api/arg-types.mdx#automatic-argtype-inference), which will prevent features like [Controls](../../essentials/controls.mdx) and [docs](../../writing-docs/autodocs.mdx) from working as expected. To use those features, you will need to [define `argTypes` manually](../../api/arg-types.mdx#manually-specifying-argtypes).
diff --git a/docs/get-started/frameworks/sveltekit.mdx b/docs/get-started/frameworks/sveltekit.mdx
index ff46962f7051..10a03af35389 100644
--- a/docs/get-started/frameworks/sveltekit.mdx
+++ b/docs/get-started/frameworks/sveltekit.mdx
@@ -18,15 +18,20 @@ You can then get started [writing stories](../whats-a-story.mdx), [running tests
### Requirements
-
+
## Run Storybook
@@ -49,32 +54,28 @@ This section covers SvelteKit support and configuration options.
All Svelte language features are supported out of the box, as the Storybook framework uses the Svelte compiler directly.
However, SvelteKit has some [Kit-specific modules](https://kit.svelte.dev/docs/modules) that aren't supported. Here's a breakdown of what will and will not work within Storybook:
-| Module | Status | Note |
-| ---------------------------------------------------------------------------------- | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
-| [`$app/environment`](https://svelte.dev/docs/kit/$app-environment) | ✅ Supported | `version` is always empty in Storybook. |
-| [`$app/forms`](https://svelte.dev/docs/kit/$app-forms) | ⚠️ **Experimental** | See [How to mock](#how-to-mock). |
-| [`$app/navigation`](https://svelte.dev/docs/kit/$app-navigation) | ⚠️ **Experimental** | See [How to mock](#how-to-mock). |
-| [`$app/paths`](https://svelte.dev/docs/kit/$app-paths) | ✅ Supported | Requires SvelteKit 1.4.0 or newer. |
-| [`$app/state`](https://svelte.dev/docs/kit/$app-state) | ⚠️ **Experimental** | Requires SvelteKit `v2.12` or newer. See [How to mock](#how-to-mock). |
-| [`$app/stores`](https://svelte.dev/docs/kit/$app-stores) | ⚠️ **Experimental** | See [How to mock](#how-to-mock). |
-| [`$env/dynamic/public`](https://svelte.dev/docs/kit/$env-dynamic-public) | 🚧 Partially supported | Only supported in development mode. Storybook is built as a static app with no server-side API, so it cannot dynamically serve content. |
-| [`$env/static/public`](https://svelte.dev/docs/kit/$env-static-public) | ✅ Supported | |
-| [`$lib`](https://svelte.dev/docs/kit/$lib) | ✅ Supported | |
-| [`@sveltejs/kit/*`](https://svelte.dev/docs/kit/@sveltejs-kit) | ✅ Supported | |
-| [`$env/dynamic/private`](https://svelte.dev/docs/kit/$env-dynamic-private) | ⛔ Not supported | This is a server-side feature, and Storybook renders all components on the client. |
-| [`$env/static/private`](https://svelte.dev/docs/kit/$env-static-private) | ⛔ Not supported | This is a server-side feature, and Storybook renders all components on the client. |
-| [`$service-worker`](https://svelte.dev/docs/kit/$service-worker) | ⛔ Not supported | This is a service worker feature, which does not apply to Storybook. |
+| Module | Status | Note |
+| -------------------------------------------------------------------------- | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
+| [`$app/environment`](https://svelte.dev/docs/kit/$app-environment) | ✅ Supported | `version` is always empty in Storybook. |
+| [`$app/forms`](https://svelte.dev/docs/kit/$app-forms) | ⚠️ **Experimental** | See [How to mock](#how-to-mock). |
+| [`$app/navigation`](https://svelte.dev/docs/kit/$app-navigation) | ⚠️ **Experimental** | See [How to mock](#how-to-mock). |
+| [`$app/paths`](https://svelte.dev/docs/kit/$app-paths) | ✅ Supported | Requires SvelteKit 1.4.0 or newer. |
+| [`$app/state`](https://svelte.dev/docs/kit/$app-state) | ⚠️ **Experimental** | Requires SvelteKit `v2.12` or newer. See [How to mock](#how-to-mock). |
+| [`$app/stores`](https://svelte.dev/docs/kit/$app-stores) | ⚠️ **Experimental** | See [How to mock](#how-to-mock). |
+| [`$env/dynamic/public`](https://svelte.dev/docs/kit/$env-dynamic-public) | 🚧 Partially supported | Only supported in development mode. Storybook is built as a static app with no server-side API, so it cannot dynamically serve content. |
+| [`$env/static/public`](https://svelte.dev/docs/kit/$env-static-public) | ✅ Supported | |
+| [`$lib`](https://svelte.dev/docs/kit/$lib) | ✅ Supported | |
+| [`@sveltejs/kit/*`](https://svelte.dev/docs/kit/@sveltejs-kit) | ✅ Supported | |
+| [`$env/dynamic/private`](https://svelte.dev/docs/kit/$env-dynamic-private) | ⛔ Not supported | This is a server-side feature, and Storybook renders all components on the client. |
+| [`$env/static/private`](https://svelte.dev/docs/kit/$env-static-private) | ⛔ Not supported | This is a server-side feature, and Storybook renders all components on the client. |
+| [`$service-worker`](https://svelte.dev/docs/kit/$service-worker) | ⛔ Not supported | This is a service worker feature, which does not apply to Storybook. |
### How to mock
To mock a SvelteKit import you can define it within `parameters.sveltekit_experimental`:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
The [available parameters](#parameters) are documented in the API section, below.
#### Mocking links
@@ -83,12 +84,8 @@ The default link-handling behavior (e.g., when clicking an `` el
You can override this by assigning an object to `parameters.sveltekit_experimental.hrefs`, where the keys are strings representing an href, and the values define your mock. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
See the [API reference](#hrefs) for more information.
## Writing native Svelte stories
@@ -96,7 +93,9 @@ See the [API reference](#hrefs) for more information.
Storybook provides a Svelte [addon](https://storybook.js.org/addons/@storybook/addon-svelte-csf) maintained by the community, enabling you to write stories for your Svelte components using the template syntax.
- The community actively maintains the Svelte CSF addon but still lacks some features currently available in the official Storybook Svelte framework support. For more information, see the [addon's documentation](https://github.com/storybookjs/addon-svelte-csf).
+
+The community actively maintains the Svelte CSF addon but still lacks some features currently available in the official Storybook Svelte framework support. For more information, see the [addon's documentation](https://github.com/storybookjs/addon-svelte-csf).
+
### Setup
@@ -105,43 +104,31 @@ If you initialized your project with the Sveltekit framework, the addon has alre
Run the following command to install the addon.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- The CLI's [`add`](../../api/cli-options.mdx#add) command automates the addon's installation and setup. To install it manually, see our [documentation](../../addons/install-addons.mdx#manual-installation) on how to install addons.
+The CLI's [`add`](../../api/cli-options.mdx#add) command automates the addon's installation and setup. To install it manually, see our [documentation](../../addons/install-addons.mdx#manual-installation) on how to install addons.
Update your Storybook configuration file (i.e., `.storybook/main.js|ts`) to enable support for this format.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Configure
By default, the Svelte [addon](https://storybook.js.org/addons/@storybook/addon-svelte-csf) addon offers zero-config support for Storybook's SvelteKit framework. However, you can extend your Storybook configuration file (i.e., `.storybook/main.js|ts`) and provide additional addon options. Listed below are the available options and examples of how to use them.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
-| Options | Description |
+| Options | Description |
| ---------------- | ------------------------------------------------------------------------------------------------------------------ |
| `legacyTemplate` | Enables support for the `Template` component for backward compatibility. `options: { legacyTemplate: true }` |
- Enabling the `legacyTemplate` option can introduce a performance overhead and should be used cautiously. For more information, refer to the [addon's documentation](https://github.com/storybookjs/addon-svelte-csf/blob/next/README.md#legacy-api).
+Enabling the `legacyTemplate` option can introduce a performance overhead and should be used cautiously. For more information, refer to the [addon's documentation](https://github.com/storybookjs/addon-svelte-csf/blob/next/README.md#legacy-api).
@@ -153,25 +140,17 @@ With the Svelte 5 release, Storybook's Svelte CSF addon has been updated to supp
If you are using the `Meta` component or the `meta` named export to define the story's metadata (e.g., [parameters](../../writing-stories/parameters.mdx)), you'll need to update your stories to use the new `defineMeta` function. This function returns an object with the required information, including a `Story` component that you must use to define your component stories.
-{/* prettier-ignore-start */ }
-
-{/* prettier-ignore-end */}
-
#### Story templates
If you used the `Template` component to control how the component renders in the Storybook, this feature was replaced with built-in children support in the `Story` component, enabling you to compose components and define the UI structure directly in the story.
-{/* prettier-ignore-start */ }
-
-{/* prettier-ignore-end */}
-
- If you need support for the `Template` component, the addon provides a feature flag for backward compatibility. For more information, see the [configuration options](#configure).
+If you need support for the `Template` component, the addon provides a feature flag for backward compatibility. For more information, see the [configuration options](#configure).
@@ -201,37 +180,25 @@ With Svelte's slot deprecation and the introduction of reusable [`snippets`](htt
If you enabled automatic documentation generation with the `autodocs` story property, you must replace it with [`tags`](../../writing-stories/tags.mdx). This property allows you to categorize and filter stories based on specific criteria and generate documentation based on the tags applied to the stories.
-{/* prettier-ignore-start */ }
-
-{/* prettier-ignore-end */}
-
## FAQ
### How do I manually install the SvelteKit framework?
First, install the framework:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Then, update your `.storybook/main.js|ts` to change the framework property:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Finally, these packages are now either obsolete or part of `@storybook/sveltekit`, so you no longer need to depend on them directly. You can remove them (`npm uninstall`, `yarn remove`, `pnpm remove`) from your project:
-* `@storybook/svelte-vite`
-* `storybook-builder-vite`
-* `@storybook/builder-vite`
+- `@storybook/svelte-vite`
+- `storybook-builder-vite`
+- `@storybook/builder-vite`
## API
@@ -351,12 +318,8 @@ An object representing the current value of [`updated`](https://svelte.dev/docs/
You can pass an options object for additional configuration if needed:
-{/* prettier-ignore-start */ }
-
-{/* prettier-ignore-end */}
-
The available options are:
#### `builder`
@@ -373,12 +336,8 @@ Default: `true`
Enables or disables automatic documentation generation for component properties. When disabled, Storybook will skip the docgen processing step during build, which can improve build performance.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### When to disable docgen
Disabling docgen can improve build performance for large projects, but [argTypes won't be inferred automatically](../../api/arg-types.mdx#automatic-argtype-inference), which will prevent features like [Controls](../../essentials/controls.mdx) and [docs](../../writing-docs/autodocs.mdx) from working as expected. To use those features, you will need to [define `argTypes` manually](../../api/arg-types.mdx#manually-specifying-argtypes).
diff --git a/docs/get-started/frameworks/vue3-vite.mdx b/docs/get-started/frameworks/vue3-vite.mdx
index b98bf9456159..74d4948cf481 100644
--- a/docs/get-started/frameworks/vue3-vite.mdx
+++ b/docs/get-started/frameworks/vue3-vite.mdx
@@ -18,15 +18,20 @@ You can then get started [writing stories](../whats-a-story.mdx), [running tests
### Requirements
-
+
## Run Storybook
@@ -65,7 +70,9 @@ setup((app) => {
### Using `vue-component-meta`
- `vue-component-meta` is only available in Storybook ≥ 8. It is currently an opt-in, but it will become the default in a future version of Storybook.
+
+`vue-component-meta` is only available in Storybook ≥ 8. It is currently an opt-in, but it will become the default in a future version of Storybook.
+
[`vue-component-meta`](https://github.com/vuejs/language-tools/tree/master/packages/component-meta) is a tool maintained by the Vue team that extracts metadata from Vue components. Storybook can use it to generate the [controls](../../essentials/controls.mdx) for your stories and documentation. It's a more full-featured alternative to `vue-docgen-api` and is recommended for most projects.
@@ -105,10 +112,10 @@ To describe a prop, including tags, you can use JSDoc comments in your component
/** The name of the user */
name: string;
/**
- * The category of the component
- *
- * @since 8.0.0
- */
+ * The category of the component
+ *
+ * @since 8.0.0
+ */
category?: string;
}
@@ -231,7 +238,9 @@ export default config;
```
- This is not a limitation of Storybook, but how `vue-component-meta` works. For more information, refer to the appropriate [GitHub issue](https://github.com/vuejs/language-tools/issues/3896).
+
+This is not a limitation of Storybook, but how `vue-component-meta` works. For more information, refer to the appropriate [GitHub issue](https://github.com/vuejs/language-tools/issues/3896).
+
Otherwise, you might face missing component types/descriptions or unresolvable import aliases like `@/some/import`.
@@ -242,42 +251,26 @@ Otherwise, you might face missing component types/descriptions or unresolvable i
First, install the framework:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Then, update your `.storybook/main.js|ts` to change the framework property:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Storybook doesn't work with my Vue 2 project
[Vue 2 entered End of Life](https://v2.vuejs.org/lts/) (EOL) on December 31st, 2023, and is no longer maintained by the Vue team. As a result, Storybook no longer supports Vue 2. We recommend you upgrade your project to Vue 3, which Storybook fully supports. If that's not an option, you can still use Storybook with Vue 2 by installing the latest version of Storybook 7 with the following command:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## API
### Options
You can pass an options object for additional configuration if needed:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### `builder`
Type: `Record`
diff --git a/docs/get-started/frameworks/web-components-vite.mdx b/docs/get-started/frameworks/web-components-vite.mdx
index a7717aa7bc65..45c1857a41e5 100644
--- a/docs/get-started/frameworks/web-components-vite.mdx
+++ b/docs/get-started/frameworks/web-components-vite.mdx
@@ -18,11 +18,15 @@ You can then get started [writing stories](../whats-a-story.mdx), [running tests
### Requirements
-
+
## Run Storybook
@@ -37,36 +41,25 @@ To build Storybook, run:
You will find the output in the configured `outputDir` (default is `storybook-static`).
## FAQ
+
### How do I manually install the Web Components framework?
First, install the framework:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Then, update your `.storybook/main.js|ts` to change the framework property:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## API
### Options
You can pass an options object for additional configuration if needed:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
The available options are:
#### `builder`
diff --git a/docs/get-started/index.mdx b/docs/get-started/index.mdx
index 2566d59476f2..4e5c8837a22a 100644
--- a/docs/get-started/index.mdx
+++ b/docs/get-started/index.mdx
@@ -3,4 +3,4 @@ title: Get started with Storybook
sidebar:
order: 1
title: Get Started
----
\ No newline at end of file
+---
diff --git a/docs/get-started/install.mdx b/docs/get-started/install.mdx
index 5cf9acdfc688..2fe7081c2e35 100644
--- a/docs/get-started/install.mdx
+++ b/docs/get-started/install.mdx
@@ -17,7 +17,8 @@ Storybook will look into your project's dependencies during its install process
Storybook is designed to work with a variety of frameworks and environments. If your project is using one of the packages listed here, please ensure that you have the following versions installed:
-
+
+
- Angular 18+
- Lit 3+
- Next.js 14+
@@ -35,6 +36,7 @@ Storybook is designed to work with a variety of frameworks and environments. If
- Vue 3+
- Webpack 5+
- Yarn 4+
+
Additionally, the Storybook app supports the following browsers:
@@ -62,29 +64,21 @@ Run this command inside your project's root directory to install the latest vers
- Install a specific version
-
- To install Storybook 8.3 or newer, you can use the `create` command with a specific version:
-
- {/* prettier-ignore-start */}
-
-
+Install a specific version
- {/* prettier-ignore-end */}
+To install Storybook 8.3 or newer, you can use the `create` command with a specific version:
- To install a Storybook version prior to 8.3, you must use the `init` command:
+
- {/* prettier-ignore-start */}
+To install a Storybook version prior to 8.3, you must use the `init` command:
-
+
- {/* prettier-ignore-end */}
+For either command, you can specify either an npm tag such as `latest` or `next`, or a (partial) version number. For example:
- For either command, you can specify either an npm tag such as `latest` or `next`, or a (partial) version number. For example:
-
- * `storybook@latest init` will initialize the latest version
- * `storybook@7.6.10 init` will initialize `7.6.10`
- * `storybook@7 init` will initialize the newest `7.x.x` version
+- `storybook@latest init` will initialize the latest version
+- `storybook@7.6.10 init` will initialize `7.6.10`
+- `storybook@7 init` will initialize the newest `7.x.x` version
@@ -94,8 +88,8 @@ When installing, Storybook will present you with a series of interactive prompts
Storybook will ask if you're new to Storybook. If you select "Yes":
-* You will be welcomed with an interactive tour
-* Example stories will be created to help you learn
+- You will be welcomed with an interactive tour
+- Example stories will be created to help you learn
If you're experienced with Storybook, you can skip the onboarding to get a minimal setup.
@@ -103,8 +97,8 @@ If you're experienced with Storybook, you can skip the onboarding to get a minim
Storybook will ask what type of configuration you want to install:
-* **Recommended**: Includes component development, [documentation](../writing-docs/autodocs.mdx), [testing](../writing-tests/integrations/vitest-addon/index.mdx), and [accessibility](../writing-tests/accessibility-testing.mdx) features
-* **Minimal**: Just the essentials for component development
+- **Recommended**: Includes component development, [documentation](../writing-docs/autodocs.mdx), [testing](../writing-tests/integrations/vitest-addon/index.mdx), and [accessibility](../writing-tests/accessibility-testing.mdx) features
+- **Minimal**: Just the essentials for component development
You can also manually select these features using the `--features` flag. For example:
@@ -114,234 +108,247 @@ npm create storybook@latest --features docs test a11y
After completing the prompts, the command above will make the following changes to your local environment:
-* 📦 Install the required dependencies.
-* 🛠 Set up the necessary scripts to run and build Storybook.
-* 🛠 Add the default Storybook configuration.
-* 📝 Add some boilerplate stories to get you started.
-* 📡 Set up telemetry to help us improve Storybook. Read more about it [here](../configure/telemetry.mdx).
+- 📦 Install the required dependencies.
+- 🛠 Set up the necessary scripts to run and build Storybook.
+- 🛠 Add the default Storybook configuration.
+- 📝 Add some boilerplate stories to get you started.
+- 📡 Set up telemetry to help us improve Storybook. Read more about it [here](../configure/telemetry.mdx).
+
+
+
+## Run the Setup Wizard
-
- ## Run the Setup Wizard
+If all goes well, you should see a setup wizard that will help you get started with Storybook introducing you to the main concepts and features, including how the UI is organized, how to write your first story, and how to test your components' response to various inputs utilizing [controls](../essentials/controls.mdx).
- If all goes well, you should see a setup wizard that will help you get started with Storybook introducing you to the main concepts and features, including how the UI is organized, how to write your first story, and how to test your components' response to various inputs utilizing [controls](../essentials/controls.mdx).
+
- 
+If you skipped the wizard, you can always run it again by adding the `?path=/onboarding` query parameter to the URL of your Storybook instance, provided that the example stories are still available.
- If you skipped the wizard, you can always run it again by adding the `?path=/onboarding` query parameter to the URL of your Storybook instance, provided that the example stories are still available.
-
+
## Start Storybook
Storybook comes with a built-in development server featuring everything you need for project development. Depending on your system configuration, running the `storybook` command will start the local development server, output the address for you, and automatically open the address in a new browser tab where a welcome screen greets you.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- Storybook collects completely anonymous data to help us improve user experience. Participation is optional, and you may [opt-out](../configure/telemetry.mdx#how-to-opt-out) if you'd not like to share any information.
+
+Storybook collects completely anonymous data to help us improve user experience. Participation is optional, and you may [opt-out](../configure/telemetry.mdx#how-to-opt-out) if you'd not like to share any information.
+

There are some noteworthy items here:
-* A collection of useful links for more in-depth configuration and customization options you have at your disposal.
-* A second set of links for you to expand your Storybook knowledge and get involved with the ever-growing Storybook community.
-* A few example stories to get you started.
+- A collection of useful links for more in-depth configuration and customization options you have at your disposal.
+- A second set of links for you to expand your Storybook knowledge and get involved with the ever-growing Storybook community.
+- A few example stories to get you started.
-
Troubleshooting
- #### Run Storybook with other package managers
+
+
Troubleshooting
+
+#### Run Storybook with other package managers
+
+The Storybook CLI includes support for the industry's popular package managers (e.g., [Yarn](https://yarnpkg.com/), [npm](https://www.npmjs.com/), and [pnpm](https://pnpm.io/)) automatically detecting the one you are using when you initialize Storybook. However, if you want to use a specific package manager as the default, add the `--package-manager` flag to the installation command. For example:
+
+
+
+#### The CLI doesn't detect my framework
- The Storybook CLI includes support for the industry's popular package managers (e.g., [Yarn](https://yarnpkg.com/), [npm](https://www.npmjs.com/), and [pnpm](https://pnpm.io/)) automatically detecting the one you are using when you initialize Storybook. However, if you want to use a specific package manager as the default, add the `--package-manager` flag to the installation command. For example:
+If auto‑detection fails or you’re using a custom setup, pass the project type explicitly with `--type` when running the initializer. The allowed values are:
- {/* prettier-ignore-start */}
+| Type | Framework |
+| ---------------------- | -------------------------------- |
+| `angular` | Angular |
+| `ember` | Ember |
+| `html` | HTML |
+| `nextjs` | Next.js |
+| `nuxt` | Nuxt |
+| `preact` | Preact |
+| `qwik` | Qwik |
+| `react` | React |
+| `react_native` | React Native |
+| `react_native_web` | React Native Web |
+| `react_native_and_rnw` | React Native (+ Web) |
+| `react_scripts` | Create React App (react-scripts) |
+| `react_project` | React Project |
+| `server` | Server renderer |
+| `solid` | Solid |
+| `svelte` | Svelte |
+| `sveltekit` | SvelteKit |
+| `vue3` | Vue 3 |
+| `web_components` | Web Components |
-
+
- {/* prettier-ignore-end */}
+#### Yarn Plug'n'Play (PnP) support with Storybook
- #### The CLI doesn't detect my framework
+If you've enabled Storybook in a project running on a new version of Yarn with [Plug'n'Play](https://yarnpkg.com/features/pnp) (PnP) enabled, you may notice that it will generate `node_modules` with some additional files and folders. This is a known constraint as Storybook relies on some directories (e.g., `.cache`) to store cache files and other data to improve performance and faster builds. You can safely ignore these files and folders, adjusting your `.gitignore` file to exclude them from the version control you're using.
- If auto‑detection fails or you’re using a custom setup, pass the project type explicitly with `--type` when running the initializer. The allowed values are:
+#### Run Storybook with Webpack 4
- | Type | Framework |
- | ----------------------------- | ---------------------------------- |
- | `angular` | Angular |
- | `ember` | Ember |
- | `html` | HTML |
- | `nextjs` | Next.js |
- | `nuxt` | Nuxt |
- | `preact` | Preact |
- | `qwik` | Qwik |
- | `react` | React |
- | `react_native` | React Native |
- | `react_native_web` | React Native Web |
- | `react_native_and_rnw` | React Native (+ Web) |
- | `react_scripts` | Create React App (react-scripts) |
- | `react_project` | React Project |
- | `server` | Server renderer |
- | `solid` | Solid |
- | `svelte` | Svelte |
- | `sveltekit` | SvelteKit |
- | `vue3` | Vue 3 |
- | `web_components` | Web Components |
+If you previously installed Storybook in a project that uses Webpack 4, it will no longer work. This is because Storybook now uses Webpack 5 by default. To solve this issue, we recommend you upgrade your project to Webpack 5 and then run the following command to migrate your project to the latest version of Storybook:
- {/* prettier-ignore-start */}
+
-
+
- {/* prettier-ignore-end */}
+#### Storybook doesn't work with an empty directory
- #### Yarn Plug'n'Play (PnP) support with Storybook
+By default, Storybook is configured to detect whether you're initializing it on an empty directory or an existing project. However, if you attempt to initialize Storybook, select a Vite-based framework (e.g., [React](./frameworks/react-vite.mdx)) in a directory that only contains a `package.json` file, you may run into issues with [Yarn Modern](https://yarnpkg.com/getting-started). This is due to how Yarn handles peer dependencies and how Storybook is set up to work with Vite-based frameworks, as it requires the [Vite](https://vitejs.dev/) package to be installed. To solve this issue, you must install Vite manually and initialize Storybook.
- If you've enabled Storybook in a project running on a new version of Yarn with [Plug'n'Play](https://yarnpkg.com/features/pnp) (PnP) enabled, you may notice that it will generate `node_modules` with some additional files and folders. This is a known constraint as Storybook relies on some directories (e.g., `.cache`) to store cache files and other data to improve performance and faster builds. You can safely ignore these files and folders, adjusting your `.gitignore` file to exclude them from the version control you're using.
+
- #### Run Storybook with Webpack 4
+
- If you previously installed Storybook in a project that uses Webpack 4, it will no longer work. This is because Storybook now uses Webpack 5 by default. To solve this issue, we recommend you upgrade your project to Webpack 5 and then run the following command to migrate your project to the latest version of Storybook:
+#### Storybook doesn't work with my Angular project using the Angular CLI
- {/* prettier-ignore-start */}
+Out of the box, adding Storybook to an Angular project using the Angular CLI requires you to run the installation command from the root of the project or, if you're working with a monorepo environment, from the directory where the Angular configuration file (i.e., `angular.json`) is located as it will be used to set up the builder configuration necessary to run Storybook. However, if you need, you can extend the builder configuration to customize Storybook's behavior. To learn more about the available options, see the [Angular framework documentation](./frameworks/angular.mdx#how-do-i-configure-angulars-builder-for-storybook).
-
+
- {/* prettier-ignore-end */}
+
-
+#### The CLI doesn't support my Ember version
- #### Storybook doesn't work with an empty directory
+The Ember framework relies on an auxiliary package named [`@storybook/ember-cli-storybook`](https://www.npmjs.com/package/@storybook/ember-cli-storybook) to help you set up Storybook in your project. During the installation process you might run into the following warning message in your terminal:
- By default, Storybook is configured to detect whether you're initializing it on an empty directory or an existing project. However, if you attempt to initialize Storybook, select a Vite-based framework (e.g., [React](./frameworks/react-vite.mdx)) in a directory that only contains a `package.json` file, you may run into issues with [Yarn Modern](https://yarnpkg.com/getting-started). This is due to how Yarn handles peer dependencies and how Storybook is set up to work with Vite-based frameworks, as it requires the [Vite](https://vitejs.dev/) package to be installed. To solve this issue, you must install Vite manually and initialize Storybook.
+```shell
+The ember generate entity-name command requires an entity name to be specified.
+For more details, use ember help.
+```
-
+It may be the case that you're using an outdated version of the package and you need to update it to the latest version to solve this issue.
-
- #### Storybook doesn't work with my Angular project using the Angular CLI
+
- Out of the box, adding Storybook to an Angular project using the Angular CLI requires you to run the installation command from the root of the project or, if you're working with a monorepo environment, from the directory where the Angular configuration file (i.e., `angular.json`) is located as it will be used to set up the builder configuration necessary to run Storybook. However, if you need, you can extend the builder configuration to customize Storybook's behavior. To learn more about the available options, see the [Angular framework documentation](./frameworks/angular.mdx#how-do-i-configure-angulars-builder-for-storybook).
-
+
-
- #### The CLI doesn't support my Ember version
+#### Storybook doesn't work with my Vue 2 project
- The Ember framework relies on an auxiliary package named [`@storybook/ember-cli-storybook`](https://www.npmjs.com/package/@storybook/ember-cli-storybook) to help you set up Storybook in your project. During the installation process you might run into the following warning message in your terminal:
+Vue 2 entered [End of Life](https://v2.vuejs.org/lts/) (EOL) on December 31st, 2023, and is no longer maintained by the Vue team. As a result, Storybook no longer supports Vue 2. We recommend you upgrade your project to Vue 3, which Storybook fully supports. If that's not an option, you can still use Storybook with Vue 2 by installing the latest version of Storybook 7 with the following command:
- ```shell
- The ember generate entity-name command requires an entity name to be specified.
- For more details, use ember help.
- ```
+
- It may be the case that you're using an outdated version of the package and you need to update it to the latest version to solve this issue.
-
+
-
- #### Storybook doesn't work with my Vue 2 project
+
- Vue 2 entered [End of Life](https://v2.vuejs.org/lts/) (EOL) on December 31st, 2023, and is no longer maintained by the Vue team. As a result, Storybook no longer supports Vue 2. We recommend you upgrade your project to Vue 3, which Storybook fully supports. If that's not an option, you can still use Storybook with Vue 2 by installing the latest version of Storybook 7 with the following command:
+#### Writing native Svelte stories
- {/* prettier-ignore-start */}
+Storybook provides a Svelte [addon](https://storybook.js.org/addons/@storybook/addon-svelte-csf) maintained by the community, enabling you to write stories for your Svelte components using the template syntax. Starting with Storybook 8.2, the addon is automatically installed and configured when you initialize your project with the Svelte framework. However, if you installed a [specific version](#custom-storybook-version) of Storybook, you'll need to take additional steps to enable this feature.
-
+Run the following command to install the addon.
- {/* prettier-ignore-end */}
-
+
-
- #### Writing native Svelte stories
+
- Storybook provides a Svelte [addon](https://storybook.js.org/addons/@storybook/addon-svelte-csf) maintained by the community, enabling you to write stories for your Svelte components using the template syntax. Starting with Storybook 8.2, the addon is automatically installed and configured when you initialize your project with the Svelte framework. However, if you installed a [specific version](#custom-storybook-version) of Storybook, you'll need to take additional steps to enable this feature.
+The CLI's [`add`](../api/cli-options.mdx#add) command automates the addon's installation and setup. To install it manually, see our [documentation](../addons/install-addons.mdx#manual-installation) on how to install addons.
- Run the following command to install the addon.
+
- {/* prettier-ignore-start */}
+Update your Storybook configuration file (i.e., `.storybook/main.js|ts`) to enable support for this format.
-
+
- {/* prettier-ignore-end */}
+
-
+The community actively maintains the Svelte CSF addon but still lacks some features currently available in the official Storybook Svelte framework support. For more information, see the [addon's documentation](https://github.com/storybookjs/addon-svelte-csf).
+
+
- The CLI's [`add`](../api/cli-options.mdx#add) command automates the addon's installation and setup. To install it manually, see our [documentation](../addons/install-addons.mdx#manual-installation) on how to install addons.
+
-
+#### The installation process seems flaky and keeps failing
- Update your Storybook configuration file (i.e., `.storybook/main.js|ts`) to enable support for this format.
+If you're still running into some issues during the installation process, we encourage you to check out the following resources:
- {/* prettier-ignore-start */}
+
-
+- Storybook's Angular [framework documentation](./frameworks/angular.mdx) for more information on how to set up Storybook in your Angular project.
+- [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
- {/* prettier-ignore-end */}
+
-
- The community actively maintains the Svelte CSF addon but still lacks some features currently available in the official Storybook Svelte framework support. For more information, see the [addon's documentation](https://github.com/storybookjs/addon-svelte-csf).
-
-
+
- #### The installation process seems flaky and keeps failing
+- [Storybook's Ember README](https://github.com/storybookjs/storybook/tree/next/code/frameworks/ember) for more information on how to set up Storybook in your Ember project.
+- [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
- If you're still running into some issues during the installation process, we encourage you to check out the following resources:
+
-
- * Storybook's Angular [framework documentation](./frameworks/angular.mdx) for more information on how to set up Storybook in your Angular project.
- * [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
-
+
-
- * [Storybook's Ember README](https://github.com/storybookjs/storybook/tree/next/code/frameworks/ember) for more information on how to set up Storybook in your Ember project.
- * [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
-
+- [Storybook's HTML Vite README](https://github.com/storybookjs/storybook/tree/next/code/frameworks/html-vite) for more information on how to set up Storybook in your HTML project with Vite.
+- [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
-
- * [Storybook's HTML Vite README](https://github.com/storybookjs/storybook/tree/next/code/frameworks/html-vite) for more information on how to set up Storybook in your HTML project with Vite.
- * [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
-
+
-
- * Storybook's Preact Vite [framework documentation](./frameworks/preact-vite.mdx) for more information on how to set up Storybook in your Preact project with Vite.
- * [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
-
+
-
- * [Storybook's Qwik README](https://github.com/literalpie/storybook-framework-qwik) for more information on how to set up Storybook in your Qwik project.
- * [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
-
+- Storybook's Preact Vite [framework documentation](./frameworks/preact-vite.mdx) for more information on how to set up Storybook in your Preact project with Vite.
+- [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
-
- * Storybook's React Vite [framework documentation](./frameworks/react-vite.mdx) for more information on how to set up Storybook in your React project with Vite.
- * Storybook's React Webpack [framework documentation](./frameworks/react-webpack5.mdx) for more information on how to set up Storybook in your React project with Webpack 5.
- * [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
-
+
-
- * [Storybook's SolidJS README](https://github.com/solidjs-community/storybook) for more information on how to set up Storybook in your SolidJS project.
- * [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
-
+
-
- * Storybook's SvelteKit [framework documentation](./frameworks/sveltekit.mdx) for more information on how to set up Storybook in your SvelteKit project.
- * Storybook's Svelte Vite [framework documentation](./frameworks/svelte-vite.mdx) for more information on how to set up Storybook in your Svelte project with Vite.
- * [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
-
+- [Storybook's Qwik README](https://github.com/literalpie/storybook-framework-qwik) for more information on how to set up Storybook in your Qwik project.
+- [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
-
- * Storybook's Vue 3 Vite [framework documentation](./frameworks/vue3-vite.mdx) for more information on how to set up Storybook in your Vue 3 project with Vite.
- * [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
-
+
+
+
+
+- Storybook's React Vite [framework documentation](./frameworks/react-vite.mdx) for more information on how to set up Storybook in your React project with Vite.
+- Storybook's React Webpack [framework documentation](./frameworks/react-webpack5.mdx) for more information on how to set up Storybook in your React project with Webpack 5.
+- [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
+
+
+
+
+
+- [Storybook's SolidJS README](https://github.com/solidjs-community/storybook) for more information on how to set up Storybook in your SolidJS project.
+- [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
+
+
+
+
+
+- Storybook's SvelteKit [framework documentation](./frameworks/sveltekit.mdx) for more information on how to set up Storybook in your SvelteKit project.
+- Storybook's Svelte Vite [framework documentation](./frameworks/svelte-vite.mdx) for more information on how to set up Storybook in your Svelte project with Vite.
+- [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
+
+
+
+
+
+- Storybook's Vue 3 Vite [framework documentation](./frameworks/vue3-vite.mdx) for more information on how to set up Storybook in your Vue 3 project with Vite.
+- [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
+
+
+
+
+
+- Storybook's Web Components Vite [framework documentation](./frameworks/web-components-vite.mdx) for more information on how to set up Storybook in your Web Components project with Vite.
+- [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
+
+
-
- * Storybook's Web Components Vite [framework documentation](./frameworks/web-components-vite.mdx) for more information on how to set up Storybook in your Web Components project with Vite.
- * [Storybook's help documentation](https://storybook.js.org/community#support) to contact the community and ask for help.
-
-
- Now that you have successfully installed Storybook and understood how it works, let's continue where you left off in the [setup wizard](#run-the-setup-wizard) and delve deeper into writing stories.
-
+
+
+Now that you have successfully installed Storybook and understood how it works, let's continue where you left off in the [setup wizard](#run-the-setup-wizard) and delve deeper into writing stories.
+
+
+
+
+
+Now that you installed Storybook successfully, let’s take a look at a story that was written for us.
-
- Now that you installed Storybook successfully, let’s take a look at a story that was written for us.
-
+
diff --git a/docs/get-started/setup.mdx b/docs/get-started/setup.mdx
index 775e833c5df3..90c25fbde4a0 100644
--- a/docs/get-started/setup.mdx
+++ b/docs/get-started/setup.mdx
@@ -9,12 +9,8 @@ Now that you’ve learned what stories are and how to browse them, let’s demo
Pick a simple component from your project, like a Button, and write a `.stories.js`, `.stories.ts`, or `.stories.svelte` file to go along with it. It might look something like this:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Go to your Storybook to view the rendered component. It’s OK if it looks a bit unusual right now.
Depending on your technology stack, you also might need to configure the Storybook environment further.
@@ -25,15 +21,15 @@ Storybook isn’t opinionated about how you generate or load CSS. It renders wha
You may have to configure your CSS tooling for Storybook’s rendering environment. Here are some setup guides for popular tools in the community.
-* [Tailwind](https://storybook.js.org/recipes/tailwindcss/)
-* [Material UI](https://storybook.js.org/recipes/@mui/material/)
-* [Vuetify](https://storybook.js.org/recipes/vuetify/)
-* [Styled Components](https://storybook.js.org/recipes/styled-components/)
-* [Emotion](https://storybook.js.org/recipes/@emotion/styled/)
-* [Sass](https://storybook.js.org/recipes/sass/)
-* [Bootstrap](https://storybook.js.org/recipes/bootstrap/)
-* [Less](https://storybook.js.org/recipes/less/)
-* [Vanilla-extract](https://storybook.js.org/recipes/@vanilla-extract/css/)
+- [Tailwind](https://storybook.js.org/recipes/tailwindcss/)
+- [Material UI](https://storybook.js.org/recipes/@mui/material/)
+- [Vuetify](https://storybook.js.org/recipes/vuetify/)
+- [Styled Components](https://storybook.js.org/recipes/styled-components/)
+- [Emotion](https://storybook.js.org/recipes/@emotion/styled/)
+- [Sass](https://storybook.js.org/recipes/sass/)
+- [Bootstrap](https://storybook.js.org/recipes/bootstrap/)
+- [Less](https://storybook.js.org/recipes/less/)
+- [Vanilla-extract](https://storybook.js.org/recipes/@vanilla-extract/css/)
Don't see the tool that you're looking for? Check out the [styling and css](../configure/styling-and-css.mdx) page for more details.
@@ -44,40 +40,44 @@ Storybook comes with a permissive [default configuration](../configure/index.mdx
Your project may have additional requirements before components can be rendered in isolation. This warrants customizing configuration further. There are three broad categories of configuration you might need.
- Build configuration like Webpack and Babel
+Build configuration like Webpack and Babel
- If you see errors on the CLI when you run the `yarn storybook` command, you likely need to make changes to Storybook’s build configuration. Here are some things to try:
+If you see errors on the CLI when you run the `yarn storybook` command, you likely need to make changes to Storybook’s build configuration. Here are some things to try:
+
+- [Presets](../addons/addon-types.mdx) bundle common configurations for various technologies into Storybook. In particular, presets exist for Create React App and Ant Design.
+- Specify a custom [Babel configuration](../configure/integration/compilers.mdx#babel) for Storybook. Storybook automatically tries to use your project’s config if it can.
+- Adjust the [Webpack configuration](../builders/webpack.mdx) that Storybook uses. Try patching in your own configuration if needed.
- * [Presets](../addons/addon-types.mdx) bundle common configurations for various technologies into Storybook. In particular, presets exist for Create React App and Ant Design.
- * Specify a custom [Babel configuration](../configure/integration/compilers.mdx#babel) for Storybook. Storybook automatically tries to use your project’s config if it can.
- * Adjust the [Webpack configuration](../builders/webpack.mdx) that Storybook uses. Try patching in your own configuration if needed.
- Runtime configuration
+Runtime configuration
+
+If Storybook builds but you see an error immediately when connecting to it in the browser, in that case, chances are one of your input files is not compiling/transpiling correctly to be interpreted by the browser. Storybook supports evergreen browsers, but you may need to check the Babel and Webpack settings (see above) to ensure your component code works correctly.
- If Storybook builds but you see an error immediately when connecting to it in the browser, in that case, chances are one of your input files is not compiling/transpiling correctly to be interpreted by the browser. Storybook supports evergreen browsers, but you may need to check the Babel and Webpack settings (see above) to ensure your component code works correctly.
- Component context
+Component context
+
+If a particular story has a problem rendering, often it means your component expects a specific environment is available to the component.
+
+A common frontend pattern is for components to assume that they render in a specific “context” with parent components higher up the rendering hierarchy (for instance, theme providers).
+
+
+
+Use [decorators](../writing-stories/decorators.mdx) to “wrap” every story in the necessary context providers. The [`.storybook/preview.*`](../configure/index.mdx#configure-story-rendering) file allows you to customize how components render in Canvas, the preview iframe. This file can be written in JavaScript (`preview.jsx`) or TypeScript (`preview.tsx`). See how you can wrap every component rendered in Storybook with [Styled Components](https://styled-components.com/) `ThemeProvider`, [Vue's Vuetify](https://vuetifyjs.com/en/), Svelte's [Bits UI](https://bits-ui.com/) `BitsConfig`, or with an Angular theme provider component in the example below.
- If a particular story has a problem rendering, often it means your component expects a specific environment is available to the component.
+
- A common frontend pattern is for components to assume that they render in a specific “context” with parent components higher up the rendering hierarchy (for instance, theme providers).
+
-
- Use [decorators](../writing-stories/decorators.mdx) to “wrap” every story in the necessary context providers. The [`.storybook/preview.*`](../configure/index.mdx#configure-story-rendering) file allows you to customize how components render in Canvas, the preview iframe. This file can be written in JavaScript (`preview.jsx`) or TypeScript (`preview.tsx`). See how you can wrap every component rendered in Storybook with [Styled Components](https://styled-components.com/) `ThemeProvider`, [Vue's Vuetify](https://vuetifyjs.com/en/), Svelte's [Bits UI](https://bits-ui.com/) `BitsConfig`, or with an Angular theme provider component in the example below.
-
-
- Use [decorators](../writing-stories/decorators.mdx) to “wrap” every story in the necessary context providers. The [`.storybook/preview.*`](../configure/index.mdx#configure-story-rendering) file allows you to customize how components render in Canvas, the preview iframe. This file can be written in JavaScript (`preview.js`) or TypeScript (`preview.ts`). See how you can wrap every component rendered in Storybook with [Styled Components](https://styled-components.com/) `ThemeProvider`, [Vue's Vuetify](https://vuetifyjs.com/en/), Svelte's [Bits UI](https://bits-ui.com/) `BitsConfig`, or with an Angular theme provider component in the example below.
-
+Use [decorators](../writing-stories/decorators.mdx) to “wrap” every story in the necessary context providers. The [`.storybook/preview.*`](../configure/index.mdx#configure-story-rendering) file allows you to customize how components render in Canvas, the preview iframe. This file can be written in JavaScript (`preview.js`) or TypeScript (`preview.ts`). See how you can wrap every component rendered in Storybook with [Styled Components](https://styled-components.com/) `ThemeProvider`, [Vue's Vuetify](https://vuetifyjs.com/en/), Svelte's [Bits UI](https://bits-ui.com/) `BitsConfig`, or with an Angular theme provider component in the example below.
- {/* prettier-ignore-start */}
+
-
+
- {/* prettier-ignore-end */}
## Load assets and resources
diff --git a/docs/get-started/whats-a-story.mdx b/docs/get-started/whats-a-story.mdx
index 252c49c57611..1d0b7aa8ab5b 100644
--- a/docs/get-started/whats-a-story.mdx
+++ b/docs/get-started/whats-a-story.mdx
@@ -2,7 +2,6 @@
title: What's a story?
sidebar:
order: 4
- title: What's a story?
---
A story captures the rendered state of a UI component. Developers write multiple stories per component that describe all the “interesting” states a component can support.
@@ -11,32 +10,28 @@ When you installed Storybook, the CLI created example components that demonstrat
- Each example component has a set of stories that show the states it supports. You can browse the stories in the UI and see the code behind them in files that end with `.stories.svelte`. Stories can be written in [Component Story Format](../api/csf/index.mdx) (CSF), an ES6 modules-based standard for writing component examples or using Svelte native template syntax, via a community-led project called [`Svelte CSF`](https://storybook.js.org/addons/@storybook/addon-svelte-csf).
+Each example component has a set of stories that show the states it supports. You can browse the stories in the UI and see the code behind them in files that end with `.stories.svelte`. Stories can be written in [Component Story Format](../api/csf/index.mdx) (CSF), an ES6 modules-based standard for writing component examples or using Svelte native template syntax, via a community-led project called [`Svelte CSF`](https://storybook.js.org/addons/@storybook/addon-svelte-csf).
- Let’s start with the `Button` component. With Svelte, a story can be defined as an object using standard CSF or with a `Story` component using Svelte CSF. Here’s how to render `Button` in the “primary” state and export a story called `Primary` using both approaches.
+Let’s start with the `Button` component. With Svelte, a story can be defined as an object using standard CSF or with a `Story` component using Svelte CSF. Here’s how to render `Button` in the “primary” state and export a story called `Primary` using both approaches.
-
- Each example component has a set of stories that show the states it supports. You can browse the stories in the UI and see the code behind them in files that end with `.stories.js|ts`. The stories are written in [Component Story Format](../api/csf/index.mdx) (CSF), an ES6 modules-based standard for writing component examples.
- Let’s start with the `Button` component. A story is an object that describes how to render the component in question. Here’s how to render `Button` in the “primary” state and export a story called `Primary`.
+Each example component has a set of stories that show the states it supports. You can browse the stories in the UI and see the code behind them in files that end with `.stories.js|ts`. The stories are written in [Component Story Format](../api/csf/index.mdx) (CSF), an ES6 modules-based standard for writing component examples.
-
+Let’s start with the `Button` component. A story is an object that describes how to render the component in question. Here’s how to render `Button` in the “primary” state and export a story called `Primary`.
-{/* prettier-ignore-start */}
+
-{/* prettier-ignore-end */}
-

View the rendered `Button` by clicking on it in the Storybook sidebar. Note how the values specified in [`args`](../writing-stories/args.mdx) are used to render the component and match those represented in the [Controls](../essentials/controls.mdx) panel. Using `args` in your stories has additional benefits:
-* `Button`'s callbacks are logged into the [Actions](../essentials/actions.mdx) panel. Click to try it.
-* `Button`'s arguments are dynamically editable in the Controls panel. Adjust the controls.
+- `Button`'s callbacks are logged into the [Actions](../essentials/actions.mdx) panel. Click to try it.
+- `Button`'s arguments are dynamically editable in the Controls panel. Adjust the controls.
## Working with stories
@@ -45,25 +40,29 @@ Storybook makes it easy to work on one component in one state (aka a story) at a
### Create a new story
- If you're working on a component that does not yet have any stories, you can click the ➕ button in the sidebar to search for your component and have a basic story created for you.
-
+If you're working on a component that does not yet have any stories, you can click the ➕ button in the sidebar to search for your component and have a basic story created for you.
+
+
+
+You can also create a story file for your new story. We recommend copy/pasting an existing story file next to the component source file, then adjusting it for your component.
- You can also create a story file for your new story. We recommend copy/pasting an existing story file next to the component source file, then adjusting it for your component.
-
+
+
+This feature is not supported with the Svelte template syntax story format. To opt-in to this feature with Svelte, you must use Storybook's [Component Story Format](../api/csf/index.mdx).
+
+
- This feature is not supported with the Svelte template syntax story format. To opt-in to this feature with Svelte, you must use Storybook's [Component Story Format](../api/csf/index.mdx).
-
-
-
- If you're working on a component that does not yet have any stories, you can create a story file for your component with a new story. We recommend copy/pasting an existing story file next to the component source file, then adjusting it for your component.
+
+If you're working on a component that does not yet have any stories, you can create a story file for your component with a new story. We recommend copy/pasting an existing story file next to the component source file, then adjusting it for your component.
+
diff --git a/docs/get-started/why-storybook.mdx b/docs/get-started/why-storybook.mdx
index 887d98dad48b..bf40bf839e6f 100644
--- a/docs/get-started/why-storybook.mdx
+++ b/docs/get-started/why-storybook.mdx
@@ -2,7 +2,6 @@
title: Why Storybook?
sidebar:
order: 1
- title: Why Storybook?
---
## The problem
@@ -33,12 +32,8 @@ When developing a component variation in isolation, save it as a story. [Stories
You write stories for granular UI component variation and then use those stories in development, testing, and documentation.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Storybook keeps track of every story
Storybook is an interactive directory of your UI components and their stories. In the past, you'd have to spin up the app, navigate to a page, and contort the UI into the right state. This is a huge waste of time and bogs down frontend development. With Storybook, you can skip all those steps and jump straight to working on a UI component in a specific state.
@@ -46,32 +41,35 @@ Storybook is an interactive directory of your UI components and their stories. I
- Where does Storybook fit into my project?
+Where does Storybook fit into my project?
+
+Storybook is packaged as a small, development-only, [workshop](https://bradfrost.com/blog/post/a-frontend-workshop-environment/) that lives alongside your app. Install it by [running a command](../get-started/install.mdx).
- Storybook is packaged as a small, development-only, [workshop](https://bradfrost.com/blog/post/a-frontend-workshop-environment/) that lives alongside your app. Install it by [running a command](../get-started/install.mdx).
+During development, run it in a separate node process. If you’re working on UI in isolation, the only thing you’ll need to run is Storybook.
- During development, run it in a separate node process. If you’re working on UI in isolation, the only thing you’ll need to run is Storybook.
- Does Storybook work with my favorite libraries?
+Does Storybook work with my favorite libraries?
- Storybook aims to integrate with industry-standard tools and platforms to simplify setup. Thanks to our ambitious developer community, we’ve made significant progress. There are hundreds of [addons](https://storybook.js.org/addons/) and tutorials that walk through how to set up Storybook in all types of projects.
+Storybook aims to integrate with industry-standard tools and platforms to simplify setup. Thanks to our ambitious developer community, we’ve made significant progress. There are hundreds of [addons](https://storybook.js.org/addons/) and tutorials that walk through how to set up Storybook in all types of projects.
+
+If you’re using a niche framework or a recently launched tool, we might not have an integration for it yet. Consider creating a [proof of concept](../addons/writing-addons.mdx) yourself first to lead the way for the rest of the community.
- If you’re using a niche framework or a recently launched tool, we might not have an integration for it yet. Consider creating a [proof of concept](../addons/writing-addons.mdx) yourself first to lead the way for the rest of the community.
- What’s the recommended Storybook workflow?
+What’s the recommended Storybook workflow?
+
+Every team is different and so is their workflow. Storybook is designed to be incrementally adoptable. Teams can gradually try features to see what works best for them.
- Every team is different and so is their workflow. Storybook is designed to be incrementally adoptable. Teams can gradually try features to see what works best for them.
+Most community members choose a [Component-Driven](https://www.componentdriven.org/) workflow. UIs are developed in isolation from the “bottom up” starting with basic components then progressively combined to assemble pages.
- Most community members choose a [Component-Driven](https://www.componentdriven.org/) workflow. UIs are developed in isolation from the “bottom up” starting with basic components then progressively combined to assemble pages.
+1. Build each component in isolation and write stories for its variations.
+2. Compose small components together to enable more complex functionality.
+3. Assemble pages by combining composite components.
+4. Integrate pages into your project by hooking up data and business logic.
- 1. Build each component in isolation and write stories for its variations.
- 2. Compose small components together to enable more complex functionality.
- 3. Assemble pages by combining composite components.
- 4. Integrate pages into your project by hooking up data and business logic.
## Benefits
@@ -102,8 +100,8 @@ Storybook is compatible with your continuous integration workflow. Add it as a C
Storybook is powered by [Component Story Format](../api/csf/index.mdx), an open standard based on JavaScript ES6 modules. This enables stories to interoperate between development, testing, and design tools. Each story is exported as a JavaScript function enabling you to reuse it with other tools. No vendor lock-in.
-Reuse stories with [Jest](https://jestjs.io/) or [Vitest](https://vitest.dev/) and [Testing Library](https://testing-library.com/) to verify interactions. Put them in [Chromatic](https://www.chromatic.com/?utm_source=storybook_website\&utm_medium=link\&utm_campaign=storybook) for visual testing. Audit story accessibility with [Axe](https://github.com/dequelabs/axe-core). Or test user flows with [Playwright](https://playwright.dev/) and [Cypress](https://www.cypress.io/). Reuse unlocks more workflows at no extra cost.
+Reuse stories with [Jest](https://jestjs.io/) or [Vitest](https://vitest.dev/) and [Testing Library](https://testing-library.com/) to verify interactions. Put them in [Chromatic](https://www.chromatic.com/?utm_source=storybook_website&utm_medium=link&utm_campaign=storybook) for visual testing. Audit story accessibility with [Axe](https://github.com/dequelabs/axe-core). Or test user flows with [Playwright](https://playwright.dev/) and [Cypress](https://www.cypress.io/). Reuse unlocks more workflows at no extra cost.
-***
+---
Storybook is purpose-built to help you develop complex UIs faster with greater durability and lower maintenance. It’s used by 100s of [leading companies](https://storybook.js.org/showcase) and thousands of [developers](https://github.com/storybookjs/storybook/).
diff --git a/docs/releases/features.mdx b/docs/releases/features.mdx
index 18f3f9dcb3b4..322f89600b9d 100644
--- a/docs/releases/features.mdx
+++ b/docs/releases/features.mdx
@@ -1,5 +1,5 @@
---
-title: 'Features Lifecycle'
+title: Features Lifecycle
sidebar:
order: 4
title: Feature Lifecycle
@@ -9,26 +9,26 @@ This page explains how the Storybook team classifies features using four lifecyc
These labels help users understand our level of commitment, the expected quality, likelihood of breaking changes, and anticipated timeline for each feature. By making this process transparent, we aim to support better adoption decisions and build trust in how Storybook evolves.
-### Experimental
+## Experimental
-This stage marks the beginning of a feature’s development, where we’re validating ideas and shaping direction.
+This stage marks the beginning of a feature’s development, where we’re validating ideas and shaping direction.
-Experimental features are functional but still evolving, with room for iteration based on real-world use. They’re ideal for trying out in prototypes or early integrations, not yet something to build critical paths around. Each experimental feature comes with an [RFC](https://github.com/storybookjs/storybook/discussions/categories/rfc) where we share the initial idea and report progress. We strongly encourage feedback to help guide the next steps.
+Experimental features are functional but still evolving, with room for iteration based on real-world use. They’re ideal for trying out in prototypes or early integrations, not yet something to build critical paths around. Each experimental feature comes with an [RFC](https://github.com/storybookjs/storybook/discussions/categories/rfc) where we share the initial idea and report progress. We strongly encourage feedback to help guide the next steps.
During this stage, we’re committed to fully exploring the concept. As such, specific implementation details may change significantly before stabilization.
-### Preview
+## Preview
-Preview features are nearly production-ready and generally reliable, with documentation in place and most known issues addressed. They should be fully functional for at least one supported framework, but may still be incomplete or less polished in others. These features are suitable for use in real projects, and we encourage teams to adopt them and share feedback.
+Preview features are nearly production-ready and generally reliable, with documentation in place and most known issues addressed. They should be fully functional for at least one supported framework, but may still be incomplete or less polished in others. These features are suitable for use in real projects, and we encourage teams to adopt them and share feedback.
While the feature is stable in direction, we may introduce minimal breaking changes in minor releases to address gaps or refine behavior. In those cases, we provide automigrations where possible to ease the transition. We aim to collect feedback and iterate for 1-2 minor releases before promoting to stable.
-### Stable
+## Stable
Stable features are fully supported and safe for production use across all projects. They are well-documented, thoroughly tested in all of our core frameworks, and follow [semantic versioning](https://semver.org). Users can expect long-term support, with any breaking changes reserved for major releases.
-### Deprecated
+## Deprecated
-Deprecated features are in the process of being phased out and will be removed in an upcoming major release. Users should begin migrating to supported alternatives as soon as possible. These features no longer receive active development or bug fixes, and their functionality may degrade over time. While they may still work, they should not be used for new development.
+Deprecated features are in the process of being phased out and will be removed in an upcoming major release. Users should begin migrating to supported alternatives as soon as possible. These features no longer receive active development or bug fixes, and their functionality may degrade over time. While they may still work, they should not be used for new development.
Typically, a deprecated feature is removed within the next major release cycle (for example, if deprecated in 8.x, removal is expected in 9.0).
diff --git a/docs/releases/index.mdx b/docs/releases/index.mdx
index 646dabc6fd0b..e5c8169a6ce2 100644
--- a/docs/releases/index.mdx
+++ b/docs/releases/index.mdx
@@ -1,5 +1,5 @@
---
-title: 'How we release Storybook'
+title: How we release Storybook
sidebar:
order: 13
title: Releases
@@ -26,6 +26,7 @@ npm create storybook@next
## Supported Versions
We actively maintain the latest major version of Storybook. Within the current major, we patch only the latest minor version. Most fixes and new work go into the next minor (or sometimes major) and are not backported. Critical security fixes may be backported more broadly based on severity:
+
- Latest major: Receives all security fixes
- Previous two majors: Receive security patches for **High or Critical [CVSS vulnerabilities](https://en.wikipedia.org/wiki/Common_Vulnerability_Scoring_System) only**
- Older versions: No longer receive any patches
@@ -42,21 +43,23 @@ For compatibility with other libraries and tools in the JavaScript ecosystem, pl
## Release Cycle
-#### Major Release
+### Major Release
**Cadence**: Roughly once per year
**Channel**: Stable (`latest`)
-Major releases introduce breaking changes and significant new features. We use major releases to keep up with ecosystem changes, evolve Storybook’s architecture and APIs, and make the tool faster, leaner, and easier to use.
+Major releases introduce breaking changes and significant new features. We use major releases to keep up with ecosystem changes, evolve Storybook’s architecture and APIs, and make the tool faster, leaner, and easier to use.
Once we start working on a major release, we pause minor releases but continue to ship patch releases as needed. Major releases go through a sequence of [pre-releases](#pre-release)—`alpha`, `beta`, and `rc` (release candidate)—before landing in the stable channel. We aim to include automated migrations and provide [a comprehensive migration guide](../releases/migration-guide.mdx) when manual changes are necessary.
- Storybook versions prior to 7 had a very different architecture. As a result, upgrading from v6 to newer versions can be more challenging. Starting in v7, we’ve focused heavily on smoother migrations. Upgrades from v7 to v8, and v8 to v9 (and beyond), should feel significantly easier thanks to automigrations and better tooling.
+
+Storybook versions prior to 7 had a very different architecture. As a result, upgrading from v6 to newer versions can be more challenging. Starting in v7, we’ve focused heavily on smoother migrations. Upgrades from v7 to v8, and v8 to v9 (and beyond), should feel significantly easier thanks to automigrations and better tooling.
+
-#### Minor Release
+### Minor Release
**Cadence**: Roughly every 8 weeks
@@ -64,7 +67,7 @@ Once we start working on a major release, we pause minor releases but continue t
Minor releases deliver new features, enhancements, and non-breaking improvements. Each minor release may be preceded by an alpha [pre-release](#pre-release) (e.g. `x.y.0-alpha`).
-#### Patch Release
+### Patch Release
**Cadence**: as needed (only for the current minor)
@@ -72,7 +75,7 @@ Minor releases deliver new features, enhancements, and non-breaking improvements
Patch releases include critical bug fixes and security updates. These are issued only for the current minor version and are not pre-released.
-#### Pre-release
+### Pre-release
**Cadence**: Regularly
diff --git a/docs/releases/migration-guide-from-older-version.mdx b/docs/releases/migration-guide-from-older-version.mdx
index 65b2bea1569a..d40c51a5933e 100644
--- a/docs/releases/migration-guide-from-older-version.mdx
+++ b/docs/releases/migration-guide-from-older-version.mdx
@@ -1,5 +1,5 @@
---
-title: 'Migration guide from Storybook 8.x to 9.1'
+title: Migration guide from Storybook 8.x to 9.1
sidebar:
order: 2
title: Migrate from 8 to 9
@@ -20,36 +20,38 @@ Storybook 9 improves performance, compatibility, and stability. Its key features
This guide is meant to help you **upgrade from Storybook 8.x to 9.1** successfully!
- **Migrating from Storybook 6 or 7?**
- We have prior migration guides for:
+**Migrating from Storybook 6 or 7?**
+
+We have prior migration guides for:
+
+- [Storybook 7.x to 8.x](../../../release-8-6/docs/migration-guide/index.mdx)
+- [Storybook 6.x to 8.x](../../../release-8-6/docs/migration-guide/from-older-version.mdx)
- - [Storybook 7.x to 8.x](../../../release-8-6/docs/migration-guide/index.mdx)
- - [Storybook 6.x to 8.x](../../../release-8-6/docs/migration-guide/from-older-version.mdx)
## Major breaking changes
The rest of this guide will help you upgrade successfully, either automatically or manually. But first, there are some [breaking changes][full-migration-notes] in Storybook 9. Here are the most impactful changes you should know about before you go further:
-* [Packages have been consolidated/removed](#package-structure-changes)
-* [Essential addons moved to core](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#essentials-addons-viewport-controls-interactions-and-actions-moved-to-core)
-* [Test addon renamed from `experimental-addon-test` to `addon-vitest`](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#experimental-test-addon-stabilized-and-renamed)
-* [`nextjs-vite` framework stabilized](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#nextjs-vite-builder-stabilized)
-* [Removed Webpack builder support for Preact, Vue, and Web Components in favor of Vite](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#dropped-webpack5-builder-support-in-favor-of-vite)
-* [Manager builder removed alias for `util`, `assert` and `process`](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#manager-builder-removed-alias-for-util-assert-and-process)
-* Ecosystem updates
- * [Node 20+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#nodejs--20)
- * [Angular 18+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#angular-require-v18-and-up)
- * [Lit v3+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#lit--require-v3-and-up)
- * [Next.js 14+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#nextjs-require-v14-and-up)
- * [Svelte 5+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#svelte-require-v5-and-up)
- * [Vite 5+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#vite-4)
- * [Vitest 3+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#vitest-addon-former-storybookexperimental-addon-test-vitest-20-support-is-dropped)
- * [npm 10+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#package-managers)
- * [pnpm 9+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#package-managers)
- * [yarn 4+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#package-managers)
- * [TypeScript 4.9+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#typescript--49)
+- [Packages have been consolidated/removed](#package-structure-changes)
+- [Essential addons moved to core](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#essentials-addons-viewport-controls-interactions-and-actions-moved-to-core)
+- [Test addon renamed from `experimental-addon-test` to `addon-vitest`](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#experimental-test-addon-stabilized-and-renamed)
+- [`nextjs-vite` framework stabilized](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#nextjs-vite-builder-stabilized)
+- [Removed Webpack builder support for Preact, Vue, and Web Components in favor of Vite](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#dropped-webpack5-builder-support-in-favor-of-vite)
+- [Manager builder removed alias for `util`, `assert` and `process`](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#manager-builder-removed-alias-for-util-assert-and-process)
+- Ecosystem updates
+ - [Node 20+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#nodejs--20)
+ - [Angular 18+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#angular-require-v18-and-up)
+ - [Lit v3+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#lit--require-v3-and-up)
+ - [Next.js 14+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#nextjs-require-v14-and-up)
+ - [Svelte 5+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#svelte-require-v5-and-up)
+ - [Vite 5+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#vite-4)
+ - [Vitest 3+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#vitest-addon-former-storybookexperimental-addon-test-vitest-20-support-is-dropped)
+ - [npm 10+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#package-managers)
+ - [pnpm 9+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#package-managers)
+ - [yarn 4+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#package-managers)
+ - [TypeScript 4.9+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#typescript--49)
If any of these changes apply to your project, please read through the linked migration notes before continuing.
@@ -61,34 +63,26 @@ You may wish to read the [full migration notes][full-migration-notes] before mig
To upgrade your Storybook, run the [upgrade](./upgrading.mdx) command in the root of your repository:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
This will:
1. Find all of the Storybook projects in your repository
2. For each project
1. Determine that none of the [breaking changes](#major-breaking-changes) apply to your project
- * If they do, you will receive instructions on how to resolve them before continuing
+ - If they do, you will receive instructions on how to resolve them before continuing
2. Upgrade your Storybook dependencies to the latest version
- 3. Run a collection of *automigrations*, which will:
- * Check for common upgrade tasks
- * Explain the necessary changes with links to more information
- * Ask for approval, then perform the task automatically on your behalf
+ 3. Run a collection of _automigrations_, which will:
+ - Check for common upgrade tasks
+ - Explain the necessary changes with links to more information
+ - Ask for approval, then perform the task automatically on your behalf
## New projects
To add Storybook to a project that isn’t currently using Storybook:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
This will:
1. Figure out which renderer (React, Vue, Angular, Web Components), builder (Webpack, Vite), or meta-framework (Next.js, SvelteKit) you’re using
@@ -131,23 +125,23 @@ The following packages are no longer published. Instead they have been consolida
The following packages have been consolidated and moved into an internal path to indicate that they are now for internal usage only. They will continue to work in `9.x` releases, but will likely be removed in `10.0`. See the [full migration notes](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#dropped-support-for-legacy-packages) for details.
-| Deprecation | Replacement |
-| ---------------------------- | ------------------------------------- |
-| `@storybook/builder-manager` | `storybook/internal/builder-manager` |
-| `@storybook/channels` | `storybook/internal/channels` |
-| `@storybook/client-logger` | `storybook/internal/client-logger` |
-| `@storybook/components` | `storybook/internal/components` |
-| `@storybook/core-common` | `storybook/internal/common` |
-| `@storybook/core-events` | `storybook/internal/core-events` |
-| `@storybook/core-server` | `storybook/internal/core-server` |
-| `@storybook/csf-tools` | `storybook/internal/csf-tools` |
-| `@storybook/docs-tools` | `storybook/internal/docs-tools` |
-| `@storybook/manager` | `storybook/internal/manager` |
-| `@storybook/node-logger` | `storybook/internal/node-logger` |
-| `@storybook/preview` | `storybook/internal/preview` |
-| `@storybook/router` | `storybook/internal/router` |
-| `@storybook/telemetry` | `storybook/internal/telemetry` |
-| `@storybook/types` | `storybook/internal/types` |
+| Deprecation | Replacement |
+| ---------------------------- | ------------------------------------ |
+| `@storybook/builder-manager` | `storybook/internal/builder-manager` |
+| `@storybook/channels` | `storybook/internal/channels` |
+| `@storybook/client-logger` | `storybook/internal/client-logger` |
+| `@storybook/components` | `storybook/internal/components` |
+| `@storybook/core-common` | `storybook/internal/common` |
+| `@storybook/core-events` | `storybook/internal/core-events` |
+| `@storybook/core-server` | `storybook/internal/core-server` |
+| `@storybook/csf-tools` | `storybook/internal/csf-tools` |
+| `@storybook/docs-tools` | `storybook/internal/docs-tools` |
+| `@storybook/manager` | `storybook/internal/manager` |
+| `@storybook/node-logger` | `storybook/internal/node-logger` |
+| `@storybook/preview` | `storybook/internal/preview` |
+| `@storybook/router` | `storybook/internal/router` |
+| `@storybook/telemetry` | `storybook/internal/telemetry` |
+| `@storybook/types` | `storybook/internal/types` |
Addon authors may continue to use the internal packages, there is currently not yet any replacement.
@@ -163,8 +157,4 @@ In addition to the automigrations and manual migrations above, there are also op
There are [many good reasons](/blog/storybook-csf3-is-here/) to convert your stories from CSF 2 to CSF 3. We provide a codemod which, in most cases, should automatically make the code changes for you (make sure to update the glob to fit your files):
-{/* prettier-ignore-start */}
-
-
-{/* prettier-ignore-end */}
\ No newline at end of file
diff --git a/docs/releases/migration-guide.mdx b/docs/releases/migration-guide.mdx
index 8a01602fff06..98495d44c96d 100644
--- a/docs/releases/migration-guide.mdx
+++ b/docs/releases/migration-guide.mdx
@@ -1,5 +1,5 @@
---
-title: 'Migration guide for Storybook 10'
+title: Migration guide for Storybook 10
sidebar:
order: 1
title: Migrate to Storybook 10
@@ -20,18 +20,20 @@ Coming soon:
This guide is meant to help you **upgrade from Storybook 9.x to 10** successfully!
- **Migrating from a Storybook version prior to 9?**
- You'll first need to [upgrade to Storybook 9](./migration-guide-from-older-version.mdx). Then you can return to this guide.
+**Migrating from a Storybook version prior to 9?**
+
+You'll first need to [upgrade to Storybook 9](./migration-guide-from-older-version.mdx). Then you can return to this guide.
+
## Major breaking changes
The rest of this guide will help you upgrade successfully, either automatically or manually. But first, there are some [breaking changes][full-migration-notes] in Storybook 10. Here are the most impactful changes you should know about before you go further:
-* [Main configuration (`.storybook/main.js|ts`) and other presets must be valid ESM](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#the-storybookmain-file-and-other-presets-must-be-valid-esm)
-* Ecosystem updates
- * [Node 20.19+ or 22.12+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#nodejs-2019-or-2212-required)
+- [Main configuration (`.storybook/main.js|ts`) and other presets must be valid ESM](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#the-storybookmain-file-and-other-presets-must-be-valid-esm)
+- Ecosystem updates
+ - [Node 20.19+ or 22.12+ is now required](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#nodejs-2019-or-2212-required)
If any of these changes apply to your project, please read through the linked migration notes before continuing.
@@ -43,34 +45,26 @@ You may wish to read the [full migration notes][full-migration-notes] before mig
To upgrade your Storybook, run the [upgrade](./upgrading.mdx) command in the root of your repository:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
This will:
1. Find all of the Storybook projects in your repository
2. For each project
1. Determine that none of the [breaking changes](#major-breaking-changes) apply to your project
- * If they do, you will receive instructions on how to resolve them before continuing
+ - If they do, you will receive instructions on how to resolve them before continuing
2. Upgrade your Storybook dependencies to the latest version
- 3. Run a collection of *automigrations*, which will:
- * Check for common upgrade tasks
- * Explain the necessary changes with links to more information
- * Ask for approval, then perform the task automatically on your behalf
+ 3. Run a collection of _automigrations_, which will:
+ - Check for common upgrade tasks
+ - Explain the necessary changes with links to more information
+ - Ask for approval, then perform the task automatically on your behalf
## New projects
To add Storybook to a project that isn’t currently using Storybook:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
This will:
1. Figure out which renderer (React, Vue, Angular, Web Components), builder (Webpack, Vite), or meta-framework (Next.js, SvelteKit) you’re using
diff --git a/docs/releases/roadmap.mdx b/docs/releases/roadmap.mdx
index fd75ab251037..e40d6914692a 100644
--- a/docs/releases/roadmap.mdx
+++ b/docs/releases/roadmap.mdx
@@ -1,16 +1,15 @@
---
-title: 'Roadmap'
+title: Roadmap
hideRendererSelector: true
sidebar:
order: 5
- title: Roadmap
---
The Storybook team maintains a [public roadmap](https://github.com/orgs/storybookjs/projects/20/views/1) in the form of a GitHub project. This page explains what's in the roadmap, how to interpret it, and how to contribute to it.
## What's in the roadmap?
-Each card represents a Storybook project. The columns represent how larger changes make their way from idea to shipped feature. Projects typically start as an [Request for Comment (RFC)](./RFC.mdx), then evolve into a [tracking issue](https://github.com/storybookjs/storybook/issues?q=is%3Aissue++sort%3Aupdated-desc+label%3ATracking+) once the team has fully scoped what it entails. We ship a Storybook [minor version](https://semver.org/) every eight weeks, and a major version once per year, typically in Feb/Mar.
+Each card represents a Storybook project. The columns represent how larger changes make their way from idea to shipped feature. Projects typically start as an [Request for Comment (RFC)](../contribute/RFC.mdx), then evolve into a [tracking issue](https://github.com/storybookjs/storybook/issues?q=is%3Aissue++sort%3Aupdated-desc+label%3ATracking+) once the team has fully scoped what it entails. We ship a Storybook [minor version](https://semver.org/) every eight weeks, and a major version once per year, typically in Feb/Mar.
### Candidates
@@ -18,7 +17,7 @@ These cards are ideas on our radar that we are considering for the current major
### Under consideration
-These are projects being discussed for the next dev cycle. For example, if the most recent minor version is `8.1`, and we are currently working on `8.2`, the projects in this column would be under consideration for `8.3`. Unlike the candidates column, which can contain any idea, the projects under consideration must be documented with an [RFC](./RFC.mdx).
+These are projects being discussed for the next dev cycle. For example, if the most recent minor version is `8.1`, and we are currently working on `8.2`, the projects in this column would be under consideration for `8.3`. Unlike the candidates column, which can contain any idea, the projects under consideration must be documented with an [RFC](../contribute/RFC.mdx).
### In progress
@@ -43,4 +42,4 @@ The Storybook core team and our community members continuously contribute bug fi
### How do I get something onto the board?
-If there's a significant product improvement that you want to see, and there is currently an issue or an [RFC](./RFC.mdx) for it, upvote that issue/discussion, and comment on it with more information about your need or use case if it's not currently captured. If you don't see anything that's quite right, please feel free to [submit an RFC](https://github.com/storybookjs/storybook/discussions/new?category=rfc). We prioritize based on a combination of user/contributor interest (upvotes, comments, [Discord](https://discord.gg/storybook) conversations, etc.) and our own strategic ambitions for the project.
+If there's a significant product improvement that you want to see, and there is currently an issue or an [RFC](../contribute/RFC.mdx) for it, upvote that issue/discussion, and comment on it with more information about your need or use case if it's not currently captured. If you don't see anything that's quite right, please feel free to [submit an RFC](https://github.com/storybookjs/storybook/discussions/new?category=rfc). We prioritize based on a combination of user/contributor interest (upvotes, comments, [Discord](https://discord.gg/storybook) conversations, etc.) and our own strategic ambitions for the project.
diff --git a/docs/releases/upgrading.mdx b/docs/releases/upgrading.mdx
index 92c6534c30f1..a1d6aa4c8665 100644
--- a/docs/releases/upgrading.mdx
+++ b/docs/releases/upgrading.mdx
@@ -1,5 +1,5 @@
---
-title: 'Upgrading Storybook'
+title: Upgrading Storybook
sidebar:
order: 3
title: Upgrading
@@ -13,31 +13,31 @@ The most common upgrade is Storybook itself. [Storybook releases](https://storyb
To help ease the pain of keeping Storybook up-to-date, we provide a command-line script that automatically detects all Storybook projects in your repository:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- **Important:** Always run the upgrade command from your repository root. The script will automatically detect all Storybook projects in your repository, including in mono-repository setups.
+
+**Important:** Always run the upgrade command from your repository root. The script will automatically detect all Storybook projects in your repository, including in mono-repository setups.
+
The `upgrade` command will use whichever version you specify. For example:
-* `storybook@latest upgrade` will upgrade to the latest version
-* `storybook@8.6.1 upgrade` will upgrade to `8.6.1`
-* `storybook@9 upgrade` will upgrade to the newest `9.x.x` version
+- `storybook@latest upgrade` will upgrade to the latest version
+- `storybook@8.6.1 upgrade` will upgrade to `8.6.1`
+- `storybook@9 upgrade` will upgrade to the newest `9.x.x` version
- The `upgrade` command is designed to upgrade from one major version to the next.
- - ✅ OK: Using Storybook 8 and running `storybook@9 upgrade`
- - ❌ Not OK: Using Storybook 7 and running `storybook@9 upgrade`
+The `upgrade` command is designed to upgrade from one major version to the next.
+
+- ✅ OK: Using Storybook 8 and running `storybook@9 upgrade`
+- ❌ Not OK: Using Storybook 7 and running `storybook@9 upgrade`
- If you want to upgrade across more than major version, run the command multiple times. For example, to upgrade from Storybook 7 to Storybook 9, you first need to upgrade to the latest version of Storybook 8 with `storybook@8 upgrade`, and then run `storybook@9 upgrade` to upgrade to the latest version of Storybook 9.
+If you want to upgrade across more than major version, run the command multiple times. For example, to upgrade from Storybook 7 to Storybook 9, you first need to upgrade to the latest version of Storybook 8 with `storybook@8 upgrade`, and then run `storybook@9 upgrade` to upgrade to the latest version of Storybook 9.
+
+The only exception to this is when upgrading from 6 to 8, where you can run `storybook@8 upgrade` directly to upgrade from 6.x.x to 8.x.x.
- The only exception to this is when upgrading from 6 to 8, where you can run `storybook@8 upgrade` directly to upgrade from 6.x.x to 8.x.x.
### Mono-repository support
@@ -58,18 +58,19 @@ STORYBOOK_PROJECT_ROOT=./packages/frontend storybook@latest upgrade
This is especially helpful in huge mono-repositories with semi-encapsulated Storybooks.
-
## Upgrade process
After running the command, the script will:
-* Detect all Storybook projects in your repository
-* Upgrade all Storybook packages to the specified version
-* Run the relevant [automigrations](../releases/migration-guide.mdx#automatic-upgrade) factoring in the [breaking changes](../releases/migration-guide.mdx#major-breaking-changes) between your current version and the specified version
-* Automatically run the [doctor command](#automatic-health-check) to verify the upgrade
+- Detect all Storybook projects in your repository
+- Upgrade all Storybook packages to the specified version
+- Run the relevant [automigrations](../releases/migration-guide.mdx#automatic-upgrade) factoring in the [breaking changes](../releases/migration-guide.mdx#major-breaking-changes) between your current version and the specified version
+- Automatically run the [doctor command](#automatic-health-check) to verify the upgrade
- In addition to running the command, we also recommend checking the [MIGRATION.md file](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md), for the detailed log of relevant changes and deprecations that might affect your upgrade.
+
+In addition to running the command, we also recommend checking the [MIGRATION.md file](https://github.com/storybookjs/storybook/blob/next/MIGRATION.md), for the detailed log of relevant changes and deprecations that might affect your upgrade.
+
### Automatic health check
@@ -98,18 +99,18 @@ storybook@latest upgrade [options]
### Available flags
-| Flag | Description |
-| -------------------------------- | ------------------------------------------------------------------------------------------ |
-| `-c, --config-dir ` | Directory or directories to find Storybook configurations |
-| `--debug` | Enable more logs for debugging (default: false) |
-| `--disable-telemetry` | Disable sending telemetry data |
-| `--enable-crash-reports` | Enable sending crash reports to telemetry data |
-| `-f, --force` | Force the upgrade, skipping autoblockers |
-| `--loglevel ` | Define log level: `debug`, `error`, `info`, `silent`, `trace`, or `warn` (default: `info`) |
-| `--package-manager ` | Force package manager: `npm`, `pnpm`, `yarn1`, `yarn2`, or `bun` |
-| `-s, --skip-check` | Skip postinstall version and automigration checks |
-| `--logfile [path]` | Write all debug logs to the specified file at the end of the run. Defaults to debug-storybook.log when [path] is not provided. |
-| `-y, --yes` | Skip prompting the user |
+| Flag | Description |
+| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
+| `-c, --config-dir ` | Directory or directories to find Storybook configurations |
+| `--debug` | Enable more logs for debugging (default: false) |
+| `--disable-telemetry` | Disable sending telemetry data |
+| `--enable-crash-reports` | Enable sending crash reports to telemetry data |
+| `-f, --force` | Force the upgrade, skipping autoblockers |
+| `--loglevel ` | Define log level: `debug`, `error`, `info`, `silent`, `trace`, or `warn` (default: `info`) |
+| `--package-manager ` | Force package manager: `npm`, `pnpm`, `yarn1`, `yarn2`, or `bun` |
+| `-s, --skip-check` | Skip postinstall version and automigration checks |
+| `--logfile [path]` | Write all debug logs to the specified file at the end of the run. Defaults to debug-storybook.log when [path] is not provided. |
+| `-y, --yes` | Skip prompting the user |
### Example usage
@@ -126,14 +127,10 @@ storybook@latest upgrade --config-dir .storybook-app .storybook-ui
## Automigrate script
-Storybook upgrades are not the only thing to consider: changes in the ecosystem also present challenges. For example well-known frontend frameworks, such as [Angular](https://update.angular.io/?l=2\&v=16.0-17.0), [Next.js](https://nextjs.org/docs/pages/building-your-application/upgrading) or [Svelte](https://svelte.dev/docs/v4-migration-guide) have been rolling out significant changes to their ecosystem, so even if you don't upgrade your Storybook version, you might need to update your configuration accordingly. That's what Automigrate is for:
-
-{/* prettier-ignore-start */}
+Storybook upgrades are not the only thing to consider: changes in the ecosystem also present challenges. For example well-known frontend frameworks, such as [Angular](https://update.angular.io/?l=2&v=16.0-17.0), [Next.js](https://nextjs.org/docs/pages/building-your-application/upgrading) or [Svelte](https://svelte.dev/docs/v4-migration-guide) have been rolling out significant changes to their ecosystem, so even if you don't upgrade your Storybook version, you might need to update your configuration accordingly. That's what Automigrate is for:
-{/* prettier-ignore-end */}
-
It runs a set of standard configuration checks, explains what is potentially out-of-date, and offers to fix it for you automatically. It also points to the relevant documentation so you can learn more. It runs automatically as part of [`storybook upgrade`](#upgrade-script) command, but it's also available on its own if you don't want to upgrade Storybook.
## Prereleases
@@ -142,24 +139,21 @@ In addition to the above, Storybook is under constant development, and we publis
To upgrade to the latest pre-release:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
The `upgrade` command will use whichever version you specify. For example:
-* `storybook@next upgrade` will upgrade to the newest pre-release version
-* `storybook@8.0.0-beta.1 upgrade` will upgrade to `8.0.0-beta.1`
-* `storybook@8 upgrade` will upgrade to the newest `8.x` version
+- `storybook@next upgrade` will upgrade to the newest pre-release version
+- `storybook@8.0.0-beta.1 upgrade` will upgrade to `8.0.0-beta.1`
+- `storybook@8 upgrade` will upgrade to the newest `8.x` version
If you'd like to downgrade to a stable version, manually edit the package version numbers in your `package.json` and re-install.
- Storybook collects completely anonymous data to help us improve user experience. Participation is optional, and you may [opt-out](../configure/telemetry.mdx#how-to-opt-out) if you'd not like to share any information.
-
+Storybook collects completely anonymous data to help us improve user experience. Participation is optional, and you may [opt-out](../configure/telemetry.mdx#how-to-opt-out) if you'd not like to share any information.
+
+
## Troubleshooting
@@ -181,16 +175,12 @@ Our automigrations usually only transform and migrate files inside of your `.sto
If you have other files that contain Storybook-specific code, you might need to manually migrate them.
-
-
- ### Storybook doesn't upgrade to the latest version when using Vue 2
-
- If you're attempting to upgrade Storybook to the latest version in your existing Vue 2 project, you will no longer be able to. This is because Vue 2 entered [End of Life](https://v2.vuejs.org/lts/) (EOL) on December 31st, 2023, and will no longer receive any updates from the Vue team. We recommend you upgrade your Vue 2 project to Vue 3 and then upgrade Storybook to the latest version. If you cannot upgrade your Vue 2 project to Vue 3, you can still upgrade Storybook, but only for the latest 7.x version. You can do this by running the following command:
+
- {/* prettier-ignore-start */}
+### Storybook doesn't upgrade to the latest version when using Vue 2
-
+If you're attempting to upgrade Storybook to the latest version in your existing Vue 2 project, you will no longer be able to. This is because Vue 2 entered [End of Life](https://v2.vuejs.org/lts/) (EOL) on December 31st, 2023, and will no longer receive any updates from the Vue team. We recommend you upgrade your Vue 2 project to Vue 3 and then upgrade Storybook to the latest version. If you cannot upgrade your Vue 2 project to Vue 3, you can still upgrade Storybook, but only for the latest 7.x version. You can do this by running the following command:
- {/* prettier-ignore-end */}
+
-
+
diff --git a/docs/sharing/design-integrations.mdx b/docs/sharing/design-integrations.mdx
index b2b7571e2bcd..81b55f527fa6 100644
--- a/docs/sharing/design-integrations.mdx
+++ b/docs/sharing/design-integrations.mdx
@@ -1,8 +1,7 @@
---
-title: 'Design integrations'
+title: Design integrations
sidebar:
order: 3
- title: Design integrations
---
Storybook integrates with design tools to speed up your development workflow. That helps you debug inconsistencies earlier in the design process, discover existing components to reuse, and compare designs to stories.
@@ -11,12 +10,12 @@ Storybook integrates with design tools to speed up your development workflow. Th
[Figma](https://www.figma.com/) is a collaborative UI design tool that allows multiple people to work on the same design simultaneously in the browser. There are two ways to integrate Storybook and Figma.
-* [**Embed Storybook in Figma**](#embed-storybook-in-figma-with-the-plugin)
-* [**Embed Figma in Storybook**](#embed-figma-in-storybook-with-the-addon)
+- [**Embed Storybook in Figma**](#embed-storybook-in-figma-with-the-plugin)
+- [**Embed Figma in Storybook**](#embed-figma-in-storybook-with-the-addon)
### Embed Storybook in Figma with the plugin
-[Storybook Connect](https://www.figma.com/community/plugin/1056265616080331589/Storybook-Connect) is a Figma plugin that allows you to embed component stories in Figma. It’s powered by [Storybook embeds](./embed.mdx) and [Chromatic](https://www.chromatic.com/?utm_source=storybook_website\&utm_medium=link\&utm_campaign=storybook), a publishing tool created by the Storybook team.
+[Storybook Connect](https://www.figma.com/community/plugin/1056265616080331589/Storybook-Connect) is a Figma plugin that allows you to embed component stories in Figma. It’s powered by [Storybook embeds](./embed.mdx) and [Chromatic](https://www.chromatic.com/?utm_source=storybook_website&utm_medium=link&utm_campaign=storybook), a publishing tool created by the Storybook team.
@@ -45,7 +44,9 @@ In Figma, select the component, open the plugin, and paste the URL.
Chromatic will automatically update your linked stories to reflect the most recent Storybook published on the branch you linked. That means the link persists even as you push new code.
- The plugin does not support linking stories to Figma layers.
+
+The plugin does not support linking stories to Figma layers.
+
#### View stories in Figma
@@ -64,12 +65,8 @@ Once they're connected, you'll be able to view the story by clicking the link in
Run the following command to install the addon.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
The CLI's [`add`](../api/cli-options.mdx#add) command automates the addon's installation and setup. To install it manually, see our [documentation](../addons/install-addons.mdx#manual-installation) on how to install addons.
@@ -80,18 +77,14 @@ The CLI's [`add`](../api/cli-options.mdx#add) command automates the addon's inst
In Figma, open the file you want to embed in Storybook. You can embed files, prototypes, components, and frames.
-* Embed a file or prototype, click the "Share" button to generate a unique URL for the file then click "Copy link".
+- Embed a file or prototype, click the "Share" button to generate a unique URL for the file then click "Copy link".
-* Embed a component or frame check "Link to selected frame" in the Share dialog. Or right click on the frame and go to "Copy/Paste as" » "Copy link".
+- Embed a component or frame check "Link to selected frame" in the Share dialog. Or right click on the frame and go to "Copy/Paste as" » "Copy link".
In Storybook, add a new [parameter](../writing-stories/parameters.mdx) named `design` to your story and paste the Figma URL. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### View designs in Storybook
Click the "Design" tab in the addon panel to view the embedded Figma design.
@@ -110,7 +103,7 @@ Zeplin's native app also supports [links to published Storybooks](https://suppor
## Zeroheight
-[Zeroheight](https://zeroheight.com/) is a collaborative styleguide generator for design systems. It showcases design, code, brand, and copywriting documentation in one place. Users can easily edit that documentation with a WYSIWYG editor.
+[Zeroheight](https://zeroheight.com/) is a collaborative styleguide generator for design systems. It showcases design, code, brand, and copywriting documentation in one place. Users can edit that documentation with a WYSIWYG editor.
Zeroheight integrates with [Storybook](https://zeroheight.com/3xlwst8/p/507ba7-storybook), enabling you to embed stories alongside your design specs.
@@ -142,5 +135,5 @@ Integrate Adobe XD with Storybook using the [design addon](https://storybook.js.
Extend and customize Storybook by building an integration. Integrate with lower-level Storybook APIs or bootstrap an addon to customize Storybook's UI and behavior.
-* [Addon documentation](../addons/index.mdx)
-* [Create an addon tutorial](../addons/writing-addons.mdx)
+- [Addon documentation](../addons/index.mdx)
+- [Create an addon tutorial](../addons/writing-addons.mdx)
diff --git a/docs/sharing/embed.mdx b/docs/sharing/embed.mdx
index 6926fae0076c..4b248a33e05a 100644
--- a/docs/sharing/embed.mdx
+++ b/docs/sharing/embed.mdx
@@ -1,5 +1,5 @@
---
-title: 'Embed stories'
+title: Embed stories
sidebar:
order: 2
title: Embed
@@ -13,11 +13,9 @@ Storybook supports `
-{/* prettier-ignore-end */}
-
#### Component-level configuration
If you want to customize the table of contents for a specific story, you can include a `toc` property in the story's meta (or default export) and provide the required [configuration](#configure-the-table-of-contents). For example, if you need to hide the table of contents for a specific story, adjust your story as follows:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Customize component documentation
Creating automated documentation with Storybook's Autodocs provides you with the starting point to build a sustainable documentation pattern. Nevertheless, it may not be suited for every case, and you may want to extend it and provide additional information. We recommend combining [MDX](./mdx.mdx) alongside Storybook's [Doc Blocks](./doc-blocks.mdx) for such cases to author your documentation.
@@ -165,12 +122,8 @@ Sometimes it's helpful to document multiple components together. For example, a
Autodocs allows you to document your "main" component, defined by the `component` property, as well as one or more `subcomponents` related to it.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-

The main component and its subcomponents will show up in a tabbed version of the [`ArgTypes` doc block](./doc-blocks.mdx#argtypes). The tab titles will correspond to the keys of the `subcomponents` object.
@@ -181,36 +134,26 @@ If you want to organize your documentation differently for component groups, we
The Docs Container is the component that wraps up the documentation page. It's responsible for rendering the documentation page in Storybook's UI. You can customize it by creating your own component and updating your Storybook UI configuration file (i.e., `.storybook/preview.jsx|tsx`) to reference it.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Override the default theme
By default, Storybook provides two themes for the UI: `light` and `dark`. If you need to customize the theme used by the documentation to match the existing one, you can update your Storybook UI configuration file (i.e., `.storybook/preview.jsx|tsx`) and apply it.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Working with custom MDX components
Out of the box, Storybook has a set of components that you can use to customize your documentation page. If you're working with a design system or component library and wish to add them to your documentation page, you can override the `MDXProvider` component inherited from `@mdx-js/react` with your own. However, there's a caveat to this, the component replacement will only have an impact if you're writing documentation using Markdown syntax (e.g., `#` for headings). Native HTML elements, such as `
`, will not be replaced with your custom implementation.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- This is not a Storybook issue but a detail of how MDX works. From their [migration guide](https://mdxjs.com/migrating/v2/#update-mdx-content):
- “We now ‘sandbox’ components, for lack of a better name. It means that when you pass a component for h1, it does get used for `# hi` but not for `
hi
`”
+This is not a Storybook issue but a detail of how MDX works. From their [migration guide](https://mdxjs.com/migrating/v2/#update-mdx-content):
+
+“We now ‘sandbox’ components, for lack of a better name. It means that when you pass a component for h1, it does get used for `# hi` but not for `
hi
`”
+
### Addon options
@@ -250,20 +193,12 @@ Out of the box, Storybook's Autodocs feature is built to generate documentation
Update your import statements to reference the component directly instead of the package's root. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Additionally, if you're developing using TypeScript, you may need to update Storybook's configuration file (i.e., `.storybook/main.js|ts`) to include the following:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
If you're still encountering issues, we recommend reaching out to the community using the default communication channels (e.g., [GitHub discussions](https://github.com/storybookjs/storybook/discussions/new?category=help)).
### The controls are not updating the story within the auto-generated documentation
@@ -272,7 +207,7 @@ If you turned off inline rendering for your stories via the [`inline`](../api/do
**Learn more about Storybook documentation**
-* Autodocs for creating documentation for your stories
-* [MDX](./mdx.mdx) for customizing your documentation
-* [Doc Blocks](./doc-blocks.mdx) for authoring your documentation
-* [Publishing docs](./build-documentation.mdx) to automate the process of publishing your documentation
+- Autodocs for creating documentation for your stories
+- [MDX](./mdx.mdx) for customizing your documentation
+- [Doc Blocks](./doc-blocks.mdx) for authoring your documentation
+- [Publishing docs](./build-documentation.mdx) to automate the process of publishing your documentation
diff --git a/docs/writing-docs/build-documentation.mdx b/docs/writing-docs/build-documentation.mdx
index d72b3c64b08c..0235604ba162 100644
--- a/docs/writing-docs/build-documentation.mdx
+++ b/docs/writing-docs/build-documentation.mdx
@@ -1,8 +1,7 @@
---
-title: 'Preview and build docs'
+title: Preview and build docs
sidebar:
order: 5
- title: Preview and build docs
---
Storybook allows you to create rich and extensive [documentation](./index.mdx) that will help you and any other stakeholder involved in the development process. Out of the box you have the tooling required to not only write it but also to preview it and build it.
@@ -27,9 +26,9 @@ It will look for any stories available either in [MDX](./mdx.mdx) or [CSF](../wr
There's some caveats to this build mode, as to the normal Storybook build:
-* The top level item refers to the primary story for your component.
-* Each individual story is now in a flattened display mode, with a different set of icons. This allows focus on the documentation itself.
-* Storybook's layout is rendered differently. The toolbar will not be displayed.
+- The top level item refers to the primary story for your component.
+- Each individual story is now in a flattened display mode, with a different set of icons. This allows focus on the documentation itself.
+- Storybook's layout is rendered differently. The toolbar will not be displayed.
## Publish Storybook's documentation
@@ -49,13 +48,13 @@ The same caveats mentioned above will apply.
You can use any hosting provider to deploy your documentation, for instance:
-* [Vercel](https://vercel.com/)
-* [Netlify](https://www.netlify.com/)
-* [S3](https://aws.amazon.com/en/s3/)
+- [Vercel](https://vercel.com/)
+- [Netlify](https://www.netlify.com/)
+- [S3](https://aws.amazon.com/en/s3/)
**Learn more about Storybook documentation**
-* [Autodocs](./autodocs.mdx) for creating documentation for your stories
-* [MDX](./mdx.mdx) for customizing your documentation
-* [Doc Blocks](./doc-blocks.mdx) for authoring your documentation
-* Publishing docs to automate the process of publishing your documentation
+- [Autodocs](./autodocs.mdx) for creating documentation for your stories
+- [MDX](./mdx.mdx) for customizing your documentation
+- [Doc Blocks](./doc-blocks.mdx) for authoring your documentation
+- Publishing docs to automate the process of publishing your documentation
diff --git a/docs/writing-docs/code-panel.mdx b/docs/writing-docs/code-panel.mdx
index f879773927d2..3ada6dcfae46 100644
--- a/docs/writing-docs/code-panel.mdx
+++ b/docs/writing-docs/code-panel.mdx
@@ -2,7 +2,6 @@
title: Code panel
sidebar:
order: 4
- title: Code panel
---
diff --git a/docs/writing-docs/doc-blocks.mdx b/docs/writing-docs/doc-blocks.mdx
index ea52c2ada97d..dc7906eeffb2 100644
--- a/docs/writing-docs/doc-blocks.mdx
+++ b/docs/writing-docs/doc-blocks.mdx
@@ -2,7 +2,6 @@
title: Doc blocks
sidebar:
order: 3
- title: Doc blocks
---
Storybook offers several doc blocks to help document your components and other aspects of your project.
@@ -15,9 +14,7 @@ The blocks are most commonly used within Storybook's [MDX documentation](./mdx.m

-{/* prettier-ignore-start */}
-
-```md title="ButtonDocs.mdx"
+```mdx title="ButtonDocs.mdx"
import { Meta, Primary, Controls, Story } from '@storybook/addon-docs/blocks';
import * as ButtonStories from './Button.stories';
@@ -49,8 +46,6 @@ A button can be of secondary importance.
{/* ... */}
```
-{/* prettier-ignore-end */}
-
## Customizing the automatic docs page
The blocks are also used to define the page template for [automatics docs](./autodocs.mdx). For example, here's the default template:
@@ -58,7 +53,14 @@ The blocks are also used to define the page template for [automatics docs](./aut

```jsx
-import { Title, Subtitle, Description, Primary, Controls, Stories } from '@storybook/addon-docs/blocks';
+import {
+ Title,
+ Subtitle,
+ Description,
+ Primary,
+ Controls,
+ Stories,
+} from '@storybook/addon-docs/blocks';
export const autoDocsTemplate = () => (
<>
@@ -76,9 +78,7 @@ If you [override the default page template](./autodocs.mdx#write-a-custom-templa
Note that some doc blocks render other blocks. For example, the `` block expands to:
-{/* prettier-ignore-start */}
-
-```md
+```mdx title="Button.mdx"
## Stories
@@ -91,8 +91,6 @@ Note that some doc blocks render other blocks. For example, the `` bl
{/* ... repeat for each story */}
```
-{/* prettier-ignore-end */}
-
As a result, for example, customizing the [`Source`](../api/doc-blocks/doc-block-source.mdx) block via parameters (see next section) will also affect the Source blocks rendered as part of [`Canvas`](../api/doc-blocks/doc-block-canvas.mdx) blocks.
## Customizing doc blocks
@@ -101,15 +99,11 @@ In both use cases (MDX and automatic docs), many of the doc blocks can be custom
For example, you can filter out the `style` prop from all [`Controls`](../api/doc-blocks/doc-block-controls.mdx) tables through your Storybook:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- Parameters can also be defined at the [component](../writing-stories/parameters.mdx#component-parameters) (or meta) level or the [story](../writing-stories/parameters.mdx#story-parameters) level, allowing you to customize Doc Blocks exactly as you need, where you need.
+Parameters can also be defined at the [component](../writing-stories/parameters.mdx#component-parameters) (or meta) level or the [story](../writing-stories/parameters.mdx#story-parameters) level, allowing you to customize Doc Blocks exactly as you need, where you need.
@@ -117,14 +111,10 @@ The blocks that accept customization via parameters are marked in the list of av
When using a doc block in MDX, it can also be customized with its props:
-{/* prettier-ignore-start */}
-
```md
```
-{/* prettier-ignore-end */}
-
## Available blocks
Each block has a dedicated API reference page detailing usage, available options, and technical details.
@@ -133,7 +123,7 @@ Each block has a dedicated API reference page detailing usage, available options
- Accepts parameters in the namespace `parameters.docs.argTypes`.
+Accepts parameters in the namespace `parameters.docs.argTypes`.
@@ -145,7 +135,7 @@ The `ArgTypes` block can be used to show a static table of [arg types](../api/ar
- Accepts parameters in the namespace `parameters.docs.canvas`.
+Accepts parameters in the namespace `parameters.docs.canvas`.
@@ -163,7 +153,7 @@ The `ColorPalette` block allows you to document all color-related items (e.g., s
- Accepts parameters in the namespace `parameters.docs.controls`.
+Accepts parameters in the namespace `parameters.docs.controls`.
@@ -193,8 +183,8 @@ The `Markdown` block allows you to import and include plain markdown in your MDX
The `Meta` block is used to [attach](#attached-vs-unattached) a custom MDX docs page alongside a component’s list of stories. It doesn’t render any content but serves two purposes in an MDX file:
-* Attaches the MDX file to a component and its stories, or
-* Controls the location of the unattached docs entry in the sidebar.
+- Attaches the MDX file to a component and its stories, or
+- Controls the location of the unattached docs entry in the sidebar.
### [Primary](../api/doc-blocks/doc-block-primary.mdx)
@@ -206,7 +196,7 @@ The `Primary` block displays the primary (first defined in the stories file) sto
- Accepts parameters in the namespace `parameters.docs.source`.
+Accepts parameters in the namespace `parameters.docs.source`.
@@ -224,8 +214,8 @@ The `Stories` block renders the full collection of stories in a stories file.
- Accepts parameters in the namespace `parameters.docs.story`.
-
+Accepts parameters in the namespace `parameters.docs.story`.
+
[Stories](../writing-stories/index.mdx) are Storybook's fundamental building blocks.
@@ -244,7 +234,7 @@ The `Subtitle` block can serve as a secondary heading for your docs entry.
- Accepts parameters in the namespace `parameters.docs.toc`.
+Accepts parameters in the namespace `parameters.docs.toc`.
@@ -280,15 +270,11 @@ Storybook also provides a [`useOf` hook](../api/doc-blocks/doc-block-useof.mdx)
Storybook's Doc Blocks are highly customizable and helpful building blocks to assist you with building your custom documentation. Although most of them enable you to customize them with parameters or globally to create custom [documentation templates](#customizing-the-automatic-docs-page), they are primarily designed for MDX files. For example, if you try to add the `ColorPalette` block to your stories as follows, you'll get an error message when the story loads in Storybook.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
**Learn more about Storybook documentation**
-* [Autodocs](./autodocs.mdx) for creating documentation for your stories
-* [MDX](./mdx.mdx) for customizing your documentation
-* Doc Blocks for authoring your documentation
-* [Publishing docs](./build-documentation.mdx) to automate the process of publishing your documentation
+- [Autodocs](./autodocs.mdx) for creating documentation for your stories
+- [MDX](./mdx.mdx) for customizing your documentation
+- Doc Blocks for authoring your documentation
+- [Publishing docs](./build-documentation.mdx) to automate the process of publishing your documentation
diff --git a/docs/writing-docs/index.mdx b/docs/writing-docs/index.mdx
index 6f43864ccd6e..7388905e595b 100644
--- a/docs/writing-docs/index.mdx
+++ b/docs/writing-docs/index.mdx
@@ -1,5 +1,5 @@
---
-title: 'How to document components'
+title: How to document components
hideRendererSelector: true
sidebar:
order: 4
diff --git a/docs/writing-docs/mdx.mdx b/docs/writing-docs/mdx.mdx
index bb871974aea5..33d46eb98e8a 100644
--- a/docs/writing-docs/mdx.mdx
+++ b/docs/writing-docs/mdx.mdx
@@ -1,8 +1,7 @@
---
-title: 'MDX'
+title: MDX
sidebar:
order: 2
- title: MDX
---
[MDX](https://mdxjs.com/) files mix Markdown and Javascript/JSX to create rich interactive documentation. You can use Markdown’s readable syntax (such as `# heading`) for your documentation, include stories defined in [Component Story Format (CSF)](../api/csf/index.mdx), and freely embed JSX component blocks at any point in the file. All at once.
@@ -15,20 +14,12 @@ In addition, you can write pure documentation pages in MDX and add them to Story
Let's start with an example, `Checkbox.mdx`, combining Markdown with a single story.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
This MDX file references a story file, `Checkbox.stories.js|ts`, that is written in [Component Story Format (CSF)](../api/csf/index.mdx):
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
And here's how that's rendered in Storybook:

@@ -41,8 +32,8 @@ Let’s break it down.
The first thing you'll notice is that the component documentation is divided into distinct formats: one for writing component stories describing each possible component state and the second one for documenting how to use them. This split leverages the best qualities of each format:
-* **CSF** is great for succinctly defining stories (component examples). If you use TypeScript, it also provides type safety and auto-completion.
-* **MDX** is great for writing structured documentation and composing it with interactive JSX elements.
+- **CSF** is great for succinctly defining stories (component examples). If you use TypeScript, it also provides type safety and auto-completion.
+- **MDX** is great for writing structured documentation and composing it with interactive JSX elements.
### Anatomy of MDX
@@ -52,62 +43,40 @@ The document consists of a number of blocks separated by blank lines. Since MDX
Going through the code blocks in sequence:
-{/* prettier-ignore-start */}
-
```mdx
-{ /* Checkbox.mdx */ }
+{/* Checkbox.mdx */}
```
-{/* prettier-ignore-end */}
-
Comments in MDX are JSX blocks that contain JS comments.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Imports the components and stories that will be used in the JSX throughout the rest of the file.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- When providing the `of` prop to the `Meta` block, make sure that you're referencing the **full set of exports** of the story file and not the component itself to prevent render issues with the generated documentation.
+
+When providing the `of` prop to the `Meta` block, make sure that you're referencing the **full set of exports** of the story file and not the component itself to prevent render issues with the generated documentation.
+
The `Meta` block defines where the document will be placed in the sidebar. In this case, it is adjacent to the Checkbox’s stories. By default, the docs sidebar node is titled `"Docs"`, but this can be customized by passing a `name` prop (e.g., ``). If you want to place a docs node at an arbitrary point in the navigation hierarchy, you can use the `title` prop (e.g., ``).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
MDX supports standard markdown (["commonmark"](https://commonmark.org/)) by default and can be extended to support [GitHub Flavored Markdown (GFM)](https://github.github.com/gfm/) and other extensions (see the [Troubleshooting section](#troubleshooting) to learn more about some of the current limitations).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Finally, MDX supports blocks of arbitrary JSX.
In this case, we are leveraging “Doc Blocks”, a library of documentation components designed to work with Storybook stories to show your stories, your component APIs & controls for interacting with your components inside your documentation, among other utilities.
In addition to Doc Blocks, MDX can incorporate arbitrary React components, making it a very flexible documentation system. Suppose you want a stylized list of “dos and don’ts” for your component; you can use off-the-shelf components or write your own.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Known limitations
While MDX supports a variety of runtimes ([React](https://mdxjs.com/packages/react/), [Preact](https://mdxjs.com/packages/preact/), [Vue](https://mdxjs.com/packages/vue/)), Storybook’s implementation is React-only. That means your documentation is rendered in React, while your stories render in the runtime of your choice (React, Vue, Angular, Web Components, Svelte, etc.).
@@ -116,50 +85,34 @@ While MDX supports a variety of runtimes ([React](https://mdxjs.com/packages/rea
In addition, to document your components with MDX, you can also extend it to write other types of content, such as guidelines or best practices on how to use them. To enable custom documentation for your stories with this format, start by updating your Storybook configuration file (i.e., `.storybook/main.js|ts|cjs`).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Create an MDX file to add your custom documentation. Depending on how you want your documentation to render in the UI, you'll need to consider the following use cases.
### Using the `Meta` Doc Block
If you need to match the component documentation to an existing story, you can configure the [`Meta`](../api/doc-blocks/doc-block-meta.mdx) Doc Block to control how the documentation gets rendered. Out of the box, it allows you to define a custom title or a reference to the story you need to document (i.e., via the `of` prop). For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Writing unattached documentation
Suppose you're documenting an existing component and only provide the `Meta` Doc Block without additional props or other blocks. In that case, Storybook will consider it as "unattached" documentation, or in other words, a "documentation-only" page, and it will render it differently in the sidebar navigation menu:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-

### Using the File System
However, providing the `Meta` Doc Block may not be required for certain use cases, such as standalone pages or even as guidelines for testing your components. In that case, you can safely omit it. Storybook will instead rely on the file's physical location to place the documentation in the sidebar, overriding any pre-existent [auto-generated](./autodocs.mdx) documentation with your own. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- If you're overriding an existing auto-generated documentation page enabled via [`tags`](./autodocs.mdx#setup-automated-docs) configuration property, we recommend removing it to avoid errors.
-
+If you're overriding an existing auto-generated documentation page enabled via [`tags`](./autodocs.mdx#set-up-automated-documentation) configuration property, we recommend removing it to avoid errors.
+
Once the custom MDX documentation is loaded, Storybook will infer the title and location using the same heuristic rules to generate [auto-title stories](../configure/user-interface/sidebar-and-urls.mdx#csf-30-auto-titles) and render it in the sidebar as a `Docs` entry.
@@ -168,12 +121,8 @@ Once the custom MDX documentation is loaded, Storybook will infer the title and
Writing standalone documentation pages is a common use case that applies not only on a per-component but also on a per-project basis. For example, you might want to document your project's onboarding process with instructions on using it. To do so, you can create a new MDX file containing your documentation using a similar structure and content:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-

When Storybook loads the documentation, it will infer the placement of the page in the sidebar navigation menu using the file's physical location and render it as a `Docs` entry.
@@ -182,34 +131,24 @@ When Storybook loads the documentation, it will infer the placement of the page
Documentation can be expensive to maintain and keep up to date when applied to every project component. To help simplify this process, Storybook provides a set of useful UI components (i.e., Doc Blocks) to help cover more advanced cases. If you need additional content, use them to help create your custom documentation.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Working with multiple components
If you need to document multiple components in a single documentation page, you can reference them directly inside your MDX file. Internally, Storybook looks for the story metadata and composes it alongside your existing documentation. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Generate documentation from Markdown
If you need to extend your documentation with additional content written in Markdown, you can use the `Markdown` Doc Block to import the available content, and Storybook will render it alongside your existing documentation. For example, if you have a `CHANGELOG.md` file, you can import it and render it in your documentation page as follows:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- The `Markdown` Doc Block provides additional configuration options to customize the rendering of your documentation. For more information, refer to the [API documentation](../api/doc-blocks/doc-block-markdown.mdx).
+
+The `Markdown` Doc Block provides additional configuration options to customize the rendering of your documentation. For more information, refer to the [API documentation](../api/doc-blocks/doc-block-markdown.mdx).
+

@@ -230,13 +169,13 @@ Instead, if you need to target a specific documentation section, you can adjust
However, cross-linking documentation isn't restricted to documentation pages. You can adjust the `path` query and supply the story's unique identifier if you need to reference a specific one. For example:
-{/*This redirects to the **Canvas** tab of the story: */}
+{/* This redirects to the **Canvas** tab of the story: */}
```md
[Go to specific story canvas](?path=/story/some--id)
```
-{/*You can also use anchors to target a specific section of a page: */}
+{/* You can also use anchors to target a specific section of a page: */}
@@ -250,14 +189,12 @@ Applying this pattern with the [Controls](../essentials/controls.mdx) feature, a
If you're extending your documentation to include specific features (e.g., tables, footnotes), you may run into some issues rendering them correctly using the current MDX version supported by Storybook. We recommend enabling the [`remark-gfm`](https://github.com/remarkjs/remark-gfm) plugin in your configuration file (i.e., [`.storybook/main.js|ts`](../configure/index.mdx)) to render them correctly.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- The [`remark-gfm`](https://github.com/remarkjs/remark-gfm) package is not included by default with Storybook and must be installed separately as a development dependency. To learn more about how to use it and the other breaking changes introduced by MDX, refer to the [GFM guide](https://mdxjs.com/guides/gfm/) and the [migration guide](https://mdxjs.com/migrating/v2/) provided by the MDX team for more information.
+
+The [`remark-gfm`](https://github.com/remarkjs/remark-gfm) package is not included by default with Storybook and must be installed separately as a development dependency. To learn more about how to use it and the other breaking changes introduced by MDX, refer to the [GFM guide](https://mdxjs.com/guides/gfm/) and the [migration guide](https://mdxjs.com/migrating/v2/) provided by the MDX team for more information.
+
### The MDX documentation doesn't render in my environment
@@ -279,7 +216,9 @@ npx @hipster/mdx2-issue-checker
```
- Depending on the volume, you may be required to run the command multiple times to fix all the issues.
+
+Depending on the volume, you may be required to run the command multiple times to fix all the issues.
+
When it finishes, it will output the list of files causing issues. You can then use this information to fix the problems manually.
@@ -302,14 +241,14 @@ If you turned off inline rendering for your stories via the [`inline`](../api/do
For most projects, Storybook's addon-docs uses the React version listed in your project's dependencies. If it does not find one, it will use React 18.2.0. There are two exceptions to this:
-* Preact projects will always use React 17
-* Next.js projects will always use the canary version that comes with the Next.js version installed, regardless of which React version is listed in the project’s dependencies.
+- Preact projects will always use React 17
+- Next.js projects will always use the canary version that comes with the Next.js version installed, regardless of which React version is listed in the project’s dependencies.
If you're having issues with the React version used, you may need to re-create your project's `node_modules` folder to ensure the correct version is used.
**Learn more about Storybook documentation**
-* [Autodocs](./autodocs.mdx) for creating documentation for your stories
-* MDX for customizing your documentation
-* [Doc Blocks](./doc-blocks.mdx) for authoring your documentation
-* [Publishing docs](./build-documentation.mdx) to automate the process of publishing your documentation
+- [Autodocs](./autodocs.mdx) for creating documentation for your stories
+- MDX for customizing your documentation
+- [Doc Blocks](./doc-blocks.mdx) for authoring your documentation
+- [Publishing docs](./build-documentation.mdx) to automate the process of publishing your documentation
diff --git a/docs/writing-stories/args.mdx b/docs/writing-stories/args.mdx
index 3796aec92a98..3d5b718bdbd3 100644
--- a/docs/writing-stories/args.mdx
+++ b/docs/writing-stories/args.mdx
@@ -1,13 +1,12 @@
---
-title: 'Args'
+title: Args
sidebar:
order: 1
- title: Args
---
-A story is a component with a set of arguments that define how the component should render. “Args” are Storybook’s mechanism for defining those arguments in a single JavaScript object. Args can be used to dynamically change props, slots, styles, inputs, etc. It allows Storybook and its addons to live edit components. You *do not* need to modify your underlying component code to use args.
+A story is a component with a set of arguments that define how the component should render. “Args” are Storybook’s mechanism for defining those arguments in a single JavaScript object. Args can be used to dynamically change props, slots, styles, inputs, etc. It allows Storybook and its addons to live edit components. You _do not_ need to modify your underlying component code to use args.
When an arg’s value changes, the component re-renders, allowing you to interact with components in Storybook’s UI via addons that affect args.
@@ -19,100 +18,76 @@ The `args` object can be defined at the [story](#story-args), [component](#compo
## Story args
-
+
- To define the args of a single story, use the `args` property in the `Story` component if you are using Svelte CSF with the native templating syntax, or use the `args` key on a CSF story file:
+To define the args of a single story, use the `args` property in the `Story` component if you are using Svelte CSF with the native templating syntax, or use the `args` key on a CSF story file:
-
+
- To define the args of a single story, use the `args` CSF story key:
+To define the args of a single story, use the `args` CSF story key:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
These args will only apply to the story for which they are attached, although you can [reuse](./build-pages-with-storybook.mdx#args-composition-for-presentational-screens) them via JavaScript object reuse:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
In the above example, we use the [object spread](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) feature of ES 2015.
## Component args
-
+
- You can also define args at the component level; they will apply to all the component's stories unless you overwrite them. To do so, use the `args` property in the `defineMeta` function of a Svelte CSF story file or via the `args` key on the default CSF export:
+You can also define args at the component level; they will apply to all the component's stories unless you overwrite them. To do so, use the `args` property in the `defineMeta` function of a Svelte CSF story file or via the `args` key on the default CSF export:
-
+
- You can also define args at the component level; they will apply to all the component's stories unless you overwrite them. To do so, use the `args` key on the `default` CSF export:
+You can also define args at the component level; they will apply to all the component's stories unless you overwrite them. To do so, use the `args` key on the `default` CSF export:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Global args
You can also define args at the global level; they will apply to every component's stories unless you overwrite them. To do so, define the `args` property in the default export of `preview.*`:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- For most uses of global args, [globals](../essentials/toolbars-and-globals.mdx) are a better tool for defining globally-applied settings, such as a theme. Using globals enables users to change the value with the toolbar menu.
+
+For most uses of global args, [globals](../essentials/toolbars-and-globals.mdx) are a better tool for defining globally-applied settings, such as a theme. Using globals enables users to change the value with the toolbar menu.
+
## Args composition
You can separate the arguments to a story to compose in other stories. Here's how you can combine args for multiple stories of the same component.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- If you find yourself re-using the same args for most of a component's stories, you should consider using [component-level args](#component-args).
+
+If you find yourself re-using the same args for most of a component's stories, you should consider using [component-level args](#component-args).
+
Args are useful when writing stories for composite components that are assembled from other components. Composite components often pass their arguments unchanged to their child components, and similarly, their stories can be compositions of their child components stories. With args, you can directly compose the arguments:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Args can modify any aspect of your component
You can use args in your stories to configure the component's appearance, similar to what you would do in an application. For example, here's how you could use a `footer` arg to populate a child component:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Setting args through the URL
You can also override the set of initial args for the active story by adding an `args` query parameter to the URL. Typically, you would use [Controls](../essentials/controls.mdx) to handle this. For example, here's how you could set a `size` and `style` arg in the Storybook's URL:
@@ -125,54 +100,41 @@ As a safeguard against [XSS](https://owasp.org/www-community/attacks/xss/) attac
The `args` param is always a set of `key: value` pairs delimited with a semicolon `;`. Values will be coerced (cast) to their respective `argTypes` (which may have been automatically inferred). Objects and arrays are supported. Special values `null` and `undefined` can be set by prefixing with a bang `!`. For example, `args=obj.key:val;arr[0]:one;arr[1]:two;nil:!null` will be interpreted as:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Similarly, special formats are available for dates and colors. Date objects will be encoded as `!date(value)` with value represented as an ISO date string. Colors are encoded as `!hex(value)`, `!rgba(value)` or `!hsla(value)`. Note that rgb(a) and hsl(a) should not contain spaces or percentage signs in the URL.
Args specified through the URL will extend and override any default values of args set on the story.
-
- ## Setting args from within a story
+
+
+## Setting args from within a story
- Interactive components often need to be controlled by their containing component or page to respond to events, modify their state and reflect those changes in the UI. For example, when a user toggles a switch component, the switch should be checked, and the arg shown in Storybook should reflect the change. To enable this, you can use the `useArgs` API exported by `storybook/preview-api`:
+Interactive components often need to be controlled by their containing component or page to respond to events, modify their state and reflect those changes in the UI. For example, when a user toggles a switch component, the switch should be checked, and the arg shown in Storybook should reflect the change. To enable this, you can use the `useArgs` API exported by `storybook/preview-api`:
- {/* prettier-ignore-start */}
+
-
+
- {/* prettier-ignore-end */}
+If you're using Storybook's hooks API in the story's render function, **do not** mix them with React's hooks such as `useState`, `useEffect`, or `useRef`. This is because side effects and re-rendering triggered by React's hooks do not run through Storybook's hook context, which can cause an error on re-render. To manage state and side effects within a story, you must use Storybook's equivalent hooks, such as `useState`, `useEffect`, and `useRef` from `storybook/preview-api`.
-
+
- If you're using Storybook's hooks API in the story's render function, **do not** mix them with React's hooks such as `useState`, `useEffect`, or `useRef`. This is because side effects and re-rendering triggered by React's hooks do not run through Storybook's hook context, which can cause an error on re-render. To manage state and side effects within a story, you must use Storybook's equivalent hooks, such as `useState`, `useEffect`, and `useRef` from `storybook/preview-api`.
-
-
-
+
## Mapping to complex arg values
Complex values such as JSX elements cannot be serialized to the manager (e.g., the Controls panel) or synced with the URL. Arg values can be "mapped" from a simple string to a complex type using the `mapping` property in `argTypes` to work around this limitation. It works in any arg but makes the most sense when used with the `select` control type.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
-Note that `mapping` does not have to be exhaustive. If the arg value is not a property of `mapping`, the value will be used directly. Keys in `mapping` always correspond to arg *values*, not their index in the `options` array.
+Note that `mapping` does not have to be exhaustive. If the arg value is not a property of `mapping`, the value will be used directly. Keys in `mapping` always correspond to arg _values_, not their index in the `options` array.
- Using args in addons
-
- If you are [writing an addon](../addons/writing-addons.mdx) that wants to read or update args, use the `useArgs` hook exported by `storybook/manager-api`:
+Using args in addons
- {/* prettier-ignore-start */}
+If you are [writing an addon](../addons/writing-addons.mdx) that wants to read or update args, use the `useArgs` hook exported by `storybook/manager-api`:
-
+
- {/* prettier-ignore-end */}
-
\ No newline at end of file
+
diff --git a/docs/writing-stories/build-pages-with-storybook.mdx b/docs/writing-stories/build-pages-with-storybook.mdx
index fb69221d384d..e917d51d926d 100644
--- a/docs/writing-stories/build-pages-with-storybook.mdx
+++ b/docs/writing-stories/build-pages-with-storybook.mdx
@@ -1,5 +1,5 @@
---
-title: 'Building pages with Storybook'
+title: Building pages with Storybook
sidebar:
order: 9
title: Building pages and screens
@@ -9,8 +9,8 @@ Storybook helps you build any component, from small “atomic” components to c
There are many ways to build pages in Storybook. Here are common patterns and solutions.
-* Pure presentational pages.
-* Connected components (e.g., network requests, context, browser environment).
+- Pure presentational pages.
+- Connected components (e.g., network requests, context, browser environment).
## Pure presentational pages
@@ -20,35 +20,27 @@ It's straightforward to write components to be fully presentational up to the sc
The benefits:
-* Easy to write stories once components are in this form.
-* All the data for the story is encoded in the args of the story, which works well with other parts of Storybook's tooling (e.g. [controls](../essentials/controls.mdx)).
+- Easy to write stories once components are in this form.
+- All the data for the story is encoded in the args of the story, which works well with other parts of Storybook's tooling (e.g. [controls](../essentials/controls.mdx)).
The downsides:
-* Your existing app may not be structured in this way, and it may be difficult to change it.
+- Your existing app may not be structured in this way, and it may be difficult to change it.
-* Fetching data in one place means that you need to drill it down to the components that use it. This can be natural in a page that composes one big GraphQL query (for instance), but other data fetching approaches may make this less appropriate.
+- Fetching data in one place means that you need to drill it down to the components that use it. This can be natural in a page that composes one big GraphQL query (for instance), but other data fetching approaches may make this less appropriate.
-* It's less flexible if you want to load data incrementally in different places on the screen.
+- It's less flexible if you want to load data incrementally in different places on the screen.
### Args composition for presentational screens
When you are building screens in this way, it is typical that the inputs of a composite component are a combination of the inputs of the various sub-components it renders. For instance, if your screen renders a page layout (containing details of the current user), a header (describing the document you are looking at), and a list (of the subdocuments), the inputs of the screen may consist of the user, document and subdocuments.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
In such cases, it is natural to use [args composition](./args.mdx#args-composition) to build the stories for the page based on the stories of the sub-components:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
This approach is beneficial when the various subcomponents export a complex list of different stories. You can pick and choose to build realistic scenarios for your screen-level stories without repeating yourself. Your story maintenance burden is minimal by reusing the data and taking a Don't-Repeat-Yourself(DRY) philosophy.
## Mocking connected components
@@ -67,79 +59,65 @@ For components that make network requests (e.g., fetching data from a REST or Gr
Components can receive data or configuration from context providers. For example, a styled component might access its theme from a ThemeProvider or Redux uses React context to provide components access to app data. You can mock a provider and the value it's providing and wrap your component with it in your stories.
-
- ### Avoiding mocking dependencies
-
- It's possible to avoid mocking the dependencies of connected "container" components entirely by passing them around via props or React context. However, it requires a strict split of the container and presentational component logic. For example, if you have a component responsible for data fetching logic and rendering DOM, it will need to be mocked as previously described.
-
- It’s common to import and embed container components amongst presentational components. However, as we discovered earlier, we’ll likely have to mock their dependencies or the imports to render them within Storybook.
-
- Not only can this quickly grow to become a tedious task, but it’s also challenging to mock container components that use local states. So, instead of importing containers directly, a solution to this problem is to create a React context that provides the container components. It allows you to freely embed container components as usual, at any level in the component hierarchy without worrying about subsequently mocking their dependencies; since we can swap out the containers themselves with their mocked presentational counterpart.
-
- We recommend dividing context containers up over specific pages or views in your app. For example, if you had a `ProfilePage` component, you might set up a file structure as follows:
+
- ```
- ProfilePage.js
- ProfilePage.stories.js
- ProfilePageContainer.js
- ProfilePageContext.js
- ```
+### Avoiding mocking dependencies
-
- It’s also often helpful to set up a “global” container context (perhaps named `GlobalContainerContext`) for container components that may be rendered on every page of your app and add them to the top level of your application. While it’s possible to place every container within this global context, it should only provide globally required containers.
-
+It's possible to avoid mocking the dependencies of connected "container" components entirely by passing them around via props or React context. However, it requires a strict split of the container and presentational component logic. For example, if you have a component responsible for data fetching logic and rendering DOM, it will need to be mocked as previously described.
- Let’s look at an example implementation of this approach.
+It’s common to import and embed container components amongst presentational components. However, as we discovered earlier, we’ll likely have to mock their dependencies or the imports to render them within Storybook.
- First, create a React context, and name it `ProfilePageContext`. It does nothing more than export a React context:
+Not only can this quickly grow to become a tedious task, but it’s also challenging to mock container components that use local states. So, instead of importing containers directly, a solution to this problem is to create a React context that provides the container components. It allows you to freely embed container components as usual, at any level in the component hierarchy without worrying about subsequently mocking their dependencies; since we can swap out the containers themselves with their mocked presentational counterpart.
- {/* prettier-ignore-start */}
+We recommend dividing context containers up over specific pages or views in your app. For example, if you had a `ProfilePage` component, you might set up a file structure as follows:
-
+```
+ProfilePage.js
+ProfilePage.stories.js
+ProfilePageContainer.js
+ProfilePageContext.js
+```
- {/* prettier-ignore-end */}
+
- `ProfilePage` is our presentational component. It will use the `useContext` hook to retrieve the container components from `ProfilePageContext`:
+It’s also often helpful to set up a “global” container context (perhaps named `GlobalContainerContext`) for container components that may be rendered on every page of your app and add them to the top level of your application. While it’s possible to place every container within this global context, it should only provide globally required containers.
- {/* prettier-ignore-start */}
+
-
+Let’s look at an example implementation of this approach.
- {/* prettier-ignore-end */}
+First, create a React context, and name it `ProfilePageContext`. It does nothing more than export a React context:
- #### Mocking containers in Storybook
+
- In the context of Storybook, instead of providing container components through context, we’ll instead provide their mocked counterparts. In most cases, the mocked versions of these components can often be borrowed directly from their associated stories.
+`ProfilePage` is our presentational component. It will use the `useContext` hook to retrieve the container components from `ProfilePageContext`:
- {/* prettier-ignore-start */}
+
-
+#### Mocking containers in Storybook
- {/* prettier-ignore-end */}
+In the context of Storybook, instead of providing container components through context, we’ll instead provide their mocked counterparts. In most cases, the mocked versions of these components can often be borrowed directly from their associated stories.
-
- If the same context applies to all `ProfilePage` stories, we can use a [decorator](./decorators.mdx).
-
+
- #### Providing containers to your application
+
- Now, in the context of your application, you’ll need to provide `ProfilePage` with all of the container components it requires by wrapping it with `ProfilePageContext.Provider`:
+If the same context applies to all `ProfilePage` stories, we can use a [decorator](./decorators.mdx).
- For example, in Next.js, this would be your `pages/profile.js` component.
+
- {/* prettier-ignore-start */}
+#### Providing containers to your application
-
+Now, in the context of your application, you’ll need to provide `ProfilePage` with all of the container components it requires by wrapping it with `ProfilePageContext.Provider`:
- {/* prettier-ignore-end */}
+For example, in Next.js, this would be your `pages/profile.js` component.
- #### Mocking global containers in Storybook
+
- If you’ve set up `GlobalContainerContext`, you’ll need to set up a decorator within Storybook’s `preview.js` to provide context to all stories. For example:
+#### Mocking global containers in Storybook
- {/* prettier-ignore-start */}
+If you’ve set up `GlobalContainerContext`, you’ll need to set up a decorator within Storybook’s `preview.js` to provide context to all stories. For example:
-
+
- {/* prettier-ignore-end */}
-
+
diff --git a/docs/writing-stories/decorators.mdx b/docs/writing-stories/decorators.mdx
index e3210d07ac23..3f16a44d0af9 100644
--- a/docs/writing-stories/decorators.mdx
+++ b/docs/writing-stories/decorators.mdx
@@ -1,8 +1,7 @@
---
-title: 'Decorators'
+title: Decorators
sidebar:
order: 3
- title: Decorators
---
A decorator is a way to wrap a story in extra “rendering” functionality. Many addons define decorators to augment your stories with extra rendering or gather details about how your story renders.
@@ -11,45 +10,33 @@ When writing stories, decorators are typically used to wrap stories with extra m
## Wrap stories with extra markup
-
+
- Some components require a “harness” to render in a useful way. For instance, if a component runs right up to its edges, you might want to space it inside Storybook. With Svelte, you'll need to take additional steps to set it up properly.
+Some components require a “harness” to render in a useful way. For instance, if a component runs right up to its edges, you might want to space it inside Storybook. With Svelte, you'll need to take additional steps to set it up properly.
- 
+
- Start by creating a new Svelte component that will act as a decorator. This component will wrap your story and provide the required spacing or layout elements.
+Start by creating a new Svelte component that will act as a decorator. This component will wrap your story and provide the required spacing or layout elements.
- {/* prettier-ignore-start */}
+
-
+Update your story to include the component and reference it to apply the required spacing or other functionality for all its stories.
- {/* prettier-ignore-end */}
+
- Update your story to include the component and reference it to apply the required spacing or other functionality for all its stories.
+If you need to pass props to the component returned by your decorator, you can do so by returning an object with `Component` and `props` keys in the decorator function. This allows you to customize the behavior of the decorator based on the [story's context](#context-for-mocking).
- {/* prettier-ignore-start */}
+
-
-
- {/* prettier-ignore-end */}
-
- If you need to pass props to the component returned by your decorator, you can do so by returning an object with `Component` and `props` keys in the decorator function. This allows you to customize the behavior of the decorator based on the [story's context](#context-for-mocking).
-
-
-
-
+
- Some components require a “harness” to render in a useful way. For instance, if a component runs right up to its edges, you might want to space it inside Storybook. Use a decorator to add spacing for all stories of the component.
-
- 
+Some components require a “harness” to render in a useful way. For instance, if a component runs right up to its edges, you might want to space it inside Storybook. Use a decorator to add spacing for all stories of the component.
- {/* prettier-ignore-start */}
+
-
-
- {/* prettier-ignore-end */}
+
@@ -59,49 +46,39 @@ When writing stories, decorators are typically used to wrap stories with extra m
The second argument to a decorator function is the **story context** which contains the properties:
-* `args` - the story arguments. You can use some [`args`](./args.mdx) in your decorators and drop them in the story implementation itself.
-* `argTypes`- Storybook's [argTypes](../api/arg-types.mdx) allow you to customize and fine-tune your stories [`args`](./args.mdx).
-* `globals` - Storybook-wide [globals](../essentials/toolbars-and-globals.mdx#globals). In particular you can use the [toolbars feature](../essentials/toolbars-and-globals.mdx#global-types-and-the-toolbar-annotation) to allow you to change these values using Storybook’s UI.
-* `hooks` - Storybook's API hooks (e.g., `useArgs`, `useGlobals`). These are available in both decorators and story render functions. When using these hooks in a render function alongside framework hooks (e.g., React's `useState`, `useEffect`), use Storybook's hook equivalents from `storybook/preview-api` instead to avoid errors on re-render.
-* `parameters`- the story's static metadata, most commonly used to control Storybook's behavior of features and addons.
-* `viewMode`- Storybook's current active window (e.g., canvas, docs).
+- `args` - the story arguments. You can use some [`args`](./args.mdx) in your decorators and drop them in the story implementation itself.
+- `argTypes`- Storybook's [argTypes](../api/arg-types.mdx) allow you to customize and fine-tune your stories [`args`](./args.mdx).
+- `globals` - Storybook-wide [globals](../essentials/toolbars-and-globals.mdx#globals). In particular you can use the [toolbars feature](../essentials/toolbars-and-globals.mdx#global-types-and-the-toolbar-annotation) to allow you to change these values using Storybook’s UI.
+- `hooks` - Storybook's API hooks (e.g., `useArgs`, `useGlobals`). These are available in both decorators and story render functions. When using these hooks in a render function alongside framework hooks (e.g., React's `useState`, `useEffect`), use Storybook's hook equivalents from `storybook/preview-api` instead to avoid errors on re-render.
+- `parameters`- the story's static metadata, most commonly used to control Storybook's behavior of features and addons.
+- `viewMode`- Storybook's current active window (e.g., canvas, docs).
This context can be used to adjust the behavior of your decorator based on the story's arguments or other metadata. For example, you could create a decorator that allows you to optionally apply a layout to the story, by defining `parameters.pageLayout = 'page'` (or `'page-mobile'`):
:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- For another example, see the section on [configuring the mock provider](./mocking-data-and-modules/mocking-providers.mdx#configuring-the-mock-provider), which demonstrates how to use the same technique to change which theme is provided to the component.
+
+For another example, see the section on [configuring the mock provider](./mocking-data-and-modules/mocking-providers.mdx#configuring-the-mock-provider), which demonstrates how to use the same technique to change which theme is provided to the component.
+
-
+
### Reactive globals
To ensure `globals` in Vue decorators are fully reactive, you must pass them through the `setup` function. You can also compute derived values with Vue's `computed` function.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Preview API hooks
The same applies to Storybook hooks you want to call in your decorator. For instance, this decorator increments a counter used by its decorated story.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
-
+
### Using decorators to provide data
@@ -109,62 +86,50 @@ If your components are “connected” and require side-loaded data to render, y
## Story decorators
-
+
- To define a decorator for a single story, use the `decorators` property in the `Story` component if you are using Svelte CSF with the native templating syntax, or use the `decorators` key on a CSF named export:
+To define a decorator for a single story, use the `decorators` property in the `Story` component if you are using Svelte CSF with the native templating syntax, or use the `decorators` key on a CSF named export:
-
+
- To define a decorator for a single story, use the `decorators` key on a named export:
+To define a decorator for a single story, use the `decorators` key on a named export:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
It is useful to ensure that the story remains a “pure” rendering of the component under test and that any extra HTML or components are used only as decorators. In particular the [Source](../api/doc-blocks/doc-block-source.mdx) Doc Block works best when you do this.
## Component decorators
-
+
- To define a decorator for all component stories, include the `decorators` property in the `defineMeta` function of a Svelte CSF story file. Alternatively, use the `decorators` key on the default CSF export:
+To define a decorator for all component stories, include the `decorators` property in the `defineMeta` function of a Svelte CSF story file. Alternatively, use the `decorators` key on the default CSF export:
-
+
- To define a decorator for all stories of a component, use the `decorators` key of the default CSF export:
+To define a decorator for all stories of a component, use the `decorators` key of the default CSF export:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Global decorators
We can also set a decorator for **all stories** via the `decorators` export of your [`.storybook/preview.ts|tsx`](../configure/index.mdx#configure-story-rendering) file (this is the file where you configure all stories):
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Decorator inheritance
Like parameters, decorators can be defined globally, at the component level, and for a single story (as we’ve seen).
All decorators relevant to a story will run in the following order once the story renders:
-* Global decorators, in the order they are defined
-* Component decorators, in the order they are defined
-* Story decorators, in the order they are defined, starting from the innermost decorator and working outwards and up the hierarchy in the same order
+- Global decorators, in the order they are defined
+- Component decorators, in the order they are defined
+- Story decorators, in the order they are defined, starting from the innermost decorator and working outwards and up the hierarchy in the same order
diff --git a/docs/writing-stories/index.mdx b/docs/writing-stories/index.mdx
index 46e336b03280..154ab8a9830b 100644
--- a/docs/writing-stories/index.mdx
+++ b/docs/writing-stories/index.mdx
@@ -1,5 +1,5 @@
---
-title: 'How to write stories'
+title: How to write stories
sidebar:
order: 2
title: Stories
@@ -7,13 +7,13 @@ sidebar:
- A story captures the rendered state of a UI component. Given a set of arguments, it can be a simple object with annotations or a component that describes its behavior and appearance.
+A story captures the rendered state of a UI component. Given a set of arguments, it can be a simple object with annotations or a component that describes its behavior and appearance.
- A story captures the rendered state of a UI component. It's an object with annotations that describe the component's behavior and appearance given a set of arguments.
+A story captures the rendered state of a UI component. It's an object with annotations that describe the component's behavior and appearance given a set of arguments.
@@ -34,17 +34,17 @@ components/
- We can define stories according to the [Component Story Format](../api/csf/index.mdx) (CSF), an ES6 module-based standard that is easy to write and portable between tools, or rely on the community-led project [`Svelte CSF`](https://storybook.js.org/addons/@storybook/addon-svelte-csf) which provides a similar experience.
-
- With Svelte CSF, the essential elements are the `defineMeta` function, which describes the component, and the `Story` component, which describes the stories. This pattern is different from the standard CSF, which uses a [default export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export#Using_the_default_export) and [named exports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export#Using_named_exports) to apply the same concepts.
-
+We can define stories according to the [Component Story Format](../api/csf/index.mdx) (CSF), an ES6 module-based standard that is easy to write and portable between tools, or rely on the community-led project [`Svelte CSF`](https://storybook.js.org/addons/@storybook/addon-svelte-csf) which provides a similar experience.
+
+With Svelte CSF, the essential elements are the `defineMeta` function, which describes the component, and the `Story` component, which describes the stories. This pattern is different from the standard CSF, which uses a [default export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export#Using_the_default_export) and [named exports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export#Using_named_exports) to apply the same concepts.
+
- We define stories according to the [Component Story Format](../api/csf/index.mdx) (CSF), an ES6 module-based standard that is easy to write and portable between tools.
+We define stories according to the [Component Story Format](../api/csf/index.mdx) (CSF), an ES6 module-based standard that is easy to write and portable between tools.
- The key ingredients are the meta (or [default export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export#Using_the_default_export)) that describes the component, and [named exports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export#Using_named_exports) that describe the stories.
+The key ingredients are the meta (or [default export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export#Using_the_default_export)) that describes the component, and [named exports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export#Using_named_exports) that describe the stories.
@@ -52,54 +52,42 @@ components/
- The `defineMeta` function in Svelte CSF with native templating syntax controls how Storybook lists your stories and provides information used by addons. However, if you're not using this story format and relying on standard CSF, use the *default* export to achieve the same result. Below is an example of a story file with both approaches:
-
- {/* prettier-ignore-start */}
+The `defineMeta` function in Svelte CSF with native templating syntax controls how Storybook lists your stories and provides information used by addons. However, if you're not using this story format and relying on standard CSF, use the _default_ export to achieve the same result. Below is an example of a story file with both approaches:
-
-
- {/* prettier-ignore-end */}
+
- The *default* export metadata controls how Storybook lists your stories and provides information used by addons. For example, here’s the meta (or default export) for a story file `Button.stories.js|ts`:
-
- {/* prettier-ignore-start */}
+The _default_ export metadata controls how Storybook lists your stories and provides information used by addons. For example, here’s the meta (or default export) for a story file `Button.stories.js|ts`:
-
+
- {/* prettier-ignore-end */}
+
-
+Starting with Storybook version 7.0, story titles are analyzed statically as part of the build process. The _default_ export must contain a `title` property that can be read statically or a `component` property from which an automatic title can be computed. Using the `id` property to customize your story URL must also be statically readable.
- Starting with Storybook version 7.0, story titles are analyzed statically as part of the build process. The *default* export must contain a `title` property that can be read statically or a `component` property from which an automatic title can be computed. Using the `id` property to customize your story URL must also be statically readable.
-
-
+
### Defining stories
-
- If you're using Svelte CSF, define your stories with the `Story` component, otherwise use the named exports of a standard CSF file. We recommend you use UpperCamelCase for your story exports. Here’s how to render `Button` in the “primary” state and export a story called `Primary` using both methods.
+
+If you're using Svelte CSF, define your stories with the `Story` component, otherwise use the named exports of a standard CSF file. We recommend you use UpperCamelCase for your story exports. Here’s how to render `Button` in the “primary” state and export a story called `Primary` using both methods.
- Use the *named* exports of a CSF file to define your component’s stories. We recommend you use UpperCamelCase for your story exports. Here’s how to render `Button` in the “primary” state and export a story called `Primary`.
+Use the _named_ exports of a CSF file to define your component’s stories. We recommend you use UpperCamelCase for your story exports. Here’s how to render `Button` in the “primary” state and export a story called `Primary`.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Unlike regular CSF, when using Svelte CSF, you cannot use [`args`](./args.mdx) for children. Instead, you pass children in-between the opening and closing `Story` tags and it will be passed to the component as the `children` snippet prop.
@@ -107,9 +95,9 @@ Unlike regular CSF, when using Svelte CSF, you cannot use [`args`](./args.mdx) f
```svelte title="Alert.stories.svelte"
+```svelte
+
+
+
+ {count}
+
+
+
+```
+
+The same setup works with Svelte stories files too, providing both type safety and autocompletion.
+
+
@@ -189,7 +190,7 @@ const meta = preview.type<{ args: MyComponentProps }>().meta({
```ts
declare global {
interface HTMLElementTagNameMap {
- "my-element": MyElement;
+ 'my-element': MyElement;
}
}
```
@@ -211,4 +212,4 @@ const meta = preview.type<{ args: MyElementProps }>().meta({
});
```
-
\ No newline at end of file
+
diff --git a/docs/writing-tests/accessibility-testing.mdx b/docs/writing-tests/accessibility-testing.mdx
index acb0bc235811..32850cdbd904 100644
--- a/docs/writing-tests/accessibility-testing.mdx
+++ b/docs/writing-tests/accessibility-testing.mdx
@@ -1,8 +1,7 @@
---
-title: 'Accessibility tests'
+title: Accessibility tests
sidebar:
order: 3
- title: Accessibility tests
---
Web accessibility is the practice of making websites and apps accessible and inclusive to all people, regardless of ability or the technology they’re using. That means supporting requirements such as keyboard navigation, screen reader support, sufficient color contrast, etc.
@@ -17,12 +16,8 @@ Storybook provides an Accessibility (a11y) addon to help ensure the accessibilit
Run this command to install and configure the addon in your project:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Storybook's [`add`](../api/cli-options.mdx#add) command automates the addon's installation and setup. To install it manually, see our [documentation](../addons/install-addons.mdx#manual-installation) on how to install addons.
@@ -45,7 +40,7 @@ The full installation instructions, including project requirements, are availabl
## Check for violations
-When you navigate to a story, automated accessibility checks are run and the results are reported in the Accessibility addon panel.
+When you navigate to a story, automated accessibility checks are run and the results are reported in the Accessibility addon panel.
The results are broken down into three sub-tabs:
@@ -57,13 +52,13 @@ The results are broken down into three sub-tabs:
Because the addon is built on top of `axe-core`, much of the configuration available maps to its available options:
-| Property | Default | Description |
-| ------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `parameters.a11y.context` | `'body'` | [Context](https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#context-parameter) passed to `axe.run`. Defines which elements to run checks against. |
+| Property | Default | Description |
+| ------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `parameters.a11y.context` | `'body'` | [Context](https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#context-parameter) passed to `axe.run`. Defines which elements to run checks against. |
| `parameters.a11y.config` | (see below) | Configuration passed to [`axe.configure()`](https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#api-name-axeconfigure). Most commonly used to [configure individual rules](#individual-rules). |
-| `parameters.a11y.options` | `{}` | [Options](https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#options-parameter) passed to `axe.run`. Can be used to adjust the rulesets checked against. |
-| `parameters.a11y.test` | `undefined` | Determines test behavior when run with the Vitest addon. [More details below](#test-behavior). |
-| `globals.a11y.manual` | `undefined` | Set to `true` to prevent stories from being automatically analyzed when visited. [More details below](#disable-automated-checks) |
+| `parameters.a11y.options` | `{}` | [Options](https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#options-parameter) passed to `axe.run`. Can be used to adjust the rulesets checked against. |
+| `parameters.a11y.test` | `undefined` | Determines test behavior when run with the Vitest addon. [More details below](#test-behavior). |
+| `globals.a11y.manual` | `undefined` | Set to `true` to prevent stories from being automatically analyzed when visited. [More details below](#disable-automated-checks) |
Default `parameters.a11y.config`
@@ -76,8 +71,8 @@ By default, Storybook disables the [region rule](https://dequeuniversity.com/rul
{
id: 'region',
enabled: false,
- }
- ]
+ },
+ ],
}
```
@@ -149,13 +144,13 @@ When you disable automated accessibility checks, the addon will not run any test
- If you are using Svelte CSF, you can turn off automated accessibility checks for stories or components by adding globals to your story or adjusting the `defineMeta` function with the required configuration. With a regular CSF story, you can add the following to your stories or meta (or default export):
+If you are using Svelte CSF, you can turn off automated accessibility checks for stories or components by adding globals to your story or adjusting the `defineMeta` function with the required configuration. With a regular CSF story, you can add the following to your stories or meta (or default export):
- Disable automated accessibility checks for stories or components by adding the following globals to your stories or meta (or default export):
+Disable automated accessibility checks for stories or components by adding the following globals to your stories or meta (or default export):
@@ -213,18 +208,12 @@ If you cannot use the Vitest addon, you can still run your tests in CI using the
You can use configuration to progressively work toward a more accessible UI by combining multiple test behaviors. For example, you can start with `'error'` to fail on accessibility violations, then switch to `'todo'` to mark components that need fixing, and finally remove the todos once all stories pass accessibility tests:
1. Update your project configuration to fail on accessibility violations by setting [`parameters.a11y.test`](#test-behavior) to `'error'`. This ensures that all new stories are tested to meet accessibility standards.
-
-
2. You will likely find that many components have accessibility failures (and maybe feel a bit overwhelmed!).
3. Take note of the components with accessibility issues and temporarily reduce their failures to warnings by applying the `'todo'` parameter value. This keeps accessibility issues visible while not blocking development. This is also a good time to commit your work as a baseline for future improvements.
-
-
-4. Pick a good starting point from the components you just marked `'todo'` (we recommend something like Button, for its simplicity and likelihood of being used within other components). Fix the issues in that component using the suggestions in the addon panel to ensure it passes accessibility tests, then remove the parameter.
-
+4. Pick a good starting point from the components you just marked `'todo'` (we recommend starting with something like Button, as it's a fundamental component used within many others). Fix the issues in that component using the suggestions in the addon panel to ensure it passes accessibility tests, then remove the parameter.
-
5. Pick another component and repeat the process until you've covered all your components and you're an accessibility hero!
## FAQ
@@ -249,12 +238,12 @@ To enable this feature flag, add the following configuration to your `.storybook
**More testing resources**
-* [Vitest addon](./integrations/vitest-addon/index.mdx) for running tests in Storybook
-* [Interaction testing](./interaction-testing.mdx) for user behavior simulation
-* [Visual testing](./visual-testing.mdx) for appearance
-* [Snapshot testing](./snapshot-testing.mdx) for rendering errors and warnings
-* [Test coverage](./test-coverage.mdx) for measuring code coverage
-* [CI](./in-ci.mdx) for running tests in your CI/CD pipeline
-* [End-to-end testing](./integrations/stories-in-end-to-end-tests.mdx) for simulating real user scenarios
-* [Unit testing](./integrations/stories-in-unit-tests.mdx) for functionality
-* [Test runner](./integrations/test-runner.mdx) to automate test execution
+- [Vitest addon](./integrations/vitest-addon/index.mdx) for running tests in Storybook
+- [Interaction testing](./interaction-testing.mdx) for user behavior simulation
+- [Visual testing](./visual-testing.mdx) for appearance
+- [Snapshot testing](./snapshot-testing.mdx) for rendering errors and warnings
+- [Test coverage](./test-coverage.mdx) for measuring code coverage
+- [CI](./in-ci.mdx) for running tests in your CI/CD pipeline
+- [End-to-end testing](./integrations/stories-in-end-to-end-tests.mdx) for simulating real user scenarios
+- [Unit testing](./integrations/stories-in-unit-tests.mdx) for functionality
+- [Test runner](./integrations/test-runner.mdx) to automate test execution
diff --git a/docs/writing-tests/in-ci.mdx b/docs/writing-tests/in-ci.mdx
index 0bd8aa72b12e..6db37dae65ec 100644
--- a/docs/writing-tests/in-ci.mdx
+++ b/docs/writing-tests/in-ci.mdx
@@ -18,7 +18,7 @@ If you cannot use the Vitest addon in your project, you can still run your stori
## Set up Storybook tests in CI
-Running Storybook tests in CI is very similar to running them via CLI on your local machine: you run the same command, just in a different place.
+Running Storybook tests in CI is very similar to running them via CLI on your local machine: you run the same command in a different environment.
Let’s go step-by-step to set things up.
@@ -27,7 +27,7 @@ Let’s go step-by-step to set things up.
For convenience, define a script in your `package.json` to run the Storybook tests. This is the same command you would run locally, but it’s useful to have it in your CI workflow.
```json title="package.json"
-{
+{
"scripts": {
"test-storybook": "vitest --project=storybook"
}
@@ -44,7 +44,6 @@ Here are some example configurations for popular CI providers:
GitHub Actions
-
Create a file in the root of your repo, `.github/workflow/test-ui.yml`:
```yaml title=".github/workflows/test-ui.yml"
@@ -61,18 +60,19 @@ jobs:
image: mcr.microsoft.com/playwright:v1.58.2-noble
steps:
- uses: actions/checkout@v4
-
+
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22.12.0
-
+
- name: Install dependencies
run: npm ci
-
+
- name: Run tests
run: npm run test-storybook
```
+
@@ -80,7 +80,7 @@ jobs:
Create a file in the root of your repo, `.gitlab-ci.yml`:
-```yaml title=".gitlab-ci.yml"
+```yaml title=".gitlab-ci.yml"
image: node:jod
stages:
@@ -102,6 +102,7 @@ Test:
script:
- npm run test-storybook
```
+
@@ -119,10 +120,10 @@ definitions:
pipelines:
default:
- stage:
- name: "UI Tests"
+ name: 'UI Tests'
steps:
- step:
- name: "Run Tests"
+ name: 'Run Tests'
# Make sure to grab the latest version of the Playwright image
# https://playwright.dev/docs/docker#pull-the-image
image: mcr.microsoft.com/playwright:v1.58.2-noble
@@ -134,6 +135,7 @@ pipelines:
- npm ci
- npm run test-storybook
```
+
@@ -143,7 +145,7 @@ Create a file in the root of your repo, `.circleci/config.yml`:
```yaml title=".circleci/config.yml"
version: 2.1
-
+
executors:
ui-testing:
docker:
@@ -175,6 +177,7 @@ workflows:
jobs:
- Test
```
+
@@ -198,10 +201,11 @@ cache: npm
jobs:
include:
- - stage: "UI Tests"
- name: "Run tests"
+ - stage: 'UI Tests'
+ name: 'Run tests'
script: npm run test-storybook
```
+
@@ -235,6 +239,7 @@ pipeline {
}
}
```
+
@@ -247,14 +252,14 @@ trigger:
- main
pool:
- vmImage: "ubuntu-latest"
+ vmImage: 'ubuntu-latest'
stages:
- stage: UI_Tests
- displayName: "UI Tests"
+ displayName: 'UI Tests'
jobs:
- job: Test
- displayName: "Storybook tests"
+ displayName: 'Storybook tests'
# Make sure to grab the latest version of the Playwright image
# https://playwright.dev/docs/docker#pull-the-image
container: mcr.microsoft.com/playwright:v1.58.2-noble
@@ -262,11 +267,11 @@ stages:
npm_config_cache: $(Pipeline.Workspace)/.npm
steps:
- task: UseNode@1
- displayName: "Install Node.js"
+ displayName: 'Install Node.js'
inputs:
- version: "22.12.0"
+ version: '22.12.0'
- task: Cache@2
- displayName: "Install and cache dependencies"
+ displayName: 'Install and cache dependencies'
inputs:
key: 'npm | "$(Agent.OS)" | package-lock.json'
restoreKeys: |
@@ -275,11 +280,12 @@ stages:
- script: npm ci
condition: ne(variables.CACHE_RESTORED, 'true')
- task: CmdLine@2
- displayName: "Run tests"
+ displayName: 'Run tests'
inputs:
script: npm run test-storybook
```
-
+
+
@@ -318,7 +324,7 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 22.12.0
-
+
- name: Install dependencies
run: npm ci
@@ -331,12 +337,8 @@ jobs:
Finally, we update the plugin configuration to use that environment variable in the [`storybookUrl` plugin option](./integrations/vitest-addon/index.mdx#storybookurl).
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Now, when a test fails in CI, the printed story URL will point to the published Storybook, making debugging that failure a breeze!
#### 2.2 Calculate code coverage
@@ -354,7 +356,7 @@ You can either adjust the command in your `package.json` scripts:
**For all tests:**
```diff title="package.json"
-{
+{
"scripts": {
+ "test": "vitest --coverage"
- "test": "vitest"
@@ -365,7 +367,7 @@ You can either adjust the command in your `package.json` scripts:
**For only Storybook tests:**
```diff title="package.json"
-{
+{
"scripts": {
+ "test-storybook": "vitest --project=storybook --coverage"
- "test-storybook": "vitest --project=storybook"
@@ -410,7 +412,7 @@ Some projects have other tests run via Vitest, e.g. unit tests, in addition to t
You can run these tests independently by specifying the project filter in a separate script. For example, for a Vitest project called “unit”:
```json title="package.json"
-{
+{
"scripts": {
"test-storybook": "vitest --project=storybook",
"test-unit": "vitest --project=unit"
@@ -427,10 +429,10 @@ Then, in your workflow, call this script alongside the Storybook one:
npm run test-storybook
```
-You may also choose to run all tests together by simply omitting the `--project=storybook` filter from the `package.json` script:
+You may also choose to run all tests together by omitting the `--project=storybook` filter from the `package.json` script:
```json title="package.json"
-{
+{
"scripts": {
"test": "vitest"
}
@@ -447,12 +449,12 @@ The workflow would then look like:
**More testing resources**
-* [Vitest addon](./integrations/vitest-addon/index.mdx) for running tests in Storybook
-* [Interaction testing](./interaction-testing.mdx) for user behavior simulation
-* [Accessibility testing](./accessibility-testing.mdx) for accessibility
-* [Visual testing](./visual-testing.mdx) for appearance
-* [Snapshot testing](./snapshot-testing.mdx) for rendering errors and warnings
-* [Test coverage](./test-coverage.mdx) for measuring code coverage
-* [End-to-end testing](./integrations/stories-in-end-to-end-tests.mdx) for simulating real user scenarios
-* [Unit testing](./integrations/stories-in-unit-tests.mdx) for functionality
-* [Test runner](./integrations/test-runner.mdx) to automate test execution
+- [Vitest addon](./integrations/vitest-addon/index.mdx) for running tests in Storybook
+- [Interaction testing](./interaction-testing.mdx) for user behavior simulation
+- [Accessibility testing](./accessibility-testing.mdx) for accessibility
+- [Visual testing](./visual-testing.mdx) for appearance
+- [Snapshot testing](./snapshot-testing.mdx) for rendering errors and warnings
+- [Test coverage](./test-coverage.mdx) for measuring code coverage
+- [End-to-end testing](./integrations/stories-in-end-to-end-tests.mdx) for simulating real user scenarios
+- [Unit testing](./integrations/stories-in-unit-tests.mdx) for functionality
+- [Test runner](./integrations/test-runner.mdx) to automate test execution
diff --git a/docs/writing-tests/index.mdx b/docs/writing-tests/index.mdx
index 099008cb5f9a..d64a0f6a837b 100644
--- a/docs/writing-tests/index.mdx
+++ b/docs/writing-tests/index.mdx
@@ -1,5 +1,5 @@
---
-title: 'How to test UIs with Storybook'
+title: How to test UIs with Storybook
hideRendererSelector: true
sidebar:
order: 3
@@ -65,46 +65,47 @@ If you are already running `vitest` as part of your CI then your stories should
If you’re not yet running Vitest in CI, you should set that up. First by adding a new script to your `package.json`:
```json title="package.json"
-{
+{
"scripts": {
"test-storybook": "vitest --project=storybook"
}
-}
+}
```
Note that this assumes you have a Vitest project called “storybook” for your stories, which is the default configuration when you install Storybook Test. If you’ve renamed it, adjust the script accordingly.
-Next, add a new CI workflow.
+Next, add a new CI workflow.
If you use Github Actions that would look like:
-
- ```yaml title=".github/workflows/test-storybook.yml"
- name: Storybook Tests
-
- on: [push]
-
- jobs:
- test:
- runs-on: ubuntu-latest
- container:
- # Make sure to grab the latest version of the Playwright image
- # https://playwright.dev/docs/docker#pull-the-image
- image: mcr.microsoft.com/playwright:v1.58.2-noble
- steps:
- - uses: actions/checkout@v4
-
- - name: Setup Node
- uses: actions/setup-node@v4
- with:
- node-version: 22.12.0
-
- - name: Install dependencies
- run: npm ci
-
- - name: Run tests
- run: npm run test-storybook
- ```
+
+```yaml title=".github/workflows/test-storybook.yml"
+name: Storybook Tests
+
+on: [push]
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+ container:
+ # Make sure to grab the latest version of the Playwright image
+ # https://playwright.dev/docs/docker#pull-the-image
+ image: mcr.microsoft.com/playwright:v1.58.2-noble
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Setup Node
+ uses: actions/setup-node@v4
+ with:
+ node-version: 22.12.0
+
+ - name: Install dependencies
+ run: npm ci
+
+ - name: Run tests
+ run: npm run test-storybook
+```
+
If you are using a different CI provider, please consult our full [CI guide](./in-ci.mdx) for more information.
@@ -161,11 +162,11 @@ Storybook Test supports a variety of testing types to help you validate your wor
### Render tests
-The most important tool for testing your components in Storybook is stories that render your components in various states.
+The most important tool for testing your components in Storybook is stories that render your components in various states.
-However, you might not be aware that a basic story is also a [smoke test](https://en.wikipedia.org/wiki/Smoke_testing_(software)), which we call a **render test**. The test passes when the story renders successfully and fails when it errors.
+However, you might not be aware that a basic story is also a [smoke test](), which we call a **render test**. The test passes when the story renders successfully and fails when it errors.
-
+
Depending on the complexity of your components, you might be able to capture many of your key UI states this way.
@@ -175,7 +176,7 @@ Render tests are a very basic kind of interaction test. To test stateful compone
-But `play` functions can also be used for setting up state, creating spies, mocking out the network, simulating user interactions with your components, asserting output, and more. They are the meat and potatoes of testing and are the foundation for the rest of your testing journey in Storybook.
+But `play` functions can also be used for setting up state, creating spies, mocking out the network, simulating user interactions with your components, asserting output, and more. They are the meat and potatoes of testing and are the foundation for the rest of your testing journey in Storybook.
Here’s a more complex example, which includes [spying and mocking](./interaction-testing.mdx#spying-on-functions-with-fn) via the `fn` utility.
@@ -227,13 +228,13 @@ If you prefer, you can reuse your Storybook stories in a traditional testing env
**More testing resources**
-* [Vitest addon](./integrations/vitest-addon/index.mdx) for running tests in Storybook
-* [Interaction testing](./interaction-testing.mdx) for user behavior simulation
-* [Accessibility testing](./accessibility-testing.mdx) for accessibility
-* [Visual testing](./visual-testing.mdx) for appearance
-* [Snapshot testing](./snapshot-testing.mdx) for rendering errors and warnings
-* [Test coverage](./test-coverage.mdx) for measuring code coverage
-* [CI](./in-ci.mdx) for running tests in your CI/CD pipeline
-* [End-to-end testing](./integrations/stories-in-end-to-end-tests.mdx) for simulating real user scenarios
-* [Unit testing](./integrations/stories-in-unit-tests.mdx) for functionality
-* [Test runner](./integrations/test-runner.mdx) to automate test execution
+- [Vitest addon](./integrations/vitest-addon/index.mdx) for running tests in Storybook
+- [Interaction testing](./interaction-testing.mdx) for user behavior simulation
+- [Accessibility testing](./accessibility-testing.mdx) for accessibility
+- [Visual testing](./visual-testing.mdx) for appearance
+- [Snapshot testing](./snapshot-testing.mdx) for rendering errors and warnings
+- [Test coverage](./test-coverage.mdx) for measuring code coverage
+- [CI](./in-ci.mdx) for running tests in your CI/CD pipeline
+- [End-to-end testing](./integrations/stories-in-end-to-end-tests.mdx) for simulating real user scenarios
+- [Unit testing](./integrations/stories-in-unit-tests.mdx) for functionality
+- [Test runner](./integrations/test-runner.mdx) to automate test execution
diff --git a/docs/writing-tests/integrations/index.mdx b/docs/writing-tests/integrations/index.mdx
index f2e7b0d9e707..6581b3dfc6a2 100644
--- a/docs/writing-tests/integrations/index.mdx
+++ b/docs/writing-tests/integrations/index.mdx
@@ -2,5 +2,4 @@
title: Integrations
sidebar:
order: 7
- title: Integrations
----
\ No newline at end of file
+---
diff --git a/docs/writing-tests/integrations/stories-in-end-to-end-tests.mdx b/docs/writing-tests/integrations/stories-in-end-to-end-tests.mdx
index 67469a26fbfd..0f045e3f6b78 100644
--- a/docs/writing-tests/integrations/stories-in-end-to-end-tests.mdx
+++ b/docs/writing-tests/integrations/stories-in-end-to-end-tests.mdx
@@ -1,5 +1,5 @@
---
-title: 'Stories in end-to-end tests'
+title: Stories in end-to-end tests
sidebar:
title: End-to-end tests
order: 4
@@ -13,24 +13,18 @@ Storybook seamlessly integrates with additional testing frameworks like [Cypress
An example of an end-to-end test with Cypress and Storybook is testing a login component for the correct inputs. For example, if you had the following story:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- The play function contains small snippets of code that run after the story renders. It allows you to sequence interactions in stories.
+
+The play function contains small snippets of code that run after the story renders. It allows you to sequence interactions in stories.
+
With Cypress, you could write the following test:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
When Cypress runs your test, it loads Storybook's isolated iframe and checks if the inputs match the test values.
## With Playwright
@@ -39,34 +33,28 @@ When Cypress runs your test, it loads Storybook's isolated iframe and checks if
A real-life scenario of user flow testing with Playwright would be how to test a login form for validity. For example, if you had the following story already created:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- The play function contains small snippets of code that run after the story renders. It allows you to sequence interactions in stories.
+
+The play function contains small snippets of code that run after the story renders. It allows you to sequence interactions in stories.
+
With Playwright, you can write a test to check if the inputs are filled and match the story:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Once you execute Playwright, it opens a new browser window, loads Storybook's isolated iframe, asserts if the inputs contain the specified values, and displays the test results in the terminal.
**More testing resources**
-* [Interaction testing](../interaction-testing.mdx) for user behavior simulation
-* [Accessibility testing](../accessibility-testing.mdx) for accessibility
-* [Visual testing](../visual-testing.mdx) for appearance
-* [Snapshot testing](../snapshot-testing.mdx) for rendering errors and warnings
-* [Test coverage](../test-coverage.mdx) for measuring code coverage
-* [CI](../in-ci.mdx) for running tests in your CI/CD pipeline
-* [Vitest addon](./vitest-addon/index.mdx) for running tests in Storybook
-* [Test runner](./test-runner.mdx) to automate test execution
-* [Unit testing](./stories-in-unit-tests.mdx) for functionality
+- [Interaction testing](../interaction-testing.mdx) for user behavior simulation
+- [Accessibility testing](../accessibility-testing.mdx) for accessibility
+- [Visual testing](../visual-testing.mdx) for appearance
+- [Snapshot testing](../snapshot-testing.mdx) for rendering errors and warnings
+- [Test coverage](../test-coverage.mdx) for measuring code coverage
+- [CI](../in-ci.mdx) for running tests in your CI/CD pipeline
+- [Vitest addon](./vitest-addon/index.mdx) for running tests in Storybook
+- [Test runner](./test-runner.mdx) to automate test execution
+- [Unit testing](./stories-in-unit-tests.mdx) for functionality
diff --git a/docs/writing-tests/integrations/stories-in-unit-tests.mdx b/docs/writing-tests/integrations/stories-in-unit-tests.mdx
index 5ebc69a51459..9b096fa0420e 100644
--- a/docs/writing-tests/integrations/stories-in-unit-tests.mdx
+++ b/docs/writing-tests/integrations/stories-in-unit-tests.mdx
@@ -1,5 +1,5 @@
---
-title: 'Stories in unit tests'
+title: Stories in unit tests
sidebar:
title: Unit tests
order: 3
@@ -17,15 +17,11 @@ Stories are a practical starting point for UI testing. Import stories into tools
Storybook provides a [`composeStories`](../../api/portable-stories/portable-stories-vitest.mdx#composestories) utility that helps convert stories from a test file into renderable elements that can be reused in your Node tests with JSDOM. It also allows you to apply other Storybook features that you have enabled your project (e.g., [decorators](../../writing-stories/decorators.mdx), [args](../../writing-stories/args.mdx)) into your tests, enabling you to reuse your stories in your testing environment of choice (e.g., [Jest](https://jestjs.io/), [Vitest](https://vitest.dev/)), ensuring your tests are always in sync with your stories without having to rewrite them. This is what we refer to as portable stories in Storybook.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
-
- You **must** [configure your test environment to use portable stories](../../api/portable-stories/portable-stories-vitest.mdx#1-apply-project-level-annotations) to ensure your stories are composed with all aspects of your Storybook configuration, such as [decorators](../../writing-stories/decorators.mdx).
+
+You **must** [configure your test environment to use portable stories](../../api/portable-stories/portable-stories-vitest.mdx#1-apply-project-level-annotations) to ensure your stories are composed with all aspects of your Storybook configuration, such as [decorators](../../writing-stories/decorators.mdx).
@@ -37,80 +33,60 @@ By default, the `setProjectAnnotations` function injects into your existing test
To avoid this, you can override the global configurations by extending either the `composeStory` or `composeStories` functions to provide test-specific configurations. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Run tests on a single story
You can use the [`composeStory`](../../api/portable-stories/portable-stories-vitest.mdx#composestory) function to allow your tests to run on a single story. However, if you're relying on this method, we recommend that you supply the story metadata (i.e., the [default export](../../writing-stories/index.mdx#default-export)) to the `composeStory` function. This ensures that your tests can accurately determine the correct information about the story. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Combine stories into a single test
If you intend to test multiple stories in a single test, use the [`composeStories`](../../api/portable-stories/portable-stories-vitest.mdx#composestories) function. It will process every component story you've specified, including any [`args`](../../writing-stories/args.mdx) or [`decorators`](../../writing-stories/decorators.mdx) you've defined. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Troubleshooting
### Run tests in other frameworks
Storybook provides community-led addons for other frameworks like [Vue 2](https://storybook.js.org/addons/@storybook/testing-vue) and [Angular](https://storybook.js.org/addons/@storybook/testing-angular). However, these addons still lack support for the latest stable Storybook release. If you're interested in helping out, we recommend reaching out to the maintainers using the default communication channels (GitHub and [Discord server](https://discord.com/channels/486522875931656193/839297503446695956)).
-
- ### The args are not being passed to the test
-
- The components returned by `composeStories` or `composeStory` not only can be rendered as React components but also come with the combined properties from the story, meta, and global configuration. This means that if you want to access args or parameters, for instance, you can do so:
-
- {/* prettier-ignore-start */}
+
-
+### The args are not being passed to the test
- {/* prettier-ignore-end */}
+The components returned by `composeStories` or `composeStory` not only can be rendered as React components but also come with the combined properties from the story, meta, and global configuration. This means that if you want to access args or parameters, for instance, you can do so:
- ### Next.js Vite cannot find the module
+
- If you are seeing error messages like `Cannot find module 'sb-original/image-context'` ensure you have included `storybookNextJsPlugin`.
+### Next.js Vite cannot find the module
- {/* prettier-ignore-start */}
+If you are seeing error messages like `Cannot find module 'sb-original/image-context'` ensure you have included `storybookNextJsPlugin`.
-
+
- {/* prettier-ignore-end */}
-
+
-
- ### The args are not being passed to the test
+
- When using the `composeStories` or `composeStory` functions, the components being rendered will have a combination of properties from the story, meta, and global configuration. Therefore, if you need to access the args or parameters, you can do so as follows:
+### The args are not being passed to the test
- {/* prettier-ignore-start */}
+When using the `composeStories` or `composeStory` functions, the components being rendered will have a combination of properties from the story, meta, and global configuration. Therefore, if you need to access the args or parameters, you can do so as follows:
-
+
- {/* prettier-ignore-end */}
-
+
**More testing resources**
-* [Interaction testing](../interaction-testing.mdx) for user behavior simulation
-* [Accessibility testing](../accessibility-testing.mdx) for accessibility
-* [Visual testing](../visual-testing.mdx) for appearance
-* [Snapshot testing](../snapshot-testing.mdx) for rendering errors and warnings
-* [Test coverage](../test-coverage.mdx) for measuring code coverage
-* [CI](../in-ci.mdx) for running tests in your CI/CD pipeline
-* [Vitest addon](./vitest-addon/index.mdx) for running tests in Storybook
-* [Test runner](./test-runner.mdx) to automate test execution
-* [End-to-end testing](./stories-in-end-to-end-tests.mdx) for simulating real user scenarios
+- [Interaction testing](../interaction-testing.mdx) for user behavior simulation
+- [Accessibility testing](../accessibility-testing.mdx) for accessibility
+- [Visual testing](../visual-testing.mdx) for appearance
+- [Snapshot testing](../snapshot-testing.mdx) for rendering errors and warnings
+- [Test coverage](../test-coverage.mdx) for measuring code coverage
+- [CI](../in-ci.mdx) for running tests in your CI/CD pipeline
+- [Vitest addon](./vitest-addon/index.mdx) for running tests in Storybook
+- [Test runner](./test-runner.mdx) to automate test execution
+- [End-to-end testing](./stories-in-end-to-end-tests.mdx) for simulating real user scenarios
diff --git a/docs/writing-tests/integrations/test-runner.mdx b/docs/writing-tests/integrations/test-runner.mdx
index 939cab57f451..a196aa8eaced 100644
--- a/docs/writing-tests/integrations/test-runner.mdx
+++ b/docs/writing-tests/integrations/test-runner.mdx
@@ -1,11 +1,12 @@
---
-title: 'Test runner'
+title: Test runner
sidebar:
order: 2
title: Test runner (Webpack)
---
+
The test runner has been superseded by the [Vitest addon](./vitest-addon/index.mdx), which offers the same functionality, powered by the faster and more modern [Vitest](https://vitest.dev/) browser mode. It also enables the full Storybook Test experience, allowing you to run interaction, accessibility, and visual tests from your Storybook app.
@@ -13,12 +14,13 @@ The test runner has been superseded by the [Vitest addon](./vitest-addon/index.m
If you are using a Vite-powered Storybook framework, we recommend using the Vitest addon instead of the test runner.
+
Storybook test runner turns all of your stories into executable tests. It is powered by [Jest](https://jestjs.io/) and [Playwright](https://playwright.dev/).
-* For those [without a play function](../../writing-stories/index.mdx): it verifies whether the story renders without any errors.
-* For those [with a play function](../../writing-stories/play-function.mdx): it also checks for errors in the play function and that all assertions passed.
+- For those [without a play function](../../writing-stories/index.mdx): it verifies whether the story renders without any errors.
+- For those [with a play function](../../writing-stories/play-function.mdx): it also checks for errors in the play function and that all assertions passed.
These tests run in a live browser and can be executed via the [command line](#cli-options) or your [CI server](#set-up-ci-to-run-tests).
@@ -28,12 +30,8 @@ The test-runner is a standalone, framework-agnostic utility that runs parallel t
Run the following command to install it.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Update your `package.json` scripts and enable the test runner.
```json title="package.json"
@@ -46,24 +44,18 @@ Update your `package.json` scripts and enable the test runner.
Start your Storybook with:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- Storybook's test runner requires either a locally running Storybook instance or a published Storybook to run all the existing tests.
+
+Storybook's test runner requires either a locally running Storybook instance or a published Storybook to run all the existing tests.
+
Finally, open a new terminal window and run the test-runner with:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Configure
Test runner offers zero-config support for Storybook. However, you can run `test-storybook --eject` for more fine-grained control. It generates a `test-runner-jest.config.js` file at the root of your project, which you can modify. Additionally, you can extend the generated configuration file and provide [testEnvironmentOptions](https://github.com/playwright-community/jest-playwright#configuration) as the test runner also uses [jest-playwright](https://github.com/playwright-community/jest-playwright) under the hood.
@@ -73,51 +65,43 @@ Test runner offers zero-config support for Storybook. However, you can run `test
The test-runner is powered by [Jest](https://jestjs.io/) and accepts a subset of its [CLI options](https://jestjs.io/docs/cli) (for example, `--watch`, `--maxWorkers`).
If you're already using any of those flags in your project, you should be able to migrate them into Storybook's test-runner without any issues. Listed below are all the available flags and examples of using them.
-| Options | Description |
-| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `--help` | Output usage information `test-storybook --help` |
-| `-s`, `--index-json` | Run in index json mode. Automatically detected (requires a compatible Storybook) `test-storybook --index-json` |
-| `--no-index-json` | Disables index json mode `test-storybook --no-index-json` |
-| `-c`, `--config-dir [dir-name]` | Directory where to load Storybook configurations from `test-storybook -c .storybook` |
-| `--watch` | Run in watch mode `test-storybook --watch` |
-| `--watchAll` | Watch files for changes and rerun all tests when something changes. `test-storybook --watchAll` |
-| `--coverage` | Runs [coverage tests](#generate-code-coverage) on your stories and components `test-storybook --coverage` |
-| `--coverageDirectory` | Directory where to write coverage report output `test-storybook --coverage --coverageDirectory coverage/ui/storybook` |
-| `--url` | Define the URL to run tests in. Useful for custom Storybook URLs `test-storybook --url http://the-storybook-url-here.com` |
-| `--browsers` | Define browsers to run tests in. One or multiple of: chromium, firefox, webkit `test-storybook --browsers firefox chromium` |
-| `--maxWorkers [amount]` | Specifies the maximum number of workers the worker-pool will spawn for running tests `test-storybook --maxWorkers=2` |
-| `--testTimeout [amount]` | Defines the maximum time in milliseconds that a test can run before it is automatically marked as failed. Useful for long-running tests `test-storybook --testTimeout=60000` |
-| `--no-cache` | Disable the cache `test-storybook --no-cache` |
-| `--clearCache` | Deletes the Jest cache directory and then exits without running tests `test-storybook --clearCache` |
-| `--verbose` | Display individual test results with the test suite hierarchy `test-storybook --verbose` |
-| `-u`, `--updateSnapshot` | Use this flag to re-record every snapshot that fails during this test run `test-storybook -u` |
-| `--eject` | Creates a local configuration file to override defaults of the test-runner `test-storybook --eject` |
-| `--json` | Prints the test results in JSON. This mode will send all other test output and user messages to stderr. `test-storybook --json` |
-| `--outputFile` | Write test results to a file when the --json option is also specified. `test-storybook --json --outputFile results.json` |
-| `--junit` | Indicates that test information should be reported in a junit file. `test-storybook --**junit**` |
-| `--ci` | Instead of the regular behavior of storing a new snapshot automatically, it will fail the test and require Jest to be run with `--updateSnapshot`. `test-storybook --ci` |
-| `--shard [index/count]` | Requires CI. Splits the test suite execution into multiple machines `test-storybook --shard=1/8` |
-| `--failOnConsole` | Makes tests fail on browser console errors `test-storybook --failOnConsole` |
+| Options | Description |
+| ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `--help` | Output usage information `test-storybook --help` |
+| `-s`, `--index-json` | Run in index json mode. Automatically detected (requires a compatible Storybook) `test-storybook --index-json` |
+| `--no-index-json` | Disables index json mode `test-storybook --no-index-json` |
+| `-c`, `--config-dir [dir-name]` | Directory where to load Storybook configurations from `test-storybook -c .storybook` |
+| `--watch` | Run in watch mode `test-storybook --watch` |
+| `--watchAll` | Watch files for changes and rerun all tests when something changes. `test-storybook --watchAll` |
+| `--coverage` | Runs [coverage tests](#generate-code-coverage) on your stories and components `test-storybook --coverage` |
+| `--coverageDirectory` | Directory where to write coverage report output `test-storybook --coverage --coverageDirectory coverage/ui/storybook` |
+| `--url` | Define the URL to run tests in. Useful for custom Storybook URLs `test-storybook --url http://the-storybook-url-here.com` |
+| `--browsers` | Define browsers to run tests in. One or multiple of: chromium, firefox, webkit `test-storybook --browsers firefox chromium` |
+| `--maxWorkers [amount]` | Specifies the maximum number of workers the worker-pool will spawn for running tests `test-storybook --maxWorkers=2` |
+| `--testTimeout [amount]` | Defines the maximum time in milliseconds that a test can run before it is automatically marked as failed. Useful for long-running tests `test-storybook --testTimeout=60000` |
+| `--no-cache` | Disable the cache `test-storybook --no-cache` |
+| `--clearCache` | Deletes the Jest cache directory and then exits without running tests `test-storybook --clearCache` |
+| `--verbose` | Display individual test results with the test suite hierarchy `test-storybook --verbose` |
+| `-u`, `--updateSnapshot` | Use this flag to re-record every snapshot that fails during this test run `test-storybook -u` |
+| `--eject` | Creates a local configuration file to override defaults of the test-runner `test-storybook --eject` |
+| `--json` | Prints the test results in JSON. This mode will send all other test output and user messages to stderr. `test-storybook --json` |
+| `--outputFile` | Write test results to a file when the --json option is also specified. `test-storybook --json --outputFile results.json` |
+| `--junit` | Indicates that test information should be reported in a junit file. `test-storybook --**junit**` |
+| `--ci` | Instead of the regular behavior of storing a new snapshot automatically, it will fail the test and require Jest to be run with `--updateSnapshot`. `test-storybook --ci` |
+| `--shard [index/count]` | Requires CI. Splits the test suite execution into multiple machines `test-storybook --shard=1/8` |
+| `--failOnConsole` | Makes tests fail on browser console errors `test-storybook --failOnConsole` |
| `--includeTags` | Experimental feature Defines a subset of stories to be tested if they match the enabled [tags](#experimental-filter-tests). `test-storybook --includeTags="test-only, pages"` |
| `--excludeTags` | Experimental feature Prevents stories from being tested if they match the provided [tags](#experimental-filter-tests). `test-storybook --excludeTags="no-tests, tokens"` |
| `--skipTags` | Experimental feature Configures the test runner to skip running tests for stories that match the provided [tags](#experimental-filter-tests). `test-storybook --skipTags="skip-test, layout"` |
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Run tests against a deployed Storybook
By default, the test-runner assumes that you're running it against a locally served Storybook on port `6006`. If you want to define a target URL to run against deployed Storybooks, you can use the `--url` flag:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Alternatively, you can set the `TARGET_URL` environment variable and run the test-runner:
```sh
@@ -140,14 +124,12 @@ To enable snapshot testing with the test-runner, you'll need to take additional
Add a new [configuration file](#test-hook-api) inside your Storybook directory with the following inside:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- The `postVisit` hook allows you to extend the test runner's default configuration. Read more about them [here](#test-hook-api).
+
+The `postVisit` hook allows you to extend the test runner's default configuration. Read more about them [here](#test-hook-api).
+
When you execute the test-runner (for example, with `yarn test-storybook`), it will run through all of your stories and run the snapshot tests, generating a snapshot file for each story in your project located in the `__snapshots__` directory.
@@ -162,20 +144,12 @@ The test-runner uses a specific naming convention and path for the generated sna
Create a `snapshot-resolver.js` file to implement a custom snapshot resolver:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Update the `test-runner-jest.config.js` file and enable the `snapshotResolver` option to use the custom snapshot resolver:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
When the test-runner is executed, it will cycle through all of your stories and run the snapshot tests, generating a snapshot file for each story in your project located in the custom directory you specified.
#### Customize snapshot serialization
@@ -184,20 +158,12 @@ By default, the test-runner uses [`jest-serializer-html`](https://github.com/alg
Create a `snapshot-serializer.js` file to implement a custom snapshot serializer:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Update the `test-runner-jest.config.js` file and enable the `snapshotSerializers` option to use the custom snapshot resolver:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
When the test-runner executes your tests, it will introspect the resulting HTML, replacing the dynamically generated attributes with the static ones provided by the regular expression in the custom serializer file before snapshotting the component. This ensures that the snapshots are consistent across different test runs.
## Generate code coverage
@@ -210,8 +176,6 @@ Engineered to work alongside modern testing tools (e.g., [Playwright](https://pl
Run the following command to install the addon.
-{/* prettier-ignore-start */}
-
@@ -222,40 +186,28 @@ The CLI's [`add`](../../api/cli-options.mdx#add) command automates the addon's i
Start your Storybook with:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Finally, open a new terminal window and run the test-runner with:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
-
+
### Configure
By default, the [`@storybook/addon-coverage`](https://storybook.js.org/addons/@storybook/addon-coverage) offers zero-config support for Storybook and instruments your code via [`istanbul-lib-instrument`](https://www.npmjs.com/package/istanbul-lib-instrument) for [Webpack](https://webpack.js.org/), or [`vite-plugin-istanbul`](https://github.com/iFaxity/vite-plugin-istanbul) for [Vite](https://vitejs.dev/). However, you can extend your Storybook configuration file (i.e., `.storybook/main.js|ts`) and provide additional options to the addon. Listed below are the available options divided by builder and examples of how to use them.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
Vite options
-| Options | Description | Type |
-| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
+| Options | Description | Type |
+| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
| `checkProd` | Configures the plugin to skip instrumentation in production environments `options: { istanbul: { checkProd: true,}}` | `boolean` |
-| `cwd` | Configures the working directory for the coverage tests. Defaults to `process.cwd()` `options: { istanbul: { cwd: process.cwd(),}}` | `string` |
-| `cypress` | Replaces the `VITE_COVERAGE` environment variable with `CYPRESS_COVERAGE`. Requires Cypress's [code coverage](https://docs.cypress.io/guides/tooling/code-coverage) `options: { istanbul: { cypress: true,}}` | `boolean` |
+| `cwd` | Configures the working directory for the coverage tests. Defaults to `process.cwd()` `options: { istanbul: { cwd: process.cwd(),}}` | `string` |
+| `cypress` | Replaces the `VITE_COVERAGE` environment variable with `CYPRESS_COVERAGE`. Requires Cypress's [code coverage](https://docs.cypress.io/guides/tooling/code-coverage) `options: { istanbul: { cypress: true,}}` | `boolean` |
| `exclude` | Overrides the [default exclude list](https://github.com/storybookjs/addon-coverage/blob/main/src/constants.ts) with the provided list of files or directories to exclude from coverage `options: { istanbul: { exclude: ['**/stories/**'],}}` | `Array` or `string` |
| `extension` | Extends the [default extension list](https://github.com/storybookjs/addon-coverage/blob/main/src/constants.ts) with the provided list of file extensions to include in coverage `options: { istanbul: { extension: ['.js', '.cjs', '.mjs'],}}` | `Array` or `string` |
| `forceBuildInstrument` | Configures the plugin to add instrumentation in build mode `options: { istanbul: { forceBuildInstrument: true,}}` | `boolean` |
@@ -268,12 +220,12 @@ By default, the [`@storybook/addon-coverage`](https://storybook.js.org/addons/@s
Webpack 5 options
-| Options | Description | Type |
-| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
+| Options | Description | Type |
+| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
| `autoWrap` | Provides support for top-level return statements by wrapping the program code in a function `options: { istanbul: { autoWrap: true,}}` | `boolean` |
| `compact` | Condenses the output of the instrumented code. Useful for debugging `options: { istanbul: { compact: false,}}` | `boolean` |
| `coverageVariable` | Defines the global variable name that Istanbul will use to store coverage results `options: { istanbul: { coverageVariable: '__coverage__',}}` | `string` |
-| `cwd` | Configures the working directory for the coverage tests. Defaults to `process.cwd()` `options: { istanbul: { cwd: process.cwd(),}}` | `string` |
+| `cwd` | Configures the working directory for the coverage tests. Defaults to `process.cwd()` `options: { istanbul: { cwd: process.cwd(),}}` | `string` |
| `debug` | Enables the debug mode for additional logging information during the instrumentation process `options: { istanbul: { debug: true,}}` | `boolean` |
| `esModules` | Enables support for ES Module syntax `options: { istanbul: { esModules: true,}}` | `boolean` |
| `exclude` | Overrides the [default exclude list](https://github.com/storybookjs/addon-coverage/blob/main/src/constants.ts) with the provided list of files or directories to exclude from coverage `options: { istanbul: { exclude: ['**/stories/**'],}}` | `Array` or `string` |
@@ -290,12 +242,8 @@ By default, the [`@storybook/addon-coverage`](https://storybook.js.org/addons/@s
Out of the box, code coverage tests work seamlessly with Storybook's test-runner and the [`@storybook/addon-coverage`](https://storybook.js.org/addons/@storybook/addon-coverage). However, that doesn't mean you can't use additional reporting tools (e.g., [Codecov](https://about.codecov.io/)). For instance, if you're working with [LCOV](https://wiki.documentfoundation.org/Development/Lcov), you can use the generated output (in `coverage/storybook/coverage-storybook.json`) and create your own report with:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
## Set up CI to run tests
You can also configure the test-runner to run tests on a CI environment. Documented below are some recipes to help you get started.
@@ -304,28 +252,24 @@ You can also configure the test-runner to run tests on a CI environment. Documen
If you're publishing your Storybook with services such as [Vercel](https://vercel.com/) or [Netlify](https://docs.netlify.com/site-deploys/notifications/#github-commit-statuses), they emit a `deployment_status` event in GitHub Actions. You can use it and set the `deployment_status.target_url` as the `TARGET_URL` environment variable. Here's how:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- The published Storybook must be publicly available for this example to work. We recommend running the test server using the recipe [below](#run-against-non-deployed-storybooks) if it requires authentication.
+
+The published Storybook must be publicly available for this example to work. We recommend running the test server using the recipe [below](#run-against-non-deployed-storybooks) if it requires authentication.
+
### Run against non-deployed Storybooks
You can use your CI provider (for example, [GitHub Actions](https://github.com/features/actions), [GitLab Pipelines](https://docs.gitlab.com/ee/ci/pipelines/), [CircleCI](https://circleci.com/)) to build and run the test runner against your built Storybook. Here's a recipe that relies on third-party libraries, that is to say, [concurrently](https://www.npmjs.com/package/concurrently), [http-server](https://www.npmjs.com/package/http-server), and [wait-on](https://www.npmjs.com/package/wait-on) to build Storybook and run tests with the test-runner.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- By default, Storybook outputs the [build](../../sharing/publish-storybook.mdx#build-storybook-as-a-static-web-application) to the `storybook-static` directory. If you're using a different build directory, you'll need to adjust the recipe accordingly.
+
+By default, Storybook outputs the [build](../../sharing/publish-storybook.mdx#build-storybook-as-a-static-web-application) to the `storybook-static` directory. If you're using a different build directory, you'll need to adjust the recipe accordingly.
+
## Advanced configuration
@@ -334,40 +278,40 @@ You can use your CI provider (for example, [GitHub Actions](https://github.com/f
The test-runner renders a story and executes its [play function](../../writing-stories/play-function.mdx) if one exists. However, certain behaviors are impossible to achieve via the play function, which executes in the browser. For example, if you want the test-runner to take visual snapshots for you, this is possible via Playwright/Jest but must be executed in Node.
-The test-runner exports test hooks that can be overridden globally to enable use cases like visual or DOM snapshots. These hooks give you access to the test lifecycle *before* and *after* the story is rendered.
+The test-runner exports test hooks that can be overridden globally to enable use cases like visual or DOM snapshots. These hooks give you access to the test lifecycle _before_ and _after_ the story is rendered.
Listed below are the available hooks and an overview of how to use them.
-| Hook | Description |
-| ----------- | --------------------------------------------------------------------------------------------------------------- |
+| Hook | Description |
+| ----------- | ---------------------------------------------------------------------------------------------------------------- |
| `prepare` | Prepares the browser for tests `async prepare({ page, browserContext, testRunnerConfig }) {}` |
| `setup` | Executes once before all the tests run `setup() {}` |
| `preVisit` | Executes before a story is initially visited and rendered in the browser `async preVisit(page, context) {}` |
| `postVisit` | Executes after the story is visited and fully rendered `async postVisit(page, context) {}` |
- These test hooks are experimental and may be subject to breaking changes. We encourage you to test as much as possible within the story's [play function](../../writing-stories/play-function.mdx).
+
+These test hooks are experimental and may be subject to breaking changes. We encourage you to test as much as possible within the story's [play function](../../writing-stories/play-function.mdx).
+
To enable the hooks API, you'll need to add a new configuration file inside your Storybook directory and set them up as follows:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- Except for the `setup` function, all other functions run asynchronously. Both `preVisit` and `postVisit` functions include two additional arguments, a [Playwright page](https://playwright.dev/docs/pages) and a context object which contains the `id`, `title`, and the `name` of the story.
+
+Except for the `setup` function, all other functions run asynchronously. Both `preVisit` and `postVisit` functions include two additional arguments, a [Playwright page](https://playwright.dev/docs/pages) and a context object which contains the `id`, `title`, and the `name` of the story.
+
When the test-runner executes, your existing tests will go through the following lifecycle:
-* The `setup` function is executed before all the tests run.
-* The context object is generated containing the required information.
-* Playwright navigates to the story's page.
-* The `preVisit` function is executed.
-* The story is rendered, and any existing `play` functions are executed.
-* The `postVisit` function is executed.
+- The `setup` function is executed before all the tests run.
+- The context object is generated containing the required information.
+- Playwright navigates to the story's page.
+- The `preVisit` function is executed.
+- The story is rendered, and any existing `play` functions are executed.
+- The `postVisit` function is executed.
### (Experimental) Filter tests
@@ -379,130 +323,96 @@ When you run the test-runner on Storybook, it tests every story by default. Howe
| `include` | Defines a subset of stories only to be tested if they match the enabled tags. |
| `skip` | Skips testing on stories if they match the provided tags. |
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- Running tests with the CLI flags takes precedence over the options provided in the configuration file and will override the available options in the configuration file.
+
+Running tests with the CLI flags takes precedence over the options provided in the configuration file and will override the available options in the configuration file.
+
#### Disabling tests
If you want to prevent specific stories from being tested by the test-runner, you can configure your story with a custom tag, enable it to the test-runner configuration file or run the test-runner with the `--excludeTags` [CLI](#cli-options) flag and exclude them from testing. This is helpful when you want to exclude stories that are not yet ready for testing or are irrelevant to your tests. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### Run tests for a subset of stories
To allow the test-runner only to run tests on a specific story or subset of stories, you can configure the story with a custom tag, enable it in the test-runner configuration file or run the test-runner with the `--includeTags` [CLI](#cli-options) flag and include them in your tests. For example, if you wanted to run tests based on the `test-only` tag, you can adjust your configuration as follows:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- Applying tags for the component's stories should either be done at the component level (using `meta`) or at the story level. Importing tags across stories is not supported in Storybook and won't work as intended.
+
+Applying tags for the component's stories should either be done at the component level (using `meta`) or at the story level. Importing tags across stories is not supported in Storybook and won't work as intended.
+
#### Skip tests
If you want to skip running tests on a particular story or subset of stories, you can configure your story with a custom tag, enable it in the test-runner configuration file, or run the test-runner with the `--skipTags` [CLI](#cli-options) flag. Running tests with this option will cause the test-runner to ignore and flag them accordingly in the test results, indicating that the tests are temporarily disabled. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Authentication for deployed Storybooks
If you use a secure hosting provider that requires authentication to host your Storybook, you may need to set HTTP headers. This is mainly because of how the test runner checks the status of the instance and the index of its stories through fetch requests and Playwright. To do this, you can modify the test-runner configuration file to include the `getHttpHeaders` function. This function takes the URL of the fetch calls and page visits as input and returns an object containing the headers that need to be set.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Helpers
The test-runner exports a few helpers that can be used to make your tests more readable and maintainable by accessing Storybook's internals (e.g., `args`, `parameters`). Listed below are the available helpers and an overview of how to use them.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### Accessing story information with the test-runner
If you need to access information about the story, such as its parameters, the test-runner includes a helper function named `getStoryContext` that you can use to retrieve it. You can then use it to customize your tests further as needed. For example, if you need to configure Playwright's page [viewport size](https://playwright.dev/docs/api/class-page#page-set-viewport-size) to use the viewport size defined in the story's parameters, you can do so as follows:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### Working with assets
If you're running a specific set of tests (e.g., image snapshot testing), the test-runner provides a helper function named `waitForPageReady` that you can use to ensure the page is fully loaded and ready before running the test. For example:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### Index.json mode
-The test-runner transforms your story files into tests when testing a local Storybook. For a remote Storybook, it uses the Storybook's [index.json](../../configure/index.mdx#feature-flags) (formerly `stories.json`) file (a static index of all the stories) to run the tests.
+The test-runner transforms your story files into tests when testing a local Storybook. For a remote Storybook, it uses the Storybook's [index.json](../../configure/index.mdx) (formerly `stories.json`) file (a static index of all the stories) to run the tests.
#### Why?
Suppose you run into a situation where the local and remote Storybooks appear out of sync, or you might not even have access to the code. In that case, the `index.json` file is guaranteed to be the most accurate representation of the deployed Storybook you are testing. To test a local Storybook using this feature, use the `--index-json` flag as follows:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
- The `index.json` mode is not compatible with the watch mode.
+
+The `index.json` mode is not compatible with the watch mode.
+
If you need to disable it, use the `--no-index-json` flag:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
#### How do I check if my Storybook has a `index.json` file?
-Index.json mode requires a `index.json` file. Open a browser window and navigate to your deployed Storybook instance (for example, `https://your-storybook-url-here.com/index.json`). You should see a JSON file that starts with a `"v": 3` key, immediately followed by another key called "stories", which contains a map of story IDs to JSON objects. If that is the case, your Storybook supports [index.json mode](../../configure/index.mdx#feature-flags).
+Index.json mode requires a `index.json` file. Open a browser window and navigate to your deployed Storybook instance (for example, `https://your-storybook-url-here.com/index.json`). You should see a JSON file that starts with a `"v": 3` key, immediately followed by another key called "stories", which contains a map of story IDs to JSON objects. If that is the case, your Storybook supports [index.json mode](../../configure/index.mdx).
## What's the difference between Chromatic and Test runner?
The test-runner is a generic testing tool that can run locally or on CI and be configured or extended to run all kinds of tests.
-[Chromatic](https://www.chromatic.com/?utm_source=storybook_website\&utm_medium=link\&utm_campaign=storybook) is a cloud-based service that runs [visual](../visual-testing.mdx) and [interaction tests](../interaction-testing.mdx) (and soon [accessibility tests](../accessibility-testing.mdx)) without setting up the test runner. It also syncs with your git provider and manages access control for private projects.
+[Chromatic](https://www.chromatic.com/?utm_source=storybook_website&utm_medium=link&utm_campaign=storybook) is a cloud-based service that runs [visual](../visual-testing.mdx) and [interaction tests](../interaction-testing.mdx) (and soon [accessibility tests](../accessibility-testing.mdx)) without setting up the test runner. It also syncs with your git provider and manages access control for private projects.
However, you might want to pair the test runner and Chromatic in some cases.
-* Use it locally and Chromatic on your CI.
-* Use Chromatic for visual and component tests and run other custom tests using the test runner.
+- Use it locally and Chromatic on your CI.
+- Use Chromatic for visual and component tests and run other custom tests using the test runner.
## Troubleshooting
@@ -550,34 +460,26 @@ This is due to the test-runner using the community-maintained package [jest-play
If you intend on running coverage tests in frameworks with special files like Vue 3 or Svelte, you'll need to adjust your configuration and enable the required file extensions. For example, if you're using Vue, you'll need to add the following to your nyc configuration file (i.e., `.nycrc.json` or `nyc.config.js`):
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### The coverage addon doesn't support optimized builds
If you generated a production build optimized for performance with the [`--test`](../../sharing/publish-storybook.mdx#customizing-the-build-for-performance) flag, and you're using the coverage addon to run tests against your Storybook, you may run into a situation where the coverage addon doesn't instrument your code. This is due to how the flag works, as it removes addons that have an impact on performance (e.g., [`Docs`](../../writing-docs/index.mdx), [coverage addon](https://storybook.js.org/addons/@storybook/addon-coverage)). To resolve this issue, you'll need to adjust your Storybook configuration file (i.e., `.storybook/main.js|ts`) and include the [`disabledAddons`](../../api/main-config/main-config-build.mdx#testdisabledaddons) option to allow the addon to run tests at the expense of a slower build.
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
### The coverage addon doesn't support instrumented code
As the [coverage addon](https://storybook.js.org/addons/@storybook/addon-coverage) is based on Webpack5 loaders and Vite plugins for code instrumentation, frameworks that don't rely upon these libraries (e.g., Angular configured with Webpack), will require additional configuration to enable code instrumentation. In that case, you can refer to the following [repository](https://github.com/yannbf/storybook-coverage-recipes) for more information.
**More testing resources**
-* [Interaction testing](../interaction-testing.mdx) for user behavior simulation
-* [Accessibility testing](../accessibility-testing.mdx) for accessibility
-* [Visual testing](../visual-testing.mdx) for appearance
-* [Snapshot testing](../snapshot-testing.mdx) for rendering errors and warnings
-* [Test coverage](../test-coverage.mdx) for measuring code coverage
-* [CI](../in-ci.mdx) for running tests in your CI/CD pipeline
-* [Vitest addon](./vitest-addon/index.mdx) for running tests in Storybook
-* [End-to-end testing](./stories-in-end-to-end-tests.mdx) for simulating real user scenarios
-* [Unit testing](./stories-in-unit-tests.mdx) for functionality
+- [Interaction testing](../interaction-testing.mdx) for user behavior simulation
+- [Accessibility testing](../accessibility-testing.mdx) for accessibility
+- [Visual testing](../visual-testing.mdx) for appearance
+- [Snapshot testing](../snapshot-testing.mdx) for rendering errors and warnings
+- [Test coverage](../test-coverage.mdx) for measuring code coverage
+- [CI](../in-ci.mdx) for running tests in your CI/CD pipeline
+- [Vitest addon](./vitest-addon/index.mdx) for running tests in Storybook
+- [End-to-end testing](./stories-in-end-to-end-tests.mdx) for simulating real user scenarios
+- [Unit testing](./stories-in-unit-tests.mdx) for functionality
diff --git a/docs/writing-tests/integrations/vitest-addon/index.mdx b/docs/writing-tests/integrations/vitest-addon/index.mdx
index 5f76c68ac4fa..501c05bcd6b8 100644
--- a/docs/writing-tests/integrations/vitest-addon/index.mdx
+++ b/docs/writing-tests/integrations/vitest-addon/index.mdx
@@ -1,8 +1,7 @@
---
-title: 'Vitest addon'
+title: Vitest addon
sidebar:
order: 1
- title: Vitest addon
isTab: true
tab:
order: 1
@@ -40,14 +39,18 @@ Before installing, make sure your project meets the following requirements:
- A Storybook framework that uses Vite (e.g. [`vue3-vite`](../../../get-started/frameworks/vue3-vite.mdx), [`react-vite`](../../../get-started/frameworks/react-vite.mdx), [`preact-vite`](../../../get-started/frameworks/preact-vite.mdx), [`nextjs-vite`](../../../get-started/frameworks/nextjs-vite.mdx), [`sveltekit`](../../../get-started/frameworks/sveltekit.mdx), etc.)
- Vitest ≥ 3.0
- - If you're not yet using Vitest, it will be installed and configured for you automatically
+ - If you're not yet using Vitest, it will be installed and configured for you automatically
- (optional) MSW ≥ 2.0
- - If MSW is installed, it must be v2.0.0 or later to not conflict with Vitest's dependency
+ - If MSW is installed, it must be v2.0.0 or later to not conflict with Vitest's dependency
+
+
**Using with Next.js** — The Vitest addon is supported in Next.js ≥ 14.1 projects, but you must be using the [`@storybook/nextjs-vite` framework](../../../get-started/frameworks/nextjs-vite.mdx). When you run the setup command below, you will be prompted to install and use the framework if you haven't already.
+
+
### Automatic setup
@@ -58,11 +61,11 @@ Run the following command to install and configure the addon automatically:
The [`add` command](../../../addons/install-addons.mdx#automatic-installation) will:
-* Install and register the Vitest addon
-* Inspect your project's Vite and Vitest setup
-* Install and configure Vitest with sensible defaults if necessary
-* Set up browser mode using Playwright's Chromium browser
-* **Prompt you to install Playwright browser binaries** if needed
+- Install and register the Vitest addon
+- Inspect your project's Vite and Vitest setup
+- Install and configure Vitest with sensible defaults if necessary
+- Set up browser mode using Playwright's Chromium browser
+- **Prompt you to install Playwright browser binaries** if needed
The setup is fully automated and handles all configuration for you. The full configuration options can be found in the [API section](#options), below.
@@ -77,7 +80,9 @@ You can install the Playwright browser binaries at any time by running [`playwri
### Manual setup (advanced)
-Manual setup instructions (only needed if automatic setup fails)
+
+Manual setup instructions (only needed if automatic setup fails)
+
For some project setups, the `add` command may be unable to automate the addon and plugin setup and ask you to complete additional setup steps. Here's what to do:
@@ -96,26 +101,18 @@ When the addon is set up automatically, it will create or adjust your Vitest con
Example Vitest config file
- The most simple application of the plugin is to include it in your Vitest configuration file:
+The most simple application of the plugin is to include it in your Vitest configuration file:
- {/* prettier-ignore-start */}
-
-
-
- {/* prettier-ignore-end */}
+Example Vitest workspace file (Vitest < 3.2)
- If you're using a [Vitest workspace](https://v3.vitest.dev/config/#workspace), you can define a new workspace project:
-
- {/* prettier-ignore-start */}
+If you're using a [Vitest workspace](https://v3.vitest.dev/config/#workspace), you can define a new workspace project:
-
-
- {/* prettier-ignore-end */}
+
@@ -196,7 +193,7 @@ This screenshot shows how you can run your Vitest tests in VSCode using the [Vit
For the most part, running your Storybook tests in CI is done [via the CLI](#cli).
-However, to have the test output link to your published Storybook on test failures, you need to provide the [`storybookUrl` option](#storybookurl) in the plugin configuration. Please reference the [detailed example in the Testing in CI guide](../../in-ci.mdx#21-debugging-test-failures-in-ci).
+However, to have the test output link to your published Storybook on test failures, you need to provide the [`storybookUrl` option](#storybookurl) in the plugin configuration. Please reference the [detailed example in the Testing in CI guide](../../in-ci.mdx#21-debug-test-failures).
## How it works
@@ -204,7 +201,7 @@ The Vitest addon works by using a Vitest plugin to transform your stories into [
Stories are tested in two ways: a smoke test to ensure it renders and, if a [play function](../../interaction-testing.mdx#writing-interaction-tests) is defined, that function is run and any [assertions made](../../interaction-testing.mdx#asserting-with-expect) within it are validated.
-When you run tests in the [Storybook UI](#storybook-ui), the addon runs Vitest in the background and reports the results in the sidebar.
+When you run tests in the [Storybook UI](#storybook-ui), the addon runs Vitest in the background and reports the results in the sidebar.
## Configuring tests
@@ -226,20 +223,12 @@ By default, the plugin will run all stories with the `test` tag. You can adjust
In this example, we'll apply the `stable` tag to all of the Button component's stories, except for ExperimentalFeatureStory, which will have the `experimental` tag:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
To connect those tags to our test behavior, we can adjust the plugin configuration to exclude the `experimental` tag:
-{/* prettier-ignore-start */}
-
-{/* prettier-ignore-end */}
-
If the same tag is in both the `include` and `exclude` arrays, the `exclude` behavior takes precedence.
## Comparison to the test runner
@@ -248,12 +237,12 @@ The [test runner](../test-runner.mdx) requires a running Storybook instance to t
| Feature | Vitest addon | test-runner |
| -------------------------------------------------------- | ------------------ | ------------------------ |
-| **Test types** |
+| **Test types** |
| - [Interaction tests](../../interaction-testing.mdx) | ✅ | ✅ |
| - [Accessibility tests](../../accessibility-testing.mdx) | ✅ | ✅ |
| - [Visual tests](../../visual-testing.mdx) | ✅ | ❌ |
| - [Snapshot tests](../../snapshot-testing.mdx) | ❌ | ✅ |
-| **Testing contexts** |
+| **Testing contexts** |
| - Storybook UI | ✅ | ❌ |
| - Editor extensions | ✅ | ❌ |
| - CLI | ✅ | ✅ |
@@ -308,7 +297,6 @@ To isolate your Storybook tests from other tests, you need to move the `test` pr
Additionally, we recommend using a [test project](#example-configuration-files) if you're using Vitest ≥ 4.0, or a workspace for previous versions to define separate configurations for your Storybook tests and other tests. This ensures each can be run either in isolation or together, depending on your needs.
-
### Why do we recommend browser mode?
Vitest's browser mode runs your tests in a real browser (Chromium, via Playwright, in the default configuration). The alternative is a simulated browser environment, like JSDom or HappyDom, which can have differences in behavior compared to a real browser. For UI components, which can often depend on browser APIs or features, running tests in a real browser is more accurate.
@@ -329,7 +317,7 @@ By default, the export name of a story is mapped to the test name. To create a m
```js title="Example.stories.js|ts"
export const Story = {
- name: 'custom, descriptive name'
+ name: 'custom, descriptive name',
};
```
@@ -346,7 +334,7 @@ export default defineConfig({
// ...
resolve: {
alias: {
- "@storybook/react-dom-shim": "@storybook/react-dom-shim/dist/react-16",
+ '@storybook/react-dom-shim': '@storybook/react-dom-shim/dist/react-16',
},
},
});
@@ -411,7 +399,7 @@ See [Vitest's sharding guide](https://vitest.dev/guide/improving-performance.htm
This addon has the following exports:
```js
-import { storybookTest } from '@storybook/addon-vitest/vitest-plugin'
+import { storybookTest } from '@storybook/addon-vitest/vitest-plugin';
```
#### `storybookTest`
@@ -492,12 +480,12 @@ You might set `disableAddonDocs` to `false` only in case your stories actually n
**More testing resources**
-* [Interaction testing](../../interaction-testing.mdx) for user behavior simulation
-* [Accessibility testing](../../accessibility-testing.mdx) for accessibility
-* [Visual testing](../../visual-testing.mdx) for appearance
-* [Snapshot testing](../../snapshot-testing.mdx) for rendering errors and warnings
-* [Test coverage](../../test-coverage.mdx) for measuring code coverage
-* [CI](../../in-ci.mdx) for running tests in your CI/CD pipeline
-* [Test runner](../test-runner.mdx) to automate test execution
-* [End-to-end testing](../stories-in-end-to-end-tests.mdx) for simulating real user scenarios
-* [Unit testing](../stories-in-unit-tests.mdx) for functionality
+- [Interaction testing](../../interaction-testing.mdx) for user behavior simulation
+- [Accessibility testing](../../accessibility-testing.mdx) for accessibility
+- [Visual testing](../../visual-testing.mdx) for appearance
+- [Snapshot testing](../../snapshot-testing.mdx) for rendering errors and warnings
+- [Test coverage](../../test-coverage.mdx) for measuring code coverage
+- [CI](../../in-ci.mdx) for running tests in your CI/CD pipeline
+- [Test runner](../test-runner.mdx) to automate test execution
+- [End-to-end testing](../stories-in-end-to-end-tests.mdx) for simulating real user scenarios
+- [Unit testing](../stories-in-unit-tests.mdx) for functionality
diff --git a/docs/writing-tests/integrations/vitest-addon/migration-guide.mdx b/docs/writing-tests/integrations/vitest-addon/migration-guide.mdx
index af8c68b5707f..9d5713dbc45e 100644
--- a/docs/writing-tests/integrations/vitest-addon/migration-guide.mdx
+++ b/docs/writing-tests/integrations/vitest-addon/migration-guide.mdx
@@ -1,5 +1,5 @@
---
-title: 'Migrating to Vitest addon from test-runner'
+title: Migrating to Vitest addon from test-runner
isTab: true
tab:
order: 2
@@ -57,9 +57,9 @@ Remove the following files:
### 3. Set up `@storybook/addon-vitest`
- Run this command, which will set up all the necessary code for you.
-
+
-
+
- Update the `package.json` script for Storybook tests, replacing the test-runner binary and using Vitest instead:
```diff title="package.json"
@@ -69,6 +69,7 @@ Remove the following files:
+ "test-storybook": "vitest --project=storybook"
}
}
+ ```
### 4. Update your CI to run Vitest instead of the test-runner
@@ -116,7 +117,7 @@ The Vitest addon relies on Vite to transform and run your stories as tests. Whic
If your Storybook project uses a non-Vite builder like Webpack or RsPack, you will need to keep using the `@storybook/test-runner` for your component testing.
-Most Webpack-based Storybook projects which do not have complex configurations can [migrate to Vite](../../../builders/vite#migrating-from-webpack) relatively easily. If you are using Next.js, you can use the [`@storybook/nextjs-vite` framework](../../../get-started/frameworks/nextjs-vite.mdx) to use Vite with Storybook.
+Most Webpack-based Storybook projects which do not have complex configurations can [migrate to Vite](../../../builders/vite.mdx#migrating-from-webpack) relatively easily. If you are using Next.js, you can use the [`@storybook/nextjs-vite` framework](../../../get-started/frameworks/nextjs-vite.mdx) to use Vite with Storybook.
### What if I am using Jest for my unit tests?
@@ -127,4 +128,4 @@ You can still migrate to use Vitest, but if you believe you won't benefit from i
There are solutions for image snapshot testing that integrate with the Storybook testing widget:
- On the cloud with the [Visual tests addon](../../visual-testing.mdx)
-- Locally with [`storybook-addon-vis`](https://github.com/repobuddy/visual-testing)
\ No newline at end of file
+- Locally with [`storybook-addon-vis`](https://github.com/repobuddy/visual-testing)
diff --git a/docs/writing-tests/interaction-testing.mdx b/docs/writing-tests/interaction-testing.mdx
index d9744c9a9bf0..7d494deac283 100644
--- a/docs/writing-tests/interaction-testing.mdx
+++ b/docs/writing-tests/interaction-testing.mdx
@@ -1,8 +1,7 @@
---
-title: 'Interaction tests'
+title: Interaction tests
sidebar:
order: 2
- title: Interaction tests
---
In Storybook, interaction tests are built as part of a [story](../writing-stories/index.mdx). That story renders the component with the necessary props and context to place it in an initial state. You then use a [play function](../writing-stories/play-function.mdx) to simulate user behavior like clicks, typing, and submitting a form and then assert on the end result.
@@ -86,8 +85,8 @@ Now, those queries are available on the `canvas` object in your `play` function:
-{/* END only web-components */}
+{/* END only web-components */}
### Simulating behavior with `userEvent`
@@ -99,8 +98,8 @@ There are many methods available on `userEvent`, which are detailed in the [`use
| ----------------- | ------------------------------------------------------------------------------------------------------------------------ |
| `click` | Clicks the element, calling a click() function `await userEvent.click()` |
| `dblClick` | Clicks the element twice `await userEvent.dblClick()` |
-| `hover` | Hovers an element `await userEvent.hover()` |
-| `unhover` | Unhovers out of element `await userEvent.unhover()` |
+| `hover` | Hovers an element `await userEvent.hover()` |
+| `unhover` | Unhovers out of element `await userEvent.unhover()` |
| `tab` | Presses the tab key `await userEvent.tab()` |
| `type` | Writes text inside inputs or textareas `await userEvent.type(, 'Some text');` |
| `keyboard` | Simulates keyboard events `await userEvent.keyboard('{Shift}');` |
@@ -110,7 +109,7 @@ There are many methods available on `userEvent`, which are detailed in the [`use
-`userEvent` methods should *always* be `await`ed inside of the play function. This ensures they can be properly logged and debugged in the Interactions panel.
+`userEvent` methods should _always_ be `await`ed inside of the play function. This ensures they can be properly logged and debugged in the Interactions panel.
@@ -128,13 +127,13 @@ The `expect` utility here combines the methods available in [Vitest’s `expect`
| -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| [`toBeInTheDocument()`](https://github.com/testing-library/jest-dom#tobeinthedocument) | Checks if the element is in the DOM `await expect().toBeInTheDocument()` |
| [`toBeVisible()`](https://github.com/testing-library/jest-dom#tobevisible) | Checks if the element is visible to the user `await expect().toBeVisible()` |
-| [`toHaveAttribute()`](https://github.com/testing-library/jest-dom#tohaveattribute) | Checks if an element has an attribute `await expect().toHaveAttribute('aria-disabled', 'true')` |
+| [`toHaveAttribute()`](https://github.com/testing-library/jest-dom#tohaveattribute) | Checks if an element has an attribute `await expect().toHaveAttribute('aria-disabled', 'true')` |
| [`toHaveBeenCalled()`](https://vitest.dev/api/expect.html#tohavebeencalled) | Checks that a spied function was called `await expect().toHaveBeenCalled()` |
| [`toHaveBeenCalledWith()`](https://vitest.dev/api/expect.html#tohavebeencalledwith) | Checks that a spied function was called with specific parameters `await expect().toHaveBeenCalledWith('example')` |
-`expect` calls should *always* be `await`ed inside of the play function. This ensures they can be properly logged and debugged in the Interactions panel.
+`expect` calls should _always_ be `await`ed inside of the play function. This ensures they can be properly logged and debugged in the Interactions panel.
@@ -143,7 +142,7 @@ The `expect` utility here combines the methods available in [Vitest’s `expect`
When your component calls a function, you can spy on that function to make assertions on its behavior using the `fn` utility from Vitest, available via the `storybook/test` module:
```js
-import { fn } from 'storybook/test'
+import { fn } from 'storybook/test';
```
Most of the time, you will use `fn` as an `arg` value when writing your story, then access that `arg` in your test:
@@ -164,7 +163,7 @@ Here's an example of using the [`mockdate`](https://github.com/boblauer/MockDate
There are two requirements to use the `mount` function:
-1. You *must* destructure the mount property from the `context` (the argument passed to your play function). This makes sure that Storybook does not start rendering the story before the play function begins.
+1. You _must_ destructure the mount property from the `context` (the argument passed to your play function). This makes sure that Storybook does not start rendering the story before the play function begins.
2. Your Storybook framework or builder must be configured to transpile to ES2017 or newer. This is because destructuring statements and async/await usages are otherwise transpiled away, which prevents Storybook from recognizing your usage of `mount`.
@@ -313,22 +312,22 @@ If you cannot use the Vitest addon, you can still run your tests in CI using the
## Troubleshooting
-#### What’s the difference between interaction tests and visual tests?
+### What’s the difference between interaction tests and visual tests?
Interaction tests can be expensive to maintain when applied wholesale to every component. We recommend combining them with other methods like visual testing for comprehensive coverage with less maintenance work.
-#### What's the difference between interaction tests and using Vitest + Testing Library alone?
+### What's the difference between interaction tests and using Vitest + Testing Library alone?
Interaction tests integrate Vitest and Testing Library into Storybook. The biggest benefit is the ability to view the component you're testing in a real browser. That helps you debug visually, instead of getting a dump of the (fake) DOM in the command line or hitting the limitations of how JSDOM mocks browser functionality. It's also more convenient to keep stories and tests together in one file than having them spread across files.
**More testing resources**
-* [Vitest addon](./integrations/vitest-addon/index.mdx) for running tests in Storybook
-* [Accessibility testing](./accessibility-testing.mdx) for accessibility
-* [Visual testing](./visual-testing.mdx) for appearance
-* [Snapshot testing](./snapshot-testing.mdx) for rendering errors and warnings
-* [Test coverage](./test-coverage.mdx) for measuring code coverage
-* [CI](./in-ci.mdx) for running tests in your CI/CD pipeline
-* [End-to-end testing](./integrations/stories-in-end-to-end-tests.mdx) for simulating real user scenarios
-* [Unit testing](./integrations/stories-in-unit-tests.mdx) for functionality
-* [Test runner](./integrations/test-runner.mdx) to automate test execution
+- [Vitest addon](./integrations/vitest-addon/index.mdx) for running tests in Storybook
+- [Accessibility testing](./accessibility-testing.mdx) for accessibility
+- [Visual testing](./visual-testing.mdx) for appearance
+- [Snapshot testing](./snapshot-testing.mdx) for rendering errors and warnings
+- [Test coverage](./test-coverage.mdx) for measuring code coverage
+- [CI](./in-ci.mdx) for running tests in your CI/CD pipeline
+- [End-to-end testing](./integrations/stories-in-end-to-end-tests.mdx) for simulating real user scenarios
+- [Unit testing](./integrations/stories-in-unit-tests.mdx) for functionality
+- [Test runner](./integrations/test-runner.mdx) to automate test execution
diff --git a/docs/writing-tests/snapshot-testing.mdx b/docs/writing-tests/snapshot-testing.mdx
index fda8c1b1f5ca..e5a1a85b7e79 100644
--- a/docs/writing-tests/snapshot-testing.mdx
+++ b/docs/writing-tests/snapshot-testing.mdx
@@ -2,12 +2,11 @@
title: Snapshot tests
sidebar:
order: 5
- title: Snapshot tests
---
## Snapshot tests
-Snapshot testing is simply rendering a component in a given state, taking a snapshot of the rendered DOM or HTML, and then comparing it against the previous snapshot. They’re convenient to create, but can be difficult and noisy to maintain if the snapshot contains too much information. For UI components, [visual tests](./visual-testing.mdx) (easier to review) or [interaction tests](./interaction-testing.mdx) (focused on functionality) are usually the better fit. However, there are some cases where snapshot testing may be necessary, such as ensuring an error is thrown correctly.
+Snapshot testing involves rendering a component in a given state, taking a snapshot of the rendered DOM or HTML, and then comparing it against the previous snapshot. They’re convenient to create, but can be difficult and noisy to maintain if the snapshot contains too much information. For UI components, [visual tests](./visual-testing.mdx) (easier to review) or [interaction tests](./interaction-testing.mdx) (focused on functionality) are usually the better fit. However, there are some cases where snapshot testing may be necessary, such as ensuring an error is thrown correctly.
You can reuse your stories as the basis of snapshot tests within another test environment, like Jest or Vitest. To enable this, Storybook provides the Portable Stories API, which composes your stories with their annotations ([args](../writing-stories/args.mdx), [decorators](../writing-stories/decorators.mdx), [parameters](../writing-stories/parameters.mdx), etc) and produces a renderable element for your tests. Portable Stories are available for:
@@ -78,10 +77,10 @@ In this example, we have a simple Button React component which for some reason a
```tsx title="Button.tsx"
function Button(props) {
if (props.doNotUseThisItWillThrowAnError) {
- throw new Error("I tried to tell you...")
+ throw new Error('I tried to tell you...');
}
- return
+ return ;
}
```
@@ -93,7 +92,7 @@ export const ThrowError = {
args: {
doNotUseThisItWillThrowAnError: true,
},
-}
+};
```
Finally, we write a test in the test file which asserts that an error is thrown with a particular message.
@@ -101,15 +100,15 @@ Finally, we write a test in the test file which asserts that an error is thrown
```ts title="Button.test.ts"
// @vitest-environment jsdom
-import { expect, test } from "vitest";
+import { expect, test } from 'vitest';
-import { composeStories } from "@storybook/react";
+import { composeStories } from '@storybook/react';
-import * as stories from "./Button.stories";
+import * as stories from './Button.stories';
const { ThrowError } = composeStories(stories);
-test("Button throws error", async () => {
+test('Button throws error', async () => {
await expect(ThrowError.run()).rejects.toThrowError('I tried to tell you...');
});
```
@@ -128,12 +127,12 @@ Visual tests capture images of stories and compare them against image baselines.
**More testing resources**
-* [Vitest addon](./integrations/vitest-addon/index.mdx) for running tests in Storybook
-* [Interaction testing](./interaction-testing.mdx) for user behavior simulation
-* [Accessibility testing](./accessibility-testing.mdx) for accessibility
-* [Visual testing](./visual-testing.mdx) for appearance
-* [Test coverage](./test-coverage.mdx) for measuring code coverage
-* [CI](./in-ci.mdx) for running tests in your CI/CD pipeline
-* [End-to-end testing](./integrations/stories-in-end-to-end-tests.mdx) for simulating real user scenarios
-* [Unit testing](./integrations/stories-in-unit-tests.mdx) for functionality
-* [Test runner](./integrations/test-runner.mdx) to automate test execution
+- [Vitest addon](./integrations/vitest-addon/index.mdx) for running tests in Storybook
+- [Interaction testing](./interaction-testing.mdx) for user behavior simulation
+- [Accessibility testing](./accessibility-testing.mdx) for accessibility
+- [Visual testing](./visual-testing.mdx) for appearance
+- [Test coverage](./test-coverage.mdx) for measuring code coverage
+- [CI](./in-ci.mdx) for running tests in your CI/CD pipeline
+- [End-to-end testing](./integrations/stories-in-end-to-end-tests.mdx) for simulating real user scenarios
+- [Unit testing](./integrations/stories-in-unit-tests.mdx) for functionality
+- [Test runner](./integrations/test-runner.mdx) to automate test execution
diff --git a/docs/writing-tests/test-coverage.mdx b/docs/writing-tests/test-coverage.mdx
index 2acdb035fb0e..4064669adfbe 100644
--- a/docs/writing-tests/test-coverage.mdx
+++ b/docs/writing-tests/test-coverage.mdx
@@ -1,8 +1,7 @@
---
-title: 'Test coverage'
+title: Test coverage
sidebar:
order: 5
- title: Test coverage
---
Test coverage is the practice of measuring whether existing tests fully cover your code. It marks which conditions, logic branches, functions and variables in your code are and are not being tested.
@@ -50,7 +49,7 @@ The report is interactive. You can click through to a component to view its sour

-
+
It's important to understand that the coverage reported in the Storybook UI has three important limitations:
@@ -102,7 +101,7 @@ Coverage is also available through Vitest's [IDE integrations](https://vitest.de
-Note that this coverage will include *all* tests in your project, not just the stories you've written.
+Note that this coverage will include _all_ tests in your project, not just the stories you've written.
@@ -166,13 +165,13 @@ Both coverage providers support [watermarks](https://vitest.dev/config/#coverage
In the testing widget, the coverage summary will show the percentage of statements covered by your tested stories, as well as whether the coverage meets the watermarks. Below the low watermark, the icon will be red, between the low and high watermarks, it will be orange, and above the high watermark, it will be green.
-
+
To configure the watermarks, you can adjust the Vitest config:
```ts title="vitest.config.ts"
import { defineConfig } from 'vitest/config';
-
+
export default defineConfig({
// ...
test: {
@@ -203,12 +202,12 @@ When calculating coverage in the Storybook UI, the following options are always
**More testing resources**
-* [Vitest addon](./integrations/vitest-addon/index.mdx) for running tests in Storybook
-* [Interaction testing](./interaction-testing.mdx) for user behavior simulation
-* [Accessibility testing](./accessibility-testing.mdx) for accessibility
-* [Visual testing](./visual-testing.mdx) for appearance
-* [Snapshot testing](./snapshot-testing.mdx) for rendering errors and warnings
-* [CI](./in-ci.mdx) for running tests in your CI/CD pipeline
-* [End-to-end testing](./integrations/stories-in-end-to-end-tests.mdx) for simulating real user scenarios
-* [Unit testing](./integrations/stories-in-unit-tests.mdx) for functionality
-* [Test runner](./integrations/test-runner.mdx) to automate test execution
+- [Vitest addon](./integrations/vitest-addon/index.mdx) for running tests in Storybook
+- [Interaction testing](./interaction-testing.mdx) for user behavior simulation
+- [Accessibility testing](./accessibility-testing.mdx) for accessibility
+- [Visual testing](./visual-testing.mdx) for appearance
+- [Snapshot testing](./snapshot-testing.mdx) for rendering errors and warnings
+- [CI](./in-ci.mdx) for running tests in your CI/CD pipeline
+- [End-to-end testing](./integrations/stories-in-end-to-end-tests.mdx) for simulating real user scenarios
+- [Unit testing](./integrations/stories-in-unit-tests.mdx) for functionality
+- [Test runner](./integrations/test-runner.mdx) to automate test execution
diff --git a/docs/writing-tests/visual-testing.mdx b/docs/writing-tests/visual-testing.mdx
index d3ba2deefc9f..fa3d31be5dc8 100644
--- a/docs/writing-tests/visual-testing.mdx
+++ b/docs/writing-tests/visual-testing.mdx
@@ -3,7 +3,6 @@ title: Visual tests
hideRendererSelector: true
sidebar:
order: 4
- title: Visual tests
---
Visual tests are the most efficient way to test your components. With the click of a button you can take snapshots of every story in your Storybook and compare those snapshots to baselines — last known “good” snapshots. Not only does this allow you to check the appearance of your components, but they are also able to check a large subset of component functionality [without having to write or maintain any test code](https://storybook.js.org/blog/visual-testing-is-the-greatest-trick-in-ui-development/)!
@@ -30,7 +29,7 @@ Already using the [Vitest addon](./integrations/vitest-addon/index.mdx)? In the

-Clicking the Run tests button at the bottom will run *all* tests, both component and visual.
+Clicking the Run tests button at the bottom will run _all_ tests, both component and visual.
@@ -125,12 +124,12 @@ Visual tests compare the rendered pixels of every story against known baselines.
**More testing resources**
-* [Vitest addon](./integrations/vitest-addon/index.mdx) for running tests in Storybook
-* [Interaction testing](./interaction-testing.mdx) for user behavior simulation
-* [Accessibility testing](./accessibility-testing.mdx) for accessibility
-* [Snapshot testing](./snapshot-testing.mdx) for rendering errors and warnings
-* [Test coverage](./test-coverage.mdx) for measuring code coverage
-* [CI](./in-ci.mdx) for running tests in your CI/CD pipeline
-* [End-to-end testing](./integrations/stories-in-end-to-end-tests.mdx) for simulating real user scenarios
-* [Unit testing](./integrations/stories-in-unit-tests.mdx) for functionality
-* [Test runner](./integrations/test-runner.mdx) to automate test execution
+- [Vitest addon](./integrations/vitest-addon/index.mdx) for running tests in Storybook
+- [Interaction testing](./interaction-testing.mdx) for user behavior simulation
+- [Accessibility testing](./accessibility-testing.mdx) for accessibility
+- [Snapshot testing](./snapshot-testing.mdx) for rendering errors and warnings
+- [Test coverage](./test-coverage.mdx) for measuring code coverage
+- [CI](./in-ci.mdx) for running tests in your CI/CD pipeline
+- [End-to-end testing](./integrations/stories-in-end-to-end-tests.mdx) for simulating real user scenarios
+- [Unit testing](./integrations/stories-in-unit-tests.mdx) for functionality
+- [Test runner](./integrations/test-runner.mdx) to automate test execution
diff --git a/package.json b/package.json
index d56fce979d06..d60afb494e39 100644
--- a/package.json
+++ b/package.json
@@ -17,6 +17,7 @@
},
"scripts": {
"ci-tests": "cd code; yarn ci-tests",
+ "docs:check": "yarn --cwd scripts docs:check",
"fmt:check": "oxfmt --check .",
"fmt:write": "oxfmt .",
"get-report-message": "cd scripts; yarn get-report-message",
diff --git a/scripts/docs/__tests__/check-docs.test.ts b/scripts/docs/__tests__/check-docs.test.ts
new file mode 100644
index 000000000000..b07dfdde5e44
--- /dev/null
+++ b/scripts/docs/__tests__/check-docs.test.ts
@@ -0,0 +1,373 @@
+import { describe, it, expect, beforeEach, vi } from 'vitest';
+import fs from 'node:fs/promises';
+import path from 'path';
+import os from 'os';
+import {
+ checkRelativeLinks,
+ checkCodeSnippetPaths,
+ checkDeprecatedIfRenderer,
+ checkCalloutVariant,
+ checkNoBodyH1,
+ checkHeadingHierarchy,
+ checkCalloutVariantPositive,
+ checkCalloutIconMismatch,
+ checkFrontmatterQuotes,
+ checkRedundantSidebarTitle,
+ checkBareUrls,
+ runAllChecks,
+} from '../check-docs';
+
+async function writeFile(filePath: string, content: string) {
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
+ await fs.writeFile(filePath, content);
+}
+
+describe('check-docs', () => {
+ let tmpDir: string;
+ let docsDir: string;
+ let snippetsDir: string;
+
+ beforeEach(async () => {
+ tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'docs-check-'));
+ docsDir = path.join(tmpDir, 'docs');
+ snippetsDir = path.join(docsDir, '_snippets');
+ await fs.mkdir(snippetsDir, { recursive: true });
+ });
+
+ describe('checkRelativeLinks', () => {
+ it('passes for valid relative links', async () => {
+ const target = path.join(docsDir, 'foo.mdx');
+ await writeFile(target, '# Foo');
+ await writeFile(path.join(docsDir, 'bar.mdx'), '[link](./foo.mdx)');
+ const errors = await checkRelativeLinks(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('errors for broken relative links', async () => {
+ await writeFile(path.join(docsDir, 'bar.mdx'), '[link](./missing.mdx)');
+ const errors = await checkRelativeLinks(docsDir);
+ expect(errors.length).toBe(1);
+ expect(errors[0].link).toContain('missing.mdx');
+ });
+ it('passes for links with #anchor to existing heading', async () => {
+ const target = path.join(docsDir, 'foo.mdx');
+ await writeFile(target, '## My section\n\nContent here.');
+ await writeFile(path.join(docsDir, 'bar.mdx'), '[link](./foo.mdx#my-section)');
+ const errors = await checkRelativeLinks(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('errors for links with #anchor to non-existent heading', async () => {
+ const target = path.join(docsDir, 'foo.mdx');
+ await writeFile(target, '## Existing heading\n\nContent here.');
+ await writeFile(path.join(docsDir, 'bar.mdx'), '[link](./foo.mdx#non-existent)');
+ const errors = await checkRelativeLinks(docsDir);
+ expect(errors.length).toBe(1);
+ expect(errors[0].message).toContain('Broken fragment');
+ expect(errors[0].message).toContain('#non-existent');
+ });
+ it('passes for links with #anchor to heading containing inline code', async () => {
+ const target = path.join(docsDir, 'foo.mdx');
+ await writeFile(target, '### `Story.test`\n\nContent here.');
+ await writeFile(path.join(docsDir, 'bar.mdx'), '[link](./foo.mdx#storytest)');
+ const errors = await checkRelativeLinks(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('passes for links with #anchor to heading containing escaped HTML', async () => {
+ const target = path.join(docsDir, 'foo.mdx');
+ await writeFile(target, '## Adding to \\\n\nContent here.');
+ await writeFile(path.join(docsDir, 'bar.mdx'), '[link](./foo.mdx#adding-to-head)');
+ const errors = await checkRelativeLinks(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('passes for links with #anchor to heading containing markdown links', async () => {
+ const target = path.join(docsDir, 'foo.mdx');
+ const other = path.join(docsDir, 'other.mdx');
+ await writeFile(other, '# Other');
+ await writeFile(target, '### [Interaction tests](./other.mdx)\n\nContent here.');
+ await writeFile(path.join(docsDir, 'bar.mdx'), '[link](./foo.mdx#interaction-tests)');
+ const errors = await checkRelativeLinks(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('ignores absolute/external links', async () => {
+ await writeFile(path.join(docsDir, 'bar.mdx'), '[google](https://google.com)');
+ const errors = await checkRelativeLinks(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('ignores cross-version links to other release branches', async () => {
+ await writeFile(
+ path.join(docsDir, 'sub', 'bar.mdx'),
+ '[old docs](../../../release-8-6/docs/migration-guide/index.mdx)\n[older docs](../../../release-6-5/docs/configure/babel.mdx)'
+ );
+ const errors = await checkRelativeLinks(docsDir);
+ expect(errors).toEqual([]);
+ });
+ });
+
+ describe('checkCodeSnippetPaths', () => {
+ it('passes for valid snippet path', async () => {
+ await writeFile(path.join(snippetsDir, 'foo.md'), 'snippet');
+ await writeFile(path.join(docsDir, 'bar.mdx'), '');
+ const errors = await checkCodeSnippetPaths(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('errors for missing snippet path', async () => {
+ await writeFile(path.join(docsDir, 'bar.mdx'), '');
+ const errors = await checkCodeSnippetPaths(docsDir);
+ expect(errors.length).toBe(1);
+ expect(errors[0].path).toBe('missing.md');
+ });
+ });
+
+ describe('checkDeprecatedIfRenderer', () => {
+ it('passes for usage', async () => {
+ await writeFile(path.join(docsDir, 'foo.mdx'), 'content');
+ const errors = await checkDeprecatedIfRenderer(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('errors for usage', async () => {
+ await writeFile(path.join(docsDir, 'foo.mdx'), 'bad');
+ const errors = await checkDeprecatedIfRenderer(docsDir);
+ expect(errors.length).toBe(1);
+ expect(errors[0].message).toContain('Deprecated ');
+ });
+ });
+
+ describe('checkCalloutVariant', () => {
+ it('passes for ', async () => {
+ await writeFile(
+ path.join(docsDir, 'foo.mdx'),
+ '\n\nContent\n\n'
+ );
+ const errors = await checkCalloutVariant(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('errors for bare ', async () => {
+ await writeFile(path.join(docsDir, 'foo.mdx'), '\n\nContent\n\n');
+ const errors = await checkCalloutVariant(docsDir);
+ expect(errors.length).toBe(1);
+ expect(errors[0].message).toContain('missing variant prop');
+ });
+ it('errors for without variant', async () => {
+ await writeFile(
+ path.join(docsDir, 'foo.mdx'),
+ '\n\nContent\n\n'
+ );
+ const errors = await checkCalloutVariant(docsDir);
+ expect(errors.length).toBe(1);
+ expect(errors[0].message).toContain('missing variant prop');
+ });
+ });
+
+ describe('checkNoBodyH1', () => {
+ it('passes when no H1 in body', async () => {
+ await writeFile(path.join(docsDir, 'foo.mdx'), '---\ntitle: Foo\n---\n\n## Section');
+ const errors = await checkNoBodyH1(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('errors for H1 in body', async () => {
+ await writeFile(path.join(docsDir, 'foo.mdx'), '---\ntitle: Foo\n---\n\n# Bad heading');
+ const errors = await checkNoBodyH1(docsDir);
+ expect(errors.length).toBe(1);
+ expect(errors[0].message).toContain('H1 heading found in body');
+ });
+ it('ignores H1 inside code blocks', async () => {
+ await writeFile(
+ path.join(docsDir, 'foo.mdx'),
+ '---\ntitle: Foo\n---\n\n```md\n# This is fine\n```'
+ );
+ const errors = await checkNoBodyH1(docsDir);
+ expect(errors).toEqual([]);
+ });
+ });
+
+ describe('checkHeadingHierarchy', () => {
+ it('passes for sequential heading levels', async () => {
+ await writeFile(
+ path.join(docsDir, 'foo.mdx'),
+ '---\ntitle: Foo\n---\n\n## H2\n\n### H3\n\n#### H4'
+ );
+ const errors = await checkHeadingHierarchy(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('errors when skipping heading levels', async () => {
+ await writeFile(path.join(docsDir, 'foo.mdx'), '---\ntitle: Foo\n---\n\n## H2\n\n#### H4');
+ const errors = await checkHeadingHierarchy(docsDir);
+ expect(errors.length).toBe(1);
+ expect(errors[0].message).toContain('jumped from H2 to H4');
+ });
+ it('ignores headings inside code blocks', async () => {
+ await writeFile(
+ path.join(docsDir, 'foo.mdx'),
+ '---\ntitle: Foo\n---\n\n## H2\n\n```md\n#### H4\n```\n\n### H3'
+ );
+ const errors = await checkHeadingHierarchy(docsDir);
+ expect(errors).toEqual([]);
+ });
+ });
+
+ describe('checkCalloutVariantPositive', () => {
+ it('passes for standard variants', async () => {
+ await writeFile(
+ path.join(docsDir, 'foo.mdx'),
+ '\n\nContent\n\n'
+ );
+ const errors = await checkCalloutVariantPositive(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('errors for variant="positive"', async () => {
+ await writeFile(
+ path.join(docsDir, 'foo.mdx'),
+ '\n\nContent\n\n'
+ );
+ const errors = await checkCalloutVariantPositive(docsDir);
+ expect(errors.length).toBe(1);
+ expect(errors[0].message).toContain('variant="positive"');
+ });
+ });
+
+ describe('checkCalloutIconMismatch', () => {
+ it('passes for ⚠️ with variant="warning"', async () => {
+ await writeFile(
+ path.join(docsDir, 'foo.mdx'),
+ '\n\nContent\n\n'
+ );
+ const errors = await checkCalloutIconMismatch(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('errors for ⚠️ with variant="info"', async () => {
+ await writeFile(
+ path.join(docsDir, 'foo.mdx'),
+ '\n\nContent\n\n'
+ );
+ const errors = await checkCalloutIconMismatch(docsDir);
+ expect(errors.length).toBe(1);
+ expect(errors[0].message).toContain('⚠️');
+ });
+ });
+
+ describe('checkFrontmatterQuotes', () => {
+ it('passes for unquoted title', async () => {
+ await writeFile(path.join(docsDir, 'foo.mdx'), '---\ntitle: My page\n---\n\nContent');
+ const errors = await checkFrontmatterQuotes(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('passes for quoted title with special characters', async () => {
+ await writeFile(path.join(docsDir, 'foo.mdx'), '---\ntitle: "Props & Args"\n---\n\nContent');
+ const errors = await checkFrontmatterQuotes(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('errors for unnecessarily quoted title', async () => {
+ await writeFile(path.join(docsDir, 'foo.mdx'), '---\ntitle: "ArgTypes"\n---\n\nContent');
+ const errors = await checkFrontmatterQuotes(docsDir);
+ expect(errors.length).toBe(1);
+ expect(errors[0].message).toContain('unnecessarily quoted');
+ });
+ });
+
+ describe('checkRedundantSidebarTitle', () => {
+ it('passes when sidebar.title differs from title', async () => {
+ await writeFile(
+ path.join(docsDir, 'foo.mdx'),
+ '---\ntitle: Component Story Format (CSF)\nsidebar:\n title: CSF\n---\n\nContent'
+ );
+ const errors = await checkRedundantSidebarTitle(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('errors when sidebar.title matches title', async () => {
+ await writeFile(
+ path.join(docsDir, 'foo.mdx'),
+ '---\ntitle: ArgTypes\nsidebar:\n title: ArgTypes\n---\n\nContent'
+ );
+ const errors = await checkRedundantSidebarTitle(docsDir);
+ expect(errors.length).toBe(1);
+ expect(errors[0].message).toContain('Redundant sidebar.title');
+ });
+ it('passes when no sidebar.title exists', async () => {
+ await writeFile(
+ path.join(docsDir, 'foo.mdx'),
+ '---\ntitle: ArgTypes\nsidebar:\n order: 1\n---\n\nContent'
+ );
+ const errors = await checkRedundantSidebarTitle(docsDir);
+ expect(errors).toEqual([]);
+ });
+ });
+
+ describe('checkBareUrls', () => {
+ it('passes for URLs in markdown link syntax', async () => {
+ await writeFile(
+ path.join(docsDir, 'foo.mdx'),
+ '---\ntitle: Foo\n---\n\n[link](https://example.com)'
+ );
+ const errors = await checkBareUrls(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('errors for bare URLs in prose', async () => {
+ await writeFile(
+ path.join(docsDir, 'foo.mdx'),
+ '---\ntitle: Foo\n---\n\nVisit https://example.com for details.'
+ );
+ const errors = await checkBareUrls(docsDir);
+ expect(errors.length).toBe(1);
+ expect(errors[0].message).toContain('Bare URL');
+ });
+ it('ignores URLs in code blocks', async () => {
+ await writeFile(
+ path.join(docsDir, 'foo.mdx'),
+ '---\ntitle: Foo\n---\n\n```\nhttps://example.com\n```'
+ );
+ const errors = await checkBareUrls(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('ignores URLs in backticks', async () => {
+ await writeFile(
+ path.join(docsDir, 'foo.mdx'),
+ '---\ntitle: Foo\n---\n\nRun `https://example.com` in browser.'
+ );
+ const errors = await checkBareUrls(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('ignores URLs in import statements', async () => {
+ await writeFile(
+ path.join(docsDir, 'foo.mdx'),
+ '---\ntitle: Foo\n---\n\nimport Foo from "https://example.com"'
+ );
+ const errors = await checkBareUrls(docsDir);
+ expect(errors).toEqual([]);
+ });
+ it('ignores URLs in JSX props', async () => {
+ await writeFile(
+ path.join(docsDir, 'foo.mdx'),
+ '---\ntitle: Foo\n---\n\n'
+ );
+ const errors = await checkBareUrls(docsDir);
+ expect(errors).toEqual([]);
+ });
+ });
+
+ describe('runAllChecks', () => {
+ it('passes for clean docs', async () => {
+ await writeFile(path.join(docsDir, 'foo.mdx'), '---\ntitle: Foo\n---\n\n## Section');
+ await writeFile(path.join(snippetsDir, 'foo.md'), 'snippet');
+ await writeFile(
+ path.join(docsDir, 'bar.mdx'),
+ '---\ntitle: Bar\n---\n\n[link](./foo.mdx)\n\nok'
+ );
+ await expect(runAllChecks(docsDir)).resolves.toBeUndefined();
+ });
+ it('aggregates mixed errors', async () => {
+ const mockExit = vi.spyOn(process, 'exit').mockImplementation(() => undefined as never);
+ const mockError = vi.spyOn(console, 'error').mockImplementation(() => {});
+
+ await writeFile(path.join(docsDir, 'badlink.mdx'), '[link](./missing.mdx)');
+ await writeFile(path.join(docsDir, 'badcode.mdx'), '');
+ await writeFile(path.join(docsDir, 'badif.mdx'), 'bad');
+
+ await runAllChecks(docsDir);
+
+ expect(mockExit).toHaveBeenCalledWith(1);
+ expect(mockError).toHaveBeenCalled();
+
+ mockExit.mockRestore();
+ mockError.mockRestore();
+ });
+ });
+});
diff --git a/scripts/docs/check-docs.ts b/scripts/docs/check-docs.ts
new file mode 100644
index 000000000000..c2244c4b9309
--- /dev/null
+++ b/scripts/docs/check-docs.ts
@@ -0,0 +1,481 @@
+import path from 'path';
+import fs from 'node:fs/promises';
+import { getMdxFiles, readFileLines, getHeadingSlugs, getLineContexts } from './utils';
+import { esMain } from '../utils/esmain';
+
+export interface RelativeLinkError {
+ file: string;
+ line: number;
+ link: string;
+ message: string;
+}
+export interface CodeSnippetPathError {
+ file: string;
+ line: number;
+ path: string;
+ message: string;
+}
+export interface DeprecatedIfRendererError {
+ file: string;
+ line: number;
+ message: string;
+}
+export interface CalloutVariantError {
+ file: string;
+ line: number;
+ message: string;
+}
+export interface DocLineError {
+ file: string;
+ line: number;
+ message: string;
+}
+
+/**
+ * Checks all relative links in .mdx files for broken targets.
+ */
+export async function checkRelativeLinks(docsDir: string): Promise {
+ const mdxFiles = await getMdxFiles(docsDir);
+ const errors: RelativeLinkError[] = [];
+ // Cross-version links point to docs on other release branches (e.g. ../../../release-8-6/docs/...)
+ // and cannot be validated locally
+ const crossVersionRegex = /^(?:\.\.\/)+release-[\w.-]+\//;
+
+ // Cache heading slugs per target file to avoid re-reading
+ const slugCache = new Map>();
+
+ for (const file of mdxFiles) {
+ const lines = await readFileLines(file);
+ await Promise.all(
+ lines.map(async (line, idx) => {
+ // Create a new regex per line to avoid shared lastIndex state across concurrent promises
+ const relLinkRegex = /\[[^\]]+\]\(((\.\.?\/)[^\)#]+)(#[^)]*)?\)/g;
+ let match;
+ while ((match = relLinkRegex.exec(line))) {
+ const relPath = match[1];
+ const anchor = match[3];
+ if (crossVersionRegex.test(relPath)) continue;
+ const targetPath = path.resolve(path.dirname(file), relPath);
+ try {
+ await fs.access(targetPath);
+ } catch {
+ errors.push({
+ file,
+ line: idx + 1,
+ link: match[0],
+ message: `Broken relative link: ${relPath}${anchor || ''}`,
+ });
+ continue;
+ }
+ // Validate the fragment if present
+ if (anchor) {
+ const fragment = anchor.slice(1); // Remove leading #
+ if (!slugCache.has(targetPath)) {
+ slugCache.set(targetPath, await getHeadingSlugs(targetPath));
+ }
+ const slugs = slugCache.get(targetPath)!;
+ if (!slugs.has(fragment)) {
+ errors.push({
+ file,
+ line: idx + 1,
+ link: match[0],
+ message: `Broken fragment: ${relPath}${anchor} (heading "#${fragment}" not found in target)`,
+ });
+ }
+ }
+ }
+ })
+ );
+ }
+ return errors;
+}
+
+/**
+ * Checks all usages for missing snippet files.
+ */
+export async function checkCodeSnippetPaths(docsDir: string): Promise {
+ const mdxFiles = await getMdxFiles(docsDir);
+ const errors: CodeSnippetPathError[] = [];
+ const snippetRegex = / {
+ let match;
+ while ((match = snippetRegex.exec(line))) {
+ const snippetPath = match[1];
+ const fullPath = path.join(snippetsDir, snippetPath);
+ try {
+ await fs.access(fullPath);
+ } catch {
+ errors.push({
+ file,
+ line: idx + 1,
+ path: snippetPath,
+ message: `Missing snippet: ${snippetPath}`,
+ });
+ }
+ }
+ })
+ );
+ }
+ return errors;
+}
+
+/**
+ * Checks for deprecated usage in .mdx files.
+ */
+export async function checkDeprecatedIfRenderer(
+ docsDir: string
+): Promise {
+ const mdxFiles = await getMdxFiles(docsDir);
+ const errors: DeprecatedIfRendererError[] = [];
+ const ifRendererRegex = / {
+ if (ifRendererRegex.test(line)) {
+ errors.push({
+ file,
+ line: idx + 1,
+ message: 'Deprecated usage. Use instead.',
+ });
+ }
+ });
+ }
+ return errors;
+}
+
+/**
+ * Checks for tags missing a variant prop.
+ */
+export async function checkCalloutVariant(docsDir: string): Promise {
+ const mdxFiles = await getMdxFiles(docsDir);
+ const errors: CalloutVariantError[] = [];
+ const calloutOpenRegex = / {
+ if (calloutOpenRegex.test(line) && !line.includes('variant=')) {
+ errors.push({
+ file,
+ line: idx + 1,
+ message: ' missing variant prop. Use variant="info" or variant="warning".',
+ });
+ }
+ });
+ }
+ return errors;
+}
+
+/**
+ * Checks for H1 headings (# ) in the body of .mdx files.
+ * H1 should only come from frontmatter title.
+ */
+export async function checkNoBodyH1(docsDir: string): Promise {
+ const mdxFiles = await getMdxFiles(docsDir);
+ const errors: DocLineError[] = [];
+
+ for (const file of mdxFiles) {
+ const lines = await readFileLines(file);
+ const contexts = getLineContexts(lines);
+ lines.forEach((line, idx) => {
+ if (contexts[idx] === 'content' && /^#\s+/.test(line)) {
+ errors.push({
+ file,
+ line: idx + 1,
+ message: 'H1 heading found in body. Use frontmatter "title" instead.',
+ });
+ }
+ });
+ }
+ return errors;
+}
+
+/**
+ * Checks for skipped heading levels (e.g. ## followed by ####).
+ */
+export async function checkHeadingHierarchy(docsDir: string): Promise {
+ const mdxFiles = await getMdxFiles(docsDir);
+ const errors: DocLineError[] = [];
+ const headingRegex = /^(#{2,6})\s+/;
+
+ for (const file of mdxFiles) {
+ const lines = await readFileLines(file);
+ const contexts = getLineContexts(lines);
+ let prevLevel = 1; // Assume H1 from frontmatter title
+
+ for (let i = 0; i < lines.length; i++) {
+ if (contexts[i] !== 'content') continue;
+ const match = headingRegex.exec(lines[i]);
+ const htmlMatch = !match ? lines[i].match(/ prevLevel + 1) {
+ errors.push({
+ file,
+ line: i + 1,
+ message: `Skipped heading level: jumped from H${prevLevel} to H${level}.`,
+ });
+ }
+ prevLevel = level;
+ }
+ }
+ return errors;
+}
+
+/**
+ * Checks for non-standard variant="positive" on Callout components.
+ */
+export async function checkCalloutVariantPositive(docsDir: string): Promise {
+ const mdxFiles = await getMdxFiles(docsDir);
+ const errors: DocLineError[] = [];
+
+ for (const file of mdxFiles) {
+ const lines = await readFileLines(file);
+ lines.forEach((line, idx) => {
+ if (/variant=["']positive["']/.test(line)) {
+ errors.push({
+ file,
+ line: idx + 1,
+ message: 'Non-standard variant="positive". Use variant="info" instead.',
+ });
+ }
+ });
+ }
+ return errors;
+}
+
+/**
+ * Checks for ⚠️ icon used with variant="info" on Callout components.
+ * The ⚠️ icon should only be used with variant="warning".
+ */
+export async function checkCalloutIconMismatch(docsDir: string): Promise {
+ const mdxFiles = await getMdxFiles(docsDir);
+ const errors: DocLineError[] = [];
+
+ for (const file of mdxFiles) {
+ const lines = await readFileLines(file);
+ lines.forEach((line, idx) => {
+ if (/ {
+ const mdxFiles = await getMdxFiles(docsDir);
+ const errors: DocLineError[] = [];
+ const specialChars = /[&|:,]/;
+
+ for (const file of mdxFiles) {
+ const lines = await readFileLines(file);
+ const contexts = getLineContexts(lines);
+ for (let i = 0; i < lines.length; i++) {
+ if (contexts[i] !== 'frontmatter') continue;
+ const match = lines[i].match(/^title:\s*(["'])(.+)\1\s*$/);
+ if (match) {
+ const value = match[2];
+ if (!specialChars.test(value)) {
+ errors.push({
+ file,
+ line: i + 1,
+ message: `Frontmatter "title" is unnecessarily quoted. Remove quotes.`,
+ });
+ }
+ }
+ }
+ }
+ return errors;
+}
+
+/**
+ * Checks for redundant sidebar.title that matches the page title.
+ */
+export async function checkRedundantSidebarTitle(docsDir: string): Promise {
+ const mdxFiles = await getMdxFiles(docsDir);
+ const errors: DocLineError[] = [];
+
+ for (const file of mdxFiles) {
+ const lines = await readFileLines(file);
+ const contexts = getLineContexts(lines);
+
+ let title = '';
+ let sidebarTitle = '';
+ let sidebarTitleLine = -1;
+
+ for (let i = 0; i < lines.length; i++) {
+ if (contexts[i] !== 'frontmatter') continue;
+ const titleMatch = lines[i].match(/^title:\s*(.+)$/);
+ if (titleMatch) {
+ title = titleMatch[1].replace(/^["']|["']$/g, '').trim();
+ }
+ const sidebarMatch = lines[i].match(/^\s+title:\s*(.+)$/);
+ if (sidebarMatch) {
+ sidebarTitle = sidebarMatch[1].replace(/^["']|["']$/g, '').trim();
+ sidebarTitleLine = i + 1;
+ }
+ }
+
+ if (title && sidebarTitle && title === sidebarTitle && sidebarTitleLine > 0) {
+ errors.push({
+ file,
+ line: sidebarTitleLine,
+ message: `Redundant sidebar.title (matches title). Remove it.`,
+ });
+ }
+ }
+ return errors;
+}
+
+/**
+ * Checks for bare URLs (not wrapped in markdown link syntax) in prose.
+ */
+export async function checkBareUrls(docsDir: string): Promise {
+ const mdxFiles = await getMdxFiles(docsDir);
+ const errors: DocLineError[] = [];
+
+ for (const file of mdxFiles) {
+ const lines = await readFileLines(file);
+ const contexts = getLineContexts(lines);
+
+ for (let i = 0; i < lines.length; i++) {
+ if (contexts[i] !== 'content') continue;
+ const line = lines[i];
+ // Skip import/export lines
+ if (/^(import|export)\s/.test(line)) continue;
+ // Skip markdown reference link definitions: [label]: URL
+ if (/^\[[^\]]+\]:\s/.test(line)) continue;
+ // Skip markdown table rows
+ if (/^\|/.test(line)) continue;
+
+ // Find all URLs in the line
+ const urlRegex = /https?:\/\/[^\s)>\]]+/g;
+ let match;
+ while ((match = urlRegex.exec(line))) {
+ const start = match.index;
+
+ // Check if inside markdown link syntax: [text](url) or ](url)
+ if (start > 0 && line[start - 1] === '(') {
+ const before = line.slice(0, start - 1);
+ if (/\[[^\]]*\]$/.test(before)) continue;
+ }
+
+ // Check if inside angle brackets:
+ if (start > 0 && line[start - 1] === '<') continue;
+
+ // Check if inside backticks
+ const beforeUrl = line.slice(0, start);
+ const backtickCount = (beforeUrl.match(/`/g) || []).length;
+ if (backtickCount % 2 === 1) continue;
+
+ // Check if inside JSX prop value: ="url" or ={'url'}
+ if (start >= 2 && /=["'{]$/.test(line.slice(Math.max(0, start - 2), start))) continue;
+ if (start >= 1 && /["']$/.test(line.slice(start - 1, start))) {
+ const priorChunk = line.slice(0, start);
+ if (/=["'{]?["']?$/.test(priorChunk)) continue;
+ }
+
+ // Check if it's a JSX src/href/id prop
+ if (/(?:src|href|id)=["']$/.test(line.slice(Math.max(0, start - 6), start))) continue;
+
+ errors.push({
+ file,
+ line: i + 1,
+ message: `Bare URL found. Wrap in markdown link syntax: [text](url)`,
+ });
+ }
+ }
+ }
+ return errors;
+}
+
+/**
+ * Runs all checks and prints a summary. Exits 1 if any errors are found.
+ */
+export async function runAllChecks(docsDir: string) {
+ const [
+ rel,
+ snippets,
+ deprecated,
+ callout,
+ bodyH1,
+ headingHierarchy,
+ variantPositive,
+ iconMismatch,
+ fmQuotes,
+ redundantSidebar,
+ bareUrls,
+ ] = await Promise.all([
+ checkRelativeLinks(docsDir),
+ checkCodeSnippetPaths(docsDir),
+ checkDeprecatedIfRenderer(docsDir),
+ checkCalloutVariant(docsDir),
+ checkNoBodyH1(docsDir),
+ checkHeadingHierarchy(docsDir),
+ checkCalloutVariantPositive(docsDir),
+ checkCalloutIconMismatch(docsDir),
+ checkFrontmatterQuotes(docsDir),
+ checkRedundantSidebarTitle(docsDir),
+ checkBareUrls(docsDir),
+ ]);
+ const all = [
+ ...rel.map((e) => ({ ...e, type: 'relative-link' })),
+ ...snippets.map((e) => ({ ...e, type: 'snippet-path' })),
+ ...deprecated.map((e) => ({ ...e, type: 'deprecated-if-renderer' })),
+ ...callout.map((e) => ({ ...e, type: 'callout-variant' })),
+ ...bodyH1.map((e) => ({ ...e, type: 'body-h1' })),
+ ...headingHierarchy.map((e) => ({ ...e, type: 'heading-hierarchy' })),
+ ...variantPositive.map((e) => ({ ...e, type: 'callout-variant-positive' })),
+ ...iconMismatch.map((e) => ({ ...e, type: 'callout-icon-mismatch' })),
+ ...fmQuotes.map((e) => ({ ...e, type: 'frontmatter-quotes' })),
+ ...redundantSidebar.map((e) => ({ ...e, type: 'redundant-sidebar-title' })),
+ ...bareUrls.map((e) => ({ ...e, type: 'bare-url' })),
+ ];
+ if (all.length === 0) {
+ console.log('✅ Docs check: no errors found.');
+ return;
+ }
+ const typeLabels: Record = {
+ 'relative-link': 'RelativeLink',
+ 'snippet-path': 'CodeSnippetPath',
+ 'deprecated-if-renderer': 'IfRenderer',
+ 'callout-variant': 'CalloutVariant',
+ 'body-h1': 'BodyH1',
+ 'heading-hierarchy': 'HeadingHierarchy',
+ 'callout-variant-positive': 'CalloutVariantPositive',
+ 'callout-icon-mismatch': 'CalloutIconMismatch',
+ 'frontmatter-quotes': 'FrontmatterQuotes',
+ 'redundant-sidebar-title': 'RedundantSidebarTitle',
+ 'bare-url': 'BareUrl',
+ };
+ for (const err of all) {
+ const loc = `${err.file}:${err.line}`;
+ const label = typeLabels[err.type] || err.type;
+ console.error(`[${label}] ${loc}: ${err.message}`);
+ }
+ console.error(`\n❌ Docs check: ${all.length} error(s) found.`);
+ process.exit(1);
+}
+
+// CLI entry point
+if (esMain(import.meta.url)) {
+ runAllChecks(path.resolve(__dirname, '../../docs')).catch((err) => {
+ console.error(err);
+ process.exit(1);
+ });
+}
diff --git a/scripts/docs/utils.ts b/scripts/docs/utils.ts
new file mode 100644
index 000000000000..e87b62a06adc
--- /dev/null
+++ b/scripts/docs/utils.ts
@@ -0,0 +1,113 @@
+import { glob } from 'tinyglobby';
+import fs from 'node:fs/promises';
+
+/**
+ * Recursively collects all .mdx files in the given docs directory.
+ */
+export async function getMdxFiles(docsDir: string): Promise {
+ return glob(['**/*.mdx'], { cwd: docsDir, absolute: true });
+}
+
+/**
+ * Reads a file and returns an array of its lines.
+ */
+export async function readFileLines(filePath: string): Promise {
+ const content = await fs.readFile(filePath, 'utf8');
+ return content.split(/\r?\n/);
+}
+
+/**
+ * Converts a heading text to a URL-friendly slug.
+ * Matches the behavior of typical MDX/rehype-slug processors.
+ */
+export function slugify(text: string): string {
+ return text
+ .toLowerCase()
+ .replace(/\[([^\]]+)\]\([^)]*\)/g, '$1') // Strip markdown links, keep text
+ .replace(/[`*_~\\]/g, '') // Strip inline formatting and MDX escape chars
+ .replace(/[<>]/g, '') // Remove angle brackets but keep their content
+ .trim()
+ .replace(/[^\w\s-]/g, '') // Remove non-word chars (except spaces and hyphens)
+ .replace(/\s+/g, '-') // Replace spaces with hyphens
+ .replace(/-+/g, '-') // Collapse multiple hyphens
+ .replace(/^-|-$/g, ''); // Trim leading/trailing hyphens
+}
+
+export type LineContext = 'frontmatter' | 'codeblock' | 'content';
+
+/**
+ * Returns a per-line context array indicating whether each line is inside
+ * frontmatter, a fenced code block, or normal content.
+ */
+export function getLineContexts(lines: string[]): LineContext[] {
+ const contexts: LineContext[] = [];
+ let inFrontmatter = false;
+ let frontmatterSeen = false;
+ let inCodeBlock = false;
+ let openFenceLen = 0;
+ let openFenceChar = '';
+
+ for (let i = 0; i < lines.length; i++) {
+ const line = lines[i];
+
+ if (!frontmatterSeen && !inFrontmatter && i === 0 && line.trim() === '---') {
+ inFrontmatter = true;
+ contexts.push('frontmatter');
+ continue;
+ }
+ if (inFrontmatter) {
+ if (line.trim() === '---') {
+ inFrontmatter = false;
+ frontmatterSeen = true;
+ }
+ contexts.push('frontmatter');
+ continue;
+ }
+
+ const fenceMatch = line.match(/^(`{3,}|~{3,})/);
+ if (fenceMatch) {
+ if (!inCodeBlock) {
+ inCodeBlock = true;
+ openFenceLen = fenceMatch[1].length;
+ openFenceChar = fenceMatch[1][0];
+ contexts.push('codeblock');
+ continue;
+ } else if (
+ fenceMatch[1][0] === openFenceChar &&
+ fenceMatch[1].length >= openFenceLen &&
+ line.trim() === fenceMatch[1]
+ ) {
+ inCodeBlock = false;
+ contexts.push('codeblock');
+ continue;
+ }
+ }
+ if (inCodeBlock) {
+ contexts.push('codeblock');
+ continue;
+ }
+
+ contexts.push('content');
+ }
+
+ return contexts;
+}
+
+/**
+ * Extracts all heading slugs from an MDX file.
+ * Returns a Set of slug strings (without the leading #).
+ */
+export async function getHeadingSlugs(filePath: string): Promise> {
+ const lines = await readFileLines(filePath);
+ const slugs = new Set();
+ const headingRegex = /^(#{1,6})\s+(.+)$/;
+
+ for (const line of lines) {
+ const match = headingRegex.exec(line);
+ if (match) {
+ slugs.add(slugify(match[2]));
+ }
+ }
+
+ return slugs;
+}
diff --git a/scripts/package.json b/scripts/package.json
index 11ca41bd541d..569b491a5b41 100644
--- a/scripts/package.json
+++ b/scripts/package.json
@@ -8,6 +8,7 @@
"build-package": "jiti ./build-package.ts",
"check": "jiti ./check/check-package.ts",
"check-package": "jiti ./check-package.ts",
+ "docs:check": "jiti ./docs/check-docs.ts",
"docs:codemod": "jiti ./snippets/codemod.ts",
"generate-sandboxes": "jiti ./sandbox/generate.ts",
"get-report-message": "jiti ./get-report-message.ts",
@@ -145,6 +146,7 @@
"sort-package-json": "^3.5.0",
"tiny-invariant": "^1.3.3",
"tinyexec": "^0.3.0",
+ "tinyglobby": "^0.2.15",
"trash": "^7.2.0",
"ts-dedent": "^2.2.0",
"type-fest": "~2.19",
diff --git a/yarn.lock b/yarn.lock
index 05874291102d..46fa9c64723f 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -8823,6 +8823,7 @@ __metadata:
sort-package-json: "npm:^3.5.0"
tiny-invariant: "npm:^1.3.3"
tinyexec: "npm:^0.3.0"
+ tinyglobby: "npm:^0.2.15"
trash: "npm:^7.2.0"
ts-dedent: "npm:^2.2.0"
type-fest: "npm:~2.19"