mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-04 20:31:08 +08:00
36 lines
755 B
Plaintext
36 lines
755 B
Plaintext
```ts
|
|
// Icon.stories.ts
|
|
|
|
import type { Meta, StoryFn } from '@storybook/angular';
|
|
|
|
import Icon from './icon.component';
|
|
|
|
import { IconA, IconB, IconC, IconD, IconE } from './icons';
|
|
|
|
// Maps the icons to a JSON serializable object to be safely used with the argTypes
|
|
const iconMap = { IconA, IconB, IconC, IconD, IconE };
|
|
|
|
export default {
|
|
title: 'My Story with Icons',
|
|
component: Icon,
|
|
argTypes: {
|
|
icon: {
|
|
options: Object.keys(iconMap),
|
|
},
|
|
},
|
|
} as Meta;
|
|
|
|
const Template: Story<Icon> = (args) => {
|
|
// retrieves the appropriate icon passes it as a component prop
|
|
const { icon } = args;
|
|
const selectedIcon = iconMap[icon];
|
|
return {
|
|
component: Icon,
|
|
props: {
|
|
...args,
|
|
icon: selectedIcon,
|
|
},
|
|
};
|
|
};
|
|
```
|