mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 11:11:53 +08:00
61 lines
1.3 KiB
Plaintext
61 lines
1.3 KiB
Plaintext
```md
|
|
<!--- YourComponent.stories.mdx -->
|
|
|
|
import { Meta, Story, Canvas } from '@storybook/addon-docs';
|
|
|
|
import YourComponent from './YourComponent.vue';
|
|
|
|
<Meta title="Example of how to use argTypes and functions" component={YourComponent}/>
|
|
|
|
<!---👇 A function to apply some computations -->
|
|
|
|
export const someFunction = (valuePropertyA, valuePropertyB) => {
|
|
|
|
<!--- Makes some computations and returns something -->
|
|
|
|
};
|
|
|
|
export const Template = (args)=>{
|
|
<!---👇 Assigns the function result to a variable -->
|
|
const functionResult = someFunction(args.propertyA, args.propertyB);
|
|
return {
|
|
components: { YourComponent },
|
|
setup() {
|
|
return {
|
|
args: {
|
|
...args,
|
|
someProperty: functionResult,
|
|
},
|
|
};
|
|
},
|
|
template: '<YourComponent v-bind="args" />',
|
|
};
|
|
}
|
|
|
|
<Canvas>
|
|
<Story
|
|
name="A complex case with a function"
|
|
argTypes={{
|
|
propertyA: {
|
|
options: [
|
|
'Item One',
|
|
'Item Two',
|
|
'Item Three'
|
|
],
|
|
},
|
|
propertyB: {
|
|
options: [
|
|
'Another Item One',
|
|
'Another Item Two',
|
|
'Another Item Three'
|
|
],
|
|
},
|
|
}}
|
|
args={{
|
|
propertyA: 'Item One',
|
|
propertyB: 'Another Item One',
|
|
}}>
|
|
{Template.bind({})}
|
|
</Story>
|
|
</Canvas>
|
|
``` |