-
Notifications
You must be signed in to change notification settings - Fork 7
/
Checkbox.stories.ts
64 lines (57 loc) · 1.49 KB
/
Checkbox.stories.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import {Args, Meta, Story} from '@storybook/html';
import template from '@components/checkbox.twig';
import Checkbox from '../../assets/js/Checkbox';
// Only respond to Storybook emulated DOM loaded event to prevent double-loading.
addEventListener('DOMContentLoaded', e => e.isTrusted || Checkbox.initTristateCheckboxes());
export default {
title: 'Form/Checkbox',
args: {
enlarge: true,
},
argTypes: {
caption_on: {
type: {name: 'string', required: true},
},
},
parameters: {
controls: {
sort: 'requiredFirst',
},
},
decorators: [
(Story, ctx) => `<form ${ctx.args.enlarge && 'style="font-size: 200%"'}>${Story()}</form>`,
],
} as Meta;
const Template: Story = (args, {loaded: {html}}) => html;
const createLoaders = () => [
async (ctx: Args) => {
return {
html: await template({...ctx.args, ...ctx.parameters}),
}
},
];
export const OnOff = Template.bind({});
OnOff.loaders = createLoaders();
OnOff.storyName = 'On/Off';
OnOff.args = {
caption_on: 'Click me',
negative: false,
};
export const AB = Template.bind({});
AB.loaders = createLoaders();
AB.storyName = 'A/B';
AB.args = {
caption_on: 'Option A',
caption_off: 'Option B',
};
export const Tri = Template.bind({});
Tri.loaders = createLoaders();
Tri.storyName = 'Tri-state';
Tri.args = {
caption_on: 'Include',
caption_off: 'Exclude',
};
Tri.parameters = {
tri: true,
name: 'foo',
}