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

Replace the UI of stories, or build your own on the headless layer.

## Overview [#overview]

`@fumadocs/story` exports `<StoryProvider />`, `useStory()` and `useStoryArgs()`, which provide the state of a story without UI:

- the selected variant, and the preset it resolves to
- the arguments of the rendered component, debounced so typing doesn't re-render it on every keystroke

The built-in panel is built on them, and you can swap the panel for your own.

## Your own panel [#your-own-panel]

`defineStoryFactory()` takes a `WithControl` component, rendered in place of the built-in panel.

```tsx title="lib/story.tsx"
import { defineStoryFactory } from '@fumadocs/story/next/client';
import { StoryPanel } from '@/components/story-panel';

export const { defineStory } = defineStoryFactory({ WithControl: StoryPanel });
```

It receives the presets of the story and the component to render.

```tsx title="components/story-panel.tsx"
'use client';
import { StoryProvider, useStory, useStoryArgs, type WithControlProps } from '@fumadocs/story';

export function StoryPanel(props: WithControlProps) {
  return (
    <StoryProvider {...props}>
      <Content />
    </StoryProvider>
  );
}

function Content() {
  const { presets, variant, setVariant, preset, Component } = useStory();
  const args = useStoryArgs();

  return (
    <div>
      <select value={variant} onChange={(e) => setVariant(e.target.value)}>
        {presets.map((item) => (
          <option key={item.variant} value={item.variant}>
            {item.variant}
          </option>
        ))}
      </select>
      <Component {...args} />
      <pre>{JSON.stringify(preset?.controls, null, 2)}</pre>
    </div>
  );
}
```

| Hook              | Description                                                                                     |
| ----------------- | ----------------------------------------------------------------------------------------------- |
| `useStory()`      | The presets, the selected `variant` with `setVariant`, the `Component` and `frame`.             |
| `useStoryArgs()`  | The arguments of the rendered component, following the controls.                                |
| `useStoryFrame()` | A ref for the iframe of [`frame`](/docs/next/integrations/story#frame), sending the arguments to it. |

Controls are edited through [`@fumari/stf`](https://github.com/fuma-nama/fumadocs/tree/dev/packages/stf), the form engine `<StoryProvider />` sets up. `preset.controls` is the [type tree](/docs/next/integrations/story#controls) of the component props.

<Callout title="Start from the built-in panel">
Writing a full control panel means handling every node kind of the type tree. Install the built-in
one below and edit it instead.
</Callout>

## Install the UI [#install-the-ui]

The entire panel, including its argument controls:

```npm
npx @fumadocs/cli add story/controls
```

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

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