• Stars
    star
    149
  • Rank 248,619 (Top 5 %)
  • Language
    JavaScript
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Custom <story> blocks for Vue single file components

vue-storybook

Custom <story> blocks for Vue single file components that work out of the box with Vue CLI 3 and vue-cli-plugin-storybook.

npm version

yarn add vue-storybook
const { storyLoader, registerStories } = require("vue-storybook");

What is this?

A Webpack loader + helper script that allows you to embellish your pre-existing Vue single file components (SFC) with a custom <story> block that's automatically translated into a Storybook-flavored story.

Hello World Example

Repo: https://github.com/mattrothenberg/vue-storybook-example-project

<story name="Disabled Button">
  <my-button :disabled="true">Can't touch this</my-button>
</story>

turns into:

screen shot 2018-03-04 at 10 43 54 am

How does it work?

Given an existing Vue CLI + vue-cli-plugin-storybook project, modify your project's vue.config.js thusly.

// vue.config.js
module.exports = {
  chainWebpack: config => {
    config.resolve.symlinks(false);
  },
  configureWebpack: config => {
    config.module.rules.push({
      resourceQuery: /blockType=story/,
      loader: "vue-storybook"
    });
  }
};

Add a custom <story> block to your single file component. The following Storybook plugins/APIs are supported:

  • Actions
  • Story Options
  • Notes
  • Knobs

It is also possible to pass options for other addons using the parameters attribute.

You can optionally group components by specifiying a group attribute.

<story
  options="{
    panelPosition: 'right'
  }"
  name="with knobs"
  group="MyButton"
  notes="### this is the coolest story ever"
  knobs="{
    initialText: {
      default: text('Initial Text', 'default value goes here')
    },
    isDisabled: {
      default: boolean('Is Disabled?', false)
    }
  }"
  parameters="{
    foo: { ... }
  }"
>
  <my-button :disabled="isDisabled" @click="action('show me the money', isDisabled)">{{initialText}}</my-button>
</story>

Then, in your main index.stories.js (or wherever your write your stories), leverage our helper script to start adding stories. NB: the signature of registerStories has changed significantly.

registerStories(req, filename, storiesOf, config);

config is now an object with the following keys,

{
  knobs: {
    // put the knobs you plan on using
    // (things like `text` or `select`)
    // in this object
  },
  decorators: [
    // an array of decorator functions
  ],
  methods: {
    action // where action is the exported member from `addon-actions`
  }
}
// Import Storybook + all 'yr plugins!
import { storiesOf } from "@storybook/vue";
import { action } from "@storybook/addon-actions";
import { withNotes } from "@storybook/addon-notes";
import { withKnobs, text, boolean } from "@storybook/addon-knobs/vue";

// Import our helper
import { registerStories } from "vue-storybook";

// Require the Vue SFC with <story> blocks inside
const req = require.context("./", true, /\.vue$/);

// Programatically register these stories
function loadStories() {
  req.keys().forEach(filename => {
    let config = {
      knobs: {
        text,
        boolean
      },
      decorators: [
        withKnobs,
        function(context, story) {
          return {
            template: `
              <div><story /></div>`
          };
        }
      ],
      methods: {
        action
      }
    };

    registerStories(req, filename, storiesOf, config);
  });
}

// Let's go!
configure(loadStories, module)

Roadmap

  • Actions
  • Knobs
  • Notes
  • Info
  • Readme

More Repositories

1

vue-overdrive

Super easy magic-move transitions for Vue apps
Vue
684
star
2

vue-flip-toolkit

A Vue.js port of the wonderful react-flip-toolkit by @aholachek
Vue
303
star
3

use-gauge

A headless React hook for building beautiful gauge charts.
TypeScript
63
star
4

tailwind-fancy-tab

Headless UI tabs treated with a futuristic visual design
TypeScript
52
star
5

vue-elucidate

A library for documenting Vue components
Vue
34
star
6

react-comparison-slider

A keyboard accessible "before & after" component for React β¬…οΈβž‘οΈ
TypeScript
33
star
7

prototyping-playbook

A winner's guide to prototyping in the browser
CSS
27
star
8

gatsbygram

A Gatsby.js clone of Pentagram's website
JavaScript
20
star
9

vue-grid-styled

Lightweight set of functional grid components
JavaScript
17
star
10

styleguide-boilerplate

A project to help Designers build living styleguides with Sass and Hologram.
CSS
17
star
11

parcel-craft-example

A Craft CMS + ParcelJS Website
JavaScript
16
star
12

react-overflow-list

A headless React component that lets you control how visible and overflown items are rendered πŸ‘€
TypeScript
12
star
13

vue-storybook-example

Vue
11
star
14

inboxclone

JavaScript
9
star
15

statamic-mapbox-address

PHP
9
star
16

webmentions

A Webmentions Tag for Statamic V3
Vue
8
star
17

location

A Location Autocomplete Field for Statamic V3
Vue
5
star
18

flat-data-to-ts

TypeScript
4
star
19

remix-github

TypeScript
4
star
20

badger

Badge generator powered by Satori πŸͺͺ
TypeScript
4
star
21

duckb-browser-block

A GitHub Next Folder Block for querying flat data in your repository
TypeScript
3
star
22

runway-cli

JavaScript
3
star
23

vscode-toolkit-ui-react

TypeScript
2
star
24

package-json-badge-block

TypeScript
2
star
25

airtable-clone

JavaScript
2
star
26

tusi

TypeScript
1
star
27

sentry-next-example

JavaScript
1
star
28

use-auto-scroll

TypeScript
1
star
29

quill-image-resize-interact

JavaScript
1
star
30

styleguide-block

TypeScript
1
star
31

labs-design-yeoman

Custom Yeoman project for Labs Designers
CSS
1
star
32

observable-plot-tooltip

TypeScript
1
star
33

directory-size-block

Visualizes the sizes of files in a directory
TypeScript
1
star
34

codeowners-block

A GUI for authoring and editing CODEOWNERS files
TypeScript
1
star
35

streeteasy-ads

Build your very own "Find Your Place" Streeteasy Ad
JavaScript
1
star
36

tailwindcss-stack-plugin

A Tailwind plugin for custom "stack" utility classes
JavaScript
1
star