@orbitcommerce/constellation-docs 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +6 -0
- package/README.md +6 -2
- package/dist/docs.css +8260 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +308 -0
- package/dist/pages/Playground-CNbBbErC.js +129 -0
- package/dist/pages/_figures-data-BDmScEny.js +606 -0
- package/dist/pages/_foundations-blXWyYh8.js +30 -0
- package/dist/pages/_overlays-specimens-Dpn6oiyH.js +310 -0
- package/dist/pages/alert-BD4e6QTh.js +769 -0
- package/dist/pages/app-shell-KbA-nRqZ.js +1479 -0
- package/dist/pages/area-chart-B91dLcGo.js +562 -0
- package/dist/pages/avatar-DPPHXJAu.js +713 -0
- package/dist/pages/badge-C9JR0thI.js +729 -0
- package/dist/pages/button-D3V912P4.js +518 -0
- package/dist/pages/calendar-DSDZ9nRH.js +630 -0
- package/dist/pages/card-DUggbis3.js +659 -0
- package/dist/pages/checkbox-DwimQaK3.js +365 -0
- package/dist/pages/colour-BwuO8xAv.js +1498 -0
- package/dist/pages/command-palette-xAD7fOg6.js +1243 -0
- package/dist/pages/date-picker-BYSa816m.js +1421 -0
- package/dist/pages/delta-CtAo0eIM.js +574 -0
- package/dist/pages/dialog-BRAf4LMh.js +1451 -0
- package/dist/pages/docs-BNOb7AqR.js +515 -0
- package/dist/pages/empty-state-C-mLrXW2.js +417 -0
- package/dist/pages/figure-tabs-CoPFzzKz.js +460 -0
- package/dist/pages/home-dashboard-CFQwDtC9.js +959 -0
- package/dist/pages/host-B6znjEgQ.js +109 -0
- package/dist/pages/icon-button-C9eSVPPW.js +861 -0
- package/dist/pages/icons-sxkTs5Ob.js +473 -0
- package/dist/pages/input-KF9Gkawf.js +1093 -0
- package/dist/pages/installation-DpsX8G_n.js +445 -0
- package/dist/pages/kbd-cNfDoikz.js +544 -0
- package/dist/pages/live-globe-ClvLn9Lb.js +571 -0
- package/dist/pages/logo-BfGF1Pq9.js +571 -0
- package/dist/pages/menu-by2sgQ09.js +1618 -0
- package/dist/pages/motion-BvTGc2Dk.js +855 -0
- package/dist/pages/orbit-spinner-Dil1Z3Oy.js +332 -0
- package/dist/pages/overview-BPEbZQ6g.js +130 -0
- package/dist/pages/pagination-BBUnGvv5.js +249 -0
- package/dist/pages/popover-Db1gLDpb.js +1136 -0
- package/dist/pages/principles-CeAIOIdt.js +483 -0
- package/dist/pages/radio-group-CkdBWWfG.js +1077 -0
- package/dist/pages/registry-CroHzK9I.js +244 -0
- package/dist/pages/release-Dvo684UJ.js +13 -0
- package/dist/pages/rolling-number-qmvH84Mq.js +529 -0
- package/dist/pages/search-field-BN7MWGQ4.js +693 -0
- package/dist/pages/segmented-control-CTbIpRBW.js +777 -0
- package/dist/pages/select-DguELoRR.js +1429 -0
- package/dist/pages/separator-CPZub9pv.js +351 -0
- package/dist/pages/shape-DKvA0YKr.js +627 -0
- package/dist/pages/skeleton-DLuBhP46.js +561 -0
- package/dist/pages/sparkline-DMMYGbHn.js +668 -0
- package/dist/pages/switch-B-Qe4kcT.js +517 -0
- package/dist/pages/table-AMoODng4.js +607 -0
- package/dist/pages/tabs-B4M-usCV.js +1455 -0
- package/dist/pages/textarea-fTuUZRQb.js +693 -0
- package/dist/pages/toast-CKP03zjy.js +1176 -0
- package/dist/pages/tooltip-CBYil3kt.js +697 -0
- package/dist/pages/typography-PCbg8Bhg.js +735 -0
- package/manifest.json +3125 -0
- package/package.json +35 -4
|
@@ -0,0 +1,1093 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { a as DocTable, d as Section, i as DocPage, l as Note, m as ThemePair, o as Example, p as SubSection, r as DoDont, s as Guidelines, u as PropsTable } from "./docs-BNOb7AqR.js";
|
|
3
|
+
import { t as Playground } from "./Playground-CNbBbErC.js";
|
|
4
|
+
import { useRef, useState } from "react";
|
|
5
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { Button, Field, IconButton, Input, Tooltip, useFieldControl } from "@orbitcommerce/constellation";
|
|
7
|
+
import { CheckCircleIcon, CheckIcon, CopySimpleIcon, EnvelopeSimpleIcon, TagIcon } from "@orbitcommerce/constellation/icons";
|
|
8
|
+
//#region src/pages/components/input.tsx
|
|
9
|
+
function Preview() {
|
|
10
|
+
return /* @__PURE__ */ jsx("div", {
|
|
11
|
+
style: { width: 216 },
|
|
12
|
+
children: /* @__PURE__ */ jsx(Field, {
|
|
13
|
+
label: "Price",
|
|
14
|
+
hint: "Includes VAT at 20%",
|
|
15
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
16
|
+
prefix: "£",
|
|
17
|
+
inputMode: "decimal",
|
|
18
|
+
defaultValue: "18.00"
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
var quote = (v) => String(v).replace(/"/g, """);
|
|
24
|
+
var PLAYGROUND = [
|
|
25
|
+
{
|
|
26
|
+
prop: "aria-label",
|
|
27
|
+
type: "text",
|
|
28
|
+
default: "Product title",
|
|
29
|
+
toAttr: (v) => `aria-label="${quote(v)}"`
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
prop: "placeholder",
|
|
33
|
+
type: "text",
|
|
34
|
+
default: "e.g. Arden ergonomic chair",
|
|
35
|
+
toAttr: (v) => v ? `placeholder="${quote(v)}"` : null
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
prop: "size",
|
|
39
|
+
type: "select",
|
|
40
|
+
options: [
|
|
41
|
+
"sm",
|
|
42
|
+
"md",
|
|
43
|
+
"lg"
|
|
44
|
+
],
|
|
45
|
+
default: "md"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
prop: "icon",
|
|
49
|
+
type: "boolean",
|
|
50
|
+
default: false,
|
|
51
|
+
toAttr: (v) => v ? "icon={<TagIcon />}" : null
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
prop: "prefix",
|
|
55
|
+
type: "select",
|
|
56
|
+
options: [
|
|
57
|
+
"none",
|
|
58
|
+
"£",
|
|
59
|
+
"https://"
|
|
60
|
+
],
|
|
61
|
+
default: "none",
|
|
62
|
+
toAttr: (v) => v === "none" ? null : `prefix="${v}"`
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
prop: "suffix",
|
|
66
|
+
type: "select",
|
|
67
|
+
options: [
|
|
68
|
+
"none",
|
|
69
|
+
"kg",
|
|
70
|
+
"GBP"
|
|
71
|
+
],
|
|
72
|
+
default: "none",
|
|
73
|
+
toAttr: (v) => v === "none" ? null : `suffix="${v}"`
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
prop: "invalid",
|
|
77
|
+
type: "boolean",
|
|
78
|
+
default: false
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
prop: "readOnly",
|
|
82
|
+
type: "boolean",
|
|
83
|
+
default: false
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
prop: "disabled",
|
|
87
|
+
type: "boolean",
|
|
88
|
+
default: false
|
|
89
|
+
}
|
|
90
|
+
];
|
|
91
|
+
function CopyAddress() {
|
|
92
|
+
const [copied, setCopied] = useState(false);
|
|
93
|
+
const address = "harbourdesk.co.uk";
|
|
94
|
+
return /* @__PURE__ */ jsx(Input, {
|
|
95
|
+
readOnly: true,
|
|
96
|
+
"aria-label": "Store address",
|
|
97
|
+
value: address,
|
|
98
|
+
suffix: /* @__PURE__ */ jsx(Tooltip, {
|
|
99
|
+
content: "Copy address",
|
|
100
|
+
children: /* @__PURE__ */ jsx(IconButton, {
|
|
101
|
+
label: "Copy address",
|
|
102
|
+
size: "xs",
|
|
103
|
+
onClick: () => {
|
|
104
|
+
navigator.clipboard?.writeText(address);
|
|
105
|
+
setCopied(true);
|
|
106
|
+
window.setTimeout(() => setCopied(false), 1400);
|
|
107
|
+
},
|
|
108
|
+
children: copied ? /* @__PURE__ */ jsx(CheckIcon, {}) : /* @__PURE__ */ jsx(CopySimpleIcon, {})
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
var EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
114
|
+
function InviteForm() {
|
|
115
|
+
const [email, setEmail] = useState("priya@harbourdesk");
|
|
116
|
+
const [error, setError] = useState();
|
|
117
|
+
const [sentTo, setSentTo] = useState();
|
|
118
|
+
const ref = useRef(null);
|
|
119
|
+
const sendInvite = (event) => {
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
const value = email.trim();
|
|
122
|
+
const problem = !value ? "Enter their email address" : !EMAIL.test(value) ? "Enter an email address in the correct format, like name@example.com" : void 0;
|
|
123
|
+
setError(problem);
|
|
124
|
+
setSentTo(problem ? void 0 : value);
|
|
125
|
+
if (problem) ref.current?.focus();
|
|
126
|
+
};
|
|
127
|
+
return /* @__PURE__ */ jsxs("form", {
|
|
128
|
+
noValidate: true,
|
|
129
|
+
onSubmit: sendInvite,
|
|
130
|
+
className: "input-invite",
|
|
131
|
+
children: [/* @__PURE__ */ jsx(Field, {
|
|
132
|
+
label: "Staff email",
|
|
133
|
+
hint: "We will email them a link to join your store.",
|
|
134
|
+
error,
|
|
135
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
136
|
+
ref,
|
|
137
|
+
type: "email",
|
|
138
|
+
icon: /* @__PURE__ */ jsx(EnvelopeSimpleIcon, {}),
|
|
139
|
+
value: email,
|
|
140
|
+
onChange: (e) => {
|
|
141
|
+
setEmail(e.target.value);
|
|
142
|
+
setError(void 0);
|
|
143
|
+
setSentTo(void 0);
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
147
|
+
className: "input-invite__footer",
|
|
148
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
149
|
+
role: "status",
|
|
150
|
+
className: "input-status",
|
|
151
|
+
children: sentTo ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
152
|
+
/* @__PURE__ */ jsx(CheckCircleIcon, {
|
|
153
|
+
weight: "fill",
|
|
154
|
+
"aria-hidden": "true"
|
|
155
|
+
}),
|
|
156
|
+
"Invite sent to ",
|
|
157
|
+
sentTo
|
|
158
|
+
] }) : null
|
|
159
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
160
|
+
type: "submit",
|
|
161
|
+
variant: "primary",
|
|
162
|
+
children: "Send invite"
|
|
163
|
+
})]
|
|
164
|
+
})]
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
var MONEY = /^\d+(\.\d{1,2})?$/;
|
|
168
|
+
function checkProduct(v) {
|
|
169
|
+
const errors = {};
|
|
170
|
+
if (!v.price.trim()) errors.price = "Enter a price";
|
|
171
|
+
else if (!MONEY.test(v.price.trim())) errors.price = "Enter a price in pounds and pence, like 18.00";
|
|
172
|
+
if (v.compareAt.trim()) {
|
|
173
|
+
if (!MONEY.test(v.compareAt.trim())) errors.compareAt = "Enter an amount in pounds and pence, like 24.00";
|
|
174
|
+
else if (!errors.price && Number(v.compareAt) <= Number(v.price)) errors.compareAt = "Make it higher than the price, or leave it empty";
|
|
175
|
+
}
|
|
176
|
+
if (v.cost.trim() && !MONEY.test(v.cost.trim())) errors.cost = "Enter a cost in pounds and pence, like 9.40";
|
|
177
|
+
if (!v.sku.trim()) errors.sku = "Enter a SKU, like ARD-CHR-BLK";
|
|
178
|
+
else if (!/^[A-Za-z0-9-]+$/.test(v.sku.trim())) errors.sku = "Use letters, numbers and dashes only";
|
|
179
|
+
if (v.barcode.trim() && !/^\d{8,14}$/.test(v.barcode.trim())) errors.barcode = "Enter the 8 to 14 digits under the barcode";
|
|
180
|
+
if (!v.weight.trim() || !/^\d+(\.\d+)?$/.test(v.weight.trim())) errors.weight = "Enter a weight in kilograms, like 12.5";
|
|
181
|
+
return errors;
|
|
182
|
+
}
|
|
183
|
+
var ORDER = [
|
|
184
|
+
"price",
|
|
185
|
+
"compareAt",
|
|
186
|
+
"cost",
|
|
187
|
+
"sku",
|
|
188
|
+
"barcode",
|
|
189
|
+
"weight"
|
|
190
|
+
];
|
|
191
|
+
function ProductForm() {
|
|
192
|
+
const [values, setValues] = useState({
|
|
193
|
+
price: "249.00",
|
|
194
|
+
compareAt: "",
|
|
195
|
+
cost: "118.50",
|
|
196
|
+
sku: "",
|
|
197
|
+
barcode: "",
|
|
198
|
+
weight: "14.2"
|
|
199
|
+
});
|
|
200
|
+
const [errors, setErrors] = useState({});
|
|
201
|
+
const [saving, setSaving] = useState(false);
|
|
202
|
+
const [saved, setSaved] = useState(false);
|
|
203
|
+
const refs = useRef({});
|
|
204
|
+
const bind = (key) => ({
|
|
205
|
+
ref: (el) => {
|
|
206
|
+
refs.current[key] = el;
|
|
207
|
+
},
|
|
208
|
+
value: values[key],
|
|
209
|
+
onChange: (e) => {
|
|
210
|
+
setValues((v) => ({
|
|
211
|
+
...v,
|
|
212
|
+
[key]: e.target.value
|
|
213
|
+
}));
|
|
214
|
+
setErrors((x) => ({
|
|
215
|
+
...x,
|
|
216
|
+
[key]: void 0
|
|
217
|
+
}));
|
|
218
|
+
setSaved(false);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
const save = (event) => {
|
|
222
|
+
event.preventDefault();
|
|
223
|
+
const found = checkProduct(values);
|
|
224
|
+
setErrors(found);
|
|
225
|
+
const first = ORDER.find((k) => found[k]);
|
|
226
|
+
if (first) {
|
|
227
|
+
setSaved(false);
|
|
228
|
+
refs.current[first]?.focus();
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
setSaving(true);
|
|
232
|
+
window.setTimeout(() => {
|
|
233
|
+
setSaving(false);
|
|
234
|
+
setSaved(true);
|
|
235
|
+
}, 900);
|
|
236
|
+
};
|
|
237
|
+
return /* @__PURE__ */ jsxs("form", {
|
|
238
|
+
noValidate: true,
|
|
239
|
+
onSubmit: save,
|
|
240
|
+
className: "input-form",
|
|
241
|
+
children: [
|
|
242
|
+
/* @__PURE__ */ jsxs("fieldset", {
|
|
243
|
+
className: "input-form__group",
|
|
244
|
+
children: [/* @__PURE__ */ jsx("legend", {
|
|
245
|
+
className: "input-form__legend",
|
|
246
|
+
children: "Pricing"
|
|
247
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
248
|
+
className: "input-form__grid",
|
|
249
|
+
children: [
|
|
250
|
+
/* @__PURE__ */ jsx(Field, {
|
|
251
|
+
label: "Price",
|
|
252
|
+
hint: "Includes VAT at 20%",
|
|
253
|
+
error: errors.price,
|
|
254
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
255
|
+
required: true,
|
|
256
|
+
prefix: "£",
|
|
257
|
+
inputMode: "decimal",
|
|
258
|
+
placeholder: "0.00",
|
|
259
|
+
...bind("price")
|
|
260
|
+
})
|
|
261
|
+
}),
|
|
262
|
+
/* @__PURE__ */ jsx(Field, {
|
|
263
|
+
label: "Compare-at price (optional)",
|
|
264
|
+
hint: "Shown crossed out beside the price",
|
|
265
|
+
error: errors.compareAt,
|
|
266
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
267
|
+
prefix: "£",
|
|
268
|
+
inputMode: "decimal",
|
|
269
|
+
placeholder: "0.00",
|
|
270
|
+
...bind("compareAt")
|
|
271
|
+
})
|
|
272
|
+
}),
|
|
273
|
+
/* @__PURE__ */ jsx(Field, {
|
|
274
|
+
label: "Cost per item (optional)",
|
|
275
|
+
hint: "Customers will not see this",
|
|
276
|
+
error: errors.cost,
|
|
277
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
278
|
+
prefix: "£",
|
|
279
|
+
inputMode: "decimal",
|
|
280
|
+
placeholder: "0.00",
|
|
281
|
+
...bind("cost")
|
|
282
|
+
})
|
|
283
|
+
})
|
|
284
|
+
]
|
|
285
|
+
})]
|
|
286
|
+
}),
|
|
287
|
+
/* @__PURE__ */ jsxs("fieldset", {
|
|
288
|
+
className: "input-form__group",
|
|
289
|
+
children: [/* @__PURE__ */ jsx("legend", {
|
|
290
|
+
className: "input-form__legend",
|
|
291
|
+
children: "Inventory and delivery"
|
|
292
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
293
|
+
className: "input-form__grid",
|
|
294
|
+
children: [
|
|
295
|
+
/* @__PURE__ */ jsx(Field, {
|
|
296
|
+
label: "SKU",
|
|
297
|
+
hint: "Letters, numbers and dashes",
|
|
298
|
+
error: errors.sku,
|
|
299
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
300
|
+
required: true,
|
|
301
|
+
icon: /* @__PURE__ */ jsx(TagIcon, {}),
|
|
302
|
+
placeholder: "e.g. ARD-CHR-BLK",
|
|
303
|
+
...bind("sku")
|
|
304
|
+
})
|
|
305
|
+
}),
|
|
306
|
+
/* @__PURE__ */ jsx(Field, {
|
|
307
|
+
label: "Barcode (optional)",
|
|
308
|
+
hint: "GTIN, EAN or UPC",
|
|
309
|
+
error: errors.barcode,
|
|
310
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
311
|
+
inputMode: "numeric",
|
|
312
|
+
...bind("barcode")
|
|
313
|
+
})
|
|
314
|
+
}),
|
|
315
|
+
/* @__PURE__ */ jsx(Field, {
|
|
316
|
+
label: "Weight",
|
|
317
|
+
hint: "Used to work out delivery rates",
|
|
318
|
+
error: errors.weight,
|
|
319
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
320
|
+
required: true,
|
|
321
|
+
suffix: "kg",
|
|
322
|
+
inputMode: "decimal",
|
|
323
|
+
...bind("weight")
|
|
324
|
+
})
|
|
325
|
+
})
|
|
326
|
+
]
|
|
327
|
+
})]
|
|
328
|
+
}),
|
|
329
|
+
/* @__PURE__ */ jsxs("div", {
|
|
330
|
+
className: "input-form__footer",
|
|
331
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
332
|
+
role: "status",
|
|
333
|
+
className: "input-status",
|
|
334
|
+
children: saved ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(CheckCircleIcon, {
|
|
335
|
+
weight: "fill",
|
|
336
|
+
"aria-hidden": "true"
|
|
337
|
+
}), "Arden ergonomic chair saved"] }) : null
|
|
338
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
339
|
+
type: "submit",
|
|
340
|
+
variant: "primary",
|
|
341
|
+
loading: saving,
|
|
342
|
+
children: "Save product"
|
|
343
|
+
})]
|
|
344
|
+
})
|
|
345
|
+
]
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
/** A custom control: a textarea that picks up the Field's wiring. */
|
|
349
|
+
function DescriptionBox(props) {
|
|
350
|
+
const field = useFieldControl();
|
|
351
|
+
return /* @__PURE__ */ jsx("textarea", {
|
|
352
|
+
id: field?.id,
|
|
353
|
+
"aria-describedby": field?.describedBy,
|
|
354
|
+
"aria-invalid": field?.invalid || void 0,
|
|
355
|
+
className: "input-textarea",
|
|
356
|
+
...props
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
var LIMIT = 160;
|
|
360
|
+
function SearchDescription() {
|
|
361
|
+
const [text, setText] = useState("The Arden ergonomic chair in black mesh, with adjustable lumbar support and 4D arms. Free UK delivery on orders over £50.");
|
|
362
|
+
const over = text.length > LIMIT;
|
|
363
|
+
return /* @__PURE__ */ jsx("div", {
|
|
364
|
+
className: "input-stack",
|
|
365
|
+
children: /* @__PURE__ */ jsx(Field, {
|
|
366
|
+
label: "Search engine description",
|
|
367
|
+
hint: `${text.length} of ${LIMIT} characters. Shown under the page title in search results.`,
|
|
368
|
+
error: over ? `Shorten it to ${LIMIT} characters or fewer, so search engines show all of it` : void 0,
|
|
369
|
+
children: /* @__PURE__ */ jsx(DescriptionBox, {
|
|
370
|
+
rows: 4,
|
|
371
|
+
value: text,
|
|
372
|
+
onChange: (e) => setText(e.target.value)
|
|
373
|
+
})
|
|
374
|
+
})
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
function Page() {
|
|
378
|
+
return /* @__PURE__ */ jsxs(DocPage, {
|
|
379
|
+
title: "Input and field",
|
|
380
|
+
status: "stable",
|
|
381
|
+
importNames: [
|
|
382
|
+
"Input",
|
|
383
|
+
"Field",
|
|
384
|
+
"useFieldControl"
|
|
385
|
+
],
|
|
386
|
+
lead: "Input is the single-line text field, for names, prices, SKUs and anything else typed on one line. Field gives a control its label, a hint and an error, and wires them together for screen readers.",
|
|
387
|
+
children: [
|
|
388
|
+
/* @__PURE__ */ jsx(Section, {
|
|
389
|
+
id: "playground",
|
|
390
|
+
title: "Playground",
|
|
391
|
+
description: /* @__PURE__ */ jsx("p", { children: "Change the props, then click into the field to see the teal focus edge and its halo." }),
|
|
392
|
+
children: /* @__PURE__ */ jsx(Playground, {
|
|
393
|
+
component: "Input",
|
|
394
|
+
controls: PLAYGROUND,
|
|
395
|
+
render: (v) => /* @__PURE__ */ jsx("div", {
|
|
396
|
+
className: "input-stage",
|
|
397
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
398
|
+
"aria-label": String(v["aria-label"]),
|
|
399
|
+
placeholder: String(v.placeholder),
|
|
400
|
+
size: v.size,
|
|
401
|
+
icon: v.icon ? /* @__PURE__ */ jsx(TagIcon, {}) : void 0,
|
|
402
|
+
prefix: v.prefix === "none" ? void 0 : String(v.prefix),
|
|
403
|
+
suffix: v.suffix === "none" ? void 0 : String(v.suffix),
|
|
404
|
+
invalid: Boolean(v.invalid),
|
|
405
|
+
readOnly: Boolean(v.readOnly),
|
|
406
|
+
disabled: Boolean(v.disabled)
|
|
407
|
+
})
|
|
408
|
+
})
|
|
409
|
+
})
|
|
410
|
+
}),
|
|
411
|
+
/* @__PURE__ */ jsxs(Section, {
|
|
412
|
+
id: "field",
|
|
413
|
+
title: "With a field",
|
|
414
|
+
description: /* @__PURE__ */ jsxs("p", { children: [
|
|
415
|
+
"Put one control inside a ",
|
|
416
|
+
/* @__PURE__ */ jsx("code", { children: "Field" }),
|
|
417
|
+
" to give it a label above and a hint below. The label points at the control, so clicking it focuses the field, and the hint becomes the control's description. Every field needs a label; an Input on its own needs an ",
|
|
418
|
+
/* @__PURE__ */ jsx("code", { children: "aria-label" }),
|
|
419
|
+
"."
|
|
420
|
+
] }),
|
|
421
|
+
children: [/* @__PURE__ */ jsx(Example, {
|
|
422
|
+
code: `
|
|
423
|
+
<Field label="Product title" hint="Shown on the product page and in search results.">
|
|
424
|
+
<Input placeholder="e.g. Arden ergonomic chair" />
|
|
425
|
+
</Field>`,
|
|
426
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
427
|
+
className: "input-stack",
|
|
428
|
+
children: /* @__PURE__ */ jsx(Field, {
|
|
429
|
+
label: "Product title",
|
|
430
|
+
hint: "Shown on the product page and in search results.",
|
|
431
|
+
children: /* @__PURE__ */ jsx(Input, { placeholder: "e.g. Arden ergonomic chair" })
|
|
432
|
+
})
|
|
433
|
+
})
|
|
434
|
+
}), /* @__PURE__ */ jsx(DocTable, {
|
|
435
|
+
columns: ["Part", "What it does"],
|
|
436
|
+
rows: [
|
|
437
|
+
["Label", "13px at 550, 7px above the control. Always visible, in sentence case."],
|
|
438
|
+
["Control", "An Input, a SearchField, or your own control reading useFieldControl."],
|
|
439
|
+
["Hint", "12.5px in quiet slate: what to enter, or how it is used. Hidden while there is an error."],
|
|
440
|
+
["Error", "12.5px in red with an icon: what is wrong and how to fix it. Replaces the hint and marks the control invalid."]
|
|
441
|
+
]
|
|
442
|
+
})]
|
|
443
|
+
}),
|
|
444
|
+
/* @__PURE__ */ jsx(Section, {
|
|
445
|
+
id: "sizes",
|
|
446
|
+
title: "Sizes",
|
|
447
|
+
description: /* @__PURE__ */ jsxs("p", { children: [
|
|
448
|
+
/* @__PURE__ */ jsx("code", { children: "sm" }),
|
|
449
|
+
" 30px, ",
|
|
450
|
+
/* @__PURE__ */ jsx("code", { children: "md" }),
|
|
451
|
+
" 36px (default) and ",
|
|
452
|
+
/* @__PURE__ */ jsx("code", { children: "lg" }),
|
|
453
|
+
" 44px: the same heights as buttons, so a field and its button share a line. Text is 13, 14 and 15px; icons are 15, 16 and 18px."
|
|
454
|
+
] }),
|
|
455
|
+
children: /* @__PURE__ */ jsx(Example, {
|
|
456
|
+
code: `
|
|
457
|
+
<Input size="sm" aria-label="Discount code" placeholder="Discount code" />
|
|
458
|
+
<Button size="sm">Apply</Button>
|
|
459
|
+
|
|
460
|
+
<Input aria-label="Discount code" placeholder="Discount code" />
|
|
461
|
+
<Button>Apply</Button>
|
|
462
|
+
|
|
463
|
+
<Input size="lg" aria-label="Discount code" placeholder="Discount code" />
|
|
464
|
+
<Button size="lg">Apply</Button>`,
|
|
465
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
466
|
+
className: "input-sizes",
|
|
467
|
+
children: [
|
|
468
|
+
/* @__PURE__ */ jsxs("div", {
|
|
469
|
+
className: "input-sizes__row",
|
|
470
|
+
children: [/* @__PURE__ */ jsx(Input, {
|
|
471
|
+
size: "sm",
|
|
472
|
+
"aria-label": "Discount code",
|
|
473
|
+
placeholder: "Discount code"
|
|
474
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
475
|
+
size: "sm",
|
|
476
|
+
children: "Apply"
|
|
477
|
+
})]
|
|
478
|
+
}),
|
|
479
|
+
/* @__PURE__ */ jsxs("div", {
|
|
480
|
+
className: "input-sizes__row",
|
|
481
|
+
children: [/* @__PURE__ */ jsx(Input, {
|
|
482
|
+
"aria-label": "Discount code",
|
|
483
|
+
placeholder: "Discount code"
|
|
484
|
+
}), /* @__PURE__ */ jsx(Button, { children: "Apply" })]
|
|
485
|
+
}),
|
|
486
|
+
/* @__PURE__ */ jsxs("div", {
|
|
487
|
+
className: "input-sizes__row",
|
|
488
|
+
children: [/* @__PURE__ */ jsx(Input, {
|
|
489
|
+
size: "lg",
|
|
490
|
+
"aria-label": "Discount code",
|
|
491
|
+
placeholder: "Discount code"
|
|
492
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
493
|
+
size: "lg",
|
|
494
|
+
children: "Apply"
|
|
495
|
+
})]
|
|
496
|
+
})
|
|
497
|
+
]
|
|
498
|
+
})
|
|
499
|
+
})
|
|
500
|
+
}),
|
|
501
|
+
/* @__PURE__ */ jsx(Section, {
|
|
502
|
+
id: "adornments",
|
|
503
|
+
title: "Icon, prefix and suffix",
|
|
504
|
+
description: /* @__PURE__ */ jsxs("p", { children: [
|
|
505
|
+
/* @__PURE__ */ jsx("code", { children: "icon" }),
|
|
506
|
+
" leads, muted until the field has focus. ",
|
|
507
|
+
/* @__PURE__ */ jsx("code", { children: "prefix" }),
|
|
508
|
+
" is text set tight against the value, so a price reads £18.00, never £ 18.00. ",
|
|
509
|
+
/* @__PURE__ */ jsx("code", { children: "suffix" }),
|
|
510
|
+
" trails: a unit, a status or a small button. Clicking the icon, the prefix or the padding focuses the input; a button in the suffix keeps its own click."
|
|
511
|
+
] }),
|
|
512
|
+
children: /* @__PURE__ */ jsx(Example, {
|
|
513
|
+
align: "fill",
|
|
514
|
+
code: `
|
|
515
|
+
<Input type="email" icon={<EnvelopeSimpleIcon />} aria-label="Email" placeholder="name@example.com" />
|
|
516
|
+
<Input prefix="£" inputMode="decimal" aria-label="Price" defaultValue="18.00" />
|
|
517
|
+
<Input prefix="https://" aria-label="Website" defaultValue="harbourdesk.co.uk" />
|
|
518
|
+
<Input suffix="kg" inputMode="decimal" aria-label="Weight" defaultValue="14.2" />
|
|
519
|
+
<Input
|
|
520
|
+
readOnly
|
|
521
|
+
aria-label="Store address"
|
|
522
|
+
value="harbourdesk.co.uk"
|
|
523
|
+
suffix={
|
|
524
|
+
<Tooltip content="Copy address">
|
|
525
|
+
<IconButton label="Copy address" size="xs" onClick={copy}><CopySimpleIcon /></IconButton>
|
|
526
|
+
</Tooltip>
|
|
527
|
+
}
|
|
528
|
+
/>`,
|
|
529
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
530
|
+
className: "input-grid",
|
|
531
|
+
children: [
|
|
532
|
+
/* @__PURE__ */ jsx(Input, {
|
|
533
|
+
type: "email",
|
|
534
|
+
icon: /* @__PURE__ */ jsx(EnvelopeSimpleIcon, {}),
|
|
535
|
+
"aria-label": "Email",
|
|
536
|
+
placeholder: "name@example.com"
|
|
537
|
+
}),
|
|
538
|
+
/* @__PURE__ */ jsx(Input, {
|
|
539
|
+
prefix: "£",
|
|
540
|
+
inputMode: "decimal",
|
|
541
|
+
"aria-label": "Price",
|
|
542
|
+
defaultValue: "18.00"
|
|
543
|
+
}),
|
|
544
|
+
/* @__PURE__ */ jsx(Input, {
|
|
545
|
+
prefix: "https://",
|
|
546
|
+
"aria-label": "Website",
|
|
547
|
+
defaultValue: "harbourdesk.co.uk"
|
|
548
|
+
}),
|
|
549
|
+
/* @__PURE__ */ jsx(Input, {
|
|
550
|
+
suffix: "kg",
|
|
551
|
+
inputMode: "decimal",
|
|
552
|
+
"aria-label": "Weight",
|
|
553
|
+
defaultValue: "14.2"
|
|
554
|
+
}),
|
|
555
|
+
/* @__PURE__ */ jsx(CopyAddress, {})
|
|
556
|
+
]
|
|
557
|
+
})
|
|
558
|
+
})
|
|
559
|
+
}),
|
|
560
|
+
/* @__PURE__ */ jsxs(Section, {
|
|
561
|
+
id: "states",
|
|
562
|
+
title: "States",
|
|
563
|
+
description: /* @__PURE__ */ jsx("p", { children: "Hover firms the hairline. Focus turns it teal and grows a soft 3px halo: click into any field to see it. An error swaps the teal for red. Read-only and disabled fields sink into the well." }),
|
|
564
|
+
children: [/* @__PURE__ */ jsx(Example, {
|
|
565
|
+
align: "fill",
|
|
566
|
+
code: `
|
|
567
|
+
<Field label="Product title">
|
|
568
|
+
<Input placeholder="e.g. Arden ergonomic chair" />
|
|
569
|
+
</Field>
|
|
570
|
+
<Field label="Product title">
|
|
571
|
+
<Input defaultValue="Arden ergonomic chair" />
|
|
572
|
+
</Field>
|
|
573
|
+
<Field label="Customer email" error="Enter an email address in the correct format, like name@example.com">
|
|
574
|
+
<Input type="email" defaultValue="priya@harbourdesk" />
|
|
575
|
+
</Field>
|
|
576
|
+
<Field label="Order number" hint="Set when the order was placed">
|
|
577
|
+
<Input readOnly value="#1042" />
|
|
578
|
+
</Field>
|
|
579
|
+
<Field label="Sale price" hint="Turn on Put on sale to set a sale price">
|
|
580
|
+
<Input disabled prefix="£" placeholder="0.00" />
|
|
581
|
+
</Field>`,
|
|
582
|
+
caption: "Empty, filled, invalid, read-only and disabled.",
|
|
583
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
584
|
+
className: "input-grid",
|
|
585
|
+
children: [
|
|
586
|
+
/* @__PURE__ */ jsx(Field, {
|
|
587
|
+
label: "Product title",
|
|
588
|
+
children: /* @__PURE__ */ jsx(Input, { placeholder: "e.g. Arden ergonomic chair" })
|
|
589
|
+
}),
|
|
590
|
+
/* @__PURE__ */ jsx(Field, {
|
|
591
|
+
label: "Product title",
|
|
592
|
+
children: /* @__PURE__ */ jsx(Input, { defaultValue: "Arden ergonomic chair" })
|
|
593
|
+
}),
|
|
594
|
+
/* @__PURE__ */ jsx(Field, {
|
|
595
|
+
label: "Customer email",
|
|
596
|
+
error: "Enter an email address in the correct format, like name@example.com",
|
|
597
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
598
|
+
type: "email",
|
|
599
|
+
defaultValue: "priya@harbourdesk"
|
|
600
|
+
})
|
|
601
|
+
}),
|
|
602
|
+
/* @__PURE__ */ jsx(Field, {
|
|
603
|
+
label: "Order number",
|
|
604
|
+
hint: "Set when the order was placed",
|
|
605
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
606
|
+
readOnly: true,
|
|
607
|
+
value: "#1042"
|
|
608
|
+
})
|
|
609
|
+
}),
|
|
610
|
+
/* @__PURE__ */ jsx(Field, {
|
|
611
|
+
label: "Sale price",
|
|
612
|
+
hint: "Turn on Put on sale to set a sale price",
|
|
613
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
614
|
+
disabled: true,
|
|
615
|
+
prefix: "£",
|
|
616
|
+
placeholder: "0.00"
|
|
617
|
+
})
|
|
618
|
+
})
|
|
619
|
+
]
|
|
620
|
+
})
|
|
621
|
+
}), /* @__PURE__ */ jsx(SubSection, {
|
|
622
|
+
title: "Read-only or disabled?",
|
|
623
|
+
children: /* @__PURE__ */ jsx(DocTable, {
|
|
624
|
+
columns: [
|
|
625
|
+
"Behaviour",
|
|
626
|
+
"Read-only",
|
|
627
|
+
"Disabled"
|
|
628
|
+
],
|
|
629
|
+
rows: [
|
|
630
|
+
[
|
|
631
|
+
"Focus and copy",
|
|
632
|
+
"Yes: it can be tabbed to, selected and copied.",
|
|
633
|
+
"No: Tab skips it."
|
|
634
|
+
],
|
|
635
|
+
[
|
|
636
|
+
"Sent with the form",
|
|
637
|
+
"Yes",
|
|
638
|
+
"No"
|
|
639
|
+
],
|
|
640
|
+
[
|
|
641
|
+
"Use it for",
|
|
642
|
+
"Values people can see but not change here: an order number, a store address.",
|
|
643
|
+
"A field that is off because of another setting. Say which one nearby."
|
|
644
|
+
]
|
|
645
|
+
]
|
|
646
|
+
})
|
|
647
|
+
})]
|
|
648
|
+
}),
|
|
649
|
+
/* @__PURE__ */ jsx(Section, {
|
|
650
|
+
id: "errors",
|
|
651
|
+
title: "Hints and errors",
|
|
652
|
+
description: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("p", { children: [
|
|
653
|
+
"A hint says what to enter or how it will be used. An error says what is wrong and how to fix it: it replaces the hint, turns the edge red, sets ",
|
|
654
|
+
/* @__PURE__ */ jsx("code", { children: "aria-invalid" }),
|
|
655
|
+
" on the control and settles 3px down into place."
|
|
656
|
+
] }), /* @__PURE__ */ jsx("p", { children: "Check when the form is sent, not on every keystroke, and clear the error as soon as the person starts fixing it. Press Send invite to try it." })] }),
|
|
657
|
+
children: /* @__PURE__ */ jsx(Example, {
|
|
658
|
+
code: `
|
|
659
|
+
const [email, setEmail] = useState('priya@harbourdesk')
|
|
660
|
+
const [error, setError] = useState<string>()
|
|
661
|
+
|
|
662
|
+
<form noValidate onSubmit={sendInvite}>
|
|
663
|
+
<Field label="Staff email" hint="We will email them a link to join your store." error={error}>
|
|
664
|
+
<Input
|
|
665
|
+
type="email"
|
|
666
|
+
icon={<EnvelopeSimpleIcon />}
|
|
667
|
+
value={email}
|
|
668
|
+
onChange={(e) => {
|
|
669
|
+
setEmail(e.target.value)
|
|
670
|
+
setError(undefined)
|
|
671
|
+
}}
|
|
672
|
+
/>
|
|
673
|
+
</Field>
|
|
674
|
+
<Button type="submit" variant="primary">Send invite</Button>
|
|
675
|
+
</form>`,
|
|
676
|
+
children: /* @__PURE__ */ jsx(InviteForm, {})
|
|
677
|
+
})
|
|
678
|
+
}),
|
|
679
|
+
/* @__PURE__ */ jsxs(Section, {
|
|
680
|
+
id: "required",
|
|
681
|
+
title: "Required and optional",
|
|
682
|
+
description: /* @__PURE__ */ jsxs("p", { children: [
|
|
683
|
+
"Field has no required prop and draws no asterisk. Pass ",
|
|
684
|
+
/* @__PURE__ */ jsx("code", { children: "required" }),
|
|
685
|
+
" to the control: it reaches the native input, so screen readers announce the field as required. Most fields in a form should be required, so mark the few that are not by ending their label with \"(optional)\"."
|
|
686
|
+
] }),
|
|
687
|
+
children: [/* @__PURE__ */ jsx(Example, {
|
|
688
|
+
code: `
|
|
689
|
+
<Field label="SKU" hint="Letters, numbers and dashes">
|
|
690
|
+
<Input required placeholder="e.g. ARD-CHR-BLK" />
|
|
691
|
+
</Field>
|
|
692
|
+
<Field label="Barcode (optional)" hint="GTIN, EAN or UPC">
|
|
693
|
+
<Input inputMode="numeric" />
|
|
694
|
+
</Field>`,
|
|
695
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
696
|
+
className: "input-stack",
|
|
697
|
+
children: [/* @__PURE__ */ jsx(Field, {
|
|
698
|
+
label: "SKU",
|
|
699
|
+
hint: "Letters, numbers and dashes",
|
|
700
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
701
|
+
required: true,
|
|
702
|
+
placeholder: "e.g. ARD-CHR-BLK"
|
|
703
|
+
})
|
|
704
|
+
}), /* @__PURE__ */ jsx(Field, {
|
|
705
|
+
label: "Barcode (optional)",
|
|
706
|
+
hint: "GTIN, EAN or UPC",
|
|
707
|
+
children: /* @__PURE__ */ jsx(Input, { inputMode: "numeric" })
|
|
708
|
+
})]
|
|
709
|
+
})
|
|
710
|
+
}), /* @__PURE__ */ jsxs(Note, { children: [
|
|
711
|
+
"With ",
|
|
712
|
+
/* @__PURE__ */ jsx("code", { children: "required" }),
|
|
713
|
+
" set, the browser shows its own message on submit unless the form has",
|
|
714
|
+
" ",
|
|
715
|
+
/* @__PURE__ */ jsx("code", { children: "noValidate" }),
|
|
716
|
+
". Set it, check the values yourself and show the problem with ",
|
|
717
|
+
/* @__PURE__ */ jsx("code", { children: "error" }),
|
|
718
|
+
", as the examples on this page do."
|
|
719
|
+
] })]
|
|
720
|
+
}),
|
|
721
|
+
/* @__PURE__ */ jsx(Section, {
|
|
722
|
+
id: "form",
|
|
723
|
+
title: "In a form",
|
|
724
|
+
description: /* @__PURE__ */ jsx("p", { children: "Pricing and inventory for a product. Fields sit two to a row on wide screens and stack on phones. Press Save product while the SKU is empty: every problem shows at once and focus moves to the first one, so a screen reader reads its error straight away." }),
|
|
725
|
+
children: /* @__PURE__ */ jsx(Example, {
|
|
726
|
+
align: "fill",
|
|
727
|
+
code: `
|
|
728
|
+
<form noValidate onSubmit={save}>
|
|
729
|
+
<fieldset>
|
|
730
|
+
<legend>Pricing</legend>
|
|
731
|
+
<Field label="Price" hint="Includes VAT at 20%" error={errors.price}>
|
|
732
|
+
<Input required prefix="£" inputMode="decimal" placeholder="0.00" value={price} onChange={...} />
|
|
733
|
+
</Field>
|
|
734
|
+
<Field label="Compare-at price (optional)" hint="Shown crossed out beside the price" error={errors.compareAt}>
|
|
735
|
+
<Input prefix="£" inputMode="decimal" placeholder="0.00" value={compareAt} onChange={...} />
|
|
736
|
+
</Field>
|
|
737
|
+
{/* Cost per item follows the same pattern */}
|
|
738
|
+
</fieldset>
|
|
739
|
+
<fieldset>
|
|
740
|
+
<legend>Inventory and delivery</legend>
|
|
741
|
+
<Field label="SKU" hint="Letters, numbers and dashes" error={errors.sku}>
|
|
742
|
+
<Input required icon={<TagIcon />} placeholder="e.g. ARD-CHR-BLK" value={sku} onChange={...} />
|
|
743
|
+
</Field>
|
|
744
|
+
{/* Barcode (optional) and Weight, with suffix="kg" */}
|
|
745
|
+
</fieldset>
|
|
746
|
+
<Button type="submit" variant="primary" loading={saving}>Save product</Button>
|
|
747
|
+
</form>`,
|
|
748
|
+
children: /* @__PURE__ */ jsx(ProductForm, {})
|
|
749
|
+
})
|
|
750
|
+
}),
|
|
751
|
+
/* @__PURE__ */ jsxs(Section, {
|
|
752
|
+
id: "custom-controls",
|
|
753
|
+
title: "Custom controls",
|
|
754
|
+
description: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("p", { children: [
|
|
755
|
+
"Field works with any single control. Input and SearchField pick up its wiring on their own; for anything else, call ",
|
|
756
|
+
/* @__PURE__ */ jsx("code", { children: "useFieldControl()" }),
|
|
757
|
+
" inside the control and put the id, description and invalid state on the element that takes focus."
|
|
758
|
+
] }), /* @__PURE__ */ jsx("p", { children: "For a real multi-line field use Textarea, which does this for you. Here a plain textarea, styled for this page, shows the wiring by hand. Type past 160 characters to see the error arrive." })] }),
|
|
759
|
+
children: [
|
|
760
|
+
/* @__PURE__ */ jsx(Example, {
|
|
761
|
+
code: `
|
|
762
|
+
function DescriptionBox(props: TextareaHTMLAttributes<HTMLTextAreaElement>) {
|
|
763
|
+
const field = useFieldControl()
|
|
764
|
+
return (
|
|
765
|
+
<textarea
|
|
766
|
+
id={field?.id}
|
|
767
|
+
aria-describedby={field?.describedBy}
|
|
768
|
+
aria-invalid={field?.invalid || undefined}
|
|
769
|
+
{...props}
|
|
770
|
+
/>
|
|
771
|
+
)
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
<Field
|
|
775
|
+
label="Search engine description"
|
|
776
|
+
hint={\`\${text.length} of 160 characters. Shown under the page title in search results.\`}
|
|
777
|
+
error={text.length > 160 ? 'Shorten it to 160 characters or fewer, so search engines show all of it' : undefined}
|
|
778
|
+
>
|
|
779
|
+
<DescriptionBox rows={4} value={text} onChange={(e) => setText(e.target.value)} />
|
|
780
|
+
</Field>`,
|
|
781
|
+
children: /* @__PURE__ */ jsx(SearchDescription, {})
|
|
782
|
+
}),
|
|
783
|
+
/* @__PURE__ */ jsx(DocTable, {
|
|
784
|
+
columns: [
|
|
785
|
+
"useFieldControl() returns",
|
|
786
|
+
"Type",
|
|
787
|
+
"Put it on"
|
|
788
|
+
],
|
|
789
|
+
rows: [
|
|
790
|
+
[
|
|
791
|
+
/* @__PURE__ */ jsx("code", { children: "id" }),
|
|
792
|
+
/* @__PURE__ */ jsx("code", { children: "string" }),
|
|
793
|
+
"The focusable element, so the label points at it."
|
|
794
|
+
],
|
|
795
|
+
[
|
|
796
|
+
/* @__PURE__ */ jsx("code", { children: "labelId" }),
|
|
797
|
+
/* @__PURE__ */ jsx("code", { children: "string" }),
|
|
798
|
+
/* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
799
|
+
"Its ",
|
|
800
|
+
/* @__PURE__ */ jsx("code", { children: "aria-labelledby" }),
|
|
801
|
+
", when a label element cannot name it (a div with a role)."
|
|
802
|
+
] })
|
|
803
|
+
],
|
|
804
|
+
[
|
|
805
|
+
/* @__PURE__ */ jsx("code", { children: "describedBy" }),
|
|
806
|
+
/* @__PURE__ */ jsx("code", { children: "string | undefined" }),
|
|
807
|
+
/* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
808
|
+
"Its ",
|
|
809
|
+
/* @__PURE__ */ jsx("code", { children: "aria-describedby" }),
|
|
810
|
+
": the id of the hint or the error."
|
|
811
|
+
] })
|
|
812
|
+
],
|
|
813
|
+
[
|
|
814
|
+
/* @__PURE__ */ jsx("code", { children: "invalid" }),
|
|
815
|
+
/* @__PURE__ */ jsx("code", { children: "boolean" }),
|
|
816
|
+
/* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
817
|
+
"Its ",
|
|
818
|
+
/* @__PURE__ */ jsx("code", { children: "aria-invalid" }),
|
|
819
|
+
", and your own error styling."
|
|
820
|
+
] })
|
|
821
|
+
]
|
|
822
|
+
]
|
|
823
|
+
}),
|
|
824
|
+
/* @__PURE__ */ jsxs(Note, { children: [
|
|
825
|
+
"The hook returns ",
|
|
826
|
+
/* @__PURE__ */ jsx("code", { children: "null" }),
|
|
827
|
+
" outside a Field, so a control that can stand alone should fall back to its own ",
|
|
828
|
+
/* @__PURE__ */ jsx("code", { children: "aria-label" }),
|
|
829
|
+
"."
|
|
830
|
+
] })
|
|
831
|
+
]
|
|
832
|
+
}),
|
|
833
|
+
/* @__PURE__ */ jsx(Section, {
|
|
834
|
+
id: "both-themes",
|
|
835
|
+
title: "In both themes",
|
|
836
|
+
description: /* @__PURE__ */ jsx("p", { children: "A filled field with a prefix, an error and a disabled field, light and dark side by side." }),
|
|
837
|
+
children: /* @__PURE__ */ jsx(ThemePair, {
|
|
838
|
+
align: "fill",
|
|
839
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
840
|
+
className: "input-stack",
|
|
841
|
+
children: [
|
|
842
|
+
/* @__PURE__ */ jsx(Field, {
|
|
843
|
+
label: "Price",
|
|
844
|
+
hint: "Includes VAT at 20%",
|
|
845
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
846
|
+
prefix: "£",
|
|
847
|
+
inputMode: "decimal",
|
|
848
|
+
defaultValue: "249.00"
|
|
849
|
+
})
|
|
850
|
+
}),
|
|
851
|
+
/* @__PURE__ */ jsx(Field, {
|
|
852
|
+
label: "SKU",
|
|
853
|
+
error: "Use letters, numbers and dashes only",
|
|
854
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
855
|
+
icon: /* @__PURE__ */ jsx(TagIcon, {}),
|
|
856
|
+
defaultValue: "ARD CHR/BLK"
|
|
857
|
+
})
|
|
858
|
+
}),
|
|
859
|
+
/* @__PURE__ */ jsx(Field, {
|
|
860
|
+
label: "Sale price",
|
|
861
|
+
hint: "Turn on Put on sale to set a sale price",
|
|
862
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
863
|
+
disabled: true,
|
|
864
|
+
prefix: "£",
|
|
865
|
+
placeholder: "0.00"
|
|
866
|
+
})
|
|
867
|
+
})
|
|
868
|
+
]
|
|
869
|
+
})
|
|
870
|
+
})
|
|
871
|
+
}),
|
|
872
|
+
/* @__PURE__ */ jsxs(Section, {
|
|
873
|
+
id: "guidelines",
|
|
874
|
+
title: "Guidelines",
|
|
875
|
+
children: [
|
|
876
|
+
/* @__PURE__ */ jsx(DoDont, {
|
|
877
|
+
do: {
|
|
878
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
879
|
+
style: {
|
|
880
|
+
width: "100%",
|
|
881
|
+
maxWidth: 260
|
|
882
|
+
},
|
|
883
|
+
children: /* @__PURE__ */ jsx(Field, {
|
|
884
|
+
label: "Product title",
|
|
885
|
+
children: /* @__PURE__ */ jsx(Input, { placeholder: "e.g. Arden ergonomic chair" })
|
|
886
|
+
})
|
|
887
|
+
}),
|
|
888
|
+
caption: "A label that stays put, and a placeholder that only gives an example."
|
|
889
|
+
},
|
|
890
|
+
dont: {
|
|
891
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
892
|
+
style: {
|
|
893
|
+
width: "100%",
|
|
894
|
+
maxWidth: 260
|
|
895
|
+
},
|
|
896
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
897
|
+
"aria-label": "Product title",
|
|
898
|
+
placeholder: "Product title"
|
|
899
|
+
})
|
|
900
|
+
}),
|
|
901
|
+
caption: "A placeholder as the label vanishes as soon as someone types, and it is too faint to rely on."
|
|
902
|
+
}
|
|
903
|
+
}),
|
|
904
|
+
/* @__PURE__ */ jsx(DoDont, {
|
|
905
|
+
do: {
|
|
906
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
907
|
+
style: {
|
|
908
|
+
width: "100%",
|
|
909
|
+
maxWidth: 260
|
|
910
|
+
},
|
|
911
|
+
children: /* @__PURE__ */ jsx(Field, {
|
|
912
|
+
label: "Price",
|
|
913
|
+
error: "Enter a price in pounds and pence, like 18.00",
|
|
914
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
915
|
+
prefix: "£",
|
|
916
|
+
inputMode: "decimal",
|
|
917
|
+
defaultValue: "18.0.0"
|
|
918
|
+
})
|
|
919
|
+
})
|
|
920
|
+
}),
|
|
921
|
+
caption: "Say what went wrong and how to put it right, in the words of the label."
|
|
922
|
+
},
|
|
923
|
+
dont: {
|
|
924
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
925
|
+
style: {
|
|
926
|
+
width: "100%",
|
|
927
|
+
maxWidth: 260
|
|
928
|
+
},
|
|
929
|
+
children: /* @__PURE__ */ jsx(Field, {
|
|
930
|
+
label: "Price",
|
|
931
|
+
error: "Invalid input",
|
|
932
|
+
children: /* @__PURE__ */ jsx(Input, {
|
|
933
|
+
prefix: "£",
|
|
934
|
+
inputMode: "decimal",
|
|
935
|
+
defaultValue: "18.0.0"
|
|
936
|
+
})
|
|
937
|
+
})
|
|
938
|
+
}),
|
|
939
|
+
caption: "\"Invalid input\" tells people they failed without telling them what to do next."
|
|
940
|
+
}
|
|
941
|
+
}),
|
|
942
|
+
/* @__PURE__ */ jsx(Guidelines, { items: [
|
|
943
|
+
"Size the field to the answer: a postcode field is short, a product title long.",
|
|
944
|
+
/* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
945
|
+
"Units go in ",
|
|
946
|
+
/* @__PURE__ */ jsx("code", { children: "prefix" }),
|
|
947
|
+
" or ",
|
|
948
|
+
/* @__PURE__ */ jsx("code", { children: "suffix" }),
|
|
949
|
+
", not the label: \"Price\" with £, not \"Price (£)\"."
|
|
950
|
+
] }),
|
|
951
|
+
/* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
952
|
+
"For money and weights use ",
|
|
953
|
+
/* @__PURE__ */ jsx("code", { children: "inputMode=\"decimal\"" }),
|
|
954
|
+
" rather than ",
|
|
955
|
+
/* @__PURE__ */ jsx("code", { children: "type=\"number\"" }),
|
|
956
|
+
": phones show a number pad, without the spinner arrows or scroll-wheel surprises."
|
|
957
|
+
] }),
|
|
958
|
+
"Labels are nouns in sentence case. Hints are one short sentence, and never repeat the label."
|
|
959
|
+
] })
|
|
960
|
+
]
|
|
961
|
+
}),
|
|
962
|
+
/* @__PURE__ */ jsx(Section, {
|
|
963
|
+
id: "accessibility",
|
|
964
|
+
title: "Accessibility",
|
|
965
|
+
children: /* @__PURE__ */ jsx(Guidelines, { items: [
|
|
966
|
+
/* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
967
|
+
"Field renders a real ",
|
|
968
|
+
/* @__PURE__ */ jsx("code", { children: "label" }),
|
|
969
|
+
" pointing at the control's id (generated when you do not pass one), so screen readers read it as the name and clicking it focuses the control."
|
|
970
|
+
] }),
|
|
971
|
+
/* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
972
|
+
"The hint or error is linked with ",
|
|
973
|
+
/* @__PURE__ */ jsx("code", { children: "aria-describedby" }),
|
|
974
|
+
", alongside any of your own. An error also sets ",
|
|
975
|
+
/* @__PURE__ */ jsx("code", { children: "aria-invalid" }),
|
|
976
|
+
". The error's icon is hidden; the words carry the message."
|
|
977
|
+
] }),
|
|
978
|
+
"Errors are not announced as they appear. After a failed submit, move focus to the first field with a problem, and it is read with its error.",
|
|
979
|
+
/* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
980
|
+
"Without a Field, give the Input an ",
|
|
981
|
+
/* @__PURE__ */ jsx("code", { children: "aria-label" }),
|
|
982
|
+
" or ",
|
|
983
|
+
/* @__PURE__ */ jsx("code", { children: "aria-labelledby" }),
|
|
984
|
+
"."
|
|
985
|
+
] }),
|
|
986
|
+
"Focus shows as a teal edge with a soft halo round the whole frame, not an outline on the text.",
|
|
987
|
+
"Numerals in the field are tabular, so amounts line up as they are typed.",
|
|
988
|
+
"Under reduced motion the error fades in without the 3px drop."
|
|
989
|
+
] })
|
|
990
|
+
}),
|
|
991
|
+
/* @__PURE__ */ jsxs(Section, {
|
|
992
|
+
id: "props",
|
|
993
|
+
title: "Props",
|
|
994
|
+
children: [
|
|
995
|
+
/* @__PURE__ */ jsx(PropsTable, {
|
|
996
|
+
title: "Input",
|
|
997
|
+
rows: [
|
|
998
|
+
{
|
|
999
|
+
name: "size",
|
|
1000
|
+
type: "'sm' | 'md' | 'lg'",
|
|
1001
|
+
default: "'md'",
|
|
1002
|
+
description: "Height from the control scale: 30, 36 or 44px, the same as buttons."
|
|
1003
|
+
},
|
|
1004
|
+
{
|
|
1005
|
+
name: "icon",
|
|
1006
|
+
type: "ReactNode",
|
|
1007
|
+
description: "Leading icon. Muted, it wakes up while the field has focus."
|
|
1008
|
+
},
|
|
1009
|
+
{
|
|
1010
|
+
name: "prefix",
|
|
1011
|
+
type: "ReactNode",
|
|
1012
|
+
description: "Leading text set tight against the value, such as £ or https://."
|
|
1013
|
+
},
|
|
1014
|
+
{
|
|
1015
|
+
name: "suffix",
|
|
1016
|
+
type: "ReactNode",
|
|
1017
|
+
description: "Trailing unit, status or small button."
|
|
1018
|
+
},
|
|
1019
|
+
{
|
|
1020
|
+
name: "invalid",
|
|
1021
|
+
type: "boolean",
|
|
1022
|
+
description: "Red edge and aria-invalid. Inside a Field, follows the Field's error unless set."
|
|
1023
|
+
},
|
|
1024
|
+
{
|
|
1025
|
+
name: "readOnly",
|
|
1026
|
+
type: "boolean",
|
|
1027
|
+
description: "Sinks into the well; still focusable and copyable."
|
|
1028
|
+
},
|
|
1029
|
+
{
|
|
1030
|
+
name: "disabled",
|
|
1031
|
+
type: "boolean",
|
|
1032
|
+
description: "Sinks into the well and dims; skipped by Tab."
|
|
1033
|
+
}
|
|
1034
|
+
]
|
|
1035
|
+
}),
|
|
1036
|
+
/* @__PURE__ */ jsxs("p", {
|
|
1037
|
+
className: "doc-section__description",
|
|
1038
|
+
children: [
|
|
1039
|
+
"Every other native input attribute, and the ",
|
|
1040
|
+
/* @__PURE__ */ jsx("code", { children: "ref" }),
|
|
1041
|
+
", go to the ",
|
|
1042
|
+
/* @__PURE__ */ jsx("code", { children: "input" }),
|
|
1043
|
+
".",
|
|
1044
|
+
" ",
|
|
1045
|
+
/* @__PURE__ */ jsx("code", { children: "className" }),
|
|
1046
|
+
" and ",
|
|
1047
|
+
/* @__PURE__ */ jsx("code", { children: "style" }),
|
|
1048
|
+
" go to the frame around it."
|
|
1049
|
+
]
|
|
1050
|
+
}),
|
|
1051
|
+
/* @__PURE__ */ jsx(PropsTable, {
|
|
1052
|
+
title: "Field",
|
|
1053
|
+
rows: [
|
|
1054
|
+
{
|
|
1055
|
+
name: "label",
|
|
1056
|
+
type: "ReactNode",
|
|
1057
|
+
required: true,
|
|
1058
|
+
description: "The visible label above the control."
|
|
1059
|
+
},
|
|
1060
|
+
{
|
|
1061
|
+
name: "hint",
|
|
1062
|
+
type: "ReactNode",
|
|
1063
|
+
description: "Help below the control. Hidden while there is an error."
|
|
1064
|
+
},
|
|
1065
|
+
{
|
|
1066
|
+
name: "error",
|
|
1067
|
+
type: "ReactNode",
|
|
1068
|
+
description: "What is wrong and how to fix it. Replaces the hint and marks the control invalid."
|
|
1069
|
+
},
|
|
1070
|
+
{
|
|
1071
|
+
name: "id",
|
|
1072
|
+
type: "string",
|
|
1073
|
+
description: "Id for the control inside. Generated when omitted."
|
|
1074
|
+
},
|
|
1075
|
+
{
|
|
1076
|
+
name: "children",
|
|
1077
|
+
type: "ReactNode",
|
|
1078
|
+
required: true,
|
|
1079
|
+
description: "One control: Input, SearchField, or anything reading useFieldControl()."
|
|
1080
|
+
}
|
|
1081
|
+
]
|
|
1082
|
+
}),
|
|
1083
|
+
/* @__PURE__ */ jsx("p", {
|
|
1084
|
+
className: "doc-section__description",
|
|
1085
|
+
children: "Other attributes go to the Field's outer element."
|
|
1086
|
+
})
|
|
1087
|
+
]
|
|
1088
|
+
})
|
|
1089
|
+
]
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
//#endregion
|
|
1093
|
+
export { Page, Preview };
|