@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,777 @@
|
|
|
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 { useId, useState } from "react";
|
|
5
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { AreaChart, Delta, SegmentedControl } from "@orbitcommerce/constellation";
|
|
7
|
+
import { DesktopIcon, DeviceMobileIcon, DeviceTabletIcon, RowsIcon, SquaresFourIcon, TextAlignCenterIcon, TextAlignLeftIcon, TextAlignRightIcon } from "@orbitcommerce/constellation/icons";
|
|
8
|
+
//#region src/pages/components/segmented-control.tsx
|
|
9
|
+
function Preview() {
|
|
10
|
+
return /* @__PURE__ */ jsx(SegmentedControl, {
|
|
11
|
+
"aria-label": "Date range",
|
|
12
|
+
defaultValue: "7d",
|
|
13
|
+
options: [
|
|
14
|
+
{
|
|
15
|
+
value: "today",
|
|
16
|
+
label: "Today"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
value: "7d",
|
|
20
|
+
label: "7 days"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
value: "30d",
|
|
24
|
+
label: "30 days"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
var quote = (v) => String(v).replace(/"/g, """);
|
|
30
|
+
var DEVICES = [
|
|
31
|
+
{
|
|
32
|
+
value: "desktop",
|
|
33
|
+
label: "Desktop",
|
|
34
|
+
icon: /* @__PURE__ */ jsx(DesktopIcon, {}),
|
|
35
|
+
name: "DesktopIcon"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
value: "tablet",
|
|
39
|
+
label: "Tablet",
|
|
40
|
+
icon: /* @__PURE__ */ jsx(DeviceTabletIcon, {}),
|
|
41
|
+
name: "DeviceTabletIcon"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
value: "phone",
|
|
45
|
+
label: "Phone",
|
|
46
|
+
icon: /* @__PURE__ */ jsx(DeviceMobileIcon, {}),
|
|
47
|
+
name: "DeviceMobileIcon"
|
|
48
|
+
}
|
|
49
|
+
];
|
|
50
|
+
function deviceOptions(form) {
|
|
51
|
+
return DEVICES.map((d) => ({
|
|
52
|
+
value: d.value,
|
|
53
|
+
label: d.label,
|
|
54
|
+
icon: form === "text" ? void 0 : d.icon,
|
|
55
|
+
iconOnly: form === "icon only"
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
function deviceOptionsCode(form) {
|
|
59
|
+
return `options={[\n ${DEVICES.map((d) => form === "text" ? `{ value: '${d.value}', label: '${d.label}' }` : form === "icon and text" ? `{ value: '${d.value}', label: '${d.label}', icon: <${d.name} /> }` : `{ value: '${d.value}', label: '${d.label}', icon: <${d.name} />, iconOnly: true }`).join(",\n ")},\n]}`;
|
|
60
|
+
}
|
|
61
|
+
var PLAYGROUND = [
|
|
62
|
+
{
|
|
63
|
+
prop: "aria-label",
|
|
64
|
+
type: "text",
|
|
65
|
+
default: "Preview size",
|
|
66
|
+
toAttr: (v) => `aria-label="${quote(v)}"`
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
prop: "options",
|
|
70
|
+
type: "select",
|
|
71
|
+
options: [
|
|
72
|
+
"text",
|
|
73
|
+
"icon and text",
|
|
74
|
+
"icon only"
|
|
75
|
+
],
|
|
76
|
+
default: "icon and text",
|
|
77
|
+
toAttr: (v) => deviceOptionsCode(v)
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
prop: "size",
|
|
81
|
+
type: "select",
|
|
82
|
+
options: ["sm", "md"],
|
|
83
|
+
default: "md"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
prop: "fullWidth",
|
|
87
|
+
type: "boolean",
|
|
88
|
+
default: false
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
prop: "disabled",
|
|
92
|
+
type: "boolean",
|
|
93
|
+
default: false
|
|
94
|
+
}
|
|
95
|
+
];
|
|
96
|
+
var RANGES = [
|
|
97
|
+
{
|
|
98
|
+
value: "7d",
|
|
99
|
+
label: "7 days"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
value: "30d",
|
|
103
|
+
label: "30 days"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
value: "90d",
|
|
107
|
+
label: "90 days"
|
|
108
|
+
}
|
|
109
|
+
];
|
|
110
|
+
var DAYS = {
|
|
111
|
+
"7d": 7,
|
|
112
|
+
"30d": 30,
|
|
113
|
+
"90d": 90
|
|
114
|
+
};
|
|
115
|
+
/** A day `offset` days before Monday 28 September 2026, as YYYY-MM-DD. */
|
|
116
|
+
function dayBefore(offset) {
|
|
117
|
+
const d = new Date(2026, 8, 28 - offset);
|
|
118
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
119
|
+
}
|
|
120
|
+
/** Invented daily takings: quieter weekends, a slow rise, a little noise. */
|
|
121
|
+
function takingsOn(offset) {
|
|
122
|
+
const day = new Date(2026, 8, 28 - offset).getDay();
|
|
123
|
+
const weekend = day === 0 || day === 6 ? .74 : 1;
|
|
124
|
+
const wave = 1 + .16 * Math.sin(offset / 5.3) + .07 * Math.sin(offset / 1.7);
|
|
125
|
+
const trend = 1 + (180 - offset) * .0016;
|
|
126
|
+
const seed = Math.sin((offset + 1) * 12.9898) * 43758.5453;
|
|
127
|
+
const noise = .86 + (seed - Math.floor(seed)) * .28;
|
|
128
|
+
return Math.round(380 * weekend * wave * trend * noise * 100) / 100;
|
|
129
|
+
}
|
|
130
|
+
function seriesFor(range) {
|
|
131
|
+
const n = DAYS[range];
|
|
132
|
+
return Array.from({ length: n }, (_, i) => {
|
|
133
|
+
const offset = n - 1 - i;
|
|
134
|
+
return {
|
|
135
|
+
date: dayBefore(offset),
|
|
136
|
+
value: takingsOn(offset),
|
|
137
|
+
compare: takingsOn(offset + n)
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
var SERIES = {
|
|
142
|
+
"7d": seriesFor("7d"),
|
|
143
|
+
"30d": seriesFor("30d"),
|
|
144
|
+
"90d": seriesFor("90d")
|
|
145
|
+
};
|
|
146
|
+
var pounds = new Intl.NumberFormat("en-GB", {
|
|
147
|
+
style: "currency",
|
|
148
|
+
currency: "GBP"
|
|
149
|
+
});
|
|
150
|
+
var formatPounds = (v) => pounds.format(v);
|
|
151
|
+
function TakingsChart() {
|
|
152
|
+
const [range, setRange] = useState("30d");
|
|
153
|
+
const data = SERIES[range];
|
|
154
|
+
const total = data.reduce((sum, d) => sum + d.value, 0);
|
|
155
|
+
const before = data.reduce((sum, d) => sum + (d.compare ?? 0), 0);
|
|
156
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
157
|
+
className: "segmented-control-chart",
|
|
158
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
159
|
+
className: "segmented-control-chart__head",
|
|
160
|
+
children: [/* @__PURE__ */ jsxs("p", {
|
|
161
|
+
className: "segmented-control-figure",
|
|
162
|
+
children: [
|
|
163
|
+
/* @__PURE__ */ jsx("span", {
|
|
164
|
+
className: "segmented-control-figure__label",
|
|
165
|
+
children: "Takings"
|
|
166
|
+
}),
|
|
167
|
+
/* @__PURE__ */ jsx("span", {
|
|
168
|
+
className: "segmented-control-figure__value",
|
|
169
|
+
children: formatPounds(total)
|
|
170
|
+
}),
|
|
171
|
+
/* @__PURE__ */ jsx("span", {
|
|
172
|
+
className: "segmented-control-figure__meta",
|
|
173
|
+
children: /* @__PURE__ */ jsx(Delta, {
|
|
174
|
+
value: (total - before) / before * 100,
|
|
175
|
+
size: "sm",
|
|
176
|
+
label: `vs the ${DAYS[range]} days before`
|
|
177
|
+
})
|
|
178
|
+
})
|
|
179
|
+
]
|
|
180
|
+
}), /* @__PURE__ */ jsx(SegmentedControl, {
|
|
181
|
+
"aria-label": "Date range",
|
|
182
|
+
size: "sm",
|
|
183
|
+
value: range,
|
|
184
|
+
onValueChange: setRange,
|
|
185
|
+
options: RANGES
|
|
186
|
+
})]
|
|
187
|
+
}), /* @__PURE__ */ jsx(AreaChart, {
|
|
188
|
+
data,
|
|
189
|
+
height: 200,
|
|
190
|
+
formatValue: formatPounds,
|
|
191
|
+
formatTick: (v) => `£${Math.round(v)}`,
|
|
192
|
+
valueLabel: `Last ${DAYS[range]} days`,
|
|
193
|
+
compareLabel: "The period before"
|
|
194
|
+
})]
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
var ACCESS = [
|
|
198
|
+
{
|
|
199
|
+
value: "full",
|
|
200
|
+
label: "Full access",
|
|
201
|
+
hint: "Everything except billing and store ownership."
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
value: "orders",
|
|
205
|
+
label: "Orders only",
|
|
206
|
+
hint: "Orders, customers and fulfilment. No settings."
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
value: "view",
|
|
210
|
+
label: "View only",
|
|
211
|
+
hint: "Can look at everything and change nothing."
|
|
212
|
+
}
|
|
213
|
+
];
|
|
214
|
+
function AccessChoice() {
|
|
215
|
+
const [access, setAccess] = useState("orders");
|
|
216
|
+
const labelId = useId();
|
|
217
|
+
const hintId = useId();
|
|
218
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
219
|
+
className: "segmented-control-group",
|
|
220
|
+
children: [
|
|
221
|
+
/* @__PURE__ */ jsx("p", {
|
|
222
|
+
id: labelId,
|
|
223
|
+
className: "segmented-control-group__label",
|
|
224
|
+
children: "Access"
|
|
225
|
+
}),
|
|
226
|
+
/* @__PURE__ */ jsx(SegmentedControl, {
|
|
227
|
+
"aria-labelledby": labelId,
|
|
228
|
+
"aria-describedby": hintId,
|
|
229
|
+
fullWidth: true,
|
|
230
|
+
value: access,
|
|
231
|
+
onValueChange: setAccess,
|
|
232
|
+
options: ACCESS.map(({ value, label }) => ({
|
|
233
|
+
value,
|
|
234
|
+
label
|
|
235
|
+
}))
|
|
236
|
+
}),
|
|
237
|
+
/* @__PURE__ */ jsx("p", {
|
|
238
|
+
id: hintId,
|
|
239
|
+
className: "segmented-control-group__hint",
|
|
240
|
+
children: ACCESS.find((a) => a.value === access)?.hint
|
|
241
|
+
})
|
|
242
|
+
]
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
function Page() {
|
|
246
|
+
return /* @__PURE__ */ jsxs(DocPage, {
|
|
247
|
+
title: "Segmented control",
|
|
248
|
+
status: "stable",
|
|
249
|
+
importNames: ["SegmentedControl"],
|
|
250
|
+
lead: "A pill track for choosing one of a few views: the date range of a chart, a grid or a list, a device to preview on. The chosen option rides a raised thumb that glides between them.",
|
|
251
|
+
children: [
|
|
252
|
+
/* @__PURE__ */ jsx(Section, {
|
|
253
|
+
id: "playground",
|
|
254
|
+
title: "Playground",
|
|
255
|
+
description: /* @__PURE__ */ jsx("p", { children: "Change the props, then click between the options to watch the thumb glide." }),
|
|
256
|
+
children: /* @__PURE__ */ jsx(Playground, {
|
|
257
|
+
component: "SegmentedControl",
|
|
258
|
+
controls: PLAYGROUND,
|
|
259
|
+
render: (v) => /* @__PURE__ */ jsx("div", {
|
|
260
|
+
className: "segmented-control-stage",
|
|
261
|
+
children: /* @__PURE__ */ jsx(SegmentedControl, {
|
|
262
|
+
"aria-label": String(v["aria-label"]),
|
|
263
|
+
options: deviceOptions(v.options),
|
|
264
|
+
size: v.size,
|
|
265
|
+
fullWidth: Boolean(v.fullWidth),
|
|
266
|
+
disabled: Boolean(v.disabled)
|
|
267
|
+
})
|
|
268
|
+
})
|
|
269
|
+
})
|
|
270
|
+
}),
|
|
271
|
+
/* @__PURE__ */ jsx(Section, {
|
|
272
|
+
id: "controlled",
|
|
273
|
+
title: "A date range for a chart",
|
|
274
|
+
description: /* @__PURE__ */ jsxs("p", { children: [
|
|
275
|
+
"The most common job: pick the period, and the figure and chart change in place. Control it with",
|
|
276
|
+
" ",
|
|
277
|
+
/* @__PURE__ */ jsx("code", { children: "value" }),
|
|
278
|
+
" and ",
|
|
279
|
+
/* @__PURE__ */ jsx("code", { children: "onValueChange" }),
|
|
280
|
+
". Typed options keep the value typed too."
|
|
281
|
+
] }),
|
|
282
|
+
children: /* @__PURE__ */ jsx(Example, {
|
|
283
|
+
align: "fill",
|
|
284
|
+
code: `
|
|
285
|
+
type Range = '7d' | '30d' | '90d'
|
|
286
|
+
|
|
287
|
+
const ranges: SegmentedControlOption<Range>[] = [
|
|
288
|
+
{ value: '7d', label: '7 days' },
|
|
289
|
+
{ value: '30d', label: '30 days' },
|
|
290
|
+
{ value: '90d', label: '90 days' },
|
|
291
|
+
]
|
|
292
|
+
|
|
293
|
+
const [range, setRange] = useState<Range>('30d')
|
|
294
|
+
|
|
295
|
+
<SegmentedControl aria-label="Date range" size="sm" value={range} onValueChange={setRange} options={ranges} />
|
|
296
|
+
<AreaChart data={takings[range]} height={200} formatValue={formatPounds} />`,
|
|
297
|
+
children: /* @__PURE__ */ jsx(TakingsChart, {})
|
|
298
|
+
})
|
|
299
|
+
}),
|
|
300
|
+
/* @__PURE__ */ jsx(Section, {
|
|
301
|
+
id: "sizes",
|
|
302
|
+
title: "Sizes",
|
|
303
|
+
description: /* @__PURE__ */ jsxs("p", { children: [
|
|
304
|
+
/* @__PURE__ */ jsx("code", { children: "md" }),
|
|
305
|
+
" is 36px tall (default) and ",
|
|
306
|
+
/* @__PURE__ */ jsx("code", { children: "sm" }),
|
|
307
|
+
" 30px, the same heights as buttons. Labels are 13px and 12px; icons 15px and 13px."
|
|
308
|
+
] }),
|
|
309
|
+
children: /* @__PURE__ */ jsx(Example, {
|
|
310
|
+
code: `
|
|
311
|
+
<SegmentedControl aria-label="Date range" options={ranges} defaultValue="30d" />
|
|
312
|
+
<SegmentedControl aria-label="Date range" size="sm" options={ranges} defaultValue="30d" />`,
|
|
313
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
314
|
+
className: "segmented-control-rows",
|
|
315
|
+
children: [/* @__PURE__ */ jsx(SegmentedControl, {
|
|
316
|
+
"aria-label": "Date range",
|
|
317
|
+
options: RANGES,
|
|
318
|
+
defaultValue: "30d"
|
|
319
|
+
}), /* @__PURE__ */ jsx(SegmentedControl, {
|
|
320
|
+
"aria-label": "Date range",
|
|
321
|
+
size: "sm",
|
|
322
|
+
options: RANGES,
|
|
323
|
+
defaultValue: "30d"
|
|
324
|
+
})]
|
|
325
|
+
})
|
|
326
|
+
})
|
|
327
|
+
}),
|
|
328
|
+
/* @__PURE__ */ jsx(Section, {
|
|
329
|
+
id: "full-width",
|
|
330
|
+
title: "Full width",
|
|
331
|
+
description: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("p", { children: [/* @__PURE__ */ jsx("code", { children: "fullWidth" }), " stretches the track and shares it equally between the options. Use it in dialogs, popovers and narrow panels, where the control is the width of the fields around it."] }), /* @__PURE__ */ jsxs("p", { children: [
|
|
332
|
+
"The control has no visible label of its own and cannot sit in a Field. For a visible label, write it above and point ",
|
|
333
|
+
/* @__PURE__ */ jsx("code", { children: "aria-labelledby" }),
|
|
334
|
+
" at it, in place of ",
|
|
335
|
+
/* @__PURE__ */ jsx("code", { children: "aria-label" }),
|
|
336
|
+
". A hint below can be linked with ",
|
|
337
|
+
/* @__PURE__ */ jsx("code", { children: "aria-describedby" }),
|
|
338
|
+
"."
|
|
339
|
+
] })] }),
|
|
340
|
+
children: /* @__PURE__ */ jsx(Example, {
|
|
341
|
+
align: "fill",
|
|
342
|
+
code: `
|
|
343
|
+
<p id="access-label">Access</p>
|
|
344
|
+
<SegmentedControl
|
|
345
|
+
aria-labelledby="access-label"
|
|
346
|
+
aria-describedby="access-hint"
|
|
347
|
+
fullWidth
|
|
348
|
+
value={access}
|
|
349
|
+
onValueChange={setAccess}
|
|
350
|
+
options={[
|
|
351
|
+
{ value: 'full', label: 'Full access' },
|
|
352
|
+
{ value: 'orders', label: 'Orders only' },
|
|
353
|
+
{ value: 'view', label: 'View only' },
|
|
354
|
+
]}
|
|
355
|
+
/>
|
|
356
|
+
<p id="access-hint">Orders, customers and fulfilment. No settings.</p>`,
|
|
357
|
+
children: /* @__PURE__ */ jsx(AccessChoice, {})
|
|
358
|
+
})
|
|
359
|
+
}),
|
|
360
|
+
/* @__PURE__ */ jsxs(Section, {
|
|
361
|
+
id: "icons",
|
|
362
|
+
title: "With icons",
|
|
363
|
+
description: /* @__PURE__ */ jsx("p", { children: "A leading icon on each option, for views that have a well-known picture." }),
|
|
364
|
+
children: [/* @__PURE__ */ jsx(Example, {
|
|
365
|
+
code: `
|
|
366
|
+
<SegmentedControl
|
|
367
|
+
aria-label="Product layout"
|
|
368
|
+
size="sm"
|
|
369
|
+
options={[
|
|
370
|
+
{ value: 'grid', label: 'Grid', icon: <SquaresFourIcon /> },
|
|
371
|
+
{ value: 'list', label: 'List', icon: <RowsIcon /> },
|
|
372
|
+
]}
|
|
373
|
+
/>`,
|
|
374
|
+
children: /* @__PURE__ */ jsx(SegmentedControl, {
|
|
375
|
+
"aria-label": "Product layout",
|
|
376
|
+
size: "sm",
|
|
377
|
+
options: [{
|
|
378
|
+
value: "grid",
|
|
379
|
+
label: "Grid",
|
|
380
|
+
icon: /* @__PURE__ */ jsx(SquaresFourIcon, {})
|
|
381
|
+
}, {
|
|
382
|
+
value: "list",
|
|
383
|
+
label: "List",
|
|
384
|
+
icon: /* @__PURE__ */ jsx(RowsIcon, {})
|
|
385
|
+
}]
|
|
386
|
+
})
|
|
387
|
+
}), /* @__PURE__ */ jsx(SubSection, {
|
|
388
|
+
title: "Icon only",
|
|
389
|
+
description: /* @__PURE__ */ jsxs("p", { children: [
|
|
390
|
+
"Set ",
|
|
391
|
+
/* @__PURE__ */ jsx("code", { children: "iconOnly" }),
|
|
392
|
+
" on an option and keep its ",
|
|
393
|
+
/* @__PURE__ */ jsx("code", { children: "label" }),
|
|
394
|
+
": the icon is centred and the label becomes what screen readers say. Options cannot carry tooltips, so only drop the words when every icon is unmistakable, like text alignment in the page builder."
|
|
395
|
+
] }),
|
|
396
|
+
children: /* @__PURE__ */ jsx(Example, {
|
|
397
|
+
code: `
|
|
398
|
+
<SegmentedControl
|
|
399
|
+
aria-label="Text alignment"
|
|
400
|
+
options={[
|
|
401
|
+
{ value: 'left', label: 'Align left', icon: <TextAlignLeftIcon />, iconOnly: true },
|
|
402
|
+
{ value: 'center', label: 'Align centre', icon: <TextAlignCenterIcon />, iconOnly: true },
|
|
403
|
+
{ value: 'right', label: 'Align right', icon: <TextAlignRightIcon />, iconOnly: true },
|
|
404
|
+
]}
|
|
405
|
+
/>`,
|
|
406
|
+
children: /* @__PURE__ */ jsx(SegmentedControl, {
|
|
407
|
+
"aria-label": "Text alignment",
|
|
408
|
+
options: [
|
|
409
|
+
{
|
|
410
|
+
value: "left",
|
|
411
|
+
label: "Align left",
|
|
412
|
+
icon: /* @__PURE__ */ jsx(TextAlignLeftIcon, {}),
|
|
413
|
+
iconOnly: true
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
value: "center",
|
|
417
|
+
label: "Align centre",
|
|
418
|
+
icon: /* @__PURE__ */ jsx(TextAlignCenterIcon, {}),
|
|
419
|
+
iconOnly: true
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
value: "right",
|
|
423
|
+
label: "Align right",
|
|
424
|
+
icon: /* @__PURE__ */ jsx(TextAlignRightIcon, {}),
|
|
425
|
+
iconOnly: true
|
|
426
|
+
}
|
|
427
|
+
]
|
|
428
|
+
})
|
|
429
|
+
})
|
|
430
|
+
})]
|
|
431
|
+
}),
|
|
432
|
+
/* @__PURE__ */ jsx(Section, {
|
|
433
|
+
id: "disabled",
|
|
434
|
+
title: "Disabled",
|
|
435
|
+
description: /* @__PURE__ */ jsxs("p", { children: [
|
|
436
|
+
"An option with ",
|
|
437
|
+
/* @__PURE__ */ jsx("code", { children: "disabled: true" }),
|
|
438
|
+
" drops to 45%, cannot be chosen and is skipped by the arrow keys. Say nearby why it is off. ",
|
|
439
|
+
/* @__PURE__ */ jsx("code", { children: "disabled" }),
|
|
440
|
+
" on the control turns off every option."
|
|
441
|
+
] }),
|
|
442
|
+
children: /* @__PURE__ */ jsx(Example, {
|
|
443
|
+
code: `
|
|
444
|
+
<SegmentedControl
|
|
445
|
+
aria-label="Delivery method"
|
|
446
|
+
defaultValue="ship"
|
|
447
|
+
options={[
|
|
448
|
+
{ value: 'ship', label: 'Ship' },
|
|
449
|
+
{ value: 'collect', label: 'Click and collect' },
|
|
450
|
+
{ value: 'local', label: 'Local delivery', disabled: true },
|
|
451
|
+
]}
|
|
452
|
+
/>
|
|
453
|
+
<SegmentedControl aria-label="Date range" options={ranges} defaultValue="30d" disabled />`,
|
|
454
|
+
caption: "Local delivery is off until it is set up in Shipping settings.",
|
|
455
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
456
|
+
className: "segmented-control-rows",
|
|
457
|
+
children: [/* @__PURE__ */ jsx(SegmentedControl, {
|
|
458
|
+
"aria-label": "Delivery method",
|
|
459
|
+
defaultValue: "ship",
|
|
460
|
+
options: [
|
|
461
|
+
{
|
|
462
|
+
value: "ship",
|
|
463
|
+
label: "Ship"
|
|
464
|
+
},
|
|
465
|
+
{
|
|
466
|
+
value: "collect",
|
|
467
|
+
label: "Click and collect"
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
value: "local",
|
|
471
|
+
label: "Local delivery",
|
|
472
|
+
disabled: true
|
|
473
|
+
}
|
|
474
|
+
]
|
|
475
|
+
}), /* @__PURE__ */ jsx(SegmentedControl, {
|
|
476
|
+
"aria-label": "Date range",
|
|
477
|
+
options: RANGES,
|
|
478
|
+
defaultValue: "30d",
|
|
479
|
+
disabled: true
|
|
480
|
+
})]
|
|
481
|
+
})
|
|
482
|
+
})
|
|
483
|
+
}),
|
|
484
|
+
/* @__PURE__ */ jsx(Section, {
|
|
485
|
+
id: "keyboard",
|
|
486
|
+
title: "Keyboard",
|
|
487
|
+
description: /* @__PURE__ */ jsx("p", { children: "It behaves as a radio group: one Tab stop, and the arrows move the choice." }),
|
|
488
|
+
children: /* @__PURE__ */ jsx(DocTable, {
|
|
489
|
+
columns: ["Key", "What it does"],
|
|
490
|
+
rows: [
|
|
491
|
+
["Tab", "Moves focus to the chosen option. The whole control is one Tab stop."],
|
|
492
|
+
["Right and down arrows", "Choose the next option, skipping disabled ones, and wrap round from the last to the first."],
|
|
493
|
+
["Left and up arrows", "Choose the previous option, the same way. Left and right swap in right-to-left layouts."],
|
|
494
|
+
["Home, End", "Choose the first or the last enabled option."]
|
|
495
|
+
]
|
|
496
|
+
})
|
|
497
|
+
}),
|
|
498
|
+
/* @__PURE__ */ jsxs(Section, {
|
|
499
|
+
id: "motion",
|
|
500
|
+
title: "The gliding thumb",
|
|
501
|
+
description: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("p", { children: "There is one thumb, and it moves: a raised pill (white in light, a step lighter than the track in dark) that glides to the new choice on the snappy spring. The chosen label turns semibold without changing width, because an invisible semibold copy of the text holds the space." }), /* @__PURE__ */ jsx("p", { children: "Under reduced motion the thumb jumps straight to the new option, and only the text colour fades. Click along the options, or use the arrow keys." })] }),
|
|
502
|
+
children: [/* @__PURE__ */ jsx(Example, {
|
|
503
|
+
code: `
|
|
504
|
+
<SegmentedControl
|
|
505
|
+
aria-label="Date range"
|
|
506
|
+
defaultValue="30d"
|
|
507
|
+
options={[
|
|
508
|
+
{ value: 'today', label: 'Today' },
|
|
509
|
+
{ value: '7d', label: '7 days' },
|
|
510
|
+
{ value: '30d', label: '30 days' },
|
|
511
|
+
{ value: '90d', label: '90 days' },
|
|
512
|
+
{ value: '12m', label: '12 months' },
|
|
513
|
+
]}
|
|
514
|
+
/>`,
|
|
515
|
+
children: /* @__PURE__ */ jsx(SegmentedControl, {
|
|
516
|
+
"aria-label": "Date range",
|
|
517
|
+
defaultValue: "30d",
|
|
518
|
+
options: [
|
|
519
|
+
{
|
|
520
|
+
value: "today",
|
|
521
|
+
label: "Today"
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
value: "7d",
|
|
525
|
+
label: "7 days"
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
value: "30d",
|
|
529
|
+
label: "30 days"
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
value: "90d",
|
|
533
|
+
label: "90 days"
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
value: "12m",
|
|
537
|
+
label: "12 months"
|
|
538
|
+
}
|
|
539
|
+
]
|
|
540
|
+
})
|
|
541
|
+
}), /* @__PURE__ */ jsx(Note, { children: "The width is only held when the label is a string. Pass words as plain strings: text wrapped in an element still turns semibold, and nudges the row when it does." })]
|
|
542
|
+
}),
|
|
543
|
+
/* @__PURE__ */ jsx(Section, {
|
|
544
|
+
id: "both-themes",
|
|
545
|
+
title: "In both themes",
|
|
546
|
+
description: /* @__PURE__ */ jsx("p", { children: "Text, icons and icon only, light and dark side by side. In dark the thumb is a lighter step of the track." }),
|
|
547
|
+
children: /* @__PURE__ */ jsx(ThemePair, { children: /* @__PURE__ */ jsxs("div", {
|
|
548
|
+
className: "segmented-control-rows",
|
|
549
|
+
children: [
|
|
550
|
+
/* @__PURE__ */ jsx(SegmentedControl, {
|
|
551
|
+
"aria-label": "Date range",
|
|
552
|
+
options: RANGES,
|
|
553
|
+
defaultValue: "30d"
|
|
554
|
+
}),
|
|
555
|
+
/* @__PURE__ */ jsx(SegmentedControl, {
|
|
556
|
+
"aria-label": "Product layout",
|
|
557
|
+
size: "sm",
|
|
558
|
+
options: [{
|
|
559
|
+
value: "grid",
|
|
560
|
+
label: "Grid",
|
|
561
|
+
icon: /* @__PURE__ */ jsx(SquaresFourIcon, {})
|
|
562
|
+
}, {
|
|
563
|
+
value: "list",
|
|
564
|
+
label: "List",
|
|
565
|
+
icon: /* @__PURE__ */ jsx(RowsIcon, {})
|
|
566
|
+
}]
|
|
567
|
+
}),
|
|
568
|
+
/* @__PURE__ */ jsx(SegmentedControl, {
|
|
569
|
+
"aria-label": "Text alignment",
|
|
570
|
+
size: "sm",
|
|
571
|
+
defaultValue: "center",
|
|
572
|
+
options: [
|
|
573
|
+
{
|
|
574
|
+
value: "left",
|
|
575
|
+
label: "Align left",
|
|
576
|
+
icon: /* @__PURE__ */ jsx(TextAlignLeftIcon, {}),
|
|
577
|
+
iconOnly: true
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
value: "center",
|
|
581
|
+
label: "Align centre",
|
|
582
|
+
icon: /* @__PURE__ */ jsx(TextAlignCenterIcon, {}),
|
|
583
|
+
iconOnly: true
|
|
584
|
+
},
|
|
585
|
+
{
|
|
586
|
+
value: "right",
|
|
587
|
+
label: "Align right",
|
|
588
|
+
icon: /* @__PURE__ */ jsx(TextAlignRightIcon, {}),
|
|
589
|
+
iconOnly: true
|
|
590
|
+
}
|
|
591
|
+
]
|
|
592
|
+
})
|
|
593
|
+
]
|
|
594
|
+
}) })
|
|
595
|
+
}),
|
|
596
|
+
/* @__PURE__ */ jsxs(Section, {
|
|
597
|
+
id: "guidelines",
|
|
598
|
+
title: "Guidelines",
|
|
599
|
+
children: [/* @__PURE__ */ jsx(DoDont, {
|
|
600
|
+
do: {
|
|
601
|
+
children: /* @__PURE__ */ jsx(SegmentedControl, {
|
|
602
|
+
"aria-label": "Date range",
|
|
603
|
+
defaultValue: "7d",
|
|
604
|
+
options: [
|
|
605
|
+
{
|
|
606
|
+
value: "today",
|
|
607
|
+
label: "Today"
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
value: "7d",
|
|
611
|
+
label: "7 days"
|
|
612
|
+
},
|
|
613
|
+
{
|
|
614
|
+
value: "30d",
|
|
615
|
+
label: "30 days"
|
|
616
|
+
}
|
|
617
|
+
]
|
|
618
|
+
}),
|
|
619
|
+
caption: "A few short options that change the view in place, at once."
|
|
620
|
+
},
|
|
621
|
+
dont: {
|
|
622
|
+
children: /* @__PURE__ */ jsx(SegmentedControl, {
|
|
623
|
+
"aria-label": "Order pages",
|
|
624
|
+
defaultValue: "orders",
|
|
625
|
+
options: [
|
|
626
|
+
{
|
|
627
|
+
value: "orders",
|
|
628
|
+
label: "Orders"
|
|
629
|
+
},
|
|
630
|
+
{
|
|
631
|
+
value: "drafts",
|
|
632
|
+
label: "Drafts"
|
|
633
|
+
},
|
|
634
|
+
{
|
|
635
|
+
value: "abandoned",
|
|
636
|
+
label: "Abandoned"
|
|
637
|
+
}
|
|
638
|
+
]
|
|
639
|
+
}),
|
|
640
|
+
caption: "Moving between pages is navigation: use links. A segmented control only changes the view in place."
|
|
641
|
+
}
|
|
642
|
+
}), /* @__PURE__ */ jsx(Guidelines, { items: [
|
|
643
|
+
"Two to five options, one or two words each. With more, or with long names, use a menu.",
|
|
644
|
+
"It changes what is on screen straight away and never waits for a Save button.",
|
|
645
|
+
"Keep the options in a natural order, such as shortest period to longest, and start on the one people use most.",
|
|
646
|
+
"Drop the words only when every icon is unmistakable, and keep a hidden label on each."
|
|
647
|
+
] })]
|
|
648
|
+
}),
|
|
649
|
+
/* @__PURE__ */ jsx(Section, {
|
|
650
|
+
id: "accessibility",
|
|
651
|
+
title: "Accessibility",
|
|
652
|
+
children: /* @__PURE__ */ jsx(Guidelines, { items: [
|
|
653
|
+
/* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
654
|
+
"A ",
|
|
655
|
+
/* @__PURE__ */ jsx("code", { children: "radiogroup" }),
|
|
656
|
+
" named by the required ",
|
|
657
|
+
/* @__PURE__ */ jsx("code", { children: "aria-label" }),
|
|
658
|
+
", with each option a",
|
|
659
|
+
" ",
|
|
660
|
+
/* @__PURE__ */ jsx("code", { children: "radio" }),
|
|
661
|
+
" button carrying ",
|
|
662
|
+
/* @__PURE__ */ jsx("code", { children: "aria-checked" }),
|
|
663
|
+
"."
|
|
664
|
+
] }),
|
|
665
|
+
"One Tab stop: focus lands on the chosen option, and the arrow keys move and choose together.",
|
|
666
|
+
/* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
667
|
+
"Disabled options are native disabled and skipped by the arrows. ",
|
|
668
|
+
/* @__PURE__ */ jsx("code", { children: "disabled" }),
|
|
669
|
+
" on the control also sets ",
|
|
670
|
+
/* @__PURE__ */ jsx("code", { children: "aria-disabled" }),
|
|
671
|
+
" on the group."
|
|
672
|
+
] }),
|
|
673
|
+
"Icons are hidden from assistive tech, so an icon-only option needs its hidden text label.",
|
|
674
|
+
"The focus ring is teal, 2px, just outside the option, for keyboard focus only.",
|
|
675
|
+
"Under reduced motion the thumb jumps instead of gliding."
|
|
676
|
+
] })
|
|
677
|
+
}),
|
|
678
|
+
/* @__PURE__ */ jsxs(Section, {
|
|
679
|
+
id: "props",
|
|
680
|
+
title: "Props",
|
|
681
|
+
description: /* @__PURE__ */ jsxs("p", { children: [
|
|
682
|
+
"Other attributes, such as ",
|
|
683
|
+
/* @__PURE__ */ jsx("code", { children: "aria-describedby" }),
|
|
684
|
+
", go to the group."
|
|
685
|
+
] }),
|
|
686
|
+
children: [/* @__PURE__ */ jsx(PropsTable, {
|
|
687
|
+
title: "SegmentedControl",
|
|
688
|
+
rows: [
|
|
689
|
+
{
|
|
690
|
+
name: "options",
|
|
691
|
+
type: "SegmentedControlOption<V>[]",
|
|
692
|
+
required: true,
|
|
693
|
+
description: "The choices, in order. See Option below."
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
name: "aria-label",
|
|
697
|
+
type: "string",
|
|
698
|
+
description: "Names the group, e.g. \"Date range\". Give this or aria-labelledby: the control has no visible label."
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
name: "aria-labelledby",
|
|
702
|
+
type: "string",
|
|
703
|
+
description: "The id of a visible heading that names the group, in place of aria-label."
|
|
704
|
+
},
|
|
705
|
+
{
|
|
706
|
+
name: "value",
|
|
707
|
+
type: "V",
|
|
708
|
+
description: "The chosen value, when you control it."
|
|
709
|
+
},
|
|
710
|
+
{
|
|
711
|
+
name: "defaultValue",
|
|
712
|
+
type: "V",
|
|
713
|
+
description: "The starting value when uncontrolled. Defaults to the first enabled option."
|
|
714
|
+
},
|
|
715
|
+
{
|
|
716
|
+
name: "onValueChange",
|
|
717
|
+
type: "(value: V) => void",
|
|
718
|
+
description: "Called when the choice changes, by click or by arrow key."
|
|
719
|
+
},
|
|
720
|
+
{
|
|
721
|
+
name: "size",
|
|
722
|
+
type: "'sm' | 'md'",
|
|
723
|
+
default: "'md'",
|
|
724
|
+
description: "30 or 36px tall."
|
|
725
|
+
},
|
|
726
|
+
{
|
|
727
|
+
name: "fullWidth",
|
|
728
|
+
type: "boolean",
|
|
729
|
+
default: "false",
|
|
730
|
+
description: "Stretch to the container, options sharing the width equally."
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
name: "disabled",
|
|
734
|
+
type: "boolean",
|
|
735
|
+
default: "false",
|
|
736
|
+
description: "Turns off every option."
|
|
737
|
+
}
|
|
738
|
+
]
|
|
739
|
+
}), /* @__PURE__ */ jsx(PropsTable, {
|
|
740
|
+
title: "Option",
|
|
741
|
+
rows: [
|
|
742
|
+
{
|
|
743
|
+
name: "value",
|
|
744
|
+
type: "V",
|
|
745
|
+
required: true,
|
|
746
|
+
description: "A string. What onValueChange reports."
|
|
747
|
+
},
|
|
748
|
+
{
|
|
749
|
+
name: "label",
|
|
750
|
+
type: "ReactNode",
|
|
751
|
+
required: true,
|
|
752
|
+
description: "The words. With iconOnly, what screen readers say."
|
|
753
|
+
},
|
|
754
|
+
{
|
|
755
|
+
name: "icon",
|
|
756
|
+
type: "ReactNode",
|
|
757
|
+
description: "Leading icon: 15px, or 13px at sm."
|
|
758
|
+
},
|
|
759
|
+
{
|
|
760
|
+
name: "iconOnly",
|
|
761
|
+
type: "boolean",
|
|
762
|
+
default: "false",
|
|
763
|
+
description: "Show the icon alone, centred on a round thumb. Needs an icon."
|
|
764
|
+
},
|
|
765
|
+
{
|
|
766
|
+
name: "disabled",
|
|
767
|
+
type: "boolean",
|
|
768
|
+
description: "Cannot be chosen; skipped by the arrow keys."
|
|
769
|
+
}
|
|
770
|
+
]
|
|
771
|
+
})]
|
|
772
|
+
})
|
|
773
|
+
]
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
//#endregion
|
|
777
|
+
export { Page, Preview };
|