-
Notifications
You must be signed in to change notification settings - Fork 3
/
semanticForms.html
287 lines (233 loc) 路 14.4 KB
/
semanticForms.html
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="format-detection" content="telephone=no">
<title>Semantic Forms</title>
<link rel="stylesheet" href="semanticForms.css">
<style>
body.light {
background-color: #fff;
color: #000;
}
body.dark {
background-color: #000;
color: #fff;
}
h1,
p {
font-family: sans-serif;
}
</style>
<script src="semanticForms.js"></script>
</head>
<body>
<main>
<article>
<h1>Semantic Forms</h1>
<p>A pattern library of forms based on semantic HTML enhanced with a modern UX.</p>
<form action="/somewhere" method="post" class="semanticForms" data-clearfield-horizontal-offset="21" data-clearfield-vertical-offset="5">
<fieldset>
<legend>Fieldset legend (high flow, JS enabled)</legend>
<dl>
<dt><label for="name">Name</label></dt>
<dd><input id="name" name="name" type="text" placeholder="e.g. John Smith"></dd>
<dt><label for="prefilled">Prefilled field</label></dt>
<dd><input id="prefilled" name="prefilled" type="text" placeholder="e.g. Stuff" value="Some text prefilled"></dd>
<dt><label for="noplaceholder">No placeholder</label></dt>
<dd><input id="noplaceholder" name="noplaceholder" type="text"></dd>
<dt><label for="password">Password field</label></dt>
<dd><input id="password" name="password" type="password"></dd>
<dt><label for="email">Email field</label></dt>
<dd><input id="email" name="email" type="email" placeholder="e.g. john.smith@somewhere.com"></dd>
<dt><label for="tel">Telephone field</label></dt>
<dd><input id="tel" name="tel" type="tel" placeholder="e.g. 555-437-1111"></dd>
<dt><label for="url">URL field</label></dt>
<dd><input id="url" name="url" type="url" placeholder="e.g. https://github.com"></dd>
<dt><label for="search">Search field</label></dt>
<dd><input id="search" name="search" type="search" placeholder="e.g. cats"></dd>
<dt><label for="number">Number</label></dt>
<dd><input id="number" name="number" type="number" placeholder="e.g. 43"></dd>
<dt><label for="selectbox">Select box</label></dt>
<dd><select id="selectbox" name="selectbox">
<option value="1">Item one</option>
<option value="2">Item two</option>
<option value="3">Item three</option>
<option value="4">Item four</option>
<option value="5">Item five</option>
<option value="6">Item six</option>
<option value="7">Item seven</option>
</select></dd>
<dt><label data-for="checkboxes">Checkboxes</label></dt>
<dd class="checkboxes">
<ul id="checkboxes">
<li><input type="checkbox" name="checkboxes" id="c_one"> <label for="c_one">One</label></li>
<li><input type="checkbox" name="checkboxes" id="c_two"> <label for="c_two">Two</label></li>
<li><input type="checkbox" name="checkboxes" id="c_three"> <label for="c_three">Three</label></li>
</ul>
</dd>
<dt><label for="checkbox">Single checkbox</label></dt>
<dd><input id="checkbox" name="checkbox" type="checkbox"></dd>
<dt><label data-for="radios">Radios</label></dt>
<dd class="radios">
<ul id="radios">
<li><input type="radio" name="radios" id="r_one"> <label for="r_one">One</label></li>
<li><input type="radio" name="radios" id="r_two"> <label for="r_two">Two</label></li>
<li><input type="radio" name="radios" id="r_three"> <label for="r_three">Three</label></li>
</ul>
</dd>
<dt><label for="color">Color field</label></dt>
<dd><input id="color" name="color" type="color"></dd>
<dt><label for="date">Date field</label></dt>
<dd><input id="date" name="date" type="date"></dd>
<dt><label for="time">Time field</label></dt>
<dd><input id="time" name="time" type="time"></dd>
<dt><label for="datetime-local">Datetime-local field</label></dt>
<dd><input id="datetime-local" name="datetime-local" type="datetime-local"></dd>
<dt><label for="month">Month field</label></dt>
<dd><input id="month" name="month" type="month"></dd>
<dt><label for="week">Week field</label></dt>
<dd><input id="week" name="week" type="week"></dd>
<dt><label for="file">File field</label></dt>
<dd><input id="file" name="file" type="file"></dd>
<dt><label for="range">Range field</label></dt>
<dd><input id="range" name="range" type="range"></dd>
<dt><label for="textarea">Textarea</label></dt>
<dd><textarea id="textarea" name="textarea" rows="5" cols="50" placeholder="e.g. He just kept talking in one incredibly unbroken sentence moving from topic to topic so that no one had a chance to interrupt it was really quite hypnotic."></textarea></dd>
<dt><label for="prefilledtextarea">Textarea (prefilled)</label></dt>
<dd><textarea id="prefilledtextarea" name="prefilledtextarea" rows="5" cols="50" placeholder="e.g. He just kept talking in one incredibly unbroken sentence moving from topic to topic so that no one had a chance to interrupt it was really quite hypnotic.">Some prefilled content...</textarea></dd>
</dl>
<input type="submit" name="button1" value="Non-grouped submit button">
<input type="reset" name="reset" value="Another one">
<p>Flexbox button layout pattern with two submit buttons:</p>
<menu>
<li><button type="submit" name="button1">Button 1</button></li>
<li><button type="reset" name="button2">Button 2</button></li>
</menu>
<p>Flexbox button layout pattern with three submit buttons:</p>
<menu>
<li><button type="submit" name="button1">Button 1</button></li>
<li><button type="reset" name="button2">Button 2</button></li>
<li><input type="submit" name="button3" value="Button 3"></li>
</menu>
</fieldset>
</form>
<form action="/somewhere" method="post" class="semanticForms lowFlow">
<fieldset>
<legend>Fieldset legend (low flow, JS disabled)</legend>
<dl>
<dt><label for="low-flow-name">Name</label></dt>
<dd><input id="low-flow-name" name="low-flow-name" type="text" placeholder="e.g. John Smith"></dd>
<dt><label for="low-flow-prefilled">Prefilled field</label></dt>
<dd><input id="low-flow-prefilled" name="low-flow-prefilled" type="text" placeholder="e.g. Stuff" value="Some text prefilled"></dd>
<dt><label for="low-flow-noplaceholder">No placeholder</label></dt>
<dd><input id="low-flow-noplaceholder" name="low-flow-noplaceholder" type="text"></dd>
<dt><label for="low-flow-password">Password field</label></dt>
<dd><input id="low-flow-password" name="low-flow-password" type="password"></dd>
<dt><label for="low-flow-email">Email field</label></dt>
<dd><input id="low-flow-email" name="low-flow-email" type="email" placeholder="e.g. john.smith@somewhere.com"></dd>
<dt><label for="low-flow-tel">Telephone field</label></dt>
<dd><input id="low-flow-tel" name="low-flow-tel" type="tel" placeholder="e.g. 555-437-1111"></dd>
<dt><label for="low-flow-url">URL field</label></dt>
<dd><input id="low-flow-url" name="low-flow-url" type="url" placeholder="e.g. https://github.com"></dd>
<dt><label for="low-flow-search">Search field</label></dt>
<dd><input id="low-flow-search" name="low-flow-search" type="search" placeholder="e.g. cats"></dd>
<dt><label for="low-flow-number">Number</label></dt>
<dd><input id="low-flow-number" name="low-flow-number" type="number" placeholder="e.g. 43"></dd>
<dt><label for="low-flow-selectbox">Select box</label></dt>
<dd><select id="low-flow-selectbox" name="low-flow-selectbox">
<option value="1">Item one</option>
<option value="2">Item two</option>
<option value="3">Item three</option>
<option value="4">Item four</option>
<option value="5">Item five</option>
<option value="6">Item six</option>
<option value="7">Item seven</option>
</select></dd>
<dt><label data-for="low-flow-checkboxes">Checkboxes</label></dt>
<dd class="checkboxes">
<ul id="low-flow-checkboxes">
<li><input type="checkbox" name="low-flow-checkboxes" id="low-flow-c_one"> <label for="low-flow-c_one">One</label></li>
<li><input type="checkbox" name="low-flow-checkboxes" id="low-flow-c_two"> <label for="low-flow-c_two">Two</label></li>
<li><input type="checkbox" name="low-flow-checkboxes" id="low-flow-c_three"> <label for="low-flow-c_three">Three</label></li>
</ul>
</dd>
<dt><label for="low-flow-checkbox">Single checkbox</label></dt>
<dd><input id="low-flow-checkbox" name="low-flow-checkbox" type="checkbox"></dd>
<dt><label data-for="low-flow-radios">Radios</label></dt>
<dd class="radios">
<ul id="low-flow-radios">
<li><input type="radio" name="low-flow-radios" id="low-flow-r_one"> <label for="low-flow-r_one">One</label></li>
<li><input type="radio" name="low-flow-radios" id="low-flow-r_two"> <label for="low-flow-r_two">Two</label></li>
<li><input type="radio" name="low-flow-radios" id="low-flow-r_three"> <label for="low-flow-r_three">Three</label></li>
</ul>
</dd>
<dt><label for="low-flow-color">Color field</label></dt>
<dd><input id="low-flow-color" name="low-flow-color" type="color"></dd>
<dt><label for="low-flow-date">Date field</label></dt>
<dd><input id="low-flow-date" name="low-flow-date" type="date"></dd>
<dt><label for="low-flow-time">Time field</label></dt>
<dd><input id="low-flow-time" name="low-flow-time" type="time"></dd>
<dt><label for="low-flow-datetime-local">Datetime-local field</label></dt>
<dd><input id="low-flow-datetime-local" name="low-flow-datetime-local" type="datetime-local"></dd>
<dt><label for="low-flow-month">Month field</label></dt>
<dd><input id="low-flow-month" name="low-flow-month" type="month"></dd>
<dt><label for="low-flow-week">Week field</label></dt>
<dd><input id="low-flow-week" name="low-flow-week" type="week"></dd>
<dt><label for="low-flow-file">File field</label></dt>
<dd><input id="low-flow-file" name="low-flow-file" type="file"></dd>
<dt><label for="low-flow-range">Range field</label></dt>
<dd><input id="low-flow-range" name="low-flow-range" type="range"></dd>
<dt><label for="low-flow-textarea">Textarea</label></dt>
<dd><textarea id="low-flow-textarea" name="low-flow-textarea" rows="5" cols="50" placeholder="e.g. He just kept talking in one incredibly unbroken sentence moving from topic to topic so that no one had a chance to interrupt it was really quite hypnotic."></textarea></dd>
<dt><label for="low-flow-prefilledtextarea">Textarea (prefilled)</label></dt>
<dd><textarea id="low-flow-prefilledtextarea" name="low-flow-prefilledtextarea" rows="5" cols="50" placeholder="e.g. He just kept talking in one incredibly unbroken sentence moving from topic to topic so that no one had a chance to interrupt it was really quite hypnotic.">Some prefilled content...</textarea></dd>
</dl>
<input type="submit" name="button1" value="Non-grouped submit button">
<input type="reset" name="reset" value="Another one">
<p>Flexbox button layout pattern with two submit buttons:</p>
<menu>
<li><button type="submit" name="button1">Button 1</button></li>
<li><button type="reset" name="button2">Button 2</button></li>
</menu>
<p>Flexbox button layout pattern with three submit buttons:</p>
<menu>
<li><button type="submit" name="button1">Button 1</button></li>
<li><button type="reset" name="button2">Button 2</button></li>
<li><input type="submit" name="button3" value="Button 3"></li>
</menu>
</fieldset>
</form>
</article>
</main>
<script>
document.addEventListener('DOMContentLoaded', () => {
document.body.insertAdjacentHTML('afterbegin', '<p id="mode"><button></button></p>')
document.querySelector('#mode button').addEventListener('click', (event) => toggleDarkMode())
if (window.matchMedia('(prefers-color-scheme: dark)').matches) toggleDarkMode('dark')
else toggleDarkMode('light')
})
function toggleDarkMode (mode) {
if (mode === 'light' || document.body.className === 'dark') {
document.body.className = 'light'
document.querySelector('#mode button').innerHTML = 'Switch to dark mode'
const forms = document.querySelectorAll('form')
for (const form of forms) {
form.classList.add('light')
form.classList.remove('dark')
}
} else {
document.body.className = 'dark'
document.querySelector('#mode button').innerHTML = 'Switch to light mode'
const forms = document.querySelectorAll('form')
for (const form of forms) {
form.classList.add('dark')
form.classList.remove('light')
}
}
}
window.semanticForms()
</script>
</body>
</html>