storybook-addon-vue-slots is a Storybook addon designed to enhance the development and documentation of Vue 3 components by providing robust support for defining and controlling component slots directly within Storybook stories. It simplifies the process of creating stories for components with complex or multiple slots, allowing developers to manage slot content via Storybook's controls interface and automatically generate relevant code snippets. The current stable version is `0.9.29`, with active development on `0.9.30-next.x` branches which include breaking changes for future Storybook versions. This addon addresses a common challenge in Vue component development by offering a structured and interactive way to visualize and test slot variations, distinguishing it from general Storybook Vue setups that might require manual template string manipulation for slots. It integrates into the Storybook ecosystem to provide a seamless workflow for Vue component libraries.
npm install storybook-addon-vue-slotsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `storybook-addon-vue-slots` to define and control both default and named slots for a Vue 3 component within Storybook. It includes the component, `main.ts` configuration, and a story file illustrating `parameters.slots` for static content and `argTypes`/`args` for dynamic control via Storybook's UI.
Ensure your Storybook project and consuming application are configured to use ES Modules (ESM). Update your `.storybook/main.js` to `.storybook/main.ts` or `.storybook/main.js` to explicitly export as ESM, e.g., by adding `"type": "module"` to your `package.json` or ensuring all relevant files use `import`/`export` syntax. Storybook's `main.js|ts` file itself must be valid ESM.
Always check the `peerDependencies` in the package's `package.json` or npm page and ensure your project's Storybook and Vue versions align. Upgrade Storybook and the addon in tandem, following their respective migration guides. Use `npx storybook@latest doctor` to identify common dependency issues.
Review the `parameters.slots` configuration. For dynamic content, use `{{ args.yourArgName }}` within the `template` string and ensure `yourArgName` is correctly defined in `argTypes` and `args` in your story. Test with simpler template strings first to isolate issues.Convert your project's Storybook configuration files (`.storybook/main.js`, `.storybook/preview.js`) to ES Modules. This typically involves using `import`/`export` syntax, ensuring your `package.json` specifies `"type": "module"` if necessary, and upgrading your build tools (e.g., Vite) to handle ESM correctly. For older projects, consider sticking to an older version of the addon that still supports CJS or performing a full migration to ESM.
First, ensure `storybook-addon-vue-slots` is installed as a dev dependency (`npm install -D storybook-addon-vue-slots`). Verify that your `tsconfig.json`'s `moduleResolution` option is set to a value that supports `"types"` conditions (e.g., `"bundler"` or `"node16"` for modern projects). For Storybook's `main.ts`, ensure the addon is correctly listed in the `addons` array as a string: `'storybook-addon-vue-slots'`. If upgrading from an older Storybook, ensure `main.ts` itself is ESM.
Double-check your `.storybook/main.ts` file to ensure `'storybook-addon-vue-slots'` is present in the `addons` array. Verify that the `parameters.slots` object in your stories follows the correct structure as outlined in the addon's documentation. Clear Storybook cache and restart the development server.