Storybook Addon for Vue Components in MDX

3.0.0 · active · verified Sun Apr 19

storybook-addon-vue-mdx facilitates the integration and rendering of Vue 3 components directly within MDX documentation files in Storybook. The current stable version is 3.0.0, which targets Storybook v10. This addon's release cadence appears to be closely tied to major Storybook releases, requiring updates to support newer Storybook versions. Its primary differentiator is enabling Vue component usage in an MDX context, leveraging `veaury` to bridge the Vue/React rendering environments within Storybook's predominantly React-based MDX compiler. It supports customization of the Vue app context via Storybook globals, allowing for the registration of Vue plugins or other app-level configurations. While powerful, it has limitations such as requiring local imports of components and a known bug affecting initial local page loads for MDX files with Vue components.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install `storybook-addon-vue-mdx`, configure it in Storybook's `main.js`, and then use a Vue component directly within an MDX documentation file, including basic component definition.

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

// .storybook/main.js
export default {
  stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx|vue)'],
  addons: [
    '@storybook/addon-essentials',
    '@storybook/addon-docs',
    'storybook-addon-vue-mdx',
  ],
  framework: {
    name: '@storybook/vue3-vite',
    options: {},
  },
  docs: {
    autodocs: 'tag',
  },
  // .storybook/preview.js
  // For customizing Vue app context (optional)
  // globals: {
  //   vueMdx: {
  //     beforeVueAppMount(app) {
  //       app.use(yourVuePlugin);
  //     },
  //   },
  // },
};

// src/components/MyButton.vue
<template>
  <button @click="onClick">{{ label }}</button>
</template>

<script setup>
import { defineProps } from 'vue';

const props = defineProps({
  label: { type: String, default: 'Click me' },
});

const onClick = () => {
  console.log('Button clicked!');
};
</script>

// src/stories/MyButton.mdx
import { Meta, Story } from '@storybook/addon-docs';
import MyButton from '../components/MyButton.vue';

<Meta title="Components/MyButton" component={MyButton} />

# MyButton

This is a custom button component.

<MyButton label="Hello from MDX" />

<Story name="Default">
  <MyButton label="Story in MDX" />
</Story>

view raw JSON →