@glimstone/react 4.9.2 → 5.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/README.md +2 -2
- package/dist/AngleSlider.d.ts +1 -1
- package/dist/AngleSlider.js +17 -4
- package/dist/Avatar.js +1 -1
- package/dist/Badge.d.ts +3 -6
- package/dist/Badge.js +2 -2
- package/dist/Card.d.ts +4 -1
- package/dist/Card.js +2 -2
- package/dist/Chart.d.ts +30 -0
- package/dist/Chart.js +22 -0
- package/dist/Checkbox.js +1 -2
- package/dist/ColorPicker.d.ts +3 -1
- package/dist/ColorPicker.js +22 -5
- package/dist/Combobox.js +14 -4
- package/dist/ConfirmDialog.js +4 -2
- package/dist/ContextMenu.d.ts +3 -1
- package/dist/ContextMenu.js +3 -3
- package/dist/DatePicker.js +6 -1
- package/dist/FieldRow.d.ts +1 -1
- package/dist/FieldRow.js +8 -4
- package/dist/FileUpload.d.ts +3 -1
- package/dist/FileUpload.js +6 -3
- package/dist/FortressPermissions.js +3 -2
- package/dist/HoverCard.d.ts +13 -3
- package/dist/HoverCard.js +3 -3
- package/dist/IconTipButton.d.ts +4 -1
- package/dist/IconTipButton.js +3 -3
- package/dist/InfoBubble.js +1 -1
- package/dist/{AboutCard.d.ts → InfoTile.d.ts} +0 -44
- package/dist/{AboutCard.js → InfoTile.js} +1 -28
- package/dist/ListRow.d.ts +19 -4
- package/dist/ListRow.js +15 -2
- package/dist/ListTable.d.ts +6 -1
- package/dist/ListTable.js +18 -6
- package/dist/Meter.d.ts +5 -1
- package/dist/Meter.js +8 -3
- package/dist/MultiSelect.js +2 -1
- package/dist/NotifyCard.js +1 -1
- package/dist/NumberField.js +2 -2
- package/dist/PasswordField.js +10 -4
- package/dist/PinInput.js +3 -3
- package/dist/Rating.js +9 -3
- package/dist/Select.js +8 -4
- package/dist/Selector.d.ts +5 -4
- package/dist/Selector.js +21 -4
- package/dist/SettingsNav.d.ts +41 -0
- package/dist/SettingsNav.js +48 -0
- package/dist/SignInTile.js +16 -15
- package/dist/SkeletonRow.d.ts +5 -1
- package/dist/SkeletonRow.js +3 -3
- package/dist/Slider.js +1 -1
- package/dist/StatusSummary.d.ts +16 -0
- package/dist/StatusSummary.js +8 -0
- package/dist/SubCard.d.ts +6 -7
- package/dist/SubCard.js +4 -6
- package/dist/TextField.d.ts +1 -1
- package/dist/TextField.js +17 -6
- package/dist/TimePicker.d.ts +30 -0
- package/dist/TimePicker.js +146 -0
- package/dist/Timer.js +6 -1
- package/dist/Toast.d.ts +3 -1
- package/dist/Toast.js +9 -7
- package/dist/Toggle.js +1 -1
- package/dist/Tour.js +6 -3
- package/dist/Window.d.ts +3 -1
- package/dist/Window.js +2 -2
- package/dist/engines.d.ts +7 -1
- package/dist/engines.js +17 -2
- package/dist/fieldErrorLine.d.ts +4 -0
- package/dist/fieldErrorLine.js +18 -0
- package/dist/glyphs.d.ts +2 -0
- package/dist/glyphs.js +2 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -2
- package/dist/searchHit.d.ts +4 -0
- package/dist/searchHit.js +10 -0
- package/dist/useTipBubble.d.ts +11 -2
- package/dist/useTipBubble.js +14 -10
- package/package.json +3 -3
- package/dist/DropdownListbox.d.ts +0 -22
- package/dist/DropdownListbox.js +0 -190
package/dist/Selector.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useId, useLayoutEffect, useRef, useState, useSyncExternalStore, } from "react";
|
|
3
|
-
import { countSelector, mediaMatches, roveSelector, rovedIndex, segmentView, selectorAxis, selectorFlex, selectorTabId, selectorView, subscribeMedia, toggleSelection, watchSelectorFit, WIDE_QUERY, } from "@glimstone/core";
|
|
3
|
+
import { countSelector, mediaMatches, slideTabPanel, tabSlideDir, roveSelector, rovedIndex, segmentView, selectorAxis, selectorFlex, selectorTabId, selectorView, subscribeMedia, toggleSelection, watchSelectorFit, watchSelectorThumb, WIDE_QUERY, } from "@glimstone/core";
|
|
4
4
|
import { useFieldName } from "./fieldName.js";
|
|
5
5
|
import { Select } from "./Select.js";
|
|
6
6
|
import { useLabelMode } from "./useLabelMode.js";
|
|
@@ -9,12 +9,13 @@ export { selectorTabId } from "@glimstone/core";
|
|
|
9
9
|
function useMedia(query) {
|
|
10
10
|
return useSyncExternalStore((fn) => subscribeMedia(query, fn), () => mediaMatches(query), () => true);
|
|
11
11
|
}
|
|
12
|
-
export function Selector({ items, label, select, value, onChange, onPress, orientation = "horizontal", size = "md", variant = "well", activation = "auto", equalWidth = false, inline: ownInline = false, fit = false, buttonHeight = false, hue = true, hueOffset, disabled = false, panelId, className = "", }) {
|
|
12
|
+
export function Selector({ items, label, select, value, onChange, onPress, orientation = "horizontal", labels, size = "md", variant = "well", activation = "auto", equalWidth = false, inline: ownInline = false, fit = false, buttonHeight = false, hue = true, hueOffset, disabled = false, panelId, className = "", }) {
|
|
13
13
|
const name = useFieldName(label);
|
|
14
14
|
const inline = ownInline || (label === undefined && name !== undefined);
|
|
15
15
|
const vertical = orientation === "vertical";
|
|
16
16
|
const many = select === "many";
|
|
17
|
-
const
|
|
17
|
+
const appMode = useLabelMode(selectorAxis(size, orientation));
|
|
18
|
+
const mode = labels ?? appMode;
|
|
18
19
|
const strip = selectorView({
|
|
19
20
|
mode,
|
|
20
21
|
select: many ? "many" : "one",
|
|
@@ -50,6 +51,22 @@ export function Selector({ items, label, select, value, onChange, onPress, orien
|
|
|
50
51
|
const { pinWidth, canSqueeze, canList } = strip;
|
|
51
52
|
return watchSelectorFit(track.current, { pinWidth, fit, canSqueeze, canList }, setLayout);
|
|
52
53
|
}, [vertical, strip.pinWidth, fit, strip.canSqueeze, strip.canList, inline, itemsKey, disabledKey, size, strip.mode]);
|
|
54
|
+
// One value glides: a thumb under the segments carries the fill from the
|
|
55
|
+
// old choice to the new one. Toggles in a `many` strip each keep their own.
|
|
56
|
+
const gliding = !vertical && !many;
|
|
57
|
+
useLayoutEffect(() => {
|
|
58
|
+
if (gliding)
|
|
59
|
+
return watchSelectorThumb(track.current);
|
|
60
|
+
}, [gliding]);
|
|
61
|
+
// A tab strip moves its panel in from the side of the tab it came from.
|
|
62
|
+
const chosenIndex = many ? -1 : items.findIndex((it) => it.id === value);
|
|
63
|
+
const lastIndex = useRef(chosenIndex);
|
|
64
|
+
useLayoutEffect(() => {
|
|
65
|
+
const dir = tabSlideDir(lastIndex.current, chosenIndex);
|
|
66
|
+
lastIndex.current = chosenIndex;
|
|
67
|
+
if (dir && panelId && strip.kind === "tab")
|
|
68
|
+
slideTabPanel(document.getElementById(panelId), dir);
|
|
69
|
+
}, [chosenIndex, panelId, strip.kind]);
|
|
53
70
|
const flex = selectorFlex({ layout, inline, fit });
|
|
54
71
|
const listed = layout?.fit === "list";
|
|
55
72
|
const chosen = many ? value : null;
|
|
@@ -79,7 +96,7 @@ export function Selector({ items, label, select, value, onChange, onPress, orien
|
|
|
79
96
|
if (strip.autoSelect && item)
|
|
80
97
|
choose(item.id);
|
|
81
98
|
}
|
|
82
|
-
return (_jsxs("div", { "data-glim": "Selector", ref: track, role: listed ? undefined : strip.role, "aria-label": listed ? undefined : name, "aria-orientation": listed || strip.role === "group" ? undefined : orientation, onKeyDown: onKeyDown, className: `${strip.className}${listed ? " glim-sel--listed" : ""} ${className}`.trim(), style: flex.track, children: [items.map((item, i) => (_jsx(Segment, { item: item, index: i, strip: strip, on: isOn(item.id), disabled: disabledFlags[i], roved: i === roved, listed: listed, share: vertical ? undefined : flex.segment, squeezed: layout?.fit === "squeezed", cut: !!layout?.cut[i], orientation: orientation, size: size, variant: variant, equalWidth: equalWidth, buttonHeight: buttonHeight, hue: hue, hueOffset: hueOffset, panelId: panelId, onSelect: () => choose(item.id) }, item.id))), listed && (_jsx("div", { className: "glim-sel-list", children: _jsx(Select, { label: name ?? "", hideLabel: true, wrap: true, width: "fill", size: size === "sm" ? "row" : "field", options: items.map((it, i) => ({ value: String(it.id), label: it.label, glyph: it.glyph, disabled: disabledFlags[i] })), value: value === null ? null : String(value), onChange: (next) => {
|
|
99
|
+
return (_jsxs("div", { "data-glim": "Selector", ref: track, role: listed ? undefined : strip.role, "aria-label": listed ? undefined : name, "aria-orientation": listed || strip.role === "group" ? undefined : orientation, onKeyDown: onKeyDown, className: `${strip.className}${listed ? " glim-sel--listed" : ""} ${className}`.trim(), style: flex.track, children: [gliding && _jsx("span", { className: "glim-sel-thumb", "aria-hidden": "true" }), items.map((item, i) => (_jsx(Segment, { item: item, index: i, strip: strip, on: isOn(item.id), disabled: disabledFlags[i], roved: i === roved, listed: listed, share: vertical ? undefined : flex.segment, squeezed: layout?.fit === "squeezed", cut: !!layout?.cut[i], orientation: orientation, size: size, variant: variant, equalWidth: equalWidth, buttonHeight: buttonHeight, hue: hue, hueOffset: hueOffset, panelId: panelId, onSelect: () => choose(item.id) }, item.id))), listed && (_jsx("div", { className: "glim-sel-list", children: _jsx(Select, { label: name ?? "", hideLabel: true, wrap: true, width: "fill", size: size === "sm" ? "row" : "field", options: items.map((it, i) => ({ value: String(it.id), label: it.label, glyph: it.glyph, disabled: disabledFlags[i] })), value: value === null ? null : String(value), onChange: (next) => {
|
|
83
100
|
const item = items.find((it) => String(it.id) === next);
|
|
84
101
|
if (item)
|
|
85
102
|
choose(item.id);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode } from "react";
|
|
2
|
+
import { type SettingsNavText } from "@glimstone/core";
|
|
3
|
+
export interface SettingsNavItem {
|
|
4
|
+
/** Stable id, handed back by onChange. */
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
/** The page's glyph, muted until the row is chosen or under the pointer. */
|
|
8
|
+
glyph?: ReactNode;
|
|
9
|
+
/** The page's own address, so a modified click opens it beside the current one.
|
|
10
|
+
* Without one the row is a button. */
|
|
11
|
+
href?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface SettingsNavGroup {
|
|
14
|
+
/** A short name in sentence case, such as "Sync". */
|
|
15
|
+
title: string;
|
|
16
|
+
items: SettingsNavItem[];
|
|
17
|
+
}
|
|
18
|
+
export interface SettingsNavProps extends Omit<HTMLAttributes<HTMLDivElement>, "onChange" | "children"> {
|
|
19
|
+
groups: SettingsNavGroup[];
|
|
20
|
+
/** The page that is showing. Without one a phone shows the list itself. */
|
|
21
|
+
value: string | null;
|
|
22
|
+
/** Called with the page a row opens, and with null from the back link. Left
|
|
23
|
+
* out, a row with an href is a plain link for the app's router. */
|
|
24
|
+
onChange?: (id: string | null) => void;
|
|
25
|
+
/** The area's name, such as "Settings": the list's accessible name and the
|
|
26
|
+
* back link's words. */
|
|
27
|
+
label: string;
|
|
28
|
+
/** Where the back link leads, the list's own address. Without one it is a button. */
|
|
29
|
+
backHref?: string;
|
|
30
|
+
/** The person's order of the pages as ids, which the tiles follow with cards.
|
|
31
|
+
* Without one they stand in the order of the groups. */
|
|
32
|
+
order?: readonly string[] | null;
|
|
33
|
+
/** Hears the whole new order once a tile is dragged or moved with Alt and an
|
|
34
|
+
* arrow key. Without it, and always without cards, nothing moves. */
|
|
35
|
+
onReorder?: (order: string[]) => void;
|
|
36
|
+
/** The words the component brings along, in the app's language. */
|
|
37
|
+
text?: Partial<SettingsNavText>;
|
|
38
|
+
/** The page that is showing. */
|
|
39
|
+
children?: ReactNode;
|
|
40
|
+
}
|
|
41
|
+
export declare function SettingsNav({ groups, value, onChange, label, backHref, order, onReorder, text, children, className, ...rest }: SettingsNavProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useRef } from "react";
|
|
3
|
+
import { moveItem, opensInApp, reorderList, SETTINGS_NAV_TEXT, settingsNavTilesView, settingsNavView } from "@glimstone/core";
|
|
4
|
+
import { useLayout } from "./engines.js";
|
|
5
|
+
import { IconBack, IconForward } from "./glyphs.js";
|
|
6
|
+
export function SettingsNav({ groups, value, onChange, label, backHref, order, onReorder, text, children, className = "", ...rest }) {
|
|
7
|
+
const id = useId();
|
|
8
|
+
const [layout] = useLayout();
|
|
9
|
+
const cards = layout !== "flat";
|
|
10
|
+
const reorder = cards && !!onReorder;
|
|
11
|
+
const view = settingsNavView(groups, value);
|
|
12
|
+
const tiles = settingsNavTilesView(groups, value, order);
|
|
13
|
+
const nav = useRef(null);
|
|
14
|
+
// The list outlives a render, so it reads the order and the words in force.
|
|
15
|
+
const latest = useRef({ tiles, onReorder, words: { ...SETTINGS_NAV_TEXT, ...text } });
|
|
16
|
+
latest.current = { tiles, onReorder, words: { ...SETTINGS_NAV_TEXT, ...text } };
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const list = nav.current;
|
|
19
|
+
if (!reorder || !list)
|
|
20
|
+
return;
|
|
21
|
+
return reorderList(list, {
|
|
22
|
+
items: () => [...list.children],
|
|
23
|
+
onMove: (from, to) => {
|
|
24
|
+
const { tiles, onReorder } = latest.current;
|
|
25
|
+
onReorder?.(moveItem(tiles.tiles.map((t) => t.item.id), from, to));
|
|
26
|
+
},
|
|
27
|
+
moved: (from, to, count) => {
|
|
28
|
+
const { tiles, words } = latest.current;
|
|
29
|
+
return words.moved(tiles.tiles[from]?.item.label ?? "", to + 1, count);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}, [reorder]);
|
|
33
|
+
const open = (next, link) => (e) => {
|
|
34
|
+
if (!onChange || (link && !opensInApp(e)))
|
|
35
|
+
return;
|
|
36
|
+
e.preventDefault();
|
|
37
|
+
if (next !== value)
|
|
38
|
+
onChange(next);
|
|
39
|
+
};
|
|
40
|
+
const Back = (backHref ? "a" : "button");
|
|
41
|
+
const page = (item, className, style, active, name) => {
|
|
42
|
+
const Row = (item.href ? "a" : "button");
|
|
43
|
+
return (_jsxs(Row, { href: item.href, ...(item.href ? {} : { type: "button" }), className: className, style: style, "aria-current": active ? "page" : undefined, "aria-keyshortcuts": reorder ? "Alt+ArrowUp Alt+ArrowDown" : undefined, onClick: open(item.id, !!item.href), children: [item.glyph, name, _jsx("span", { className: "glim-settings-chevron", "aria-hidden": "true", children: _jsx(IconForward, {}) })] }, item.id));
|
|
44
|
+
};
|
|
45
|
+
return (_jsxs("div", { "data-glim": "SettingsNav", ...rest, "data-root": view.root ? "" : undefined, className: `glim-settings ${className}`.trim(), children: [_jsx("nav", { ref: nav, className: `glim-settings-nav${cards ? " glim-settings-tiles" : ""}${reorder ? " glim-settings-tiles--reorder" : ""}`, "aria-label": label, children: cards
|
|
46
|
+
? tiles.tiles.map(({ item, className: tileClass, style, active }) => page(item, tileClass, style, active, _jsx("span", { className: "glim-sel-tile-label", children: item.label })))
|
|
47
|
+
: view.groups.map((g, i) => (_jsxs("div", { className: "glim-settings-group", role: "group", "aria-labelledby": `${id}-${i}`, children: [_jsx("div", { id: `${id}-${i}`, className: "glim-settings-group-title", children: g.title }), g.rows.map(({ item, className: rowClass, style, active }) => page(item, rowClass, style, active, _jsx("span", { className: "glim-nav-label", children: item.label })))] }, g.title))) }), _jsxs("div", { className: "glim-settings-page", children: [_jsxs(Back, { href: backHref, ...(backHref ? {} : { type: "button" }), className: "glim-settings-back", onClick: open(null, !!backHref), children: [_jsx(IconBack, {}), _jsx("span", { children: label })] }), children] })] }));
|
|
48
|
+
}
|
package/dist/SignInTile.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
3
|
-
import { accountFacts, createSignInTileFlow, fill, passkeyFacts, passwordGoes, plural, qrCode, removalQuestion, sessionFacts, showTileRefusal, SIGN_IN_TILE_CARDS, SIGN_IN_TILE_KEYS, SIGN_IN_TOKEN_LIVES, signInDevice, signInRedirectAddress, signInScopeItems, signInServiceActions, signInServiceBadge, signInServiceLabel, signInRoleItems, signInServiceName, signInServicePicker, signInServiceQuiet, signInServiceStatus, signInTestLabel, signInTileCards, signInWhen, signInCardNotice, signInShortHint, signInPasswordAsks, signInPasswordElsewhere, tokenFacts, } from "@glimstone/core";
|
|
3
|
+
import { accountFacts, createSignInTileFlow, fill, passkeyFacts, passwordGoes, plural, qrCode, removalQuestion, sessionFacts, showTileRefusal, SIGN_IN_TILE_CARDS, SIGN_IN_TILE_KEYS, SIGN_IN_TOKEN_LIVES, signInDevice, signInRedirectAddress, signInScopeItems, signInServiceActions, signInServiceBadge, signInServiceLabel, signInRoleItems, signInServiceName, signInServicePicker, signInServiceQuiet, signInServiceStatus, signInTestLabel, signInTileCards, signInWhen, signInCardGlyphKey, signInCardNotice, signInShortHint, signInPasswordAsks, signInPasswordElsewhere, tokenFacts, } from "@glimstone/core";
|
|
4
4
|
import { Accordion } from "./Accordion.js";
|
|
5
5
|
import { Badge } from "./Badge.js";
|
|
6
6
|
import { Button } from "./Button.js";
|
|
@@ -80,8 +80,9 @@ export function SignInTile(props) {
|
|
|
80
80
|
function rowText(ctx, edit = ctx.text.services.edit) {
|
|
81
81
|
return { test: ctx.text.services.test, edit, remove: ctx.text.remove };
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
// A card that waits for a password draws the empty state its list would, with the card's glyph.
|
|
84
|
+
function Notice({ notice, glyph }) {
|
|
85
|
+
return _jsx(EmptyState, { nested: true, glyph: glyph, title: notice.title });
|
|
85
86
|
}
|
|
86
87
|
function PasswordCard({ ctx, hue }) {
|
|
87
88
|
const { s, flow, text, keys, eye, err } = ctx;
|
|
@@ -90,34 +91,34 @@ function PasswordCard({ ctx, hue }) {
|
|
|
90
91
|
const open = s.me?.via === "open";
|
|
91
92
|
const elsewhere = signInPasswordElsewhere(text, s);
|
|
92
93
|
const asks = signInPasswordAsks(s, ctx.cards) && !s.editing;
|
|
93
|
-
return (_jsx(Card, { title: t.title, hint: open ? t.openHint : fill(t.hint, { min: s.offer?.minPassword ?? 12 }), hueIndex: hue, "data-signin-card": "password", children: elsewhere ? (_jsxs("div", { className: "glim-signin-tile-body", children: [_jsx("p", { className: "glim-signin-tile-text", children: elsewhere }), asks && _jsx(AskPasswordRow, { ctx: ctx })] })) : (_jsxs("div", { className: "glim-signin-tile-body", children: [had ? (_jsxs(FieldRowGroup, { children: [_jsx(FieldRow, { label: t.state, value: t.set }), asks && _jsx(AskPasswordRow, { ctx: ctx })] })) : (!s.editing && _jsx(EmptyState, { nested: true, glyph: glyphFor(keys.setPassword), title: t.none
|
|
94
|
+
return (_jsx(Card, { title: t.title, hint: open ? t.openHint : fill(t.hint, { min: s.offer?.minPassword ?? 12 }), hueIndex: hue, "data-signin-card": "password", children: elsewhere ? (_jsxs("div", { className: "glim-signin-tile-body", children: [_jsx("p", { className: "glim-signin-tile-text", children: elsewhere }), asks && _jsx(AskPasswordRow, { ctx: ctx })] })) : (_jsxs("div", { className: "glim-signin-tile-body", children: [had ? (_jsxs(FieldRowGroup, { children: [_jsx(FieldRow, { label: t.state, value: t.set }), asks && _jsx(AskPasswordRow, { ctx: ctx })] })) : (!s.editing && _jsx(EmptyState, { nested: true, glyph: glyphFor(keys.setPassword), title: t.none })), s.editing && (_jsxs(FieldRowGroup, { children: [had && (_jsx(FieldRow, { label: t.current, children: _jsx(PasswordField, { autoComplete: "current-password", value: s.draft.current, onChange: (e) => flow.set("current", e.target.value), text: eye, error: err("current") }) })), _jsx(FieldRow, { label: t.next, children: _jsx(PasswordField, { confirm: true, value: s.draft.next, onChange: (e) => flow.set("next", e.target.value), onConfirmedChange: flow.setConfirmed, text: eye, error: err("next"), note: signInShortHint(t.shortHint, s.draft.next, s.offer?.minPassword ?? 12) }) })] })), _jsx("div", { className: "glim-signin-tile-foot", children: s.editing ? (_jsxs(_Fragment, { children: [_jsx(Button, { label: text.cancel, labelKey: "common.cancel", glyph: _jsx(IconCancel, {}), onClick: flow.cancelPassword }), _jsx(Button, { label: t.save, labelKey: keys.savePassword, tone: "accent", busy: s.busy === "save-password", disabled: !s.confirmed || (had && s.draft.current === ""), "data-signin-tile": "save-password", onClick: () => void flow.savePassword() })] })) : (_jsxs(_Fragment, { children: [had && _jsx(Button, { label: t.remove, labelKey: keys.removePassword, "data-signin-tile": "ask-remove-password", onClick: flow.askRemovePassword }), _jsx(Button, { label: had ? t.change : t.add, labelKey: had ? keys.change : keys.setPassword, "data-signin-tile": "edit-password", onClick: flow.editPassword })] })) })] })) }));
|
|
94
95
|
}
|
|
95
96
|
function AskPasswordRow({ ctx }) {
|
|
96
97
|
const { s, flow, text } = ctx;
|
|
97
98
|
return (_jsx(FieldRow, { label: text.askPassword.label, hint: text.askPassword.when, children: _jsx(Toggle, { checked: !!s.settings?.askPassword, onChange: (on) => void flow.setAskPassword(on), "data-signin-tile": "ask-password" }) }));
|
|
98
99
|
}
|
|
99
100
|
function AskPasswordCard({ ctx, hue }) {
|
|
100
|
-
const { s, text } = ctx;
|
|
101
|
+
const { s, text, keys } = ctx;
|
|
101
102
|
const t = text.askPassword;
|
|
102
103
|
const notice = signInCardNotice(text, s, "askPassword");
|
|
103
|
-
return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "askPassword", children: notice ? _jsx(Notice, { notice: notice }) : _jsx(AskPasswordRow, { ctx: ctx }) }));
|
|
104
|
+
return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "askPassword", children: notice ? _jsx(Notice, { notice: notice, glyph: glyphFor(keys[signInCardGlyphKey("askPassword")]) }) : _jsx(AskPasswordRow, { ctx: ctx }) }));
|
|
104
105
|
}
|
|
105
106
|
function TwoFactorCard({ ctx, hue }) {
|
|
106
107
|
const { s, flow, text, lang, keys } = ctx;
|
|
107
108
|
const t = text.twoFactor;
|
|
108
109
|
const notice = signInCardNotice(text, s, "twoFactor");
|
|
109
110
|
const on = !!s.me?.twoFactor;
|
|
110
|
-
return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "twoFactor", children: notice ? (_jsx(Notice, { notice: notice })) : (_jsxs("div", { className: "glim-signin-tile-body", children: [on ? (_jsxs(FieldRowGroup, { children: [_jsx(FieldRow, { label: t.state, value: t.on, tone: "ok" }), _jsx(FieldRow, { label: t.codesLeft, value: plural(lang, t.codesLeftValue, s.me?.recoveryLeft ?? 0) })] })) : (_jsx(EmptyState, { nested: true, glyph: glyphFor(keys.setUp), title: t.none
|
|
111
|
+
return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "twoFactor", children: notice ? (_jsx(Notice, { notice: notice, glyph: glyphFor(keys[signInCardGlyphKey("twoFactor")]) })) : (_jsxs("div", { className: "glim-signin-tile-body", children: [on ? (_jsxs(FieldRowGroup, { children: [_jsx(FieldRow, { label: t.state, value: t.on, tone: "ok" }), _jsx(FieldRow, { label: t.codesLeft, value: plural(lang, t.codesLeftValue, s.me?.recoveryLeft ?? 0) })] })) : (_jsx(EmptyState, { nested: true, glyph: glyphFor(keys.setUp), title: t.none })), _jsx("div", { className: "glim-signin-tile-foot", children: on ? (_jsxs(_Fragment, { children: [_jsx(Button, { label: t.newCodes, labelKey: keys.newCodes, busy: s.busy === "two-factor-codes", "data-signin-tile": "two-factor-codes", onClick: () => void flow.newCodes() }), _jsx(Button, { label: t.turnOff, labelKey: keys.turnOff, "data-signin-tile": "ask-two-factor-off", onClick: flow.askTwoFactorOff })] })) : (_jsx(Button, { label: t.setUp, labelKey: keys.setUp, busy: s.busy === "two-factor-set-up", "data-signin-tile": "two-factor-set-up", onClick: () => void flow.setUpTwoFactor() })) })] })) }));
|
|
111
112
|
}
|
|
112
113
|
function PasskeysCard({ ctx, hue }) {
|
|
113
114
|
const { s, flow, text, keys, when, ask } = ctx;
|
|
114
115
|
const t = text.passkeys;
|
|
115
116
|
const notice = signInCardNotice(text, s, "passkeys");
|
|
116
117
|
const here = s.passkeysHere;
|
|
117
|
-
return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "passkeys", children: notice ? (_jsx(Notice, { notice: notice })) : (_jsxs("div", { className: "glim-signin-tile-body", children: [!here && _jsx(UnavailableNotice, { title: t.unavailableTitle, reason: t.unavailable }), s.passkeys.length > 0 ? (_jsx("div", { className: "glim-signin-tile-rows", children: s.passkeys.map((p) => {
|
|
118
|
+
return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "passkeys", children: notice ? (_jsx(Notice, { notice: notice, glyph: glyphFor(keys[signInCardGlyphKey("passkeys")]) })) : (_jsxs("div", { className: "glim-signin-tile-body", children: [!here && _jsx(UnavailableNotice, { title: t.unavailableTitle, reason: t.unavailable }), s.passkeys.length > 0 ? (_jsx("div", { className: "glim-signin-tile-rows", children: s.passkeys.map((p) => {
|
|
118
119
|
const facts = passkeyFacts(text, p, when);
|
|
119
120
|
return (_jsx(ConnectionRow, { name: p.name, mark: glyphFor(keys.passkey), status: facts.added, text: rowText(ctx, t.rename), labelKeys: { edit: keys.rename, remove: keys.remove }, onEdit: () => flow.askRenamePasskey(p.id), onRemove: () => ask("passkey", p.id, p.name), children: _jsx("p", { className: "glim-connection-status", children: facts.more }) }, p.id));
|
|
120
|
-
}) })) : (here && _jsx(EmptyState, { nested: true, glyph: glyphFor(keys.passkey), title: t.none
|
|
121
|
+
}) })) : (here && _jsx(EmptyState, { nested: true, glyph: glyphFor(keys.passkey), title: t.none })), here && (_jsx("div", { className: "glim-signin-tile-foot", children: _jsx(Button, { label: t.add, labelKey: keys.add, "data-signin-tile": "passkey-ask-add", onClick: () => flow.askAddPasskey() }) }))] })) }));
|
|
121
122
|
}
|
|
122
123
|
function SessionsCard({ ctx, hue }) {
|
|
123
124
|
const { s, flow, text, keys, when } = ctx;
|
|
@@ -125,7 +126,7 @@ function SessionsCard({ ctx, hue }) {
|
|
|
125
126
|
const others = s.sessions.some((x) => !x.current);
|
|
126
127
|
const notice = signInCardNotice(text, s, "sessions");
|
|
127
128
|
if (notice) {
|
|
128
|
-
return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "sessions", children: _jsx(Notice, { notice: notice }) }));
|
|
129
|
+
return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "sessions", children: _jsx(Notice, { notice: notice, glyph: glyphFor(keys[signInCardGlyphKey("sessions")]) }) }));
|
|
129
130
|
}
|
|
130
131
|
return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "sessions", children: _jsxs("div", { className: "glim-signin-tile-body", children: [_jsx("div", { className: "glim-signin-tile-rows", children: s.sessions.map((x) => {
|
|
131
132
|
const device = signInDevice(x.agent, t);
|
|
@@ -136,26 +137,26 @@ function TokensCard({ ctx, hue }) {
|
|
|
136
137
|
const { s, flow, text, keys, when, ask } = ctx;
|
|
137
138
|
const t = text.tokens;
|
|
138
139
|
const notice = signInCardNotice(text, s, "tokens");
|
|
139
|
-
return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "tokens", children: notice ? (_jsx(Notice, { notice: notice })) : (_jsxs("div", { className: "glim-signin-tile-body", children: [s.tokens.length > 0 ? (_jsx("div", { className: "glim-signin-tile-rows", children: s.tokens.map((k) => (_jsx(ConnectionRow, { name: k.name, mark: glyphFor(keys.token), status: tokenFacts(text, k, when).join(" · "), badges: k.scopes.length > 0 &&
|
|
140
|
-
k.scopes.map((scope) => (_jsx(Badge, { size: "small", children: t.scopes[scope] ?? scope }, scope))), text: rowText(ctx), actions: [{ id: "revoke", label: t.revoke, labelKey: keys.revoke, onClick: () => ask("token", k.id, k.name) }] }, k.id))) })) : (_jsx(EmptyState, { nested: true, glyph: glyphFor(keys.token), title: t.none
|
|
140
|
+
return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "tokens", children: notice ? (_jsx(Notice, { notice: notice, glyph: glyphFor(keys[signInCardGlyphKey("tokens")]) })) : (_jsxs("div", { className: "glim-signin-tile-body", children: [s.tokens.length > 0 ? (_jsx("div", { className: "glim-signin-tile-rows", children: s.tokens.map((k) => (_jsx(ConnectionRow, { name: k.name, mark: glyphFor(keys.token), status: tokenFacts(text, k, when).join(" · "), badges: k.scopes.length > 0 &&
|
|
141
|
+
k.scopes.map((scope) => (_jsx(Badge, { size: "small", children: t.scopes[scope] ?? scope }, scope))), text: rowText(ctx), actions: [{ id: "revoke", label: t.revoke, labelKey: keys.revoke, onClick: () => ask("token", k.id, k.name) }] }, k.id))) })) : (_jsx(EmptyState, { nested: true, glyph: glyphFor(keys.token), title: t.none })), _jsx("div", { className: "glim-signin-tile-foot", children: _jsx(Button, { label: t.create, labelKey: keys.createToken, "data-signin-tile": "token-ask", onClick: flow.askToken }) })] })) }));
|
|
141
142
|
}
|
|
142
143
|
function ServicesCard({ ctx, hue, providers }) {
|
|
143
144
|
const { s, flow, text, keys, when, ask } = ctx;
|
|
144
145
|
const t = text.services;
|
|
145
146
|
const notice = signInCardNotice(text, s, "services");
|
|
146
|
-
return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "services", children: notice ? (_jsx(Notice, { notice: notice })) : (_jsxs("div", { className: "glim-signin-tile-body", children: [(s.services?.length ?? 0) > 0
|
|
147
|
+
return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "services", children: notice ? (_jsx(Notice, { notice: notice, glyph: glyphFor(keys[signInCardGlyphKey("services")]) })) : (_jsxs("div", { className: "glim-signin-tile-body", children: [(s.services?.length ?? 0) > 0 ? (_jsx("div", { className: "glim-signin-tile-rows", children: (s.services ?? []).map((x) => {
|
|
147
148
|
const badge = signInServiceBadge(text, x);
|
|
148
149
|
const label = signInServiceLabel(x, providers, text);
|
|
149
150
|
const own = !x.fromConfig;
|
|
150
151
|
return (_jsx(ConnectionRow, { name: label.name, mark: label.mark ?? glyphFor(keys.service), status: signInServiceStatus(text, x, when), badges: badge && (_jsx(Badge, { size: "small", tone: badge.tone, children: badge.label })), "data-signin-service": x.provider, control: own && (_jsx(Toggle, { checked: x.on, label: t.show, hideLabel: true, refused: !x.tested || x.paused ? t.mustTest : undefined, onChange: (on) => void flow.setServiceOn(x.id, on), "data-signin-tile": `service-on-${x.id}` })), text: rowText(ctx), labelKeys: { test: keys.test, edit: keys.edit, remove: keys.remove }, actions: signInServiceActions(text, x, s, keys.turnOn, (id) => void flow.confirmService(id)), test: s.rowTests[x.id], onTest: own ? () => void flow.testService(x.id) : undefined, onEdit: own ? () => flow.editService(x.id) : undefined, onRemove: own ? () => ask("service", x.id, label.name) : undefined }, x.id));
|
|
151
|
-
}) })), _jsx("div", { className: "glim-signin-tile-foot", children: _jsx(Button, { label: t.add, labelKey: keys.addService, "data-signin-tile": "service-pick", onClick: flow.pickService }) })] })) }));
|
|
152
|
+
}) })) : (_jsx(EmptyState, { nested: true, glyph: glyphFor(keys.service), title: t.none })), _jsx("div", { className: "glim-signin-tile-foot", children: _jsx(Button, { label: t.add, labelKey: keys.addService, "data-signin-tile": "service-pick", onClick: flow.pickService }) })] })) }));
|
|
152
153
|
}
|
|
153
154
|
function AccountsCard({ ctx, hue }) {
|
|
154
155
|
const { s, flow, text, keys, when, ask } = ctx;
|
|
155
156
|
const t = text.accounts;
|
|
156
157
|
const notice = signInCardNotice(text, s, "accounts");
|
|
157
158
|
if (notice) {
|
|
158
|
-
return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "accounts", children: _jsx(Notice, { notice: notice }) }));
|
|
159
|
+
return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "accounts", children: _jsx(Notice, { notice: notice, glyph: glyphFor(keys[signInCardGlyphKey("accounts")]) }) }));
|
|
159
160
|
}
|
|
160
161
|
return (_jsx(Card, { title: t.title, hint: t.hint, hueIndex: hue, "data-signin-card": "accounts", children: _jsx("div", { className: "glim-signin-tile-rows", children: (s.accounts ?? []).map((a) => {
|
|
161
162
|
const mine = a.owner || a.id === s.me?.account;
|
package/dist/SkeletonRow.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ export interface SkeletonRowProps {
|
|
|
5
5
|
tile?: boolean;
|
|
6
6
|
/** The badge at the row's end, for a list whose rows have one. */
|
|
7
7
|
badge?: boolean;
|
|
8
|
+
/** A bar in the value column, for a list whose rows carry a `value`. */
|
|
9
|
+
value?: boolean;
|
|
10
|
+
/** How many row buttons to keep room for, so the value bar stands where the real rows put their figures. */
|
|
11
|
+
actions?: number;
|
|
8
12
|
className?: string;
|
|
9
13
|
}
|
|
10
|
-
export declare function SkeletonRow({ delay, tile, badge, className }: SkeletonRowProps): import("react").JSX.Element;
|
|
14
|
+
export declare function SkeletonRow({ delay, tile, badge, value, actions, className }: SkeletonRowProps): import("react").JSX.Element;
|
package/dist/SkeletonRow.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { skeletonRowView } from "@glimstone/core";
|
|
3
|
-
export function SkeletonRow({ delay, tile = true, badge = true, className }) {
|
|
4
|
-
const view = skeletonRowView({ delay, tile, badge });
|
|
5
|
-
return (_jsxs("div", { "data-glim": "SkeletonRow", "aria-hidden": "true", className: className ? `${view.className} ${className}` : view.className, style: view.style, children: [view.tile && _jsx("span", { className: "glim-skeleton-block glim-skeleton-tile" }), _jsx("span", { className: "glim-skeleton-block glim-skeleton-name" }), view.badge && _jsx("span", { className: "glim-skeleton-block glim-skeleton-badge" })] }));
|
|
3
|
+
export function SkeletonRow({ delay, tile = true, badge = true, value = false, actions = 0, className }) {
|
|
4
|
+
const view = skeletonRowView({ delay, tile, badge, value, actions });
|
|
5
|
+
return (_jsxs("div", { "data-glim": "SkeletonRow", "aria-hidden": "true", className: className ? `${view.className} ${className}` : view.className, style: view.style, children: [view.tile && _jsx("span", { className: "glim-skeleton-block glim-skeleton-tile" }), _jsx("span", { className: "glim-skeleton-block glim-skeleton-name" }), view.badge && _jsx("span", { className: "glim-skeleton-block glim-skeleton-badge" }), view.value && _jsx("span", { className: "glim-skeleton-block glim-skeleton-value" }), view.actions > 0 && _jsx("span", { className: "glim-skeleton-actions" })] }));
|
|
6
6
|
}
|
package/dist/Slider.js
CHANGED
|
@@ -16,5 +16,5 @@ export function Slider({ label, value, onChange, min, max, step = 1, format, dis
|
|
|
16
16
|
getAriaValueText: (d) => format(d.value),
|
|
17
17
|
});
|
|
18
18
|
const api = slider.connect(service, normalizeProps);
|
|
19
|
-
return (_jsxs("div", { "data-glim": "Slider", ...api.getRootProps(), className: "glim-slider", children: [_jsxs("div", { className: "glim-slider-head", children: [_jsx("label", { ...api.getLabelProps(), className: label === undefined ? "glim-sr-only" : "glim-field-label", children: name }), _jsx("output", { ...api.getValueTextProps(), className: "glim-slider-value", children: format(api.value[0]) })] }), _jsxs("div", { ...api.getControlProps(), className: "glim-slider-control", children: [_jsx("div", { ...api.getTrackProps(), className: "glim-slider-track", children: _jsx("div", { ...api.getRangeProps(), className: "glim-slider-range" }) }), api.value.map((_, index) => (
|
|
19
|
+
return (_jsxs("div", { "data-glim": "Slider", ...api.getRootProps(), className: "glim-slider", children: [_jsxs("div", { className: "glim-slider-head", children: [_jsx("label", { ...api.getLabelProps(), className: label === undefined ? "glim-sr-only" : "glim-field-label", children: name }), _jsx("output", { ...api.getValueTextProps(), className: "glim-slider-value", children: format(api.value[0]) })] }), _jsxs("div", { ...api.getControlProps(), className: "glim-slider-control", children: [_jsx("div", { ...api.getTrackProps(), className: "glim-slider-track", children: _jsx("div", { ...api.getRangeProps(), className: "glim-slider-range" }) }), api.value.map((_, index) => (_jsxs("div", { ...api.getThumbProps({ index }), className: "glim-slider-thumb", children: [_jsx("span", { className: "glim-slider-bubble", "aria-hidden": "true", children: format(api.value[index]) }), _jsx("input", { ...api.getHiddenInputProps({ index }) })] }, index)))] })] }));
|
|
20
20
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { type StatusNeed as CoreStatusNeed, type StatusSummaryTone } from "@glimstone/core";
|
|
3
|
+
export type { StatusSummaryTone } from "@glimstone/core";
|
|
4
|
+
export type StatusNeed = CoreStatusNeed<ReactNode>;
|
|
5
|
+
export interface StatusSummaryProps {
|
|
6
|
+
/** How things stand. A summary that says `ok` while something waits shows the warning's mark. */
|
|
7
|
+
tone: StatusSummaryTone;
|
|
8
|
+
/** The one sentence, such as "Documents needs a look" or "All is well". */
|
|
9
|
+
title: string;
|
|
10
|
+
/** A quiet line under it, such as when the last run was and when the next one is. */
|
|
11
|
+
detail?: string;
|
|
12
|
+
/** What waits for the person. A count of zero is left out, and with none the sentence stands alone. */
|
|
13
|
+
needs?: StatusNeed[];
|
|
14
|
+
className?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function StatusSummary({ tone, title, detail, needs, className }: StatusSummaryProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { statusSummaryView } from "@glimstone/core";
|
|
3
|
+
import { Button } from "./Button.js";
|
|
4
|
+
import { MarkSvg } from "./glyphs.js";
|
|
5
|
+
export function StatusSummary({ tone, title, detail, needs, className }) {
|
|
6
|
+
const view = statusSummaryView(tone, needs);
|
|
7
|
+
return (_jsxs("div", { "data-glim": "StatusSummary", "data-tone": view.tone, className: className ? `glim-status-summary ${className}` : "glim-status-summary", children: [_jsxs("div", { className: "glim-status-summary-line", children: [_jsx("span", { className: "glim-status-summary-mark", "aria-hidden": "true", children: _jsx(MarkSvg, { mark: view.mark }) }), _jsxs("div", { children: [_jsx("p", { className: "glim-status-summary-title", children: title }), detail && _jsx("p", { className: "glim-status-summary-detail", children: detail })] })] }), view.needs.length > 0 && (_jsx("ul", { className: "glim-card glim-status-summary-needs", children: view.needs.map((need) => (_jsxs("li", { className: "glim-status-summary-need", onClick: () => need.action.disabled || need.action.onClick(), children: [_jsx("span", { className: "glim-status-summary-count glim-num", "data-tone": need.tone, children: need.count }), _jsx("span", { className: "glim-status-summary-label", children: need.label }), _jsx(Button, { tone: "subtle", label: need.action.label, labelKey: need.action.labelKey, glyph: need.action.glyph, disabled: need.action.disabled })] }, need.label))) }))] }));
|
|
8
|
+
}
|
package/dist/SubCard.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
/**
|
|
3
|
-
* A
|
|
4
|
-
*
|
|
5
|
-
* click.
|
|
6
|
-
* not vanish into its fill.
|
|
3
|
+
* A titled group that lies directly on a card or a window. It groups without a
|
|
4
|
+
* second surface and takes the place of a fold-out, so nothing hides behind a
|
|
5
|
+
* click.
|
|
7
6
|
*/
|
|
8
7
|
export declare function SubCard({ title, hint, end, children, }: {
|
|
9
|
-
/** The group's name,
|
|
8
|
+
/** The group's name, a title above its content. */
|
|
10
9
|
title?: string;
|
|
11
|
-
/** One line on what the group does, drawn as an "(i)"
|
|
10
|
+
/** One line on what the group does, drawn as an "(i)" beside the title. */
|
|
12
11
|
hint?: string;
|
|
13
12
|
/** What belongs to the whole group, such as a switch, at the end of the
|
|
14
|
-
*
|
|
13
|
+
* title's line. */
|
|
15
14
|
end?: ReactNode;
|
|
16
15
|
children: ReactNode;
|
|
17
16
|
}): import("react").JSX.Element;
|
package/dist/SubCard.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useId } from "react";
|
|
3
|
-
import { Badge } from "./Badge.js";
|
|
4
3
|
import { InfoBubble } from "./InfoBubble.js";
|
|
5
4
|
/**
|
|
6
|
-
* A
|
|
7
|
-
*
|
|
8
|
-
* click.
|
|
9
|
-
* not vanish into its fill.
|
|
5
|
+
* A titled group that lies directly on a card or a window. It groups without a
|
|
6
|
+
* second surface and takes the place of a fold-out, so nothing hides behind a
|
|
7
|
+
* click.
|
|
10
8
|
*/
|
|
11
9
|
export function SubCard({ title, hint, end, children, }) {
|
|
12
10
|
const titleId = useId();
|
|
13
|
-
return (_jsxs("section", { "data-glim": "SubCard", "data-glim-title": title, className: `glim-subcard${title ? " glim-subcard--titled" : ""}`, "aria-labelledby": title ? titleId : undefined, children: [title && (
|
|
11
|
+
return (_jsxs("section", { "data-glim": "SubCard", "data-glim-title": title, className: `glim-subcard${title ? " glim-subcard--titled" : ""}`, "aria-labelledby": title ? titleId : undefined, children: [(title || end) && (_jsxs("div", { className: "glim-subcard-head", children: [title && (_jsxs("h3", { className: "glim-subcard-title", children: [_jsx("span", { id: titleId, children: title }), hint && _jsx(InfoBubble, { tip: hint })] })), end && _jsx("div", { className: "glim-subcard-end", children: end })] })), children] }));
|
|
14
12
|
}
|
package/dist/TextField.d.ts
CHANGED
|
@@ -24,4 +24,4 @@ export interface TextAreaProps extends TextareaHTMLAttributes<HTMLTextAreaElemen
|
|
|
24
24
|
className?: string;
|
|
25
25
|
ref?: Ref<HTMLTextAreaElement>;
|
|
26
26
|
}
|
|
27
|
-
export declare function TextArea({ label, mono, width, error, className, id, "aria-describedby": describedBy, ...rest }: TextAreaProps): import("react").JSX.Element;
|
|
27
|
+
export declare function TextArea({ label, mono, width, error, className, id, ref, onInput, "aria-describedby": describedBy, ...rest }: TextAreaProps): import("react").JSX.Element;
|
package/dist/TextField.js
CHANGED
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useId } from "react";
|
|
3
|
-
import { fieldErrorView, textFieldClass } from "@glimstone/core";
|
|
4
|
-
import {
|
|
2
|
+
import { useId, useLayoutEffect, useRef } from "react";
|
|
3
|
+
import { fieldErrorView, fitTextArea, textFieldClass } from "@glimstone/core";
|
|
4
|
+
import { FieldErrorLine } from "./fieldErrorLine.js";
|
|
5
5
|
import { useFieldName } from "./fieldName.js";
|
|
6
6
|
export function TextField({ label, mono, width, error, className, type = "text", id, "aria-describedby": describedBy, ...rest }) {
|
|
7
7
|
const name = useFieldName(label);
|
|
8
8
|
const own = useId();
|
|
9
9
|
const err = fieldErrorView(error, id ?? own, describedBy);
|
|
10
|
-
return (_jsxs(_Fragment, { children: [_jsx("input", { "data-glim": "TextField", "aria-label": name, ...rest, id: id, "aria-invalid": err.invalid, "aria-describedby": err.describedBy, type: type, className: `${textFieldClass({ width, mono })} ${className ?? ""}`.trim() }),
|
|
10
|
+
return (_jsxs(_Fragment, { children: [_jsx("input", { "data-glim": "TextField", "aria-label": name, ...rest, id: id, "aria-invalid": err.invalid, "aria-describedby": err.describedBy, type: type, className: `${textFieldClass({ width, mono })} ${className ?? ""}`.trim() }), _jsx(FieldErrorLine, { id: err.errorId, error: error })] }));
|
|
11
11
|
}
|
|
12
|
-
export function TextArea({ label, mono, width, error, className, id, "aria-describedby": describedBy, ...rest }) {
|
|
12
|
+
export function TextArea({ label, mono, width, error, className, id, ref, onInput, "aria-describedby": describedBy, ...rest }) {
|
|
13
13
|
const name = useFieldName(label);
|
|
14
14
|
const own = useId();
|
|
15
15
|
const err = fieldErrorView(error, id ?? own, describedBy);
|
|
16
|
-
|
|
16
|
+
const area = useRef(null);
|
|
17
|
+
useLayoutEffect(() => fitTextArea(area.current), [rest.value]);
|
|
18
|
+
return (_jsxs(_Fragment, { children: [_jsx("textarea", { "data-glim": "TextArea", "aria-label": name, ...rest, ref: (el) => {
|
|
19
|
+
area.current = el;
|
|
20
|
+
if (typeof ref === "function")
|
|
21
|
+
ref(el);
|
|
22
|
+
else if (ref)
|
|
23
|
+
ref.current = el;
|
|
24
|
+
}, onInput: (e) => {
|
|
25
|
+
fitTextArea(e.currentTarget);
|
|
26
|
+
onInput?.(e);
|
|
27
|
+
}, id: id, "aria-invalid": err.invalid, "aria-describedby": err.describedBy, className: `${textFieldClass({ width, mono, area: true })} ${className ?? ""}`.trim() }), _jsx(FieldErrorLine, { id: err.errorId, error: error })] }));
|
|
17
28
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type TimePickerText } from "@glimstone/core";
|
|
2
|
+
export type { TimePickerText } from "@glimstone/core";
|
|
3
|
+
export interface TimePickerProps {
|
|
4
|
+
label?: string;
|
|
5
|
+
/** The time as "08:30", or null while a segment is empty. */
|
|
6
|
+
value: string | null;
|
|
7
|
+
onChange: (value: string | null) => void;
|
|
8
|
+
/** How far an arrow moves the minutes. */
|
|
9
|
+
minuteStep?: number;
|
|
10
|
+
/** The name the time is sent under in a form. */
|
|
11
|
+
name?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
/** The segments' names. English where left out. */
|
|
14
|
+
text?: Partial<TimePickerText>;
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface TimeRangePickerProps {
|
|
18
|
+
label?: string;
|
|
19
|
+
/** The start and the end as "08:00", each null while one of its segments is empty. */
|
|
20
|
+
value: [string | null, string | null];
|
|
21
|
+
onChange: (value: [string | null, string | null]) => void;
|
|
22
|
+
/** How far an arrow moves the minutes. */
|
|
23
|
+
minuteStep?: number;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/** The segments' names, the halves' and the word between them. English where left out. */
|
|
26
|
+
text?: Partial<TimePickerText>;
|
|
27
|
+
className?: string;
|
|
28
|
+
}
|
|
29
|
+
export declare function TimePicker({ value, onChange, name, ...shared }: TimePickerProps): import("react").JSX.Element;
|
|
30
|
+
export declare function TimeRangePicker({ value, onChange, ...shared }: TimeRangePickerProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
3
|
+
import { DIAL, TIME_PICKER_TEXT, anchorName, attachDial, dialAngle, dialInner, dialMarks, dialSegment, faceOf, floatBeside, formatTime, nearestTurn, parseTime, segmentText, stepSegment, timeKey, timeRangeValue, timeWheel, wheelSegments, } from "@glimstone/core";
|
|
4
|
+
import { useFieldName } from "./fieldName.js";
|
|
5
|
+
export function TimePicker({ value, onChange, name, ...shared }) {
|
|
6
|
+
const [values, setValues] = useSegments([value]);
|
|
7
|
+
return (_jsx(TimeShell, { ...shared, "data-glim": "TimePicker", values: values, onValues: (next) => {
|
|
8
|
+
setValues(next);
|
|
9
|
+
const time = formatTime(next);
|
|
10
|
+
if (time !== value)
|
|
11
|
+
onChange(time);
|
|
12
|
+
}, children: name && _jsx("input", { type: "hidden", name: name, value: formatTime(values) ?? "" }) }));
|
|
13
|
+
}
|
|
14
|
+
export function TimeRangePicker({ value, onChange, ...shared }) {
|
|
15
|
+
const [values, setValues] = useSegments(value);
|
|
16
|
+
return (_jsx(TimeShell, { ...shared, "data-glim": "TimeRangePicker", values: values, onValues: (next) => {
|
|
17
|
+
setValues(next);
|
|
18
|
+
const span = timeRangeValue(next);
|
|
19
|
+
if (span[0] !== value[0] || span[1] !== value[1])
|
|
20
|
+
onChange(span);
|
|
21
|
+
} }));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The segments of one or two times. A time from the app replaces its
|
|
25
|
+
* segments, and so does a null that clears a whole time, but a half-typed
|
|
26
|
+
* time the app only knows as null stays.
|
|
27
|
+
*/
|
|
28
|
+
function useSegments(times) {
|
|
29
|
+
const [values, setValues] = useState(() => times.flatMap(parseTime));
|
|
30
|
+
const key = times.join("|");
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
setValues((now) => times.flatMap((time, i) => {
|
|
33
|
+
const half = now.slice(i * 2, i * 2 + 2);
|
|
34
|
+
return time === null && formatTime(half) === null ? half : parseTime(time);
|
|
35
|
+
}));
|
|
36
|
+
}, [key]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
37
|
+
return [values, setValues];
|
|
38
|
+
}
|
|
39
|
+
function TimeShell({ "data-glim": glim, label, values, onValues, minuteStep = 1, disabled = false, text, className, children, }) {
|
|
40
|
+
const fieldName = useFieldName(label);
|
|
41
|
+
const words = { ...TIME_PICKER_TEXT, ...text };
|
|
42
|
+
const typed = useRef("");
|
|
43
|
+
const root = useRef(null);
|
|
44
|
+
const segments = useRef([]);
|
|
45
|
+
const range = values.length > 2;
|
|
46
|
+
// The segment the clock face edits while it is open.
|
|
47
|
+
const [dial, setDial] = useState(null);
|
|
48
|
+
const wheel = useRef(() => false);
|
|
49
|
+
useLayoutEffect(() => {
|
|
50
|
+
wheel.current = (at, deltaY) => {
|
|
51
|
+
const next = disabled ? null : timeWheel(values, at, deltaY, minuteStep);
|
|
52
|
+
if (next)
|
|
53
|
+
onValues(next);
|
|
54
|
+
return next !== null;
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
useEffect(() => wheelSegments(root.current, (at, deltaY) => wheel.current(at, deltaY)), []);
|
|
58
|
+
function focus(at) {
|
|
59
|
+
typed.current = "";
|
|
60
|
+
segments.current[at]?.focus();
|
|
61
|
+
}
|
|
62
|
+
function onKeyDown(at, e) {
|
|
63
|
+
if (disabled)
|
|
64
|
+
return;
|
|
65
|
+
const result = timeKey(values, at, e.key, typed.current, minuteStep);
|
|
66
|
+
if (!result)
|
|
67
|
+
return;
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
if (result.values.some((v, i) => v !== values[i]))
|
|
70
|
+
onValues(result.values);
|
|
71
|
+
if (result.focus !== at)
|
|
72
|
+
focus(result.focus);
|
|
73
|
+
else
|
|
74
|
+
typed.current = result.buffer;
|
|
75
|
+
}
|
|
76
|
+
// A press into the field opens the face for the segment it hit, and a press
|
|
77
|
+
// beside the segments lands on the hours, as on a text field's padding.
|
|
78
|
+
function onMouseDown(e) {
|
|
79
|
+
if (disabled)
|
|
80
|
+
return;
|
|
81
|
+
const target = e.target;
|
|
82
|
+
const pressed = target.closest(".glim-time-seg");
|
|
83
|
+
const half = target.closest(".glim-time-half");
|
|
84
|
+
const at = dialSegment(pressed ? segments.current.indexOf(pressed) : null, half ? [...root.current.querySelectorAll(".glim-time-half")].indexOf(half) : null);
|
|
85
|
+
if (!pressed) {
|
|
86
|
+
e.preventDefault();
|
|
87
|
+
focus(at);
|
|
88
|
+
}
|
|
89
|
+
setDial(at);
|
|
90
|
+
}
|
|
91
|
+
function setSegment(at, value) {
|
|
92
|
+
if (values[at] !== value)
|
|
93
|
+
onValues(values.map((v, i) => (i === at ? value : v)));
|
|
94
|
+
}
|
|
95
|
+
const segment = (at) => (_jsx("span", { ref: (el) => {
|
|
96
|
+
segments.current[at] = el;
|
|
97
|
+
}, role: "spinbutton", tabIndex: disabled ? -1 : 0, "aria-label": at % 2 === 0 ? words.hour : words.minute, "aria-valuemin": 0, "aria-valuemax": at % 2 === 0 ? 23 : 59, "aria-valuenow": values[at] ?? undefined, "aria-valuetext": values[at] === null ? undefined : segmentText(values[at]), "aria-disabled": disabled || undefined, "data-empty": values[at] === null ? "" : undefined, "data-editing": dial === at ? "" : undefined, className: "glim-time-seg", onKeyDown: (e) => onKeyDown(at, e), onFocus: () => {
|
|
98
|
+
typed.current = "";
|
|
99
|
+
if (dial !== null)
|
|
100
|
+
setDial(at);
|
|
101
|
+
}, children: segmentText(values[at]) }));
|
|
102
|
+
const time = (first) => (_jsxs(_Fragment, { children: [segment(first), _jsx("span", { className: "glim-time-colon", "aria-hidden": "true", children: ":" }), segment(first + 1)] }));
|
|
103
|
+
return (_jsxs("div", { ref: root, "data-glim": glim, role: "group", "aria-label": fieldName, "data-disabled": disabled ? "" : undefined, className: ["glim-time", className].filter(Boolean).join(" "), onMouseDown: onMouseDown, onBlur: (e) => {
|
|
104
|
+
if (!e.currentTarget.contains(e.relatedTarget))
|
|
105
|
+
setDial(null);
|
|
106
|
+
}, children: [range
|
|
107
|
+
? [0, 2].map((first) => (_jsxs(Fragment, { children: [first > 0 && (_jsx("span", { className: "glim-time-to", "aria-hidden": "true", children: words.to })), _jsx("span", { role: "group", "aria-label": first === 0 ? words.start : words.end, className: "glim-time-half", children: time(first) })] }, first)))
|
|
108
|
+
: time(0), dial !== null && (_jsx(TimeDial, { anchor: root.current, face: faceOf(dial), value: values[dial] ?? null, minuteStep: minuteStep, onPoint: (value, done) => {
|
|
109
|
+
setSegment(dial, value);
|
|
110
|
+
if (!done)
|
|
111
|
+
return;
|
|
112
|
+
if (dial % 2 === 0)
|
|
113
|
+
focus(dial + 1);
|
|
114
|
+
else
|
|
115
|
+
setDial(null);
|
|
116
|
+
}, onTurn: (delta) => setSegment(dial, stepSegment(values[dial] ?? null, dial, delta, dial % 2 === 1 ? minuteStep : 1)), onClose: () => setDial(null) })), children] }));
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The clock face over a time field, a pointer aid on top of the segments: it
|
|
120
|
+
* floats beside the field without the focus and is hidden from a screen
|
|
121
|
+
* reader, since the segments it edits are the controls.
|
|
122
|
+
*/
|
|
123
|
+
function TimeDial({ anchor, face, value, minuteStep, onPoint, onTurn, onClose, }) {
|
|
124
|
+
const panel = useRef(null);
|
|
125
|
+
const plate = useRef(null);
|
|
126
|
+
const id = useId();
|
|
127
|
+
const latest = useRef({ face, minuteStep, onPoint, onTurn, onClose });
|
|
128
|
+
useLayoutEffect(() => {
|
|
129
|
+
latest.current = { face, minuteStep, onPoint, onTurn, onClose };
|
|
130
|
+
});
|
|
131
|
+
useLayoutEffect(() => floatBeside(panel.current, anchor, anchorName(id), () => latest.current.onClose()), [anchor, id]);
|
|
132
|
+
useEffect(() => attachDial(plate.current, {
|
|
133
|
+
face: () => latest.current.face,
|
|
134
|
+
step: () => latest.current.minuteStep,
|
|
135
|
+
point: (v, done) => latest.current.onPoint(v, done),
|
|
136
|
+
turn: (delta) => latest.current.onTurn(delta),
|
|
137
|
+
}), []);
|
|
138
|
+
// The hand keeps the turn it stands at, so the next value is reached the short way round.
|
|
139
|
+
const turned = useRef(0);
|
|
140
|
+
if (value !== null)
|
|
141
|
+
turned.current = nearestTurn(turned.current, dialAngle(face, value));
|
|
142
|
+
const reach = value !== null && dialInner(face, value) ? DIAL.inner : DIAL.outer;
|
|
143
|
+
const marks = dialMarks(face);
|
|
144
|
+
const middle = DIAL.size / 2;
|
|
145
|
+
return (_jsx("div", { ref: panel, popover: "manual", "aria-hidden": "true", "data-face": face, className: "glim-popover glim-time-dial", children: _jsxs("svg", { ref: plate, viewBox: `0 0 ${DIAL.size} ${DIAL.size}`, children: [_jsx("circle", { className: "glim-time-dial-plate", cx: middle, cy: middle, r: middle }), value !== null && (_jsxs("g", { className: "glim-time-dial-hand", "data-value": value, style: { transform: `rotate(${turned.current}deg)` }, children: [_jsx("line", { x1: middle, y1: middle, x2: middle, y2: middle - reach }), _jsx("circle", { cx: middle, cy: middle - reach, r: reach === DIAL.inner ? 14 : 16 }), !marks.some((m) => m.value === value) && _jsx("circle", { className: "glim-time-dial-dot", cx: middle, cy: middle - reach, r: 2 })] })), _jsx("circle", { className: "glim-time-dial-hub", cx: middle, cy: middle, r: 3 }), _jsx("g", { className: "glim-time-dial-marks", children: marks.map((m) => (_jsx("g", { className: "glim-time-dial-mark", "data-value": m.value, "data-inner": m.inner ? "" : undefined, "data-chosen": m.value === value ? "" : undefined, children: _jsx("text", { x: m.x, y: m.y, children: m.text }) }, m.value))) }, face)] }) }));
|
|
146
|
+
}
|