fbredius/storybook

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

Summary

Maintainability
Test Coverage
```ts
// YourComponent.stories.ts

import { Meta, Story} from '@storybook/angular';

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

export default {
  /* 👇 The title prop is optional.
  * See https://storybook.js.org/docs/angular/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'],
    },
  },
} as Meta;

//👇 Some function to demonstrate the behavior
const someFunction = (valuePropertyA: String, valuePropertyB: String) => {
  // Makes some computations and returns something
};

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

export const ExampleStory = Template.bind({});
ExampleStory.args= {
  propertyA: 'Item One',
  propertyB: 'Another Item One',
};
```