fbredius/storybook

View on GitHub
docs/snippets/vue/button-story-using-args.3.js.mdx

Summary

Maintainability
Test Coverage
```js
// Button.stories.js

import Button from './Button.vue';

export default {
  /* πŸ‘‡ The title prop is optional.
  * See https://storybook.js.org/docs/vue/configure/overview#configure-story-loading
  * to learn how to generate automatic titles
  */
  title: 'Button',
  component: Button,
};

//πŸ‘‡ We create a β€œtemplate” of how args map to rendering
const Template = (args) => ({
  components: { Button },
  setup() {
    return { args };
  },
  template: '<Button v-bind="args" />',
});
//πŸ‘‡ Each story then reuses that template
export const Primary = Template.bind({});
Primary.args = { background: '#ff0', label: 'Button' };

export const Secondary = Template.bind({});
Secondary.args = { ...Primary.args, label: 'πŸ˜„πŸ‘πŸ˜πŸ’―' };

export const Tertiary = Template.bind({});
Tertiary.args = { ...Primary.args, label: 'πŸ“šπŸ“•πŸ“ˆπŸ€“' };
```