Storybook: Decorators for Vue stories

Created on 14 Aug 2017  路  6Comments  路  Source: storybookjs/storybook

Hi, I wasn't able to make work decorators when using Vue Stories and the documentation only reference an react example.

Are those supported?

vue question / support

Most helpful comment

This should be added to the documentation. It was actually an effort to find this here.

For anyone looking for a solution similar to the one shown in the docs, I solved with:

import { addDecorator } from '@storybook/vue';

// Decorator to center-align all stories
addDecorator(() => ({
  template: '<div style="textAlign: center"><story/></div>',
}));

All 6 comments

@kazupon I can't find any documentation for how to actually _use_ decorators with Vue...

@smiller171, for decorators with Vue, try:

// .storybook/stories/index.js 

import YourButton from 'path/to/YourButton.vue'

function Reded() {
  return {
    template: '<div style="color: red;"><story/></div>',
  }
}

storiesOf('YourButton', module)
  .addDecorator(Reded)
  .add('default form', () => ({
    components: {YourButton },
    template:   '<YourButton  />',
  }))

This should be added to the documentation. It was actually an effort to find this here.

For anyone looking for a solution similar to the one shown in the docs, I solved with:

import { addDecorator } from '@storybook/vue';

// Decorator to center-align all stories
addDecorator(() => ({
  template: '<div style="textAlign: center"><story/></div>',
}));

@adi-zz This is good to add a decorator in my story but what about for pre-existing decorators in scss files.

For example, in Vue.js I have @import "~theme/colors.scss";, which returns me the error: Module parse failed: Unexpected character '@'

Was this page helpful?
0 / 5 - 0 ratings