-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathTextInput.stories.js
124 lines (110 loc) · 3.01 KB
/
TextInput.stories.js
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
import React, {useState} from 'react';
import TextInput from '../components/TextInput';
/**
* We use the Component Story Format for writing stories. Follow the docs here:
*
* https://storybook.js.org/docs/react/writing-stories/introduction#component-story-format
*/
const story = {
title: 'Components/TextInput',
component: TextInput,
};
// eslint-disable-next-line react/jsx-props-no-spreading
const Template = args => <TextInput {...args} />;
// Arguments can be passed to the component by binding
// See: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
const AutoFocus = Template.bind({});
AutoFocus.args = {
label: 'Auto-focused text input',
name: 'AutoFocus',
autoFocus: true,
};
const DefaultInput = Template.bind({});
DefaultInput.args = {
label: 'Default text input',
name: 'Default',
};
const DefaultValueInput = Template.bind({});
DefaultValueInput.args = {
label: 'Default value input',
name: 'DefaultValue',
defaultValue: 'My default value',
};
const ErrorInput = Template.bind({});
ErrorInput.args = {
label: 'Error input',
name: 'InputWithError',
errorText: 'Oops! Looks like there\'s an error',
};
const ForceActiveLabel = Template.bind({});
ForceActiveLabel.args = {
label: 'Force active label',
placeholder: 'My placeholder text',
forceActiveLabel: true,
};
const PlaceholderInput = Template.bind({});
PlaceholderInput.args = {
label: 'Placeholder input',
name: 'Placeholder',
placeholder: 'My placeholder text',
};
const AutoGrowInput = Template.bind({});
AutoGrowInput.args = {
label: 'Autogrow input',
name: 'AutoGrow',
placeholder: 'My placeholder text',
autoGrow: true,
textInputContainerStyles: [{
minWidth: 150,
}],
};
const PrefixedInput = Template.bind({});
PrefixedInput.args = {
label: 'Prefixed input',
name: 'Prefixed',
placeholder: 'My placeholder text',
prefixCharacter: '@',
};
const MaxLengthInput = Template.bind({});
MaxLengthInput.args = {
label: 'MaxLength input',
name: 'MaxLength',
placeholder: 'My placeholder text',
maxLength: 50,
};
const HintAndErrorInput = (args) => {
const [error, setError] = useState('');
return (
<TextInput
// eslint-disable-next-line react/jsx-props-no-spreading
{...args}
onChangeText={(value) => {
if (value && value.toLowerCase() === 'oops!') {
setError('Oops! Looks like there\'s an error');
return;
}
setError('');
}}
errorText={error}
/>
);
};
HintAndErrorInput.args = {
label: 'HintAndError input',
name: 'HintAndError',
placeholder: 'My placeholder text',
hint: 'Type "Oops!" to see the error',
};
export default story;
export {
AutoFocus,
DefaultInput,
DefaultValueInput,
ErrorInput,
ForceActiveLabel,
PlaceholderInput,
AutoGrowInput,
PrefixedInput,
MaxLengthInput,
HintAndErrorInput,
};