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
65
66
67
68
69
70
71
72
73
74
75
76
77
|
import { observable } from 'mobx';
import { observer } from 'mobx-react';
import React from 'react';
import { v4 as uuid } from 'uuid';
import { Toggle } from '@meetfranz/forms';
import { storiesOf } from '../stores/stories';
interface IStoreArgs {
value?: boolean;
checked?: boolean;
label?: string;
id?: string;
name?: string;
disabled?: boolean;
error?: string;
}
const createStore = (args?: IStoreArgs) =>
observable({
id: `element-${uuid()}`,
name: 'toggle',
label: 'Label',
value: true,
checked: false,
disabled: false,
error: '',
...args,
});
const WithStoreToggle = observer(({ store }: { store: any }) => (
<>
<Toggle
value={store.value}
checked={store.checked}
label={store.label}
id={store.id}
name={store.name}
disabled={store.disabled}
error={store.error}
onChange={() => (store.checked = !store.checked)}
/>
</>
));
storiesOf('Toggle')
.add('Basic', () => <WithStoreToggle store={createStore()} />)
.add('Checked', () => (
<WithStoreToggle
store={createStore({
checked: true,
})}
/>
))
.add('Disabled', () => (
<WithStoreToggle
store={createStore({
checked: true,
disabled: true,
})}
/>
))
.add('Long label', () => (
<WithStoreToggle
store={createStore({
label:
'Hello world, this is an insanely long label for this toggle. We need to make sure that it will be displayed correctly.',
})}
/>
))
.add('With error', () => (
<WithStoreToggle
store={createStore({
error: 'Something went wrong',
})}
/>
));
|