/
docs.forms._index.jsx
272 lines (256 loc) · 7.62 KB
/
docs.forms._index.jsx
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
import { useRef } from "react";
import Code from "~/components/Code";
import Heading from "~/components/Heading";
import Link from "~/components/Link";
import Content from "~/components/docs/Content";
import EditOnGithub from "~/components/docs/EditOnGithub";
import Header from "~/components/docs/Header";
import TableOfContents from "~/components/docs/TableOfContents";
import metaData from "~/data/meta";
const { titleSuffix } = metaData;
export const meta = () => [
{ title: `Forms overview ${titleSuffix}` },
{
name: "description",
content:
"All form elements are fully responsive with pure semantic HTML, enabling forms to scale gracefully across devices and viewports.",
},
];
export default function Forms() {
const preventDefault = (e) => e.preventDefault();
const introductionRef = useRef();
const usageWithGridRef = useRef();
const usageWithGroupRef = useRef();
const helperTextRef = useRef();
return (
<>
{/* Header */}
<Header
title="Forms overview"
description="All form elements are fully responsive with pure semantic HTML, enabling forms to scale gracefully across devices and viewports."
/>
{/* Table of content */}
<TableOfContents
data={[
{
anchor: "",
title: "Introduction",
ref: introductionRef,
},
{
anchor: "helper-text",
title: "Helper text",
ref: helperTextRef,
},
{
anchor: "usage-with-grid",
title: "Usage with grid",
ref: usageWithGridRef,
},
{
anchor: "usage-with-group",
title: "Usage with group",
ref: usageWithGroupRef,
},
]}
/>
{/* Content */}
<Content>
<section aria-label="Introduction" ref={introductionRef}>
<p>
Inputs are <Code display="inline" language="css">{`width: 100%;`}</Code> by default and
are the same size as the buttons to build consistent forms.
</p>
<article aria-label="Form example" className="component">
<form onSubmit={preventDefault}>
<fieldset>
<label>
First name
<input name="first_name" placeholder="First name" autoComplete="given-name" />
</label>
<label>
Email
<input type="email" name="email" placeholder="Email" autoComplete="email" />
</label>
</fieldset>
<input type="submit" value="Subscribe" />
</form>
<Code as="footer">{`<form>
<fieldset>
<label>
First name
<input
name="first_name"
placeholder="First name"
autocomplete="given-name"
/>
</label>
<label>
Email
<input
type="email"
name="email"
placeholder="Email"
autocomplete="email"
/>
</label>
</fieldset>
<input
type="submit"
value="Subscribe"
/>
</form>`}</Code>
</article>
<p>
<Code display="inline">{`<input>`}</Code> can be inside or outside{" "}
<Code display="inline">{`<label>`}</Code>.
</p>
<article aria-label="Label and input syntax" className="component">
<form>
<label>
First name
<input name="first_name" placeholder="First name" autoComplete="given-name" />
</label>
<label htmlFor="email">Email</label>
<input type="email" id="email" placeholder="Email" autoComplete="email" />
</form>
<Code as="footer">{`<form>
<!-- Input inside label -->
<label>
First name
<input
name="first_name"
placeholder="First name"
autocomplete="given-name"
/>
</label>
<!-- Input outside label -->
<label for="email">Email</label>
<input
type="email"
id="email"
placeholder="Email"
autocomplete="email"
/>
</form>`}</Code>
</article>
</section>
<section ref={helperTextRef}>
<Heading level={2} anchor="helper-text">
Helper text
</Heading>
<p>
<Code display="inline">{`<small>`}</Code> below form elements are muted and act as
helper texts.
</p>
<article aria-label="Form helpers example" className="component">
<input
type="email"
name="email"
placeholder="Email"
autoComplete="email"
aria-label="Email"
aria-describedby="email-helper"
/>
<small id="email-helper">We’ll never share your email with anyone else.</small>
<Code as="footer">{`<input
type="email"
name="email"
placeholder="Email"
autoComplete="email"
aria-label="Email"
aria-describedby="email-helper"
/>
<small id="email-helper">
We'll never share your email with anyone else.
</small>`}</Code>
</article>
</section>
<section ref={usageWithGridRef}>
<Heading level={2} anchor="usage-with-grid">
Usage with grid
</Heading>
<p>
You can use <code>.grid</code> inside a form. See <Link to="/docs/grid">Grid</Link>.
</p>
<article aria-label="Form and grid example" className="component">
<form onSubmit={preventDefault}>
<fieldset className="grid">
<input
name="login"
placeholder="Login"
aria-label="Login"
autoComplete="username"
/>
<input
type="password"
name="password"
placeholder="Password"
aria-label="Password"
autoComplete="current-password"
/>
<input type="submit" value="Log in" />
</fieldset>
</form>
<Code as="footer">{`<form>
<fieldset class="grid">
<input
name="login"
placeholder="Login"
aria-label="Login"
autocomplete="username"
/>
<input
type="password"
name="password"
placeholder="Password"
aria-label="Password"
autocomplete="current-password"
/>
<input
type="submit"
value="Log in"
/>
</fieldset>
</form>`}</Code>
</article>
</section>
<section ref={usageWithGroupRef}>
<Heading level={2} anchor="usage-with-group">
Usage with group
</Heading>
<p>
You can use <code>role="group"</code> with form elements. See{" "}
<Link to="/docs/group">Group</Link>.
</p>
<article className="component" aria-label="Form group example">
<form onSubmit={preventDefault}>
<fieldset role="group">
<input
type="email"
name="email"
placeholder="Enter your email"
autoComplete="email"
/>
<input type="submit" value="Subscribe" />
</fieldset>
</form>
<Code as="footer">{`<form>
<fieldset role="group">
<input
type="email"
name="email"
placeholder="Enter your email"
autocomplete="email"
/>
<input type="submit" value="Subscribe" />
</fieldset>
</form>`}</Code>
</article>
</section>
{/* Edit on GitHub */}
<EditOnGithub file="docs.forms._index.jsx" />
</Content>
</>
);
}