@gemboss/ui 0.66.0 → 0.68.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 +217 -2
- package/README.md +9 -4
- package/catalog/editor.html +1 -1
- package/catalog/index.html +3 -3
- package/gemboss-ui.css +3 -3
- package/package.json +5 -1
- package/parts/components.css +2 -2
- package/parts/core.css +1 -1
- package/parts/shell.css +1 -1
- package/src/assistant/engine.tsx +2 -18
- package/src/board-auto-more.tsx +168 -0
- package/src/collections.tsx +10 -1
- package/src/confirm-buttons.ts +4 -2
- package/src/confirm-dialog.tsx +7 -3
- package/src/copy-field.css +1 -0
- package/src/copy-field.tsx +48 -0
- package/src/copy-text.ts +20 -0
- package/src/create-shell.css +1 -1
- package/src/dialog.tsx +68 -11
- package/src/editor/choice-cards.tsx +71 -0
- package/src/editor/controls.tsx +10 -5
- package/src/editor/field-control.tsx +117 -57
- package/src/editor/field-spec.ts +45 -9
- package/src/editor/grow-to-text.ts +51 -0
- package/src/editor/index.ts +11 -2
- package/src/editor/items-field.tsx +185 -0
- package/src/editor/items.ts +126 -0
- package/src/editor/label-side.ts +2 -1
- package/src/editor/repeater.tsx +37 -7
- package/src/editor/secret-field.tsx +5 -3
- package/src/editor/switch.tsx +34 -0
- package/src/editor-grow.css +1 -0
- package/src/editor-insert.css +1 -1
- package/src/editor-repeater.css +1 -1
- package/src/editor-switch.css +1 -0
- package/src/editor.css +1 -1
- package/src/gemboss-field.css +1 -1
- package/src/index.ts +3 -0
- package/src/kit-plain.css +1 -1
- package/src/segmented.tsx +4 -2
package/src/confirm-dialog.tsx
CHANGED
|
@@ -75,9 +75,13 @@ export interface ConfirmDialogProps {
|
|
|
75
75
|
children: ReactNode;
|
|
76
76
|
/** 620 wide (Polaris' default Modal) instead of the kit's 460: a question that lists what goes (images, photos). */
|
|
77
77
|
wide?: boolean;
|
|
78
|
+
/** The refused button's words (default "Try again") and the ✕'s name (default "Close"), for a surface in the viewer's language
|
|
79
|
+
* (GemCommunity: en / vi / zh; 09/11/2026). */
|
|
80
|
+
retryLabel?: string;
|
|
81
|
+
closeLabel?: string;
|
|
78
82
|
}
|
|
79
83
|
|
|
80
|
-
export function ConfirmDialog({ open, title, action, destructive = true, alternative, cancelLabel = "Cancel", busyCloseLabel, disabled = false, busy, error, canRetry = true, onConfirm, onClose, children, wide = false }: ConfirmDialogProps) {
|
|
84
|
+
export function ConfirmDialog({ open, title, action, destructive = true, alternative, cancelLabel = "Cancel", busyCloseLabel, disabled = false, busy, error, canRetry = true, onConfirm, onClose, children, wide = false, retryLabel, closeLabel }: ConfirmDialogProps) {
|
|
81
85
|
const closable = !busy || Boolean(busyCloseLabel);
|
|
82
86
|
// onClose is the person closing it. The kit's Dialog also reports the close that `open` turning false makes (the caller closing
|
|
83
87
|
// it when the thing is done): not forwarded, so a caller hears one close, as with the Polaris Modal this replaced.
|
|
@@ -95,13 +99,13 @@ export function ConfirmDialog({ open, title, action, destructive = true, alterna
|
|
|
95
99
|
if (open !== wasOpen) { setWasOpen(open); if (open) { setLast("main"); setShown(true); } }
|
|
96
100
|
const closed = () => { setShown(false); close(); };
|
|
97
101
|
const b = confirmButtons({ action, alternative: alternative?.content, cancelLabel, busyCloseLabel, disabled, alternativeDisabled: Boolean(alternative?.disabled),
|
|
98
|
-
busy, error: error !== null, canRetry, last });
|
|
102
|
+
busy, error: error !== null, canRetry, last, retryLabel });
|
|
99
103
|
const spinner = <span className="ui-spinner" aria-hidden="true" />;
|
|
100
104
|
// An off button stays focusable (aria-disabled, never disabled: the kit's rule, Gems/CLAUDE.md §13), so the focus stays in the
|
|
101
105
|
// question while the server answers, and its press does nothing.
|
|
102
106
|
const off = (o: boolean) => (o ? { "aria-disabled": true as const } : {});
|
|
103
107
|
return (
|
|
104
|
-
<Dialog open={open} onClose={closed} title={title} dismissible={closable} wide={wide} className="ui-confirm" footer={(
|
|
108
|
+
<Dialog open={open} onClose={closed} title={title} dismissible={closable} wide={wide} className="ui-confirm" closeLabel={closeLabel} footer={(
|
|
105
109
|
<>
|
|
106
110
|
{alternative && b.alternative ? (
|
|
107
111
|
<button type="button" className="ui-btn" {...off(b.alternative.disabled || b.alternative.loading)} aria-busy={b.alternative.loading || undefined}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.ui-copy-field{display:flex;flex-wrap:wrap;align-items:center;gap:8px;min-width:0}.ui-copy-field__value{flex:1 1 220px;min-width:0;background:var(--gemboss-divider-soft)}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// A VALUE TO TAKE AWAY (09/11/2026; Chris 08/11: one control set). A link to send traffic to, a review link, a code: the value in a box the
|
|
3
|
+
// seller can select but not change (focus selects it whole), and Copy beside it, which says Copied for two seconds, or "Copy it by hand"
|
|
4
|
+
// when the browser refuses the clipboard (the box is selected then, so ⌘C / Ctrl+C takes it). More actions on the same row come after
|
|
5
|
+
// Copy (`children`: an Open). The admin drew this by hand on several screens (Go live's link, a share-for-review link), each its own box.
|
|
6
|
+
import "./copy-field.css"; // its own stylesheet travels with it: a surface that never draws it never loads it
|
|
7
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
8
|
+
import { copyText } from "./copy-text";
|
|
9
|
+
|
|
10
|
+
export interface CopyFieldProps {
|
|
11
|
+
value: string;
|
|
12
|
+
/** The box's accessible name ("Link for your traffic"). */
|
|
13
|
+
label: string;
|
|
14
|
+
/** The button's words. Default "Copy link". */
|
|
15
|
+
copyLabel?: string;
|
|
16
|
+
/** More actions on the row, after Copy (an Open). */
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
/** Told after a press: copied (true), or the browser refused (false). */
|
|
19
|
+
onCopied?: (ok: boolean) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function CopyField({ value, label, copyLabel = "Copy link", children, onCopied }: CopyFieldProps) {
|
|
23
|
+
const [said, setSaid] = useState<"idle" | "done" | "failed">("idle");
|
|
24
|
+
const box = useRef<HTMLInputElement>(null);
|
|
25
|
+
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
26
|
+
useEffect(() => () => { if (timer.current) clearTimeout(timer.current); }, []);
|
|
27
|
+
const say = (s: "done" | "failed") => {
|
|
28
|
+
setSaid(s);
|
|
29
|
+
if (timer.current) clearTimeout(timer.current);
|
|
30
|
+
timer.current = setTimeout(() => { timer.current = null; setSaid("idle"); }, 2000);
|
|
31
|
+
};
|
|
32
|
+
// The kit's one copy (copyText: the Clipboard API, else the old way). Refused both ways, the box takes the focus with its text selected,
|
|
33
|
+
// so ⌘C / Ctrl+C is the next key.
|
|
34
|
+
const copy = () => {
|
|
35
|
+
void copyText(value).then((ok) => {
|
|
36
|
+
if (!ok) box.current?.focus(); // its onFocus selects it whole
|
|
37
|
+
say(ok ? "done" : "failed");
|
|
38
|
+
onCopied?.(ok);
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
return (
|
|
42
|
+
<div className="ui-copy-field">
|
|
43
|
+
<input ref={box} className="gemboss-field ui-copy-field__value" value={value} readOnly aria-label={label} onFocus={(e) => e.currentTarget.select()} />
|
|
44
|
+
<button type="button" className="ui-btn" onClick={copy}>{said === "done" ? "Copied" : said === "failed" ? "Copy it by hand" : copyLabel}</button>
|
|
45
|
+
{children}
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
package/src/copy-text.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Text onto the clipboard: the Clipboard API, else (an http:// page, a refused permission, an old Safari) a selected text area and
|
|
2
|
+
// execCommand. True when it got there. Its own module (09/11/2026, CopyField): the assistant's engine re-exports it.
|
|
3
|
+
/** Copies through the async clipboard, else through a selected textarea (an http:// page, an old Safari). */
|
|
4
|
+
export async function copyText(text: string): Promise<boolean> {
|
|
5
|
+
try {
|
|
6
|
+
if (navigator.clipboard?.writeText) { await navigator.clipboard.writeText(text); return true; }
|
|
7
|
+
} catch { /* permission refused: try the old way */ }
|
|
8
|
+
try {
|
|
9
|
+
const ta = document.createElement("textarea");
|
|
10
|
+
ta.value = text;
|
|
11
|
+
ta.setAttribute("readonly", "");
|
|
12
|
+
ta.style.position = "fixed";
|
|
13
|
+
ta.style.opacity = "0";
|
|
14
|
+
document.body.appendChild(ta);
|
|
15
|
+
ta.select();
|
|
16
|
+
const ok = document.execCommand("copy");
|
|
17
|
+
ta.remove();
|
|
18
|
+
return ok;
|
|
19
|
+
} catch { return false; }
|
|
20
|
+
}
|
package/src/create-shell.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.ui-create-icon{display:grid;place-items:center;width:100%;height:100%;min-width:30px;min-height:30px;border-radius:var(--gemboss-radius-md, 8px);background:var(--gemboss-accent-soft, #eef0fe);color:var(--gemboss-accent, #5661f5)}.ui-create-steps{display:flex;align-items:center;gap:8px;margin:0;padding:0;list-style:none;font-size:var(--gemboss-fs-caption, 12px);color:var(--ui-text-muted)}.ui-create-step{display:flex;align-items:center;gap:6px;white-space:nowrap}.ui-create-step+.ui-create-step:before{content:"";width:24px;height:1px;margin-right:2px;background:var(--ui-border)}.ui-create-step__n{display:grid;place-items:center;width:20px;height:20px;box-sizing:border-box;border:1px solid var(--ui-border);border-radius:999px;font-size:var(--gemboss-fs-micro, 11px)}.ui-create-step--on{font-weight:600;color:var(--ui-text)}.ui-create-step--on .ui-create-step__n{border-color:var(--ui-text);background:var(--ui-text);color:var(--gemboss-surface, #fff)}.ui-create-step--done .ui-create-step__n{border-color:transparent;background:var(--gemboss-success-soft, #e6f4ee);color:var(--gemboss-success, #007f5f)}.ui-create-rail{display:flex;flex-direction:column;gap:20px;min-height:100%;box-sizing:border-box;padding:20px;background:var(--ui-surface)}.ui-create-rail__foot{margin:auto 0 0;font-size:var(--gemboss-fs-caption, 12px);line-height:1.5;color:var(--ui-text-muted)}.ui-create-group{display:flex;flex-direction:column;gap:8px}.ui-create-label{font-size:var(--gemboss-fs-micro, 11px);font-weight:600;letter-spacing:.08em;text-transform:uppercase;color:var(--ui-text-muted)}.ui-create-door{display:flex;align-items:center;gap:12px;width:100%;min-height:56px;padding:8px 12px;text-align:left;cursor:pointer;border:1px solid var(--ui-border);border-radius:var(--gemboss-radius-lg, 12px);background:var(--gemboss-surface, #fff);color:var(--ui-text);font:inherit}.ui-create-door:hover{border-color:var(--ui-text-muted)}.ui-create-door--on{border-color:var(--ui-text);box-shadow:inset 0 0 0 1px var(--ui-text)}.ui-create-door:disabled{opacity:.5;cursor:default}.ui-create-door__art{flex:none;display:grid;place-items:center;width:32px;height:32px;border-radius:var(--gemboss-radius-md, 8px);background:var(--gemboss-accent-soft, #eef0fe);color:var(--gemboss-accent, #5661f5)}.ui-create-door__col{display:flex;flex-direction:column;gap:2px;min-width:0}.ui-create-door__col b{font-size:var(--gemboss-fs-body, 14px);font-weight:600}.ui-create-door__col span{font-size:var(--gemboss-fs-caption, 12px);line-height:1.4;color:var(--ui-text-muted)}.ui-create-chips{display:flex;flex-wrap:wrap;gap:6px}.ui-create-chip{display:inline-flex;align-items:center;gap:6px;min-height:32px;padding:0 12px;cursor:pointer;border:1px solid var(--ui-border);border-radius:999px;background:var(--gemboss-surface, #fff);color:var(--ui-text);font:inherit;font-size:var(--gemboss-fs-caption, 12px)}.ui-create-chip--on{border-color:var(--ui-text);background:var(--ui-text);color:var(--gemboss-surface, #fff);font-weight:600}.ui-create-chip__n{opacity:.6}.ui-create-dot{flex:none;width:8px;height:8px;border-radius:999px;background:#a4a6ad}.ui-create-dot--cold{background:#5661f5}.ui-create-dot--warm{background:#c27c0e}.ui-create-dot--ready{background:#d9480f}.ui-create-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(240px,100%),1fr));gap:16px}.ui-create-grid--wide{grid-template-columns:repeat(auto-fill,minmax(min(
|
|
1
|
+
.ui-create-icon{display:grid;place-items:center;width:100%;height:100%;min-width:30px;min-height:30px;border-radius:var(--gemboss-radius-md, 8px);background:var(--gemboss-accent-soft, #eef0fe);color:var(--gemboss-accent, #5661f5)}.ui-create-steps{display:flex;align-items:center;gap:8px;margin:0;padding:0;list-style:none;font-size:var(--gemboss-fs-caption, 12px);color:var(--ui-text-muted)}.ui-create-step{display:flex;align-items:center;gap:6px;white-space:nowrap}.ui-create-step+.ui-create-step:before{content:"";width:24px;height:1px;margin-right:2px;background:var(--ui-border)}.ui-create-step__n{display:grid;place-items:center;width:20px;height:20px;box-sizing:border-box;border:1px solid var(--ui-border);border-radius:999px;font-size:var(--gemboss-fs-micro, 11px)}.ui-create-step--on{font-weight:600;color:var(--ui-text)}.ui-create-step--on .ui-create-step__n{border-color:var(--ui-text);background:var(--ui-text);color:var(--gemboss-surface, #fff)}.ui-create-step--done .ui-create-step__n{border-color:transparent;background:var(--gemboss-success-soft, #e6f4ee);color:var(--gemboss-success, #007f5f)}.ui-create-rail{display:flex;flex-direction:column;gap:20px;min-height:100%;box-sizing:border-box;padding:20px;background:var(--ui-surface)}.ui-create-rail__foot{margin:auto 0 0;font-size:var(--gemboss-fs-caption, 12px);line-height:1.5;color:var(--ui-text-muted)}.ui-create-group{display:flex;flex-direction:column;gap:8px}.ui-create-label{font-size:var(--gemboss-fs-micro, 11px);font-weight:600;letter-spacing:.08em;text-transform:uppercase;color:var(--ui-text-muted)}.ui-create-door{display:flex;align-items:center;gap:12px;width:100%;min-height:56px;padding:8px 12px;text-align:left;cursor:pointer;border:1px solid var(--ui-border);border-radius:var(--gemboss-radius-lg, 12px);background:var(--gemboss-surface, #fff);color:var(--ui-text);font:inherit}.ui-create-door:hover{border-color:var(--ui-text-muted)}.ui-create-door--on{border-color:var(--ui-text);box-shadow:inset 0 0 0 1px var(--ui-text)}.ui-create-door:disabled{opacity:.5;cursor:default}.ui-create-door__art{flex:none;display:grid;place-items:center;width:32px;height:32px;border-radius:var(--gemboss-radius-md, 8px);background:var(--gemboss-accent-soft, #eef0fe);color:var(--gemboss-accent, #5661f5)}.ui-create-door__col{display:flex;flex-direction:column;gap:2px;min-width:0}.ui-create-door__col b{font-size:var(--gemboss-fs-body, 14px);font-weight:600}.ui-create-door__col span{font-size:var(--gemboss-fs-caption, 12px);line-height:1.4;color:var(--ui-text-muted)}.ui-create-chips{display:flex;flex-wrap:wrap;gap:6px}.ui-create-chip{display:inline-flex;align-items:center;gap:6px;min-height:32px;padding:0 12px;cursor:pointer;border:1px solid var(--ui-border);border-radius:999px;background:var(--gemboss-surface, #fff);color:var(--ui-text);font:inherit;font-size:var(--gemboss-fs-caption, 12px)}.ui-create-chip--on{border-color:var(--ui-text);background:var(--ui-text);color:var(--gemboss-surface, #fff);font-weight:600}.ui-create-chip__n{opacity:.6}.ui-create-dot{flex:none;width:8px;height:8px;border-radius:999px;background:#a4a6ad}.ui-create-dot--cold{background:#5661f5}.ui-create-dot--warm{background:#c27c0e}.ui-create-dot--ready{background:#d9480f}.ui-create-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(240px,100%),1fr));gap:16px}.ui-create-grid--wide{grid-template-columns:repeat(auto-fill,minmax(min(340px,100%),1fr));gap:20px}.ui-create-card{display:flex;flex-direction:column;min-width:0;overflow:hidden;border:1px solid var(--ui-border);border-radius:var(--gemboss-radius-xl, 16px);background:var(--gemboss-surface, #fff)}.ui-create-card--on{border-color:var(--ui-text);box-shadow:inset 0 0 0 1px var(--ui-text)}.ui-create-card--dashed{border-style:dashed}.ui-create-card__pic{position:relative;height:150px}.ui-create-card__pic>.ui-stage{height:100%;box-sizing:border-box;border-radius:0}.ui-create-card__pic--wide{height:auto;aspect-ratio:16 / 9;overflow:hidden;border-bottom:1px solid var(--ui-border);background:var(--gemboss-surface, #fff)}.ui-create-card__badge{position:absolute;top:8px;left:8px;z-index:1;padding:2px 8px;border-radius:999px;background:var(--gemboss-surface, #fff);color:var(--ui-text);font-size:var(--gemboss-fs-micro, 11px);font-weight:600}.ui-create-card__body{display:flex;flex:1 1 auto;flex-direction:column;gap:6px;padding:12px 16px 16px}.ui-create-card__eyebrow{display:flex;align-items:center;gap:6px;font-size:var(--gemboss-fs-micro, 11px);font-weight:600;letter-spacing:.06em;text-transform:uppercase;color:var(--ui-text-muted)}.ui-create-card__eyebrow--cold{color:#5661f5}.ui-create-card__eyebrow--warm{color:#a86a0a}.ui-create-card__eyebrow--ready{color:#c2410c}.ui-create-card__title{margin:0;font-size:var(--gemboss-fs-body-lg, 16px);font-weight:600;color:var(--ui-text)}.ui-create-card__line{margin:0;font-size:var(--gemboss-fs-body, 14px);line-height:1.45;color:var(--ui-text-muted)}.ui-create-card__inside{margin:0;font-size:var(--gemboss-fs-caption, 12px);line-height:1.5;color:var(--ui-text)}.ui-create-card__note{margin:0;font-size:var(--gemboss-fs-caption, 12px);line-height:1.5;color:var(--ui-text-muted)}.ui-create-card__act{display:flex;flex-wrap:wrap;gap:8px;margin-top:auto;padding-top:8px}.ui-stage.ui-create-pic{justify-content:center;gap:6px;padding:16px 20%}.ui-create-pic .ui-stage__tile{padding:6px 12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ui-create-pic__more{align-self:center;color:var(--ui-stage-ink-dim)}.ui-create-pic--path{display:flex;align-items:center;justify-content:center;height:100%;box-sizing:border-box;padding:16px;background:radial-gradient(rgba(86,97,245,.13) 1px,transparent 1.5px) 0 0 / 16px 16px,linear-gradient(180deg,var(--gemboss-accent-wash, #f7f8ff),#f2f3fe);border-bottom:1px solid var(--gemboss-accent-tint, #dfe2ff);color:var(--ui-text);font-size:var(--gemboss-fs-caption, 12px)}.ui-create-path{display:flex;align-items:center;justify-content:center;flex-wrap:wrap;gap:6px}.ui-create-path__step{display:flex;align-items:center;gap:6px}.ui-create-path__arrow{color:#8b93ff}.ui-create-path__tile{display:flex;flex-direction:column;align-items:center;gap:4px;max-width:76px;padding:6px;text-align:center;border:1px solid var(--gemboss-accent-tint, #dfe2ff);border-radius:var(--gemboss-radius-md, 8px);background:var(--gemboss-surface, #fff);box-shadow:0 1px 2px #1b1c1e0f;font-size:var(--gemboss-fs-micro, 11px);line-height:1.2}.ui-create-path__tile img{width:40px;height:40px;object-fit:cover;border-radius:var(--gemboss-radius-sm, 6px);background:#f2f3fe}@media (max-width: 47.9975em){.ui-create-step:not(.ui-create-step--on){display:none}.ui-create-step+.ui-create-step:before{display:none}}@media (pointer: coarse){.ui-create-chip{min-height:44px}}
|
package/src/dialog.tsx
CHANGED
|
@@ -14,10 +14,13 @@
|
|
|
14
14
|
* to the right edge: it renders `Dialog` and brings sheet.css, so the markup and the behaviour each have one owner.
|
|
15
15
|
*/
|
|
16
16
|
import "./dialog.css"; // its frame travels with it (09/11/2026): a surface that loads ui.css alone (the admin) draws it too
|
|
17
|
-
import React, { useEffect, useId, useRef } from "react";
|
|
17
|
+
import React, { useEffect, useId, useRef, useState } from "react";
|
|
18
18
|
import { flushSync } from "react-dom";
|
|
19
19
|
import { Icon } from "./icons";
|
|
20
20
|
import { consumeEscape } from "./escape";
|
|
21
|
+
// The question `dirty` asks (10/11/2026). ConfirmDialog draws itself with this file's Dialog; it is used only when one renders, so
|
|
22
|
+
// the two modules may name each other.
|
|
23
|
+
import { ConfirmDialog } from "./confirm-dialog";
|
|
21
24
|
|
|
22
25
|
const cx = (...p: Array<string | false | null | undefined>) => p.filter(Boolean).join(" ");
|
|
23
26
|
|
|
@@ -39,6 +42,8 @@ const cx = (...p: Array<string | false | null | undefined>) => p.filter(Boolean)
|
|
|
39
42
|
* - `dismissible: false` (08/11/2026, ConfirmDialog while the server answers): Escape, the backdrop and ✕ do not close it. The
|
|
40
43
|
* browser's `cancel` is prevented, and when it closes anyway (Chrome lets a second Escape with no press between go through) it
|
|
41
44
|
* opens again at once; only `open` turning false closes it then.
|
|
45
|
+
* - `ask` (10/11/2026, Dialog's `dirty`): Escape, the backdrop and ✕ call it instead of closing (the caller asks first), and a
|
|
46
|
+
* close the browser makes anyway opens it again and asks. `leave()` is the close the answer makes: it goes through.
|
|
42
47
|
*/
|
|
43
48
|
// The control a press last landed on (24/10/2026). Polaris' buttons blur themselves on mouseup (UnstyledButton's
|
|
44
49
|
// handleMouseUpByBlurring), so a popup opened by a click on one found <body> focused and gave the focus back to <body> on Escape:
|
|
@@ -72,10 +77,15 @@ export function holdTab(e: React.KeyboardEvent<HTMLElement>): void {
|
|
|
72
77
|
if (own === e.currentTarget) e.stopPropagation();
|
|
73
78
|
}
|
|
74
79
|
|
|
75
|
-
export function useModalDialog(open: boolean, onClose: () => void, { focusPanel = false, returnFocusTo, dismissible = true }: { focusPanel?: boolean; returnFocusTo?: string; dismissible?: boolean } = {}) {
|
|
80
|
+
export function useModalDialog(open: boolean, onClose: () => void, { focusPanel = false, returnFocusTo, dismissible = true, ask = null }: { focusPanel?: boolean; returnFocusTo?: string; dismissible?: boolean; ask?: (() => void) | null } = {}) {
|
|
76
81
|
const ref = useRef<HTMLDialogElement>(null);
|
|
77
82
|
const dismiss = useRef(dismissible);
|
|
78
83
|
dismiss.current = dismissible;
|
|
84
|
+
const asks = useRef(ask);
|
|
85
|
+
asks.current = ask;
|
|
86
|
+
// Set by `leave()`, the close an answer makes ("Discard and close"): it is not asked about again. Cleared on every opening.
|
|
87
|
+
const leaving = useRef(false);
|
|
88
|
+
const asking = () => (asks.current && !leaving.current ? asks.current : null);
|
|
79
89
|
const openNow = useRef(open);
|
|
80
90
|
openNow.current = open;
|
|
81
91
|
const opener = useRef<Element | null>(null);
|
|
@@ -94,6 +104,7 @@ export function useModalDialog(open: boolean, onClose: () => void, { focusPanel
|
|
|
94
104
|
const d = ref.current;
|
|
95
105
|
if (!d) return;
|
|
96
106
|
if (open && !d.open) {
|
|
107
|
+
leaving.current = false;
|
|
97
108
|
opener.current = openerNow();
|
|
98
109
|
d.showModal();
|
|
99
110
|
shown.current = true;
|
|
@@ -106,10 +117,17 @@ export function useModalDialog(open: boolean, onClose: () => void, { focusPanel
|
|
|
106
117
|
const d = ref.current;
|
|
107
118
|
if (!d) return undefined;
|
|
108
119
|
// Not dismissible: Escape does nothing (the browser's cancel is prevented)…
|
|
109
|
-
|
|
120
|
+
// …and while it asks first (`ask`), a close request asks instead (the Escape a focus outside it sends, a phone's Back).
|
|
121
|
+
const onCancel = (e: Event) => {
|
|
122
|
+
if (!dismiss.current) { e.preventDefault(); return; }
|
|
123
|
+
const a = asking();
|
|
124
|
+
if (a) { e.preventDefault(); a(); }
|
|
125
|
+
};
|
|
110
126
|
const onNativeClose = () => {
|
|
111
|
-
// …and a close the browser made anyway (a second Escape) is undone while the caller still has it open
|
|
112
|
-
|
|
127
|
+
// …and a close the browser made anyway (a second Escape) is undone while the caller still has it open; one that would
|
|
128
|
+
// have asked asks now.
|
|
129
|
+
const a = dismiss.current ? asking() : null;
|
|
130
|
+
if ((!dismiss.current || a) && openNow.current) { try { d.showModal(); } catch { /* not connected: it is going anyway */ } a?.(); return; }
|
|
113
131
|
shown.current = false;
|
|
114
132
|
// What closing changes is on the page before the focus goes back: a picker's typed handle, saved as it closes, replaces its
|
|
115
133
|
// "Choose a product" with the chosen row, and the focus went to that button an instant before it left (measured, 24/10/2026).
|
|
@@ -134,10 +152,13 @@ export function useModalDialog(open: boolean, onClose: () => void, { focusPanel
|
|
|
134
152
|
}, [open, dismissible]);
|
|
135
153
|
const onPointerDown = (e: React.PointerEvent<HTMLDialogElement>) => { pressOnBackdrop.current = e.target === e.currentTarget; };
|
|
136
154
|
const onClick = (e: React.MouseEvent<HTMLDialogElement>) => {
|
|
137
|
-
if (e.target === e.currentTarget && pressOnBackdrop.current && dismiss.current) e.currentTarget.close();
|
|
155
|
+
if (e.target === e.currentTarget && pressOnBackdrop.current && dismiss.current) { const a = asking(); if (a) a(); else e.currentTarget.close(); }
|
|
138
156
|
pressOnBackdrop.current = false;
|
|
139
157
|
};
|
|
140
|
-
|
|
158
|
+
/** ✕, or the answer to the question `ask` opened: the second goes through without asking again. */
|
|
159
|
+
const requestClose = () => { const a = asking(); if (a) a(); else ref.current?.close(); };
|
|
160
|
+
const leave = () => { leaving.current = true; ref.current?.close(); };
|
|
161
|
+
return { ref, onClick, onPointerDown, onKeyDown: holdTab, requestClose, leave, asking };
|
|
141
162
|
}
|
|
142
163
|
|
|
143
164
|
export interface DialogProps {
|
|
@@ -163,13 +184,33 @@ export interface DialogProps {
|
|
|
163
184
|
returnFocusTo?: string;
|
|
164
185
|
/** False while it must stay (ConfirmDialog waiting for the server): Escape, the backdrop and ✕ do not close it. Default true. */
|
|
165
186
|
dismissible?: boolean;
|
|
187
|
+
/** Closing now would lose work nobody saved (typed words, a pasted picture; 10/11/2026, one control set): Escape, ✕ and the
|
|
188
|
+
* backdrop ask first, in the kit's ConfirmDialog over it, as the admin's PluginPopup does (popup-close.ts): "Discard unsaved
|
|
189
|
+
* changes?", Keep editing (it stays as it was) or Discard and close (`onClose`). `open` turning false never asks: the caller
|
|
190
|
+
* closes on purpose. Passed at all (false too), the question is mounted, ready; left out, nothing changes. */
|
|
191
|
+
dirty?: boolean;
|
|
192
|
+
/** The question's words, for a surface's own words or its viewer's language ("Close the composer?"). English by default. */
|
|
193
|
+
dirtyAsk?: { title?: string; body?: React.ReactNode; action?: string; cancelLabel?: string; closeLabel?: string };
|
|
166
194
|
}
|
|
167
195
|
|
|
168
|
-
|
|
169
|
-
|
|
196
|
+
const DIRTY_ASK = { title: "Discard unsaved changes?", body: "You have changes that aren’t saved. If you close now, they’re lost.",
|
|
197
|
+
action: "Discard and close", cancelLabel: "Keep editing" };
|
|
198
|
+
|
|
199
|
+
export function Dialog({ open, onClose, title, subtitle, actions, children, footer, wide = false, closeLabel = "Close", className, focusPanel = false, returnFocusTo, lead, dismissible = true, dirty, dirtyAsk }: DialogProps) {
|
|
200
|
+
const [asked, setAsked] = useState(false);
|
|
201
|
+
// Discard pressed: the question closes first (its effect, a child's, runs before this one), then this popup, so the focus goes
|
|
202
|
+
// back to what opened IT, not to a control of a popup that is going.
|
|
203
|
+
const discarding = useRef(false);
|
|
204
|
+
const { ref, onClick, onPointerDown, onKeyDown, requestClose, leave, asking } = useModalDialog(open, onClose,
|
|
205
|
+
{ focusPanel, returnFocusTo, dismissible, ask: dirty ? () => setAsked(true) : null });
|
|
206
|
+
useEffect(() => { if (!asked && discarding.current) { discarding.current = false; leave(); } }, [asked]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
207
|
+
// Closed by its caller while asking (saved elsewhere, a route change): the question goes with it.
|
|
208
|
+
if (!open && asked) setAsked(false);
|
|
170
209
|
const titleId = useId();
|
|
171
210
|
const subId = useId();
|
|
211
|
+
const words = { ...DIRTY_ASK, ...dirtyAsk };
|
|
172
212
|
return (
|
|
213
|
+
<>
|
|
173
214
|
<dialog ref={ref} className={cx("ui-modal", wide && "ui-modal--wide", className)} aria-labelledby={titleId}
|
|
174
215
|
aria-describedby={subtitle ? subId : undefined} tabIndex={focusPanel ? -1 : undefined} onClick={onClick} onPointerDown={onPointerDown}
|
|
175
216
|
// Its Escape closes it and only it, as the kit's Popover: the browser closes the <dialog>, and neither the keydown nor the keyup
|
|
@@ -177,19 +218,35 @@ export function Dialog({ open, onClose, title, subtitle, actions, children, foot
|
|
|
177
218
|
// words on Escape (PickerList's) consumes the key before it gets here.
|
|
178
219
|
// Not dismissible: the key's default is prevented too, so the browser makes no close request at all (a prevented `cancel`
|
|
179
220
|
// only holds once: Chrome lets a second Escape with no press between close it).
|
|
180
|
-
|
|
221
|
+
// Asking first (`dirty`): its Escape asks, and makes no close request either.
|
|
222
|
+
onKeyDown={(e) => {
|
|
223
|
+
onKeyDown(e);
|
|
224
|
+
if (e.key !== "Escape" || e.nativeEvent.isComposing) return;
|
|
225
|
+
consumeEscape(e);
|
|
226
|
+
if (!dismissible) { e.preventDefault(); return; }
|
|
227
|
+
const a = asking();
|
|
228
|
+
if (a) { e.preventDefault(); a(); }
|
|
229
|
+
}}>
|
|
181
230
|
<div className="ui-modal__head">
|
|
182
231
|
{lead}
|
|
183
232
|
{subtitle
|
|
184
233
|
? <div className="ui-modal__title"><span id={titleId}>{title}</span><span className="ui-modal__subtitle" id={subId}>{subtitle}</span></div>
|
|
185
234
|
: <div className="ui-modal__title" id={titleId}>{title}</div>}
|
|
186
235
|
{actions ? <div className="ui-modal__actions">{actions}</div> : null}
|
|
187
|
-
<button type="button" className="ui-modal__close" aria-label={closeLabel} disabled={!dismissible} onClick={
|
|
236
|
+
<button type="button" className="ui-modal__close" aria-label={closeLabel} disabled={!dismissible} onClick={requestClose}>
|
|
188
237
|
<Icon name="close" size={20} />
|
|
189
238
|
</button>
|
|
190
239
|
</div>
|
|
191
240
|
<div className="ui-modal__body">{children}</div>
|
|
192
241
|
{footer ? <div className="ui-modal__foot">{footer}</div> : null}
|
|
193
242
|
</dialog>
|
|
243
|
+
{/* Beside it, not in it: the question's keys and presses are its own, and it opens over this popup in the top layer. */}
|
|
244
|
+
{dirty !== undefined ? (
|
|
245
|
+
<ConfirmDialog open={asked} title={words.title} action={words.action} cancelLabel={words.cancelLabel} closeLabel={words.closeLabel ?? closeLabel}
|
|
246
|
+
busy={false} error={null} onClose={() => setAsked(false)} onConfirm={() => { discarding.current = true; setAsked(false); }}>
|
|
247
|
+
{words.body}
|
|
248
|
+
</ConfirmDialog>
|
|
249
|
+
) : null}
|
|
250
|
+
</>
|
|
194
251
|
);
|
|
195
252
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// CHOICE CARDS (09/11/2026, one control set: Chris 08/11 "các control phải có bộ control và kiểu có sự tái sử dụng dùng chung shared
|
|
3
|
+
// component… đừng mỗi cho mỗi kiểu"). One choice of a few where each needs its words and a picture to be told apart BEFORE it is picked:
|
|
4
|
+
// Global styles' form set (a sample field drawn from each set's values, what it suits) and its style pack (four swatches, its fonts and
|
|
5
|
+
// buttons). A list or chips would show the names only; choice tiles (tiles.tsx) a picture and a name. The admin drew both by hand, each
|
|
6
|
+
// with its own radio card.
|
|
7
|
+
//
|
|
8
|
+
// · `.gemboss-ei-choices[role=radiogroup]` › one `label.gemboss-ei-choice` per option (the whole card is the radio's label, so it is
|
|
9
|
+
// one target, at least 44px tall at every width) › `input[type=radio].gemboss-ei-choice-input` · the words (`-name`, `-line`s) ·
|
|
10
|
+
// the picture (`-pic`), before the words or after them (`pictureAt`);
|
|
11
|
+
// · real radios in one group (`name`): Tab enters at the one picked, the arrow keys move the pick and Space picks, as the browser's own
|
|
12
|
+
// radios do; a pick calls `onChange` (a host that applies on a button of its own keeps the pick until then);
|
|
13
|
+
// · the caller owns the value: a value no card has (a set of the theme's own) checks none.
|
|
14
|
+
// Its look is editor.css's (the harnesses that draw a settings panel already load it).
|
|
15
|
+
import "../editor.css";
|
|
16
|
+
import { forwardRef, type CSSProperties, type ReactNode } from "react";
|
|
17
|
+
|
|
18
|
+
export interface ChoiceCard {
|
|
19
|
+
value: string;
|
|
20
|
+
/** Its name: the card's first line, in bold. */
|
|
21
|
+
label: ReactNode;
|
|
22
|
+
/** Lines under the name, muted (what it suits, its fonts and buttons). */
|
|
23
|
+
lines?: readonly ReactNode[];
|
|
24
|
+
/** Its picture (a sample, swatches): drawn at the group's `pictureAt`. Decorative: the words name the choice. */
|
|
25
|
+
picture?: ReactNode;
|
|
26
|
+
/** Shown but not choosable (Erase my data for a member who is not the store's Owner): its radio off, the card faded. Its `lines` say
|
|
27
|
+
* why. */
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ChoiceCardsProps {
|
|
32
|
+
/** The radios' name, one group on the page. */
|
|
33
|
+
name: string;
|
|
34
|
+
/** The group's accessible name (the setting's). */
|
|
35
|
+
label: string;
|
|
36
|
+
options: readonly ChoiceCard[];
|
|
37
|
+
/** The card that is checked; null or a value no card has: none. */
|
|
38
|
+
value: string | null;
|
|
39
|
+
onChange: (value: string) => void;
|
|
40
|
+
disabled?: boolean;
|
|
41
|
+
/** Where each card's picture goes: before its words (`start`, default) or after them (`end`). */
|
|
42
|
+
pictureAt?: "start" | "end";
|
|
43
|
+
/** The group's id (a button that shows it points at it: `aria-controls`). */
|
|
44
|
+
id?: string;
|
|
45
|
+
/** On the group: a host's layout (a long list held to a height that scrolls). Never a look. */
|
|
46
|
+
style?: CSSProperties;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const ChoiceCards = forwardRef<HTMLDivElement, ChoiceCardsProps>(function ChoiceCards({ name, label, options, value, onChange, disabled, pictureAt = "start", id, style }, ref) {
|
|
50
|
+
return (
|
|
51
|
+
<div ref={ref} id={id} className="gemboss-ei-choices" role="radiogroup" aria-label={label} style={style}>
|
|
52
|
+
{options.map((o) => {
|
|
53
|
+
const checked = value === o.value;
|
|
54
|
+
const off = disabled || o.disabled;
|
|
55
|
+
const pic = o.picture != null ? <span className="gemboss-ei-choice-pic" aria-hidden="true">{o.picture}</span> : null;
|
|
56
|
+
return (
|
|
57
|
+
<label key={o.value} className="gemboss-ei-choice" data-checked={checked ? "" : undefined} data-disabled={off ? "" : undefined}>
|
|
58
|
+
<input type="radio" className="gemboss-ei-choice-input" name={name} value={o.value} checked={checked} disabled={off}
|
|
59
|
+
onChange={() => onChange(o.value)} />
|
|
60
|
+
{pictureAt === "start" ? pic : null}
|
|
61
|
+
<span className="gemboss-ei-choice-words">
|
|
62
|
+
<span className="gemboss-ei-choice-name">{o.label}</span>
|
|
63
|
+
{(o.lines ?? []).map((line, i) => <span key={i} className="gemboss-ei-choice-line">{line}</span>)}
|
|
64
|
+
</span>
|
|
65
|
+
{pictureAt === "end" ? pic : null}
|
|
66
|
+
</label>
|
|
67
|
+
);
|
|
68
|
+
})}
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
71
|
+
});
|
package/src/editor/controls.tsx
CHANGED
|
@@ -48,6 +48,8 @@ export interface SegProps<T extends string = string> {
|
|
|
48
48
|
style?: React.CSSProperties;
|
|
49
49
|
/** Options per row: more wrap into rows (Segmented's `wrap`). ValueControl sets it past six chips. */
|
|
50
50
|
wrap?: number;
|
|
51
|
+
/** A line that describes the group (its reason, what the setting does), on the group (`aria-describedby`). */
|
|
52
|
+
describedBy?: string;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
/**
|
|
@@ -55,9 +57,9 @@ export interface SegProps<T extends string = string> {
|
|
|
55
57
|
* other switch in the editors (0.20.0; it was a grey track with a raised white tab of its own). `gemboss-ei-seg` stays on
|
|
56
58
|
* the group as the hook editor-plain.js finds, and each button carries its `data-value`.
|
|
57
59
|
*/
|
|
58
|
-
export function Seg<T extends string = string>({ options, value, onChange, disabled, label, style, wrap }: SegProps<T>) {
|
|
60
|
+
export function Seg<T extends string = string>({ options, value, onChange, disabled, label, style, wrap, describedBy }: SegProps<T>) {
|
|
59
61
|
return (
|
|
60
|
-
<Segmented<T> fill wrap={wrap} className="gemboss-ei-seg" style={style} ariaLabel={label ?? ""} value={(value ?? "") as T | ""} onChange={onChange} disabled={disabled}
|
|
62
|
+
<Segmented<T> fill wrap={wrap} className="gemboss-ei-seg" style={style} ariaLabel={label ?? ""} describedBy={describedBy} value={(value ?? "") as T | ""} onChange={onChange} disabled={disabled}
|
|
61
63
|
options={options.map((o) => ({ value: o.value, label: o.label ?? o.value, ...(o.name ? { ariaLabel: o.name, title: o.name } : {}) }))} />
|
|
62
64
|
);
|
|
63
65
|
}
|
|
@@ -195,6 +197,9 @@ export const PickButton = forwardRef<HTMLButtonElement, PickButtonProps>(functio
|
|
|
195
197
|
export interface CheckboxProps {
|
|
196
198
|
/** Its own words, beside the box: the box and its words are one control (a label wraps both), so it has no label side. */
|
|
197
199
|
label: React.ReactNode;
|
|
200
|
+
/** Its words read only, where its row or tile already says what it is (a tick on a print file's tile): the box alone, in the middle of a
|
|
201
|
+
* 44px square target. */
|
|
202
|
+
labelHidden?: boolean;
|
|
198
203
|
checked: boolean;
|
|
199
204
|
onChange: (checked: boolean) => void;
|
|
200
205
|
disabled?: boolean;
|
|
@@ -213,12 +218,12 @@ export interface CheckboxProps {
|
|
|
213
218
|
* the same wherever it is drawn; `.gemboss-ei-check` carries them in editor.css for a host without kit-plain.css. Not a setting's On / Off:
|
|
214
219
|
* a setting is FieldControl's `toggle`; this is a consent or a pick in a list.
|
|
215
220
|
*/
|
|
216
|
-
export function Checkbox({ label, checked, onChange, disabled, id, describedBy, why }: CheckboxProps) {
|
|
221
|
+
export function Checkbox({ label, labelHidden = false, checked, onChange, disabled, id, describedBy, why }: CheckboxProps) {
|
|
217
222
|
return (
|
|
218
|
-
<label className="ui-check gemboss-ei-check" data-disabled={disabled ? "" : undefined} title={disabled && why ? why : undefined}>
|
|
223
|
+
<label className={labelHidden ? "ui-check gemboss-ei-check gemboss-ei-check--bare" : "ui-check gemboss-ei-check"} data-disabled={disabled ? "" : undefined} title={disabled && why ? why : undefined}>
|
|
219
224
|
<input type="checkbox" className="gemboss-ei-checkbox" id={id} checked={checked} disabled={disabled} aria-describedby={describedBy}
|
|
220
225
|
onChange={(e) => onChange(e.target.checked)} />
|
|
221
|
-
<span className="gemboss-ei-check-words">{label}</span>
|
|
226
|
+
<span className={labelHidden ? "gemboss-ei-check-words ui-sr-only" : "gemboss-ei-check-words"}>{label}</span>
|
|
222
227
|
</label>
|
|
223
228
|
);
|
|
224
229
|
}
|