diff options
author | 2019-01-11 21:07:21 +0100 | |
---|---|---|
committer | 2019-01-11 21:07:21 +0100 | |
commit | 0ac2806481852249c6a2d4a032cc2c0324a58ef8 (patch) | |
tree | 03292af10a5a97b824293ff8878d2a5c821d5ed2 /uidev/src/stories | |
parent | expose legacy styles (diff) | |
download | ferdium-app-0ac2806481852249c6a2d4a032cc2c0324a58ef8.tar.gz ferdium-app-0ac2806481852249c6a2d4a032cc2c0324a58ef8.tar.zst ferdium-app-0ac2806481852249c6a2d4a032cc2c0324a58ef8.zip |
Add toggle element to @meetfranz/forms
Diffstat (limited to 'uidev/src/stories')
-rw-r--r-- | uidev/src/stories/input.stories.tsx (renamed from uidev/src/stories/input.tsx) | 2 | ||||
-rw-r--r-- | uidev/src/stories/toggle.stories.tsx | 70 |
2 files changed, 70 insertions, 2 deletions
diff --git a/uidev/src/stories/input.tsx b/uidev/src/stories/input.stories.tsx index dc8f6e997..9862ee479 100644 --- a/uidev/src/stories/input.tsx +++ b/uidev/src/stories/input.stories.tsx | |||
@@ -3,8 +3,6 @@ import React from 'react'; | |||
3 | import { Input } from '@meetfranz/forms'; | 3 | import { Input } from '@meetfranz/forms'; |
4 | import { storiesOf } from '../stores/stories'; | 4 | import { storiesOf } from '../stores/stories'; |
5 | 5 | ||
6 | export const stories = () => (<div>input stories</div>); | ||
7 | |||
8 | const defaultProps = { | 6 | const defaultProps = { |
9 | label: 'Label', | 7 | label: 'Label', |
10 | id: 'test1', | 8 | id: 'test1', |
diff --git a/uidev/src/stories/toggle.stories.tsx b/uidev/src/stories/toggle.stories.tsx new file mode 100644 index 000000000..091342496 --- /dev/null +++ b/uidev/src/stories/toggle.stories.tsx | |||
@@ -0,0 +1,70 @@ | |||
1 | import { observable } from 'mobx'; | ||
2 | import { observer } from 'mobx-react'; | ||
3 | import React from 'react'; | ||
4 | import uuid from 'uuid/v4'; | ||
5 | |||
6 | import { Toggle } from '@meetfranz/forms'; | ||
7 | import { storiesOf } from '../stores/stories'; | ||
8 | |||
9 | interface IStoreArgs { | ||
10 | value?: boolean; | ||
11 | checked?: boolean; | ||
12 | label?: string; | ||
13 | id?: string; | ||
14 | name?: string; | ||
15 | disabled?: boolean; | ||
16 | error?: string; | ||
17 | } | ||
18 | |||
19 | const createStore = (args?: IStoreArgs) => { | ||
20 | return observable(Object.assign({ | ||
21 | id: `element-${uuid()}`, | ||
22 | name: 'toggle', | ||
23 | label: 'Label', | ||
24 | value: true, | ||
25 | checked: false, | ||
26 | disabled: false, | ||
27 | error: '', | ||
28 | }, args)); | ||
29 | }; | ||
30 | |||
31 | const WithStoreToggle = observer(({ store }: { store: any }) => ( | ||
32 | <> | ||
33 | <Toggle | ||
34 | value={store.value} | ||
35 | checked={store.checked} | ||
36 | label={store.label} | ||
37 | id={store.id} | ||
38 | name={store.name} | ||
39 | disabled={store.disabled} | ||
40 | error={store.error} | ||
41 | onChange={() => store.checked = !store.checked} | ||
42 | /> | ||
43 | </> | ||
44 | )); | ||
45 | |||
46 | storiesOf('Toggle') | ||
47 | .add('Basic', () => ( | ||
48 | <WithStoreToggle store={createStore()} /> | ||
49 | )) | ||
50 | .add('Checked', () => ( | ||
51 | <WithStoreToggle store={createStore({ | ||
52 | checked: true, | ||
53 | })} /> | ||
54 | )) | ||
55 | .add('Disabled', () => ( | ||
56 | <WithStoreToggle store={createStore({ | ||
57 | checked: true, | ||
58 | disabled: true, | ||
59 | })} /> | ||
60 | )) | ||
61 | .add('Long label', () => ( | ||
62 | <WithStoreToggle store={createStore({ | ||
63 | label: 'Hello world, this is an insanely long label for this toggle. We need to make sure that it will be displayed correctly.', | ||
64 | })} /> | ||
65 | )) | ||
66 | .add('With error', () => ( | ||
67 | <WithStoreToggle store={createStore({ | ||
68 | error: 'Something went wrong', | ||
69 | })} /> | ||
70 | )); | ||