storybook/examples/html-kitchen-sink/stories/addon-actions.stories.js

108 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-02-23 20:18:42 -05:00
import { withActions, decorate } from '@storybook/addon-actions';
2018-05-02 20:31:53 +03:00
const pickTarget = decorate([args => [args[0].target]]);
2020-02-23 19:26:29 -05:00
const buttonStory = () => () => `<button type="button">Hello World</button>`;
2018-05-02 20:31:53 +03:00
export default {
title: 'Addons/Actions',
};
2020-02-23 18:30:30 -05:00
export const Story1 = buttonStory();
2020-02-23 19:26:29 -05:00
Story1.story = {
2020-02-23 18:30:30 -05:00
name: 'Hello World',
parameters: {
actions: {
2020-02-23 19:26:29 -05:00
handles: ['click'],
},
},
2020-02-23 18:30:30 -05:00
};
2020-02-23 18:30:30 -05:00
export const Story2 = buttonStory();
2020-02-23 19:26:29 -05:00
Story2.story = {
2020-02-23 18:30:30 -05:00
name: 'Multiple actions',
parameters: {
actions: {
2020-02-23 19:26:29 -05:00
handles: ['click', 'contextmenu'],
},
},
2020-02-23 18:30:30 -05:00
};
2020-02-23 18:30:30 -05:00
export const Story3 = buttonStory();
2020-02-23 19:26:29 -05:00
Story3.story = {
2020-02-23 18:30:30 -05:00
name: 'Multiple actions + config',
parameters: {
actions: {
2020-02-23 19:26:29 -05:00
handles: ['click', 'contextmenu', { clearOnStoryChange: false }],
},
},
};
2020-02-23 18:30:30 -05:00
export const Story4 = buttonStory();
Story4.story = {
name: 'Multiple actions, object',
parameters: {
actions: {
2020-02-23 19:26:29 -05:00
handles: [{ click: 'clicked', contextmenu: 'right clicked' }],
},
},
2020-02-23 18:30:30 -05:00
};
export const Story5 = () => `
2018-05-02 20:31:53 +03:00
<div>
Clicks on this button will be logged: <button class="btn" type="button">Button</button>
</div>
2020-02-23 18:30:30 -05:00
`;
2020-02-23 19:26:29 -05:00
Story5.story = {
2020-02-23 18:30:30 -05:00
name: 'Multiple actions, selector',
parameters: {
actions: {
2020-02-23 19:26:29 -05:00
handles: [{ 'click .btn': 'clicked', contextmenu: 'right clicked' }],
},
},
2020-02-23 18:30:30 -05:00
};
export const Story6 = buttonStory();
Story6.story = {
name: 'Multiple actions, object + config',
parameters: {
actions: {
2020-02-23 19:26:29 -05:00
handles: [{ click: 'clicked', contextmenu: 'right clicked' }, { clearOnStoryChange: false }],
},
},
2020-02-23 18:30:30 -05:00
};
2020-02-24 11:49:16 -05:00
export const DecoratedStory1 = pickTarget.withActions('click', 'contextmenu')(buttonStory());
DecoratedStory1.story = {
name: 'Decorated actions',
};
2020-02-24 11:49:16 -05:00
export const DecoratedStory2 = pickTarget.withActions('click', 'contextmenu', {
clearOnStoryChange: false,
})(buttonStory());
DecoratedStory2.story = { name: 'Decorated actions + config' };
2020-02-23 18:30:30 -05:00
2020-02-24 11:49:16 -05:00
export const DeprecatedDecoratorsStory1 = buttonStory();
DeprecatedDecoratorsStory1.story = {
2020-02-23 20:18:42 -05:00
name: 'Deprecated decorators - Single action',
decorators: [withActions('click')],
};
2020-02-24 11:49:16 -05:00
export const DeprecatedDecoratorsStory2 = buttonStory();
DeprecatedDecoratorsStory2.story = {
2020-02-23 20:18:42 -05:00
name: 'Deprecated decorators - Multiple actions',
decorators: [withActions('click', 'contextmenu')],
};
2020-02-24 11:49:16 -05:00
export const DeprecatedDecoratorsStory3 = buttonStory();
DeprecatedDecoratorsStory3.story = {
name: 'Deprecated decorators - Multiple actions + config',
2020-02-23 20:18:42 -05:00
decorators: [withActions('click', 'contextmenu', { clearOnStoryChange: false })],
};
2020-02-24 11:49:16 -05:00
export const DeprecatedDecoratorsStory4 = buttonStory();
DeprecatedDecoratorsStory4.story = {
name: 'Deprecated decorators - Multiple actions, object',
2020-02-23 20:18:42 -05:00
decorators: [withActions({ click: 'clicked', contextmenu: 'right clicked' })],
2020-02-23 19:26:29 -05:00
};