@gemboss/ui 0.50.0 → 0.51.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/CHANGELOG.md +197 -0
- package/README.md +153 -1
- package/catalog/editor.html +25 -12
- package/catalog/index.html +635 -93
- package/gemboss-ui.css +3 -3
- package/package.json +8 -1
- package/parts/components.css +1 -1
- package/parts/core.css +1 -1
- package/parts/shell.css +1 -1
- package/src/auth-extras.css +1 -0
- package/src/auth-footer.css +1 -0
- package/src/auth-footer.tsx +71 -0
- package/src/auth-signin-plain.js +1 -1
- package/src/auth-sso-plain.js +1 -1
- package/src/auth-steps.css +1 -0
- package/src/auth-steps.tsx +179 -0
- package/src/auth.css +1 -1
- package/src/auth.tsx +159 -31
- package/src/dialog.tsx +3 -0
- package/src/editor/color-picker.tsx +183 -0
- package/src/editor/controls.tsx +49 -33
- package/src/editor/index.ts +8 -0
- package/src/editor/picker-grid.tsx +186 -0
- package/src/editor/picker.tsx +275 -0
- package/src/editor/popover.tsx +160 -0
- package/src/editor/swatch.ts +2 -1
- package/src/editor-color.css +1 -0
- package/src/editor-picker-grid.css +1 -0
- package/src/editor-picker.css +1 -0
- package/src/editor-plain.js +1 -1
- package/src/editor-popover.css +1 -0
- package/src/editor.css +1 -1
- package/src/icons.tsx +4 -0
- package/src/index.ts +4 -1
- package/src/theme.tsx +13 -3
package/src/editor/controls.tsx
CHANGED
|
@@ -11,10 +11,13 @@
|
|
|
11
11
|
// · the edge box hands each keystroke to the caller (`onChange(side, raw)`) and says when to commit (`onCommit`, on
|
|
12
12
|
// blur): the caller decides what an empty edge means, and the admin has three answers to that on purpose.
|
|
13
13
|
import "../editor.css"; // its own stylesheet travels with it (0.23.0): a surface that never renders it never loads it
|
|
14
|
+
import "../editor-color.css"; // the swatch button (ColorControl); the picker's own rules are in it too
|
|
14
15
|
import { useEffect, useId, useRef, useState } from "react";
|
|
15
16
|
import type React from "react";
|
|
16
17
|
import { cssUrl } from "./css-url";
|
|
17
|
-
import {
|
|
18
|
+
import { ColorPicker } from "./color-picker";
|
|
19
|
+
import { Popover } from "./popover";
|
|
20
|
+
import { opacityOf, parseColor, swatchState, swatchWhy, withOpacity } from "./swatch";
|
|
18
21
|
import { Segmented } from "../segmented";
|
|
19
22
|
|
|
20
23
|
const blurOnEnter = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
@@ -156,32 +159,49 @@ export interface ColorControlProps {
|
|
|
156
159
|
/** Colours offered as chips while the field is in use (the focus inside it): the theme's colours by role, each with the colour
|
|
157
160
|
* the page draws for it, then the ones used lately. A click writes `value`. None: no chips (the theme inspector, no page). */
|
|
158
161
|
choices?: readonly ColorChoice[];
|
|
162
|
+
/** The picker's None, which empties the field (default true). False where an empty value is not one (a gradient's stop). */
|
|
163
|
+
allowNone?: boolean;
|
|
164
|
+
/** An id the text box is also described by (a field's "not saved" line), beside the swatch's own reason. */
|
|
165
|
+
describedBy?: string;
|
|
166
|
+
/** The text box as it is typed, each keystroke, before its commit (blur / Enter). A host that keeps unsaved edits (a claims
|
|
167
|
+
* queue, a flush when the panel switches) holds the typing with it: kept only here, a value landing from elsewhere replaced
|
|
168
|
+
* the half-typed one unseen, and a switch that unmounts the box without a blur dropped it (review of #5323). */
|
|
169
|
+
onDraft?: (text: string) => void;
|
|
159
170
|
}
|
|
160
171
|
|
|
161
|
-
/** One chip: what it writes (`var(--gem-color-accent)`, `#3366ff`), what it is called, and the colour it paints.
|
|
162
|
-
|
|
172
|
+
/** One chip: what it writes (`var(--gem-color-accent)`, `#3366ff`), what it is called, and the colour it paints. `group`: where the
|
|
173
|
+
* picker shows it ("Theme" or "Recent"); unset is a theme colour. */
|
|
174
|
+
export interface ColorChoice { value: string; label: string; swatch: string; group?: "theme" | "recent" }
|
|
163
175
|
|
|
164
176
|
/**
|
|
165
|
-
* `.gemboss-ei-color`: a
|
|
166
|
-
* (`swatchState`: hex, rgb, hsl, oklch)
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
* the
|
|
177
|
+
* `.gemboss-ei-color`: a swatch beside a text box, and the colour's opacity in percent. The swatch shows any one colour
|
|
178
|
+
* (`swatchState`: hex, rgb, hsl, oklch) over a checkerboard, and opens the kit's colour picker beside the settings column
|
|
179
|
+
* (`Popover` + `ColorPicker`, 24/10/2026: it opened the operating system's picker, a different window on every machine with no
|
|
180
|
+
* opacity and no theme colours); a pick keeps the value's transparency and way of writing (`pickSwatch`). It is DISABLED (with
|
|
181
|
+
* the reason under it) for what is not one colour, a token or a gradient: a pick would overwrite it. The opacity box shows for
|
|
182
|
+
* a colour only (A4, 21/10/2026: 17% of the colours on real pages carry an alpha, which no control could change).
|
|
170
183
|
*/
|
|
171
|
-
export function ColorControl({ id, value, onChange, disabled, label, placeholder, choices }: ColorControlProps) {
|
|
184
|
+
export function ColorControl({ id, value, onChange, disabled, label, placeholder, choices, allowNone = true, describedBy, onDraft }: ColorControlProps) {
|
|
172
185
|
const [draft, setDraft] = useState(value);
|
|
173
186
|
useEffect(() => { setDraft(value); }, [value]);
|
|
174
|
-
// THE THEME'S COLOURS, CLICKED (A4b, 21/10/2026; Chris: "bấm trước gõ sau"):
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
|
|
187
|
+
// THE THEME'S COLOURS, CLICKED (A4b, 21/10/2026; Chris: "bấm trước gõ sau"): in the picker the swatch opens, under Theme and
|
|
188
|
+
// Recent, two clicks as before. Not any more as chips under the row while it had the focus (24/10/2026): they went when the focus
|
|
189
|
+
// left, so a press on the row below moved up under the pointer and its click was lost (review of #5296, measured: 38px). A theme
|
|
190
|
+
// colour the field holds shows on the swatch as the colour the page draws for it, and a pick there writes that colour as your own.
|
|
178
191
|
const chosen = choices?.find((c) => c.value === draft.trim()) ?? null;
|
|
179
192
|
const shown = chosen ? swatchState(chosen.swatch) : null;
|
|
180
193
|
// NOT SET IS NOT BLACK (control standard §13b U7, Chris 20/10/2026): an empty colour drew the swatch black beside "Not set", so a
|
|
181
194
|
// seller read a colour nobody chose. Empty, the swatch is white with the slash a colour picker draws for "none" (editor.css
|
|
182
195
|
// `[data-empty]`), and opens on white.
|
|
183
196
|
const empty = !draft.trim();
|
|
184
|
-
const {
|
|
197
|
+
const { usable } = shown?.usable ? shown : swatchState(draft);
|
|
198
|
+
// What the swatch paints: the colour with its opacity (the checkerboard shows through). Nothing for what it cannot show (a
|
|
199
|
+
// gradient, an unknown token): the native swatch painted those black, a colour nobody chose (SwatchState's rule).
|
|
200
|
+
const parsed = usable ? parseColor(chosen ? chosen.swatch : draft) : null;
|
|
201
|
+
const paint = parsed ? `rgba(${Math.round(parsed.r)}, ${Math.round(parsed.g)}, ${Math.round(parsed.b)}, ${parsed.a})` : null;
|
|
202
|
+
const rowRef = useRef<HTMLDivElement>(null);
|
|
203
|
+
const swatchRef = useRef<HTMLButtonElement>(null);
|
|
204
|
+
const [picking, setPicking] = useState(false);
|
|
185
205
|
// Why the swatch is off, said under it, read with it (a tooltip alone reached neither a finger nor the keys). The COMMITTED
|
|
186
206
|
// value's reason, and kept while the panel saves (it disables every field): taken from the draft or dropped while saving, the
|
|
187
207
|
// line came and went on every write and while a hex was typed (review of #4636). A draft that is a whole hex has none.
|
|
@@ -198,14 +218,22 @@ export function ColorControl({ id, value, onChange, disabled, label, placeholder
|
|
|
198
218
|
if (next !== draft) { setDraft(next); onChange(next); }
|
|
199
219
|
};
|
|
200
220
|
return (
|
|
201
|
-
<div className="gemboss-ei-color"
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
disabled={disabled || !usable}
|
|
221
|
+
<div ref={rowRef} className="gemboss-ei-color">
|
|
222
|
+
<button ref={swatchRef} type="button" className="gemboss-ei-swatch" aria-label={`${label} swatch`} aria-haspopup="dialog" aria-expanded={picking}
|
|
223
|
+
data-empty={empty ? "" : undefined} disabled={disabled || !usable}
|
|
205
224
|
title={usable ? undefined : swatchWhy(draft) ?? undefined} aria-describedby={why ? whyId : undefined}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
225
|
+
onClick={() => setPicking((p) => !p)}>
|
|
226
|
+
<span className="gemboss-ei-swatch-fill" style={paint ? { "--sw": paint } as React.CSSProperties : undefined} />
|
|
227
|
+
</button>
|
|
228
|
+
{/* Open from the swatch's click until it is closed: not shut by a save in flight (the panels disable every field while one
|
|
229
|
+
runs, which closed it on each pick and opened it again with the focus: review of #5296), nor by the text box holding a
|
|
230
|
+
half-typed colour (it closed at "#" and opened at "#123", taking the focus and the rest of the typing). */}
|
|
231
|
+
<Popover open={picking} anchor={rowRef.current} returnTo={swatchRef.current} title={label} onClose={() => setPicking(false)}>
|
|
232
|
+
<ColorPicker value={draft} base={chosen ? chosen.swatch : draft} label={label} choices={choices} allowNone={allowNone}
|
|
233
|
+
onChange={(next) => { setDraft(next); onChange(next); }} />
|
|
234
|
+
</Popover>
|
|
235
|
+
<input id={id} className="gemboss-field gemboss-ei-inp" placeholder={placeholder ?? "Not set"} value={draft} disabled={disabled} aria-describedby={describedBy}
|
|
236
|
+
onChange={(e) => { setDraft(e.target.value); onDraft?.(e.target.value); }} onBlur={() => onChange(draft)} onKeyDown={blurOnEnter} />
|
|
209
237
|
{/* A fixed narrow box beside the wide one (the row's own rule makes every .gemboss-ei-inp flex: 1): inline, not a new rule. */}
|
|
210
238
|
{opacity !== null ? (
|
|
211
239
|
// `data-alpha`: the hook editor-plain.js finds it by (the same box on a page without React).
|
|
@@ -213,18 +241,6 @@ export function ColorControl({ id, value, onChange, disabled, label, placeholder
|
|
|
213
241
|
value={alphaDraft ?? `${opacity}%`} disabled={disabled}
|
|
214
242
|
onChange={(e) => setAlphaDraft(e.target.value)} onBlur={(e) => commitAlpha(e.target.value)} onKeyDown={blurOnEnter} />
|
|
215
243
|
) : null}
|
|
216
|
-
{inUse && choices?.length ? (
|
|
217
|
-
// The kit's colour chips (.gemboss-ei-swatches / .gemboss-ei-sw, the theme inspector's Background row), on a line of their own.
|
|
218
|
-
<div className="gemboss-ei-swatches" role="group" aria-label={`${label} colors`} style={{ flexBasis: "100%", flexWrap: "wrap" }}>
|
|
219
|
-
{choices.map((c) => {
|
|
220
|
-
const on = c.value === draft.trim();
|
|
221
|
-
return (
|
|
222
|
-
<button key={c.value} type="button" className={`gemboss-ei-sw${on ? " on" : ""}`} title={c.label} aria-label={c.label} aria-pressed={on}
|
|
223
|
-
style={{ background: c.swatch }} disabled={disabled} onClick={() => { setDraft(c.value); onChange(c.value); }} />
|
|
224
|
-
);
|
|
225
|
-
})}
|
|
226
|
-
</div>
|
|
227
|
-
) : null}
|
|
228
244
|
{why ? <p id={whyId} className="gemboss-ei-color-why">{why}</p> : null}
|
|
229
245
|
</div>
|
|
230
246
|
);
|
package/src/editor/index.ts
CHANGED
|
@@ -53,4 +53,12 @@ export { SortableLayerList, type SortableLayerListProps, useRowDrag, dropIndex }
|
|
|
53
53
|
export { RepeaterList, useKeyedRows, type RepeaterListProps, type KeyedRows } from "./repeater";
|
|
54
54
|
// 16/10/2026: a closed choice of shapes (an image's ratio, a layout) as picture tiles; its own CSS part, editor-tiles.css.
|
|
55
55
|
export { ChoiceTiles, type ChoiceTile, type ChoiceTilesProps } from "./tiles";
|
|
56
|
+
// 24/10/2026: a setting's small panel beside the settings column (top layer; a sheet at phone width); its own CSS part.
|
|
57
|
+
export { Popover, type PopoverProps } from "./popover";
|
|
58
|
+
// 24/10/2026: the colour picker ColorControl's swatch opens (square, hue, opacity, hex, eyedropper, theme/recent/None).
|
|
59
|
+
export { ColorPicker, type ColorPickerProps } from "./color-picker";
|
|
60
|
+
// 24/10/2026: the body of every "choose one" popup (search, rows, states); its own CSS part, editor-picker.css.
|
|
61
|
+
export { PickerList, type PickerItem, type PickerListProps, type PickerTone } from "./picker";
|
|
62
|
+
// 24/10/2026: the same search and states for things chosen by their picture (the shop's images, an icon library); its own CSS part.
|
|
63
|
+
export { PickerGrid, type PickerTile, type PickerGridProps } from "./picker-grid";
|
|
56
64
|
export { LayerTree, type LayerTreeProps, type LayerTreeRow } from "./tree";
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// PICKER GRID (24/10/2026, picker standard slice 3): PickerList's search box, highlight and states for things chosen by their
|
|
3
|
+
// PICTURE (the shop's images, an icon library): tiles in as many columns as fit; a click selects, a double click or Enter uses at
|
|
4
|
+
// once where the caller has a "use" (the image picker's Use image); a tile being uploaded or that failed shows, cannot be chosen,
|
|
5
|
+
// and is said aloud from outside the grid (an option's children are presentational: an alert inside one is not announced).
|
|
6
|
+
// Keys, the WAI-ARIA grid combobox's: ↑ ↓ move by a row, to the tile in the next row nearest the column (the last row may be
|
|
7
|
+
// short; a row of tiles in flight is passed); in the search box ← → Home End are the caret's until ↑ or ↓ has stepped into the
|
|
8
|
+
// grid, and the grid's from then until the next keystroke typed (review of slice 3: with the box always keeping ← →, a keyboard
|
|
9
|
+
// reached only the highlighted tile's column). Without a box the grid has the focus and every key is the grid's.
|
|
10
|
+
// Its own part (`editor-picker-grid.css`); the shared pieces are editor-picker.css's.
|
|
11
|
+
import "../editor-picker.css";
|
|
12
|
+
import "../editor-picker-grid.css";
|
|
13
|
+
import React, { useEffect, useId, useRef, useState } from "react";
|
|
14
|
+
import { Icon } from "../icons";
|
|
15
|
+
import { PickNothing, PickSearch, typesFirst, usePickHighlight, type PickerSearch } from "./picker";
|
|
16
|
+
|
|
17
|
+
export interface PickerTile {
|
|
18
|
+
/** What `onSelect` / `onActivate` get, and what `selected` is compared with. */
|
|
19
|
+
key: string;
|
|
20
|
+
title: string;
|
|
21
|
+
/** A second line under the name (where the image came from). */
|
|
22
|
+
subtitle?: string;
|
|
23
|
+
/** The tile's tooltip, its title when left out: the image picker's file address, which tells two files of one name apart. */
|
|
24
|
+
tooltip?: string;
|
|
25
|
+
/** A photo: a URL, or null for one that could have a picture and has none (a grey square keeps its place). */
|
|
26
|
+
image?: string | null;
|
|
27
|
+
/** A drawn picture instead (an icon's SVG), centred in the tile. */
|
|
28
|
+
picture?: React.ReactNode;
|
|
29
|
+
/** The photo whole inside its square (a logo, a cut-out) instead of filling it; `checker`: on a checkerboard (a cut-out). */
|
|
30
|
+
fit?: "cover" | "contain";
|
|
31
|
+
checker?: boolean;
|
|
32
|
+
/** A tile not yet a choice: being uploaded (`busy`), or one that failed (`error`, said in red). Shown, not choosable. */
|
|
33
|
+
status?: { busy?: boolean; error?: string };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface PickerGridProps {
|
|
37
|
+
/** The grid's accessible name ("Your images", "Icons"). */
|
|
38
|
+
label: string;
|
|
39
|
+
tiles: readonly PickerTile[];
|
|
40
|
+
/** The tile now chosen: a check, `aria-selected`, and the one highlighted first. */
|
|
41
|
+
selected?: string | null;
|
|
42
|
+
/** A click, Space: the tile chosen (the image picker's selection; an icon library's pick). */
|
|
43
|
+
onSelect: (key: string) => void;
|
|
44
|
+
/** A double click, Enter: the tile used at once (the image picker's Use image). Without it they select. */
|
|
45
|
+
onActivate?: (key: string) => void;
|
|
46
|
+
search?: PickerSearch;
|
|
47
|
+
state?: "ready" | "loading" | "reloading" | "error";
|
|
48
|
+
error?: { message: string; onRetry?: () => void };
|
|
49
|
+
empty?: { title: string; body?: string; action?: React.ReactNode };
|
|
50
|
+
more?: { onClick: () => void; busy?: boolean; label?: string };
|
|
51
|
+
/** `photo`: square pictures, 120px wide at least, a name and a line (the default). `icon`: a 26px drawing over its name (two
|
|
52
|
+
* lines at most), 88px wide at least. */
|
|
53
|
+
size?: "photo" | "icon";
|
|
54
|
+
/** Skeleton tiles while loading (default 8). */
|
|
55
|
+
loadingTiles?: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function PickerGrid({ label, tiles, selected = null, onSelect, onActivate, search, state = "ready", error, empty, more, size = "photo", loadingTiles = 8 }: PickerGridProps) {
|
|
59
|
+
const base = useId();
|
|
60
|
+
const boxRef = useRef<HTMLInputElement>(null);
|
|
61
|
+
const gridRef = useRef<HTMLUListElement>(null);
|
|
62
|
+
const phase = state === "reloading" && tiles.length === 0 ? "loading" : state;
|
|
63
|
+
const shown = phase === "ready" || phase === "reloading" ? tiles : [];
|
|
64
|
+
const live = phase === "ready";
|
|
65
|
+
const choosable = (t: PickerTile | undefined) => !!t && !t.status;
|
|
66
|
+
const query = search?.value ?? "";
|
|
67
|
+
const tileId = (i: number) => `${base}-t${i}`;
|
|
68
|
+
const { active, highlight } = usePickHighlight(shown, choosable, selected, query, tileId);
|
|
69
|
+
// In the box: ↑ or ↓ has stepped into the grid, so ← → Home End move the highlight; a keystroke typed gives them back to the caret.
|
|
70
|
+
const [stepping, setStepping] = useState(false);
|
|
71
|
+
useEffect(() => { setStepping(false); }, [query]);
|
|
72
|
+
|
|
73
|
+
// Columns as laid out now (as many as fit): the tiles on the first row.
|
|
74
|
+
const columns = () => {
|
|
75
|
+
const els = gridRef.current ? [...gridRef.current.querySelectorAll<HTMLElement>("[role=option]")] : [];
|
|
76
|
+
const top = els[0]?.offsetTop;
|
|
77
|
+
const n = els.findIndex((e) => e.offsetTop !== top);
|
|
78
|
+
return Math.max(1, n < 0 ? els.length : n);
|
|
79
|
+
};
|
|
80
|
+
const move = (step: "up" | "down" | "left" | "right" | "first" | "last") => {
|
|
81
|
+
const can = shown.flatMap((t, i) => (choosable(t) ? [i] : []));
|
|
82
|
+
if (!can.length) return;
|
|
83
|
+
const to = (i: number | undefined) => { if (i !== undefined) highlight(shown[i]!.key, "keys"); };
|
|
84
|
+
if (step === "first" || active < 0) return to(can[0]);
|
|
85
|
+
if (step === "last") return to(can[can.length - 1]);
|
|
86
|
+
if (step === "right") return to(can.find((i) => i > active));
|
|
87
|
+
if (step === "left") return to([...can].reverse().find((i) => i < active));
|
|
88
|
+
// A row up or down: the next row holding a choice, its tile nearest this column (a short last row, a row of uploads).
|
|
89
|
+
const cols = columns(), col = active % cols, dir = step === "down" ? 1 : -1;
|
|
90
|
+
for (let row = Math.floor(active / cols) + dir; row >= 0 && row * cols < shown.length; row += dir) {
|
|
91
|
+
const inRow = can.filter((i) => Math.floor(i / cols) === row);
|
|
92
|
+
if (inRow.length) return to(inRow.reduce((a, b) => (Math.abs((b % cols) - col) < Math.abs((a % cols) - col) ? b : a)));
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const choose = (t: PickerTile | undefined, use: boolean) => {
|
|
96
|
+
if (!live || !choosable(t)) return;
|
|
97
|
+
if (use && onActivate) onActivate(t!.key); else onSelect(t!.key);
|
|
98
|
+
};
|
|
99
|
+
const clear = () => { search?.onChange(""); boxRef.current?.focus(); };
|
|
100
|
+
// As PickerList: `search.autoFocus`, the box takes the focus once, as the grid appears.
|
|
101
|
+
useEffect(() => { if (typesFirst(search)) boxRef.current?.focus(); }, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
102
|
+
const keyDown = (e: React.KeyboardEvent, fromBox: boolean) => {
|
|
103
|
+
if (e.nativeEvent.isComposing || e.keyCode === 229) return;
|
|
104
|
+
// A keystroke typed gives ← → back to the caret now, in this event: the effect on the query lands a render later, and the
|
|
105
|
+
// next key can come first.
|
|
106
|
+
if (fromBox && (e.key.length === 1 || e.key === "Backspace" || e.key === "Delete")) { if (stepping) setStepping(false); return; }
|
|
107
|
+
const grid = !fromBox || stepping;
|
|
108
|
+
const go = (step: Parameters<typeof move>[0]) => { e.preventDefault(); move(step); };
|
|
109
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") { if (fromBox) setStepping(true); go(e.key === "ArrowDown" ? "down" : "up"); }
|
|
110
|
+
else if (grid && e.key === "ArrowRight") go("right");
|
|
111
|
+
else if (grid && e.key === "ArrowLeft") go("left");
|
|
112
|
+
else if (grid && e.key === "Home") go("first");
|
|
113
|
+
else if (grid && e.key === "End") go("last");
|
|
114
|
+
else if (e.key === "Enter") { if (shown.length) e.preventDefault(); choose(shown[active], true); }
|
|
115
|
+
else if (!fromBox && e.key === " ") { e.preventDefault(); choose(shown[active], false); }
|
|
116
|
+
else if (fromBox && e.key === "Escape" && query) { e.preventDefault(); e.stopPropagation(); clear(); }
|
|
117
|
+
};
|
|
118
|
+
// The uploads in flight, said aloud from outside the grid (below).
|
|
119
|
+
const sending = tiles.filter((t) => t.status?.busy).map((t) => t.title);
|
|
120
|
+
|
|
121
|
+
const listId = `${base}-grid`;
|
|
122
|
+
const hasTiles = shown.length > 0;
|
|
123
|
+
const activeId = live && active >= 0 && shown[active] ? tileId(active) : undefined;
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<div className="gemboss-ei-pick">
|
|
127
|
+
{search ? <PickSearch search={search} boxRef={boxRef} listId={listId} hasList={hasTiles} activeId={activeId} onKeyDown={(e) => keyDown(e, true)} onClear={clear} /> : null}
|
|
128
|
+
{phase === "loading" || phase === "error" || !hasTiles ? (
|
|
129
|
+
<PickNothing phase={phase === "loading" ? "loading" : phase === "error" ? "error" : "empty"} error={error} empty={empty} query={query} onClear={clear}
|
|
130
|
+
skeleton={
|
|
131
|
+
<div className={`gemboss-ei-pickgrid${size === "icon" ? " is-icon" : ""}`} role="status" aria-label="Loading">
|
|
132
|
+
{Array.from({ length: loadingTiles }, (_, i) => (
|
|
133
|
+
<div key={i} className="gemboss-ei-pickgrid-skeleton" aria-hidden>
|
|
134
|
+
<span className="gemboss-ei-pickgrid-pic ui-skeleton__line" />
|
|
135
|
+
<span className="ui-skeleton__line" />
|
|
136
|
+
</div>
|
|
137
|
+
))}
|
|
138
|
+
</div>
|
|
139
|
+
} />
|
|
140
|
+
) : (
|
|
141
|
+
<>
|
|
142
|
+
<ul ref={gridRef} id={listId} className={`gemboss-ei-pickgrid${size === "icon" ? " is-icon" : ""}${live ? "" : " is-reloading"}`} role="listbox" aria-label={label}
|
|
143
|
+
aria-busy={live ? undefined : true} tabIndex={search ? -1 : 0} aria-activedescendant={search ? undefined : activeId}
|
|
144
|
+
onKeyDown={search ? undefined : (e) => keyDown(e, false)}>
|
|
145
|
+
{shown.map((t, i) => {
|
|
146
|
+
const chosen = t.key === selected;
|
|
147
|
+
const off = !live || !!t.status;
|
|
148
|
+
return (
|
|
149
|
+
<li key={t.key} id={tileId(i)} role="option" aria-selected={chosen} aria-disabled={off ? true : undefined} title={t.tooltip ?? t.title}
|
|
150
|
+
className={`gemboss-ei-pickgrid-tile${i === active ? " is-active" : ""}${t.status?.busy ? " is-busy" : ""}${t.status?.error ? " is-error" : ""}`} data-key={t.key}
|
|
151
|
+
onMouseDown={(e) => { if (search) e.preventDefault(); /* the search box keeps the focus */ }}
|
|
152
|
+
onMouseMove={() => { if (choosable(t) && i !== active) highlight(t.key, "pointer"); }}
|
|
153
|
+
onClick={() => choose(t, false)} onDoubleClick={() => choose(t, true)}>
|
|
154
|
+
{t.picture ? <span className="gemboss-ei-pickgrid-pic is-drawn" aria-hidden>{t.picture}</span>
|
|
155
|
+
: t.image ? <img className={`gemboss-ei-pickgrid-pic${t.fit === "contain" ? " is-whole" : ""}${t.checker ? " is-checker" : ""}`} src={t.image} alt="" loading="lazy" />
|
|
156
|
+
: <span className="gemboss-ei-pickgrid-pic" aria-hidden>{t.status?.error ? "!" : null}</span>}
|
|
157
|
+
<span className="gemboss-ei-pickgrid-name">{t.title}</span>
|
|
158
|
+
{t.status?.error || t.status?.busy || t.subtitle ? (
|
|
159
|
+
<span className="gemboss-ei-pickgrid-sub">
|
|
160
|
+
{t.status?.error ?? (t.status?.busy ? "Uploading…" : t.subtitle)}
|
|
161
|
+
</span>
|
|
162
|
+
) : null}
|
|
163
|
+
{chosen ? <Icon name="check" size={16} className="gemboss-ei-pickgrid-check" /> : null}
|
|
164
|
+
</li>
|
|
165
|
+
);
|
|
166
|
+
})}
|
|
167
|
+
</ul>
|
|
168
|
+
</>
|
|
169
|
+
)}
|
|
170
|
+
{/* Said aloud from outside the grid (an option's children are presentational) and kept across its states: each failure once,
|
|
171
|
+
a log ADDS (one alert string with every failure read the first again with the second: review of #5325); the uploads in
|
|
172
|
+
flight as one line. */}
|
|
173
|
+
<div className="ui-sr-only" role="log" aria-live="assertive">
|
|
174
|
+
{tiles.filter((t) => t.status?.error).map((t) => <p key={t.key}>{`${t.title}: ${t.status!.error}`}</p>)}
|
|
175
|
+
</div>
|
|
176
|
+
<p className="ui-sr-only" role="status">{sending.length ? `Uploading ${sending.join(", ")}…` : ""}</p>
|
|
177
|
+
{/* After the grid, or after "no results" / an empty grid: the next page may hold what this one did not (the first page of a
|
|
178
|
+
store's Shopify files, all held already or none matching, kept Load more out of reach: review of #5325). */}
|
|
179
|
+
{more && (phase === "ready" || phase === "reloading") ? (
|
|
180
|
+
<div className="gemboss-ei-pick-more">
|
|
181
|
+
<button type="button" className="ui-btn" disabled={more.busy} onClick={more.onClick}>{more.busy ? "Loading…" : (more.label ?? "Show more")}</button>
|
|
182
|
+
</div>
|
|
183
|
+
) : null}
|
|
184
|
+
</div>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// PICKER LIST (24/10/2026, Chris: the editor's pickers looked bare and each drew its own; "chuẩn hoá theo ui kit"). One body for
|
|
3
|
+
// every "choose one of these" popup in the editors: a link's product, page or section, a video, a font, a page. Before it, five
|
|
4
|
+
// pickers drew five lists in the admin's own CSS (rows, search box, empty and loading lines), each a little different.
|
|
5
|
+
//
|
|
6
|
+
// Polaris' pattern for picking from a searchable list is a Combobox over a Listbox, and this is that, at the kit's numbers:
|
|
7
|
+
// · the search box keeps the focus: ↑ ↓ move the highlighted row, Enter picks it, Escape clears the box first (the popup's own
|
|
8
|
+
// Escape closes it when the box is empty); with no search box the list takes the focus and the same keys work on it. An
|
|
9
|
+
// Enter or an Escape that ends an IME composition (Vietnamese, Chinese) is the typing's, not the list's (as SearchDialog);
|
|
10
|
+
// · the highlight is a ROW, kept by its key: a list that changes under it never leaves it on another row for a frame (review
|
|
11
|
+
// of #5290); the pointer moves it too, and it is painted only while the picker has the focus;
|
|
12
|
+
// · `.gemboss-ei-pick-row[role=option]`: a 40px picture (a photo, or an icon for a page or a section), the title (20px line,
|
|
13
|
+
// 650) with a status pill (`ui-tag`), a second line; the row now chosen has a check and `aria-selected`; one click picks;
|
|
14
|
+
// · the second line puts a NOTE first, in its own box the ellipsis never reaches (review of gemboss #5283: "Opens the popup"
|
|
15
|
+
// at the end of a long line was cut off), then the rest, cut with "…";
|
|
16
|
+
// · a row that cannot be picked is shown, says why (its note), and does nothing (`aria-disabled`);
|
|
17
|
+
// · states (the kit's collection states): loading keeps the rows' place with skeletons; RELOADING keeps the rows of the last
|
|
18
|
+
// answer dimmed and `aria-busy`, and nothing is picked from them (they answer another search: an Enter there wrote the
|
|
19
|
+
// previous query's first row, review of #5290); an error is the kit's danger notice with Try again; a search that finds
|
|
20
|
+
// nothing says so and offers Clear search; an empty list says what the caller gives it; "Show more" ends a long list.
|
|
21
|
+
// Its grid sibling, PickerGrid (picker-grid.tsx), draws the same search box, highlight and states (PickSearch, usePickHighlight,
|
|
22
|
+
// PickNothing, exported for it, not from the package).
|
|
23
|
+
// Its own part (`editor-picker.css`): only a surface that draws a picker loads it.
|
|
24
|
+
import "../editor-picker.css";
|
|
25
|
+
import React, { useEffect, useId, useMemo, useRef, useState } from "react";
|
|
26
|
+
import { Icon, type IconName } from "../icons";
|
|
27
|
+
|
|
28
|
+
export type PickerTone = "neutral" | "info" | "success" | "warning" | "critical";
|
|
29
|
+
|
|
30
|
+
export interface PickerItem {
|
|
31
|
+
/** What `onPick` gets, and what `current` is compared with. */
|
|
32
|
+
key: string;
|
|
33
|
+
title: string;
|
|
34
|
+
/** The title drawn as what it names: a font's name in its own face, at a size its shape reads at (`{ fontFamily, fontSize }`). */
|
|
35
|
+
titleStyle?: React.CSSProperties;
|
|
36
|
+
/** The rest of the second line (a path, a heading), cut with "…" when it does not fit. */
|
|
37
|
+
subtitle?: string;
|
|
38
|
+
/** What to know before picking, first on the second line and never cut ("Opens the popup", "Opens once it is active"). */
|
|
39
|
+
note?: string;
|
|
40
|
+
/** A short status beside the title, as a pill ("Draft", "Archived"). */
|
|
41
|
+
badge?: { label: string; tone?: PickerTone };
|
|
42
|
+
/** A photo: a URL, or null for a thing that could have one and has none (a grey square keeps its place). */
|
|
43
|
+
image?: string | null;
|
|
44
|
+
/** For a thing that has no photo (a page, a section): its icon in the same 40px tile. */
|
|
45
|
+
icon?: IconName;
|
|
46
|
+
/** A drawn picture of the caller's instead (an SVG the kit has no icon for: a cart, a product tag), in the same 40px tile. */
|
|
47
|
+
picture?: React.ReactNode;
|
|
48
|
+
/** The row opens a list of its own (the page picker's Products, Collections): a chevron at its end instead of the check,
|
|
49
|
+
* and picking it is the caller's step into that list. Current, it is marked by the chosen row's tint (and `aria-selected`). */
|
|
50
|
+
drill?: boolean;
|
|
51
|
+
/** Present: shown, not pickable, and this is said as its note (a locked row says why). */
|
|
52
|
+
disabledReason?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface PickerListProps {
|
|
56
|
+
/** The list's accessible name ("Sections", "Products"). */
|
|
57
|
+
label: string;
|
|
58
|
+
items: readonly PickerItem[];
|
|
59
|
+
/** The key now chosen: its row has the check (a drill row: the tint), and is the one highlighted first. */
|
|
60
|
+
current?: string | null;
|
|
61
|
+
onPick: (key: string) => void;
|
|
62
|
+
/** The search box above the list; leave it out for a short list. The caller filters `items` (or asks a server). `autoFocus`:
|
|
63
|
+
* the box takes the focus when the list appears, and is the `[data-autofocus]` the kit's Dialog and Popover focus on opening
|
|
64
|
+
* (every picker in the editors sets it: the search box is where a picker is used from). */
|
|
65
|
+
search?: PickerSearch;
|
|
66
|
+
/**
|
|
67
|
+
* `loading`: skeleton rows in the list's place (a first read). `reloading`: `items` are the last answer, kept on screen
|
|
68
|
+
* dimmed while the next one is read (a search being typed), and not pickable. `error`: `error.message`, Try again with
|
|
69
|
+
* `error.onRetry`.
|
|
70
|
+
*/
|
|
71
|
+
state?: "ready" | "loading" | "reloading" | "error";
|
|
72
|
+
error?: { message: string; onRetry?: () => void };
|
|
73
|
+
/** What an empty list says when nothing is searched ("This page has no sections yet."), and one action. */
|
|
74
|
+
empty?: { title: string; body?: string; action?: React.ReactNode };
|
|
75
|
+
/** More rows than these: "Show more" after the last one. */
|
|
76
|
+
more?: { onClick: () => void; busy?: boolean; label?: string };
|
|
77
|
+
/** Skeleton rows while loading (default 4). */
|
|
78
|
+
loadingRows?: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** @internal shared with picker-grid.tsx */
|
|
82
|
+
export type PickerSearch = { value: string; onChange: (value: string) => void; placeholder?: string; label?: string; autoFocus?: boolean };
|
|
83
|
+
|
|
84
|
+
/** @internal shared with picker-grid.tsx. `search.autoFocus` under a mouse only: under a finger (the kit's `(pointer: coarse)`, as
|
|
85
|
+
* §9.1's targets) a focused box raises the on-screen keyboard over the list the person came to tap (review, 24/10/2026). */
|
|
86
|
+
export const typesFirst = (search?: PickerSearch) =>
|
|
87
|
+
Boolean(search?.autoFocus) && !(typeof window !== "undefined" && window.matchMedia?.("(pointer: coarse)").matches);
|
|
88
|
+
|
|
89
|
+
/** The search box both pickers draw: the kit's grouped field (an icon in the box, as the admin's "Find a setting"), `gemboss-field`
|
|
90
|
+
* owning the look, here only the icon and the ✕ placed (text-fields-share-one-look.test.ts). A text box with a search keyboard, not
|
|
91
|
+
* type=search: it is a combobox, and the browser's own ✕ would sit beside the kit's. */
|
|
92
|
+
export function PickSearch({ search, boxRef, listId, hasList, activeId, onKeyDown, onClear }: {
|
|
93
|
+
search: PickerSearch; boxRef: React.RefObject<HTMLInputElement>; listId: string; hasList: boolean; activeId?: string;
|
|
94
|
+
onKeyDown: (e: React.KeyboardEvent) => void; onClear: () => void;
|
|
95
|
+
}) {
|
|
96
|
+
return (
|
|
97
|
+
<label className="gemboss-field gemboss-field--group gemboss-ei-pick-search">
|
|
98
|
+
<Icon name="search" size={16} className="gemboss-ei-pick-search-icon" />
|
|
99
|
+
<input ref={boxRef} type="text" inputMode="search" enterKeyHint="search" className="gemboss-field__bare" value={search.value} placeholder={search.placeholder ?? "Search"}
|
|
100
|
+
aria-label={search.label ?? search.placeholder ?? "Search"} role="combobox" aria-expanded={hasList} aria-controls={hasList ? listId : undefined}
|
|
101
|
+
aria-autocomplete="list" aria-activedescendant={activeId} autoComplete="off" spellCheck={false} data-autofocus={typesFirst(search) ? "" : undefined}
|
|
102
|
+
onChange={(e) => search.onChange(e.target.value)} onKeyDown={onKeyDown} />
|
|
103
|
+
{search.value ? (
|
|
104
|
+
<button type="button" className="gemboss-ei-pick-clear" aria-label="Clear search" onClick={onClear}>
|
|
105
|
+
<Icon name="close" size={16} />
|
|
106
|
+
</button>
|
|
107
|
+
) : null}
|
|
108
|
+
</label>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** What both pickers draw instead of their items: skeletons (given), the kit's error, a search that found nothing, an empty list. */
|
|
113
|
+
export function PickNothing({ phase, skeleton, error, empty, query, onClear }: {
|
|
114
|
+
phase: "loading" | "error" | "empty"; skeleton: React.ReactNode; error?: { message: string; onRetry?: () => void };
|
|
115
|
+
empty?: { title: string; body?: string; action?: React.ReactNode }; query: string; onClear: () => void;
|
|
116
|
+
}) {
|
|
117
|
+
if (phase === "loading") return <>{skeleton}</>;
|
|
118
|
+
if (phase === "error") {
|
|
119
|
+
// The kit's error (CollectionState's): a danger notice, never an empty list.
|
|
120
|
+
return (
|
|
121
|
+
<div className="ui-notice ui-notice--danger gemboss-ei-pick-error" role="alert">
|
|
122
|
+
<b>{error?.message ?? "This list could not be read."}</b>
|
|
123
|
+
{error?.onRetry ? <button type="button" className="ui-btn" onClick={error.onRetry}>Try again</button> : null}
|
|
124
|
+
</div>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
return query.trim() ? (
|
|
128
|
+
<div className="ui-empty">
|
|
129
|
+
<p className="ui-empty__title">No results for “{query.trim()}”</p>
|
|
130
|
+
<p className="ui-empty__body">Check the spelling or search for something else.</p>
|
|
131
|
+
<button type="button" className="ui-btn" onClick={onClear}>Clear search</button>
|
|
132
|
+
{/* The caller's way forward too (the image picker's Upload): a library with nothing in it, searched, hid it (review of #5325). */}
|
|
133
|
+
{empty?.action ?? null}
|
|
134
|
+
</div>
|
|
135
|
+
) : (
|
|
136
|
+
<div className="ui-empty">
|
|
137
|
+
<p className="ui-empty__title">{empty?.title ?? "Nothing to choose yet."}</p>
|
|
138
|
+
{empty?.body ? <p className="ui-empty__body">{empty.body}</p> : null}
|
|
139
|
+
{empty?.action ?? null}
|
|
140
|
+
</div>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** @internal shared with picker-grid.tsx. The highlight both pickers keep: a KEY (a list that changes under it never leaves it on
|
|
145
|
+
* another item for a frame, review of #5290), forgotten when the search changes; unset or gone, the chosen item when it can be
|
|
146
|
+
* picked, else the first that can. It is scrolled into view when the keys (or the list) move it, never when the pointer does:
|
|
147
|
+
* a pointer resting on a half-shown tile scrolled the grid under itself, and the next tile under it moved it again (review of
|
|
148
|
+
* slice 3). */
|
|
149
|
+
export function usePickHighlight<T extends { key: string }>(shown: readonly T[], can: (t: T) => boolean, chosen: string | null, query: string, idOf: (i: number) => string) {
|
|
150
|
+
const [activeKey, setActiveKey] = useState<string | null>(null);
|
|
151
|
+
// The key the pointer put the highlight on: that one is not scrolled to (a flag alone stayed set when the pointer's move left
|
|
152
|
+
// the highlight where it was, and the next move by the keys or the list skipped its scroll: review of #5325).
|
|
153
|
+
const byPointer = useRef<string | null>(null);
|
|
154
|
+
useEffect(() => { setActiveKey(null); }, [query]);
|
|
155
|
+
const byKey = activeKey === null ? -1 : shown.findIndex((t) => t.key === activeKey && can(t));
|
|
156
|
+
const atChosen = shown.findIndex((t) => t.key === chosen && can(t));
|
|
157
|
+
const active = byKey >= 0 ? byKey : atChosen >= 0 ? atChosen : shown.findIndex(can);
|
|
158
|
+
useEffect(() => {
|
|
159
|
+
if (active >= 0 && byPointer.current !== shown[active]?.key) document.getElementById(idOf(active))?.scrollIntoView?.({ block: "nearest" });
|
|
160
|
+
byPointer.current = null;
|
|
161
|
+
}, [active]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
162
|
+
const highlight = (key: string, by: "keys" | "pointer") => { byPointer.current = by === "pointer" ? key : null; setActiveKey(key); };
|
|
163
|
+
return { active, highlight };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// A row that opens a list of its own ends with this.
|
|
167
|
+
const DRILL = <Icon name="chevronRight" size={16} className="gemboss-ei-pick-drill" />;
|
|
168
|
+
|
|
169
|
+
const TONE: Record<PickerTone, string> = { neutral: "ui-tag", info: "ui-tag ui-tag--accent", success: "ui-tag ui-tag--success", warning: "ui-tag ui-tag--warning", critical: "ui-tag ui-tag--danger" };
|
|
170
|
+
|
|
171
|
+
export function PickerList({ label, items, current = null, onPick, search, state = "ready", error, empty, more, loadingRows = 4 }: PickerListProps) {
|
|
172
|
+
const base = useId();
|
|
173
|
+
const boxRef = useRef<HTMLInputElement>(null);
|
|
174
|
+
// Reloading with nothing to keep is a first read: skeletons, not "nothing here".
|
|
175
|
+
const phase = state === "reloading" && items.length === 0 ? "loading" : state;
|
|
176
|
+
const shown = phase === "ready" || phase === "reloading" ? items : [];
|
|
177
|
+
const live = phase === "ready";
|
|
178
|
+
const pickable = useMemo(() => shown.map((it, i) => (it.disabledReason ? -1 : i)).filter((i) => i >= 0), [shown]);
|
|
179
|
+
const query = search?.value ?? "";
|
|
180
|
+
const optionId = (i: number) => `${base}-o${i}`;
|
|
181
|
+
const { active, highlight } = usePickHighlight(shown, (it) => !it.disabledReason, current, query, optionId);
|
|
182
|
+
|
|
183
|
+
const pick = (it: PickerItem | undefined) => { if (live && it && !it.disabledReason) onPick(it.key); };
|
|
184
|
+
const move = (by: 1 | -1 | "first" | "last") => {
|
|
185
|
+
if (!pickable.length) return;
|
|
186
|
+
const at = pickable.indexOf(active);
|
|
187
|
+
const next = by === "first" ? 0 : by === "last" ? pickable.length - 1 : at < 0 ? 0 : Math.min(pickable.length - 1, Math.max(0, at + by));
|
|
188
|
+
highlight(shown[pickable[next]!]!.key, "keys");
|
|
189
|
+
};
|
|
190
|
+
const clear = () => { search?.onChange(""); boxRef.current?.focus(); };
|
|
191
|
+
// The box carries `data-autofocus`, which the kit's Dialog and Popover focus as they open; this covers a list that appears in a
|
|
192
|
+
// container already open (a drill-down's new list). Once, as the list appears.
|
|
193
|
+
useEffect(() => { if (typesFirst(search)) boxRef.current?.focus(); }, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
194
|
+
const keyDown = (e: React.KeyboardEvent, fromBox: boolean) => {
|
|
195
|
+
if (e.nativeEvent.isComposing || e.keyCode === 229) return;
|
|
196
|
+
if (e.key === "ArrowDown") { e.preventDefault(); move(1); }
|
|
197
|
+
else if (e.key === "ArrowUp") { e.preventDefault(); move(-1); }
|
|
198
|
+
else if (!fromBox && e.key === "Home") { e.preventDefault(); move("first"); }
|
|
199
|
+
else if (!fromBox && e.key === "End") { e.preventDefault(); move("last"); }
|
|
200
|
+
else if (e.key === "Enter" || (!fromBox && e.key === " ")) {
|
|
201
|
+
// Reloading: the rows answer another search; Enter waits for this one (nothing is written).
|
|
202
|
+
if (shown.length) e.preventDefault();
|
|
203
|
+
pick(shown[active]);
|
|
204
|
+
} else if (fromBox && e.key === "Escape" && query) { e.preventDefault(); e.stopPropagation(); clear(); }
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const listId = `${base}-list`;
|
|
208
|
+
const hasList = shown.length > 0;
|
|
209
|
+
const activeId = live && active >= 0 && shown[active] ? optionId(active) : undefined;
|
|
210
|
+
|
|
211
|
+
return (
|
|
212
|
+
<div className="gemboss-ei-pick">
|
|
213
|
+
{search ? <PickSearch search={search} boxRef={boxRef} listId={listId} hasList={hasList} activeId={activeId} onKeyDown={(e) => keyDown(e, true)} onClear={clear} /> : null}
|
|
214
|
+
|
|
215
|
+
{phase === "loading" || phase === "error" || !hasList ? (
|
|
216
|
+
<PickNothing phase={phase === "loading" ? "loading" : phase === "error" ? "error" : "empty"} error={error} empty={empty} query={query} onClear={clear}
|
|
217
|
+
skeleton={
|
|
218
|
+
<div className="gemboss-ei-pick-skeleton" role="status" aria-label="Loading">
|
|
219
|
+
{Array.from({ length: loadingRows }, (_, i) => (
|
|
220
|
+
<div key={i} className="gemboss-ei-pick-skeleton-row" aria-hidden>
|
|
221
|
+
<span className="gemboss-ei-pick-media ui-skeleton__line" />
|
|
222
|
+
<span className="gemboss-ei-pick-skeleton-text"><span className="ui-skeleton__line" /><span className="ui-skeleton__line" /></span>
|
|
223
|
+
</div>
|
|
224
|
+
))}
|
|
225
|
+
</div>
|
|
226
|
+
} />
|
|
227
|
+
) : (
|
|
228
|
+
<>
|
|
229
|
+
<ul id={listId} className={`gemboss-ei-pick-list${live ? "" : " is-reloading"}`} role="listbox" aria-label={label} aria-busy={live ? undefined : true}
|
|
230
|
+
tabIndex={search ? -1 : 0} aria-activedescendant={search ? undefined : activeId} onKeyDown={search ? undefined : (e) => keyDown(e, false)}>
|
|
231
|
+
{shown.map((it, i) => {
|
|
232
|
+
const chosen = it.key === current;
|
|
233
|
+
const note = it.disabledReason ?? it.note;
|
|
234
|
+
return (
|
|
235
|
+
<li key={it.key} id={optionId(i)} role="option" aria-selected={chosen} aria-disabled={it.disabledReason || !live ? true : undefined}
|
|
236
|
+
className={`gemboss-ei-pick-row${i === active ? " is-active" : ""}`} data-key={it.key}
|
|
237
|
+
onMouseDown={(e) => e.preventDefault() /* the search box keeps the focus */}
|
|
238
|
+
onMouseMove={() => { if (!it.disabledReason && i !== active) highlight(it.key, "pointer"); }}
|
|
239
|
+
onClick={() => pick(it)}>
|
|
240
|
+
{it.image !== undefined ? (
|
|
241
|
+
it.image ? <img className="gemboss-ei-pick-media" src={it.image} alt="" loading="lazy" /> : <span className="gemboss-ei-pick-media" aria-hidden />
|
|
242
|
+
) : it.icon ? (
|
|
243
|
+
<span className="gemboss-ei-pick-media gemboss-ei-pick-media--icon" aria-hidden><Icon name={it.icon} size={20} /></span>
|
|
244
|
+
) : it.picture ? (
|
|
245
|
+
<span className="gemboss-ei-pick-media gemboss-ei-pick-media--icon" aria-hidden>{it.picture}</span>
|
|
246
|
+
) : null}
|
|
247
|
+
<span className="gemboss-ei-pick-text">
|
|
248
|
+
<span className="gemboss-ei-pick-head">
|
|
249
|
+
<span className="gemboss-ei-pick-title" style={it.titleStyle}>{it.title}</span>
|
|
250
|
+
{it.badge ? <span className={TONE[it.badge.tone ?? "neutral"]}>{it.badge.label}</span> : null}
|
|
251
|
+
</span>
|
|
252
|
+
{note || it.subtitle ? (
|
|
253
|
+
<span className="gemboss-ei-pick-sub">
|
|
254
|
+
{note ? <span className={`gemboss-ei-pick-note${it.disabledReason ? " is-blocked" : ""}`}>{note}</span> : null}
|
|
255
|
+
{it.subtitle ? <span className="gemboss-ei-pick-rest">{note ? `· ${it.subtitle}` : it.subtitle}</span> : null}
|
|
256
|
+
</span>
|
|
257
|
+
) : null}
|
|
258
|
+
</span>
|
|
259
|
+
{it.drill ? DRILL : chosen ? <Icon name="check" size={20} className="gemboss-ei-pick-check" /> : null}
|
|
260
|
+
</li>
|
|
261
|
+
);
|
|
262
|
+
})}
|
|
263
|
+
</ul>
|
|
264
|
+
</>
|
|
265
|
+
)}
|
|
266
|
+
{/* After the list, or after "no results" / an empty list: the next page may hold what this one did not (the first page of a
|
|
267
|
+
store's Shopify files, all held already or none matching, kept Load more out of reach: review of #5325). */}
|
|
268
|
+
{more && (phase === "ready" || phase === "reloading") ? (
|
|
269
|
+
<div className="gemboss-ei-pick-more">
|
|
270
|
+
<button type="button" className="ui-btn" disabled={more.busy} onClick={more.onClick}>{more.busy ? "Loading…" : (more.label ?? "Show more")}</button>
|
|
271
|
+
</div>
|
|
272
|
+
) : null}
|
|
273
|
+
</div>
|
|
274
|
+
);
|
|
275
|
+
}
|