fbredius/storybook

View on GitHub
docs/snippets/angular/component-story-custom-args-complex.mdx.mdx

Summary

Maintainability
Test Coverage
```md
<!-- YourComponent.stories.mdx -->

import { Canvas, Meta, Story } from '@storybook/addon-docs';

import { YourComponent } from './your-component.component';

<Meta title="YourComponent" component={YourComponent}/>

<!--👇 A function to apply some computations -->

export const someFunction = (valuePropertyA, valuePropertyB) => {

  // Makes some computations and returns something

};

export const Template = (args) => {
  const { propertyA, propertyB } = args;

  // 👇 Assigns the function result to a variable 
  const someFunctionResult = someFunction(propertyA, propertyB);
  return {
    props: {
      ...args,
      someProperty: someFunctionResult,
    },
  };
};

<Canvas>
  <Story
    name="ExampleStory"
    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
```