mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-04 16:01:06 +08:00
53 lines
1.5 KiB
Plaintext
53 lines
1.5 KiB
Plaintext
```js
|
|
// YourComponent.stories.js
|
|
|
|
import YourComponent from './YourComponent.vue';
|
|
|
|
export default {
|
|
/* 👇 The title prop is optional.
|
|
* See https://storybook.js.org/docs/7.0/vue/configure/overview#configure-story-loading
|
|
* to learn how to generate automatic titles
|
|
*/
|
|
title: 'YourComponent',
|
|
component: YourComponent,
|
|
//👇 Creates specific argTypes with options
|
|
argTypes: {
|
|
propertyA: {
|
|
options: ['Item One', 'Item Two', 'Item Three'],
|
|
control: { type: 'select' }, // automatically inferred when 'options' is defined
|
|
},
|
|
propertyB: {
|
|
options: ['Another Item One', 'Another Item Two', 'Another Item Three'],
|
|
},
|
|
},
|
|
};
|
|
|
|
//👇 Some function to demonstrate the behavior
|
|
const someFunction = (valuePropertyA, valuePropertyB) => {
|
|
// Makes some computations and returns something
|
|
};
|
|
|
|
export const ExampleStory = {
|
|
render: ({ args }) => {
|
|
const { propertyA, propertyB } = args;
|
|
//👇 Assigns the function result to a variable
|
|
const functionResult = someFunction(propertyA, propertyB);
|
|
return {
|
|
components: { YourComponent },
|
|
setup() {
|
|
return {
|
|
...args,
|
|
//👇 Replaces arg variable with the override (without the need of mutation)
|
|
someProperty: functionResult,
|
|
};
|
|
},
|
|
template:
|
|
'<YourComponent :propertyA="propertyA" :propertyB="propertyB" :someProperty="someProperty"/>',
|
|
};
|
|
},
|
|
args: {
|
|
propertyA: 'Item One',
|
|
propertyB: 'Another Item One',
|
|
},
|
|
};
|
|
``` |