aboutsummaryrefslogtreecommitdiffstats
path: root/uidev/src/stories/button.stories.tsx
blob: 400063ceab337cb4531a37335aa1f1892c990454 (plain) (blame)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import { mdiInformation } from '@mdi/js';
import { observable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import injectSheet from 'react-jss';

import { Button, Input } from '@meetfranz/forms';
import { Classes } from 'jss';
import { storiesOf } from '../stores/stories';

const defaultProps = {
  label: 'Button',
  id: 'test1',
  name: 'test1',
  type: 'button',
  disabled: false,
};

const styles = {
  combinedElements: {
    display: 'flex',
    justifyContent: 'space-between',
  },
  input: {
    flex: 1,
    marginRight: 20,
  },
};

const createStore = (args?: any) => observable({ ...defaultProps, ...args });

const WithStoreButton = observer(({ store }: { store: any }) => (
  <>
    <Button
      {...{ ...defaultProps, ...store }}
      onClick={
        !store.onClick
          ? () => {
              store.busy = !store.busy;

              window.setTimeout(() => {
                store.busy = !store.busy;
              }, 1000);
            }
          : store.onClick
      }
    />
  </>
));

storiesOf('Button')
  .add('Basic', () => <WithStoreButton store={createStore()} />)
  .add('Secondary', () => (
    <WithStoreButton
      store={createStore({
        buttonType: 'secondary',
      })}
    />
  ))
  .add('Success', () => (
    <WithStoreButton
      store={createStore({
        buttonType: 'success',
      })}
    />
  ))
  .add('Warning', () => (
    <WithStoreButton
      store={createStore({
        buttonType: 'warning',
      })}
    />
  ))
  .add('Danger', () => (
    <WithStoreButton
      store={createStore({
        buttonType: 'danger',
      })}
    />
  ))
  .add('Inverted', () => (
    <WithStoreButton
      store={createStore({
        buttonType: 'inverted',
      })}
    />
  ))
  .add('Full width', () => (
    <WithStoreButton
      store={createStore({
        stretch: true,
      })}
    />
  ))
  .add('Disabled', () => (
    <WithStoreButton
      store={createStore({
        disabled: true,
      })}
    />
  ))
  .add('With loader', () => (
    <WithStoreButton
      store={createStore({
        busy: true,
      })}
    />
  ))
  .add('With icon', () => (
    <WithStoreButton
      store={createStore({
        icon: mdiInformation,
      })}
    />
  ))
  .add('As link', () => (
    <WithStoreButton
      store={createStore({
        href: 'https://meetfranz.com',
      })}
    />
  ))
  .add('As link (target=_blank)', () => (
    <WithStoreButton
      store={createStore({
        href: 'https://meetfranz.com',
        target: '_blank',
      })}
    />
  ))
  .add('As link (with onClick)', () => (
    <WithStoreButton
      store={createStore({
        href: 'https://meetfranz.com',
        onClick: (e: React.MouseEvent<HTMLAnchorElement>) => {
          e.preventDefault();
          alert('Click event');
        },
      })}
    />
  ))
  .add('Long multi-line button', () => (
    <WithStoreButton
      store={createStore({
        label:
          'But there is something that I must say to my people, who stand on the warm threshold which leads into the palace of justice: In the process of gaining our rightful place, we must not be guilty of wrongful deeds. Let us not seek to satisfy our thirst for freedom by drinking from the cup of bitterness and hatred. We must forever conduct our struggle on the high plane of dignity and discipline. We must not allow our creative protest to degenerate into physical violence. Again and again, we must rise to the majestic heights of meeting physical force with soul force.',
      })}
    />
  ))
  .add(
    'Button with Input',
    injectSheet(styles)(
      observer(({ classes }: { classes: Classes }) => (
        <div className={classes.combinedElements}>
          <Input showLabel={false} className={classes.input} noMargin />
          <WithStoreButton store={createStore({})} />
        </div>
      )),
    ),
  )
  .add(
    'Icon Button with Input',
    injectSheet(styles)(
      observer(({ classes }: { classes: Classes }) => (
        <div className={classes.combinedElements}>
          <Input showLabel={false} className={classes.input} noMargin />
          <WithStoreButton
            store={createStore({
              icon: mdiInformation,
            })}
          />
        </div>
      )),
    ),
  );