Storybook: How to pass props to Vue.js component's story?

Created on 2 Nov 2017  路  3Comments  路  Source: storybookjs/storybook

I wanted to add some stories for vue-select, but I'm struggling with more complicated cases, which involve passing props or methods and storybook examples, sorry to say, are not very helpful.

When I pass props inside the template it works:

    storiesOf('VSelect', module)
    .add('with labeled custom options', () => ({
            components: {VSelect},
            template:   `<v-select :options='[{value: "CA", label: "Canada"}, {value: "UK", label: "United Kingdom"}]' />`
        }))

I find it not very readable, so I wanted to pass them separately as props or data:

    .add('with labeled custom options as props', () => ({
            components: {VSelect},
            props:      {options: [{value: "CA", label: "Canada"}, {value: "UK", label: "United Kingdom"}]},
            data:       {options: [{value: "CA", label: "Canada"}, {value: "UK", label: "United Kingdom"}]},
            template:   `<v-select />`
        }))

but neither data, nor props are not recognized by storybook - they seem to be ignored.

In imported VSelect.vue the template is digesting the passed options:

<template>
    <v-select :on-change="onchangecallback"
              :multiple="multiple"
              v-model="selected" :options="options"></v-select>
</template>

and I have default options set as props already:

<script>
    import Vue from 'vue'
    import vSelect from 'vue-select'

    Vue.component('v-select', vSelect);

    export default {
        props: {
            options: {
                default: function() { return ['one', 'two'] },
                type: Array
            },
            multiple: {
                default: false,
                type: Boolean
            },
            onchangecallback: {
                default: () => {alert('default')},
                type: Function
            }
        },
        data() {
            return {
                selected: null
            }
        }
    }
</script>
vue inactive question / support

Most helpful comment

All 3 comments

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 60 days. Thanks!

Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tirli picture tirli  路  3Comments

miljan-aleksic picture miljan-aleksic  路  3Comments

rpersaud picture rpersaud  路  3Comments

shilman picture shilman  路  3Comments

xogeny picture xogeny  路  3Comments