Skip to content

Commit 46ce2e5

Browse files
committed
ref(Form): destructure options in params
1 parent 65b7286 commit 46ce2e5

File tree

1 file changed

+39
-19
lines changed
  • packages/feedback/src/widget

1 file changed

+39
-19
lines changed

packages/feedback/src/widget/Form.ts

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,33 @@ function retrieveStringValue(formData: FormData, key: string): string {
4949
/**
5050
* Creates the form element
5151
*/
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 {
5373
const {
5474
$el: $submit,
5575
setDisabled: setSubmitDisabled,
5676
setEnabled: setSubmitEnabled,
5777
} = SubmitButton({
58-
label: options.submitButtonLabel,
78+
label: submitButtonLabel,
5979
});
6080

6181
function handleSubmit(e: Event): void {
@@ -100,21 +120,21 @@ export function Form({ defaultName, defaultEmail, onCancel, onSubmit, options }:
100120

101121
const $name = h('input', {
102122
id: 'name',
103-
type: options.showName ? 'text' : 'hidden',
104-
ariaHidden: options.showName ? 'false' : 'true',
123+
type: showName ? 'text' : 'hidden',
124+
ariaHidden: showName ? 'false' : 'true',
105125
name: 'name',
106126
className: 'form__input',
107-
placeholder: options.namePlaceholder,
127+
placeholder: namePlaceholder,
108128
value: defaultName,
109129
});
110130

111131
const $email = h('input', {
112132
id: 'email',
113-
type: options.showEmail ? 'text' : 'hidden',
114-
ariaHidden: options.showEmail ? 'false' : 'true',
133+
type: showEmail ? 'text' : 'hidden',
134+
ariaHidden: showEmail ? 'false' : 'true',
115135
name: 'email',
116136
className: 'form__input',
117-
placeholder: options.emailPlaceholder,
137+
placeholder: emailPlaceholder,
118138
value: defaultEmail,
119139
});
120140

@@ -124,7 +144,7 @@ export function Form({ defaultName, defaultEmail, onCancel, onSubmit, options }:
124144
rows: '5',
125145
name: 'message',
126146
className: 'form__input form__input--textarea',
127-
placeholder: options.messagePlaceholder,
147+
placeholder: messagePlaceholder,
128148
onKeyup: (e: Event) => {
129149
if (!(e.currentTarget instanceof HTMLTextAreaElement)) {
130150
return;
@@ -147,7 +167,7 @@ export function Form({ defaultName, defaultEmail, onCancel, onSubmit, options }:
147167
onCancel && onCancel(e);
148168
},
149169
},
150-
options.cancelButtonLabel,
170+
cancelButtonLabel,
151171
);
152172

153173
const $form = h(
@@ -159,37 +179,37 @@ export function Form({ defaultName, defaultEmail, onCancel, onSubmit, options }:
159179
[
160180
$error,
161181

162-
!options.isAnonymous &&
163-
options.showName &&
182+
!isAnonymous &&
183+
showName &&
164184
h(
165185
'label',
166186
{
167187
htmlFor: 'name',
168188
className: 'form__label',
169189
},
170-
[options.nameLabel, $name],
190+
[nameLabel, $name],
171191
),
172-
!options.isAnonymous && !options.showName && $name,
192+
!isAnonymous && !showName && $name,
173193

174-
!options.isAnonymous &&
175-
options.showEmail &&
194+
!isAnonymous &&
195+
showEmail &&
176196
h(
177197
'label',
178198
{
179199
htmlFor: 'email',
180200
className: 'form__label',
181201
},
182-
[options.emailLabel, $email],
202+
[emailLabel, $email],
183203
),
184-
!options.isAnonymous && !options.showEmail && $email,
204+
!isAnonymous && !showEmail && $email,
185205

186206
h(
187207
'label',
188208
{
189209
htmlFor: 'message',
190210
className: 'form__label',
191211
},
192-
[options.messageLabel, $message],
212+
[messageLabel, $message],
193213
),
194214

195215
h(

0 commit comments

Comments
 (0)