-
Notifications
You must be signed in to change notification settings - Fork 13
/
story.tsx
183 lines (171 loc) · 4.6 KB
/
story.tsx
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
176
177
178
179
180
181
182
183
import * as React from 'react';
import { storiesOf } from '@storybook/react';
import { action, decorateAction } from '@storybook/addon-actions';
import { withReadme } from 'storybook-readme';
import { Input } from './Input';
import Readme from './README.md';
import { Box } from '../Core';
import { Badge } from '../Badge';
import { Button } from '../Button';
import { Icon } from '../Icon';
const stories = storiesOf('Components|Input', module).addDecorator(withReadme(Readme));
const firstArgAction = decorateAction([(args: any) => [args[0].target.value]]);
type State = {
status: {
type?: 'error' | 'valid' | 'warning';
message?: string;
};
input: any;
};
class InputWrapper extends React.Component<any, State> {
constructor(props: any) {
super(props);
this.state = {
status: {},
input: '',
};
}
handleClick() {
if (!this.state.input || Number.isNaN(parseFloat(this.state.input))) {
this.setState({ status: { type: 'error', message: 'Please enter a valid number' } });
} else if (this.state.input < 10) {
this.setState({ status: { type: 'warning', message: 'You can do more than 10!' } });
} else {
this.setState({ status: { type: 'valid', message: 'Good job!' } });
}
}
handleChange(e: React.FormEvent<HTMLInputElement>) {
const target = e.target as HTMLInputElement;
this.setState({ input: target.value });
}
handleFocus() {
this.setState({ status: {} });
}
render() {
return (
<div>
<Input
placeholder="Input with error message..."
id="error"
onChange={e => this.handleChange(e)}
onFocus={() => this.handleFocus()}
label="Enter a number"
status={this.state.status.type as any}
statusMessage={this.state.status.message}
/>
<br />
<Button onClick={() => this.handleClick()}>Submit</Button>
</div>
);
}
}
stories.add('Story', () => (
<div>
<Box mb={3}>
<h3>Simple text input</h3>
<Input id="simple" label="Label" placeholder="Placeholder text..." />
</Box>
<Box mb={3}>
<h3>Advanced text input</h3>
<Input
id="advanced"
label="Label"
labelHelper={
<Badge type="info" size="small">
Label Helper
</Badge>
}
textHelper="Text Helper"
description="Description text"
placeholder="Placeholder text..."
prefix="$"
suffix="*"
/>
</Box>
<h2>States</h2>
<Box mb={3}>
<Input placeholder="Placeholder text..." />
</Box>
<Box mb={3}>
<Input placeholder="Hover input..." />
</Box>
<Box mb={3}>
<Input placeholder="Focus input..." />
</Box>
<Box mb={3}>
<Input readOnly value="Readonly input" />
</Box>
<Box mb={3}>
<Input disabled placeholder="Disabled input..." />
</Box>
<Box mb={3}>
<Input
status="valid"
placeholder="Valid input..."
prefix={<Icon name="customers" />}
suffix={<Icon name="info" color="secondary" />}
/>
</Box>
<Box mb={3}>
<Input status="warning" placeholder="Warning input..." />
</Box>
<Box mb={3}>
<Input status="error" placeholder="Error input..." />
</Box>
<div>
<h2>Size</h2>
<Box mb={3}>
<Input size="small" placeholder="Small input..." />
</Box>
<Box mb={3}>
<Input placeholder="Normal input..." />
</Box>
<Box mb={3}>
<Input size="large" placeholder="Large input..." />
</Box>
</div>
<div>
<h2>Input Error Text</h2>
<Box mb={3}>
<Input
placeholder="This is some text on an input that has an error"
status="error"
statusMessage="This is an error message"
/>
</Box>
</div>
<div>
<h2>Input Error Text (using the legacy API)</h2>
<Box mb={3}>
<Input
placeholder="This is some text on an input that has an error"
status={{ type: 'error', message: 'This is an error message' }}
/>
</Box>
</div>
</div>
));
stories.add(
'Events',
() => (
<div>
<Box mb={3}>
<Input
placeholder="Input with onChange event (see Action Logger)"
onChange={firstArgAction('onChange')}
/>
</Box>
<Box mb={3}>
<Input
placeholder="Input with onFocus & onBlur events (see Action Logger)"
onFocus={action('onFocus')}
onBlur={action('onBlur')}
/>
</Box>
<Box mb={3}>
<InputWrapper />
</Box>
</div>
),
{ percy: { skip: true } },
);