@domenico
To write a decorator in Typescript for Storybook, you can follow these steps:
1 2 3 4 5 6 7 8 9 10 |
import React from 'react'; import { StoryFn } from '@storybook/addons'; export const withCustomDecorator = (Story: StoryFn) => { return ( <div style={{ padding: '20px', backgroundColor: '#f7f7f7' }}> <Story /> </div> ); }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import React from 'react'; import { Meta, Story } from '@storybook/react'; import Button from '../Button'; import { withCustomDecorator } from './storybookDecorator'; export default { title: 'Button', component: Button, decorators: [withCustomDecorator], } as Meta; const Template: Story = () => <Button label="Click me" />; export const Primary = Template.bind({}); |
That's it! You have successfully written a decorator in Typescript for Storybook.