@@ -49,13 +49,33 @@ function retrieveStringValue(formData: FormData, key: string): string {
49
49
/**
50
50
* Creates the form element
51
51
*/
52
- export function Form ( { defaultName, defaultEmail, onCancel, onSubmit, options } : Props ) : FormComponent {
52
+ export function Form ( {
53
+ options : {
54
+ showName,
55
+ showEmail,
56
+ isAnonymous,
57
+
58
+ nameLabel,
59
+ namePlaceholder,
60
+ emailLabel,
61
+ emailPlaceholder,
62
+ messageLabel,
63
+ messagePlaceholder,
64
+ cancelButtonLabel,
65
+ submitButtonLabel,
66
+ } ,
67
+
68
+ defaultName,
69
+ defaultEmail,
70
+ onCancel,
71
+ onSubmit,
72
+ } : Props ) : FormComponent {
53
73
const {
54
74
$el : $submit ,
55
75
setDisabled : setSubmitDisabled ,
56
76
setEnabled : setSubmitEnabled ,
57
77
} = SubmitButton ( {
58
- label : options . submitButtonLabel ,
78
+ label : submitButtonLabel ,
59
79
} ) ;
60
80
61
81
function handleSubmit ( e : Event ) : void {
@@ -100,21 +120,21 @@ export function Form({ defaultName, defaultEmail, onCancel, onSubmit, options }:
100
120
101
121
const $name = h ( 'input' , {
102
122
id : 'name' ,
103
- type : options . showName ? 'text' : 'hidden' ,
104
- ariaHidden : options . showName ? 'false' : 'true' ,
123
+ type : showName ? 'text' : 'hidden' ,
124
+ ariaHidden : showName ? 'false' : 'true' ,
105
125
name : 'name' ,
106
126
className : 'form__input' ,
107
- placeholder : options . namePlaceholder ,
127
+ placeholder : namePlaceholder ,
108
128
value : defaultName ,
109
129
} ) ;
110
130
111
131
const $email = h ( 'input' , {
112
132
id : 'email' ,
113
- type : options . showEmail ? 'text' : 'hidden' ,
114
- ariaHidden : options . showEmail ? 'false' : 'true' ,
133
+ type : showEmail ? 'text' : 'hidden' ,
134
+ ariaHidden : showEmail ? 'false' : 'true' ,
115
135
name : 'email' ,
116
136
className : 'form__input' ,
117
- placeholder : options . emailPlaceholder ,
137
+ placeholder : emailPlaceholder ,
118
138
value : defaultEmail ,
119
139
} ) ;
120
140
@@ -124,7 +144,7 @@ export function Form({ defaultName, defaultEmail, onCancel, onSubmit, options }:
124
144
rows : '5' ,
125
145
name : 'message' ,
126
146
className : 'form__input form__input--textarea' ,
127
- placeholder : options . messagePlaceholder ,
147
+ placeholder : messagePlaceholder ,
128
148
onKeyup : ( e : Event ) => {
129
149
if ( ! ( e . currentTarget instanceof HTMLTextAreaElement ) ) {
130
150
return ;
@@ -147,7 +167,7 @@ export function Form({ defaultName, defaultEmail, onCancel, onSubmit, options }:
147
167
onCancel && onCancel ( e ) ;
148
168
} ,
149
169
} ,
150
- options . cancelButtonLabel ,
170
+ cancelButtonLabel ,
151
171
) ;
152
172
153
173
const $form = h (
@@ -159,37 +179,37 @@ export function Form({ defaultName, defaultEmail, onCancel, onSubmit, options }:
159
179
[
160
180
$error ,
161
181
162
- ! options . isAnonymous &&
163
- options . showName &&
182
+ ! isAnonymous &&
183
+ showName &&
164
184
h (
165
185
'label' ,
166
186
{
167
187
htmlFor : 'name' ,
168
188
className : 'form__label' ,
169
189
} ,
170
- [ options . nameLabel , $name ] ,
190
+ [ nameLabel , $name ] ,
171
191
) ,
172
- ! options . isAnonymous && ! options . showName && $name ,
192
+ ! isAnonymous && ! showName && $name ,
173
193
174
- ! options . isAnonymous &&
175
- options . showEmail &&
194
+ ! isAnonymous &&
195
+ showEmail &&
176
196
h (
177
197
'label' ,
178
198
{
179
199
htmlFor : 'email' ,
180
200
className : 'form__label' ,
181
201
} ,
182
- [ options . emailLabel , $email ] ,
202
+ [ emailLabel , $email ] ,
183
203
) ,
184
- ! options . isAnonymous && ! options . showEmail && $email ,
204
+ ! isAnonymous && ! showEmail && $email ,
185
205
186
206
h (
187
207
'label' ,
188
208
{
189
209
htmlFor : 'message' ,
190
210
className : 'form__label' ,
191
211
} ,
192
- [ options . messageLabel , $message ] ,
212
+ [ messageLabel , $message ] ,
193
213
) ,
194
214
195
215
h (
0 commit comments