npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

storybook-vue-addon

v0.6.1

Published

Storybook stories in native Vue format

Downloads

5,226

Readme

Storybook Vue Addon

NPM version NPM downloads Github Actions Codecov

A Storybook addon that allows to write stories in native Vue syntax and compiles it to Storybook's CSF format.

Example: Button.stories.vue

<script setup lang="ts">
import Button from './Button.vue'
</script>
<template>
  <Stories
    title="Stories in Vue format 😍"
    :component="Button"
  >
    <Story title="Primary">
      <Button
        background="#ff0"
        label="Button"
      />
    </Story>
    <Story title="Secondary">
      <Button
        background="#ff0"
        label="😄👍😍💯"
      />
    </Story>
    <Story title="Tertiary">
      <Button
        background="#ff0"
        label="📚📕📈🤓"
      />
    </Story>
  </Stories>
</template>

Features

  • Write stories as idiomatic Vue templates, bye bye string-based templates, as wished for in storybookjs/storybook#9768
  • Syntax highlighting and full editor support (including Volar) for writing story templates
  • Add markdown documentation in a custom docs block, directly in your stories.vue files (see below for details)
  • The component that is displayed needs only be declared once (via <Stories :component="...">) and not for every story
  • Simple integration with Storybook and automatic Vite support
  • Light: Vue stories are transpiled into ordinary CSF stories on the fly with minimal overhead

This package is currently in an early alpha stage and supports only the fundamental Storybook features. Compatibility with more advanced features and addons is work in progress. Please open an issue if you encounter any bugs or missing integrations.

The way to write stories as idiomatic Vue templates is heavily inspired by the great Histoire.

Installation

Note: Currently, only the @storybook/vue3-vite builder is supported (or the deprecated @storybook/builder-vite version 0.2.7 or higher).

  1. Add storybook-vue-addon to your dev-dependencies.

    # npm
    npm install --save-dev storybook-vue-addon
    
    # yarn
    yarn add -D storybook-vue-addon
    
    # pnpm
    pnpm add -D storybook-vue-addon
  2. In .storybook/main.js, add *.stories.vue to the stories patterns and storybook-vue-addon as an addon.

      "stories": [
        "../src/**/*.stories.mdx",
    -    "../src/**/*.stories.@(js|jsx|ts|tsx)"
    +    "../src/**/*.stories.@(js|jsx|ts|tsx|vue)"
      ],
      ...
      "addons": [
        "@storybook/addon-essentials",
    +   "storybook-vue-addon"
      ],
    

Adding documentation

You can add documentation for your components directly in your story SFC using the custom docs block.

<template>Define your stories here as above</template>

<docs lang="md">
import { Canvas } from '@storybook/blocks';

# Documentation

Everything in one place. Isn't it great?

You can render stories in the docs using the `<Canvas>` component.

<Canvas />
</docs>

You can use Markdown’s readable syntax (such as # heading) for your documentation, include stories, and freely embed JSX component blocks at any point in the file. See Storybook Docs for more information. There are a few minor differences to standard MDX documentation pages:

  • The <Meta of=...> tag is not needed.
  • You don't need to import the stories file. Simply refer to the defined stories by their name. For example:
    <template>
      <Stories>
        <Story title="Unchecked">
          <Checkbox label="Unchecked" />
        </Story>
      </Stories>
    </template>
    <docs>
      import { Canvas } from '@storybook/blocks';
      <Canvas of={Unchecked} />
    </docs>

Typescript support

Volar should be able to automatically recognize the Stories and Story components. It is also possible to import them from storybook-vue-addon:

import type { Stories, Story } from 'storybook-vue-addon/core'

Manual usage

If for whatever reason you process Storybook stories in your build pipeline, you probably want to first transpile the Vue stories to classical CSF stories by adding storybook-vue-addon to your build.

// vite.config.ts
import VueStories from 'storybook-vue-addon/vite'

export default defineConfig({
  plugins: [
    VueStories({
      /* options */
    }),
  ],
})

Example: playground/

// rollup.config.js
import VueStories from 'storybook-vue-addon/rollup'

export default {
  plugins: [
    VueStories({
      /* options */
    }),
  ],
}

// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require('storybook-vue-addon/webpack')({
      /* options */
    }),
  ],
}

// nuxt.config.js
export default {
  buildModules: [
    [
      'storybook-vue-addon/nuxt',
      {
        /* options */
      },
    ],
  ],
}

This module works for both Nuxt 2 and Nuxt Vite

// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require('storybook-vue-addon/webpack')({
        /* options */
      }),
    ],
  },
}

// esbuild.config.js
import { build } from 'esbuild'
import VueStories from 'storybook-vue-addon/esbuild'

build({
  plugins: [VueStories()],
})

💻 Development

  • Clone this repository
  • Enable Corepack using corepack enable (use npm i -g corepack for Node.js < 16.10).
  • Install dependencies using pnpm install.

Commands:

  • build: Build everything. Output can be found in dist.
  • build:types: Build the types for the Story and Stories components, to ease development in the components.d.ts file.
  • dev: Build in watch mode.
  • lint: Check for eslint and prettier issues.
  • test: Run the tests.
  • example:vite: Open the example storybook (using vite). You need to run build or dev first.
  • play: Run the playground (currently not used).
  • release: Release a new version to npm.

Sponsors

Thanks to Chromatic for providing the visual testing platform that helps us review UI changes and catch visual regressions.