# Fumadocs (Framework Mode, Next.js): Story
URL: /docs/next/integrations/story
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/(framework)/[framework]/integrations/story/index.mdx

Display components with controls.

<story.WithControl />

## Introduction [#introduction]

Fumadocs Story displays and documents components.
It is a simple, docs-focused alternative to [Storybook](https://storybook.js.org), mainly designed for component libraries.

If you are new to the concept of Story, this is a short explanation from **Storybook** docs:

<blockquote>
  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.
</blockquote>

<Callout title="When to use it over Storybook?">
Fumadocs Story is not a replacement for Storybook. We still recommend Storybook for proper UI testing.
</Callout>

## Installation [#installation]

```npm
npm i @fumadocs/story
```

Add the Tailwind CSS preset:

```css title="Tailwind CSS"
/* [!code ++] */
@import '@fumadocs/story/css/preset.css';
```

Add the Turbopack and Webpack plugin:

```ts title="next.config.mts"
import type { NextConfig } from 'next';
// [!code ++]
import { createNextStory } from '@fumadocs/story/next';

const config: NextConfig = {
  // ...
};

// [!code ++]
const withStory = createNextStory();

// wrap the config with `withStory()`
// if you have other plugins like `withMDX()`, keep it like `withStory(withMDX(config))` [!code highlight:2]
export default withStory(config);
```

### Create a Story [#create-a-story]

Create a story factory to store your global settings:

```ts title="lib/story.ts"
import { defineStoryFactory } from '@fumadocs/story/next/client';

export const { defineStory } = defineStoryFactory();
```

Now create your first story:

```tsx tab="my-component.story.tsx"
import { defineStory } from '@/lib/story';
import { MyComponent } from './my-component';

export const story = defineStory({
  // the passed component must be a client component
  Component: MyComponent,
  args: {
    // default props (recommended)
    initial: {},
  },
});
```

```tsx tab="my-component.tsx"
'use client';

export interface MyComponentProps {
  title?: string;
}

export function MyComponent({ title }: MyComponentProps) {
  return <p>{title}</p>;
}
```

<Callout type="warn">
The plugin only transforms files matching `*.story.{js,jsx,ts,tsx}`. Change it with the `filter` option of `createNextStory()`.
</Callout>

### Render a Story [#render-a-story]

Render the story in your MDX files:

```mdx title="index.mdx"
import { story } from '@/components/my-component.story';

<story.WithControl />
```

## Configurations [#configurations]

### Variants [#variants]

You can provide multiple variants of the component with `args`:

```ts
import { defineStory } from '@/lib/story';
import { Callout } from '@/components/callout';

export const story = defineStory({
  Component: Callout,
  args: [
    {
      variant: 'Default',
      initial: {
        title: 'This is a Callout',
      },
    },
    {
      variant: 'Warning',
      initial: {
        title: 'This is a Callout',
      },
      // fixed values for props
      fixed: {
        type: 'warning',
      },
    },
  ],
});
```

### `controls` [#controls]

Controls are generated from the component props. Specify the control nodes to replace them:

```tsx
import { defineStory } from '@/lib/story';
import { GraphView } from '@/components/graph-view';

export const story = defineStory({
  Component: GraphView,
  args: {
    controls: {
      node: {
        type: 'object',
        properties: [],
      },
    },
  },
});
```

### `frame` [#frame]

Components filling the viewport, like layouts, can be rendered in an iframe.
The story panel scales the frame down to fit, with a button to open it in fullscreen.

```tsx title="components/my-layout.story.tsx"
import { defineStory } from '@/lib/story';
import { MyLayout } from './my-layout.lazy';
import { Window } from './window';

export const story = defineStory({
  Component: MyLayout,
  frame: {
    src: '/story/my-layout',
    // viewport size, optional
    width: 1280,
    height: 800,
    // wraps the frame, e.g. in a window, optional
    Container: Window,
  },
});
```

Create a page at `src` to render the component. It receives the arguments from the story panel:

```tsx title="app/story/my-layout/page.tsx"
import { story } from '@/components/my-layout.story';

export default function Page() {
  return <story.Frame />;
}
```

The story loads its component on every page that renders it. Pass a lazy component instead, so only the frame loads it:

```tsx title="components/my-layout.lazy.tsx"
'use client';
import dynamic from 'next/dynamic';

export const MyLayout = dynamic(() => import('./my-layout').then((mod) => mod.MyLayout));
```

<Callout title="Good to know">
- The page must be on the same origin as your docs.
- Arguments are sent with `postMessage()`, so they must be serializable (no functions or JSX).

- `Container` must be a client component.
</Callout>

### Internationalization [#internationalization]

Assuming you have configured [Internationalization](/docs/next/internationalization) at UI level:

```tsx title="layout.shared.tsx"
import { defineI18n } from 'fumadocs-core/i18n';
import { uiTranslations } from 'fumadocs-ui/i18n';
import { storyTranslations } from '@fumadocs/story/i18n';

const i18n = defineI18n({
  languages: ['en', 'cn'],
  defaultLanguage: 'en',
});

export const translations = i18n
  .translations()
  .extend(uiTranslations())
  // [!code ++]
  .extend(storyTranslations())
  .add({
    cn: {
      displayName: 'Chinese',
      // [!code ++]
      'Add Item(story arguments form)': '新增項目',
    },
  });
```

See [Translations](/docs/ui/translations) for more details.