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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
import { useArgs } from '@storybook/client-api';
import type { Meta, StoryObj } from '@storybook/react';
import { type ChangeEvent, useCallback } from 'react';
import { Input, type InputProps } from './input';
const meta = {
component: Input,
title: 'Atoms/Forms/Fields/Input',
excludeStories: /Controlled.*$/,
} satisfies Meta<typeof Input>;
export default meta;
type Story = StoryObj<typeof meta>;
export const ControlledInput = ({ value, ...args }: InputProps) => {
const [_, updateArgs] = useArgs<InputProps>();
const handleChange = useCallback(
(e: ChangeEvent<HTMLInputElement>) => {
updateArgs({ ...args, value: e.target.value });
},
[args, updateArgs]
);
return <Input {...args} onChange={handleChange} value={value} />;
};
const InputTemplate: Story = {
args: {
id: 'default',
isDisabled: false,
isReadOnly: false,
isRequired: false,
name: 'default',
type: 'text',
value: '',
},
render: ControlledInput,
};
export const IsEditable: Story = {
...InputTemplate,
name: 'State: Editable',
args: {
...InputTemplate.args,
'aria-label': 'Example of an editable input field',
id: 'editable-input',
name: 'editable',
},
};
export const IsDisabled: Story = {
...InputTemplate,
name: 'State: Disabled',
args: {
...InputTemplate.args,
'aria-label': 'Example of a disabled input field',
id: 'disabled-input',
isDisabled: true,
name: 'disabled',
},
};
export const IsReadOnly: Story = {
...InputTemplate,
name: 'State: Readonly',
args: {
...InputTemplate.args,
'aria-label': 'Example of a read-only input field',
id: 'readonly-input',
isReadOnly: true,
name: 'readonly',
},
};
export const IsRequired: Story = {
...InputTemplate,
name: 'State: Required',
args: {
...InputTemplate.args,
'aria-label': 'Example of a required input field',
id: 'required-input',
isRequired: true,
name: 'required',
},
};
export const DateInput: Story = {
...InputTemplate,
name: 'Type: Date',
args: {
...InputTemplate.args,
'aria-label': 'Example of a date field',
id: 'date',
name: 'date',
type: 'date',
},
};
export const DatetimeInput: Story = {
...InputTemplate,
name: 'Type: Datetime',
args: {
...InputTemplate.args,
'aria-label': 'Example of a datetime field',
id: 'datetime',
name: 'datetime',
type: 'datetime-local',
},
};
export const EmailInput: Story = {
...InputTemplate,
name: 'Type: Email',
args: {
...InputTemplate.args,
'aria-label': 'Example of an email field',
id: 'email',
name: 'email',
type: 'email',
},
};
export const MonthInput: Story = {
...InputTemplate,
name: 'Type: Month',
args: {
...InputTemplate.args,
'aria-label': 'Example of a month field',
id: 'month',
name: 'month',
type: 'month',
},
};
export const NumberInput: Story = {
...InputTemplate,
name: 'Type: Number',
args: {
...InputTemplate.args,
'aria-label': 'Example of a number field',
id: 'number',
name: 'number',
type: 'number',
},
};
export const PasswordInput: Story = {
...InputTemplate,
name: 'Type: Password',
args: {
...InputTemplate.args,
'aria-label': 'Example of a password field',
id: 'password',
name: 'password',
type: 'password',
},
};
export const SearchInput: Story = {
...InputTemplate,
name: 'Type: Search',
args: {
...InputTemplate.args,
'aria-label': 'Example of a search field',
id: 'search',
name: 'search',
type: 'search',
},
};
export const TelInput: Story = {
...InputTemplate,
name: 'Type: Tel',
args: {
...InputTemplate.args,
'aria-label': 'Example of a tel field',
id: 'tel',
name: 'tel',
type: 'tel',
},
};
export const TextInput: Story = {
...InputTemplate,
name: 'Type: Text',
args: {
...InputTemplate.args,
'aria-label': 'Example of a text field',
id: 'text',
name: 'text',
type: 'text',
},
};
export const TimeInput: Story = {
...InputTemplate,
name: 'Type: Time',
args: {
...InputTemplate.args,
'aria-label': 'Example of a time field',
id: 'time',
name: 'time',
type: 'time',
},
};
export const UrlInput: Story = {
...InputTemplate,
name: 'Type: Url',
args: {
...InputTemplate.args,
'aria-label': 'Example of an url field',
id: 'url',
name: 'url',
type: 'url',
},
};
export const WeekInput: Story = {
...InputTemplate,
name: 'Type: Week',
args: {
...InputTemplate.args,
'aria-label': 'Example of a week field',
id: 'week',
name: 'week',
type: 'week',
},
};
|