storybook/docs/snippets/svelte/component-story-custom-args-complex.js.mdx
2021-08-28 01:52:57 +01:00

44 lines
1.0 KiB
Plaintext

```js
// YourComponent.stories.js
import YourComponent from './YourComponent.svelte';
export default {
component: YourComponent,
//👇 Creates specific argTypes
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 = {
args: {
propertyA: 'Something',
propertyB: 'Something else',
},
render: (args) => {
const { propertyA, propertyB } = args;
//👇 Assigns the function result to a variable
const someFunctionResult = someFunction(propertyA, propertyB);
return {
Component: YourComponent,
props: {
...args,
someProperty: someFunctionResult,
},
};
},
};
```