Skip to content

How to write stories? โ€‹

Create a Vue file ending in .story.vue and put <Story> at the root of its template.

vue
<!-- Meow.story.vue -->
<template>
  <Story>
    ๐Ÿฑ
  </Story>
</template>

Set the optional title prop to name the story in the workbench.

vue
<template>
  <Story title="๐Ÿฑ Meow">
    ๐Ÿฑ
  </Story>
</template>

Import components and add styles as you would in any Vue file.

vue
<!-- Meow.story.vue -->
<script setup>
import Meow from './Meow.vue'
</script>

<template>
  <Story>
    <Meow />
  </Story>
</template>

Variants โ€‹

Use variants to show different states or use cases. Add each variant with the <Variant> tag. Give each variant a readable title, such as โ€œDisabledโ€.

vue
<template>
  <Story title="Cars">
    <Variant title="default">
      ๐Ÿš—
    </Variant>
    <Variant title="Fast">
      ๐ŸŽ๏ธ
    </Variant>
    <Variant title="Slow">
      ๐Ÿšœ
    </Variant>
  </Story>
</template>

Layout โ€‹

Set the storyโ€™s layout.type to choose how its variants appear. For stories without an explicit layout, Histoire uses your local or project default, which falls back to Grid. A view in the URL or a remembered view can override the story layout.

Single layout โ€‹

Use type: "single" to display one variant at a time. The variant runs in an iframe so CSS media queries use its own viewport.

Stories always render inside an iframe. Remove the iframe option when migrating. The story iframe owns live state. See state ownership during migration.

vue
<template>
  <Story
    title="Cars"
    :layout="{ type: 'single' }"
  >
    <Variant title="default">
      ๐Ÿš—
    </Variant>
    <Variant title="Fast">
      ๐ŸŽ๏ธ
    </Variant>
    <Variant title="Slow">
      ๐Ÿšœ
    </Variant>
  </Story>
</template>

Grid layout โ€‹

Use type: "grid" to compare variants side by side.

vue
<template>
  <Story
    title="Cars"
    :layout="{ type: 'grid' }"
  >
    <Variant title="default">
      ๐Ÿš—
    </Variant>
    <Variant title="Fast">
      ๐ŸŽ๏ธ
    </Variant>
    <Variant title="Slow">
      ๐Ÿšœ
    </Variant>
  </Story>
</template>

Released under the MIT License.