forked from DNNCommunity/dnn-elements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdnn-example-form.tsx
243 lines (238 loc) · 9.02 KB
/
dnn-example-form.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
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
232
233
234
235
236
237
238
239
240
241
242
243
import { Component, Host, h, State } from '@stencil/core';
/** Do not use this component in production, it is meant for testing purposes only and is not distributed in the production package. */
@Component({
tag: 'dnn-example-form',
styleUrl: 'dnn-example-form.scss',
})
export class DnnExampleForm {
@State() resume: File;
@State() profilePicData: string;
@State() profilePicConfirmed = false;
private fieldset: HTMLDnnFieldsetElement;
private resumeDropped(detail: File[]): void {
var singleFile = detail[0];
this.resume = singleFile;
}
private profilePicCropped(imageData: string): void {
this.profilePicData = imageData;
}
render() {
return (
<Host>
<dnn-fieldset
class="full-form-width"
ref={el => this.fieldset = el}
label="Sample Form"
helpText="This is some help text."
>
<div slot="label-prefix">
<svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 -960 960 960"
>
<path d="m120-200 180-280-180-280h480q20 0 37.5 9t28.5 25l174 246-174 246q-11 16-28.5 25t-37.5 9H120Zm146-80h334l142-200-142-200H266l130 200-130 200Zm130-200L266-680l130 200-130 200 130-200Z"/>
</svg>
</div>
<div slot="label-suffix">
<svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 -960 960 960"
>
<path d="M480-79q-16 0-30.5-6T423-102L102-423q-11-12-17-26.5T79-480q0-16 6-31t17-26l321-321q12-12 26.5-17.5T480-881q16 0 31 5.5t26 17.5l321 321q12 11 17.5 26t5.5 31q0 16-5.5 30.5T858-423L537-102q-11 11-26 17t-31 6Zm0-80 321-321-321-321-321 321 321 321Zm-40-281h80v-240h-80v240Zm40 120q17 0 28.5-11.5T520-360q0-17-11.5-28.5T480-400q-17 0-28.5 11.5T440-360q0 17 11.5 28.5T480-320Zm0-160Z"/>
</svg>
</div>
<h2>This is a sample form</h2>
<p>It includes dnn elements commonly used in forms.</p>
<button onClick={() => this.fieldset.setFocused()}>Focus</button>
<button onClick={() => this.fieldset.setBlurred()}>Blur</button>
<button onClick={() => this.fieldset.disable()}>Disable</button>
<button onClick={() => this.fieldset.enable()}>Enable</button>
<button onClick={() => this.fieldset.setValidity(false, "Field is not valid!")}>Set Invalid</button>
<button onClick={() => this.fieldset.setValidity(true)}>Set Valid</button>
<button onClick={() => this.fieldset.pinLabel()}>Pin Label</button>
<button onClick={() => this.fieldset.unpinLabel()}>Unpin Label</button>
</dnn-fieldset>
<form
onSubmit={e => {
e.preventDefault();
/* eslint-disable no-console */
console.group("Form submitted");
console.log(e);
console.groupEnd();
console.group("Form data");
const formData = new FormData(e.target as HTMLFormElement);
formData.forEach((value, key) => {
console.log(key, value);
});
console.groupEnd();
/* eslint-enable no-console */
}}
>
<dnn-fieldset label="User Information">
<div class="fields">
<dnn-input
label="First Name"
type="text"
required
name="firstName"
/>
<dnn-input
label="Last Name"
type="text"
required
name="lastName"
/>
<dnn-input
label="Email"
type="email"
required
helpText='We will never share your email with anyone else.'
name="email"
/>
<dnn-input
label="Gmail"
type="email"
helpText="Please enter your Gmail address."
name="gmail"
pattern=".+@gmail\.com"
/>
<dnn-input
label="Password"
type="password"
required
minlength={8}
allowShowPassword
helpText='Your password must be at least 8 characters long.'
name="password"
/>
<dnn-input
label="Confirm Password"
type="password"
required
minlength={8}
allowShowPassword
helpText='Please confirm your password.'
name="confirmPassword"
/>
<dnn-input
label="Phone"
type="tel"
pattern="\d{3}[\-]\d{3}[\-]\d{4}"
required
helpText='Please enter your phone number in the format 123-456-7890.'
name="phone"
/>
<dnn-input
label="Date of Birth"
type="date"
required
name="dateOfBirth"
/>
<dnn-input
label="Date and Time of Birth"
type="datetime-local"
helpText="If you have such a good memory... (optional)"
name="dateTimeOfBirth"
/>
<dnn-input
type="number"
label="Age"
min={0}
max={115}
name="age"
/>
<dnn-input
label="Notification Time"
type="time"
helpText="Optionaly indicate your preferred time for notifications."
name="notificationTime"
/>
<dnn-input
label="Website"
type="url"
helpText="Please enter the URL of your website."
name="website"
/>
<dnn-checkbox name="rememberMe" value="true">
Remember me
</dnn-checkbox>
<dnn-color-input
label="Favorite Color"
name="favoriteColor"
helpText="If you have any..."
/>
<dnn-select
label="Gender"
name="gender"
required
>
<option value="">--- Select ---</option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Prefer not to say</option>
</dnn-select>
<dnn-textarea
label="Review"
name="review"
value="This is a review."
helpText="Please enter your review."
required
/>
<label>
Subscribe to our newsletter
<dnn-toggle name="subscribe"/>
</label>
<dnn-fieldset label="Your Resume">
{this.resume === undefined &&
<dnn-dropzone name="resume" onFilesSelected={e => this.resumeDropped(e.detail)} />
}
{this.resume &&
<p class="filename">
File: {this.resume.name}
<dnn-button type="danger" onClick={() => this.resume = undefined}>Remove</dnn-button>
</p>
}
</dnn-fieldset>
<dnn-fieldset label="Your profile Picture">
<div class="profile-pic">
{this.profilePicConfirmed === false &&
<dnn-image-cropper name="profilePic" onImageCropChanged={e => this.profilePicCropped(e.detail)}/>
}
{this.profilePicConfirmed === false && this.profilePicData != undefined &&
<dnn-button onClick={() => this.profilePicConfirmed = true}>Confirm Crop</dnn-button>
}
{this.profilePicConfirmed &&
[
<img src={this.profilePicData} alt="Profile Picture" />
,
<dnn-button type="danger"
onClick={
() => {
this.profilePicData = undefined;
this.profilePicConfirmed = false;
}
}
>
Remove
</dnn-button>
]
}
</div>
</dnn-fieldset>
<label class="vertical">
Some code
<dnn-monaco-editor name="code" value="<p>Some html</p>" />
</label>
<label class="vertical">
Biography
<dnn-richtext name="biography" value="<p>Some html</p>" />
</label>
</div>
</dnn-fieldset>
<div class="controls">
<dnn-button reversed formButtonType="reset">Reset</dnn-button>
<dnn-button formButtonType="submit">Submit</dnn-button>
</div>
</form>
</Host>
);
}
}