@glimstone/react 4.0.0 → 4.1.1
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 +14 -0
- package/dist/Button.d.ts +19 -6
- package/dist/Button.js +10 -5
- package/dist/Card.d.ts +3 -1
- package/dist/Card.js +2 -2
- package/dist/Checkbox.d.ts +14 -0
- package/dist/Checkbox.js +7 -0
- package/dist/ColorPicker.d.ts +21 -0
- package/dist/ColorPicker.js +68 -0
- package/dist/Combobox.d.ts +1 -1
- package/dist/Combobox.js +3 -1
- package/dist/ContextMenu.d.ts +25 -0
- package/dist/ContextMenu.js +137 -0
- package/dist/CopyField.d.ts +17 -0
- package/dist/CopyField.js +26 -0
- package/dist/FieldRow.d.ts +20 -0
- package/dist/FieldRow.js +13 -0
- package/dist/FieldRowGroup.d.ts +9 -0
- package/dist/FieldRowGroup.js +5 -0
- package/dist/GlyphField.d.ts +16 -0
- package/dist/GlyphField.js +8 -0
- package/dist/GlyphTile.d.ts +12 -0
- package/dist/GlyphTile.js +5 -0
- package/dist/IconButton.d.ts +16 -0
- package/dist/IconButton.js +9 -0
- package/dist/IconTipButton.d.ts +6 -4
- package/dist/IconTipButton.js +4 -9
- package/dist/Kbd.d.ts +5 -0
- package/dist/Kbd.js +6 -0
- package/dist/ListRow.d.ts +16 -0
- package/dist/ListRow.js +14 -0
- package/dist/MenuBar.d.ts +20 -0
- package/dist/MenuBar.js +40 -0
- package/dist/Meter.d.ts +18 -0
- package/dist/Meter.js +9 -0
- package/dist/NumberField.d.ts +1 -1
- package/dist/NumberField.js +4 -2
- package/dist/PasswordField.d.ts +16 -0
- package/dist/PasswordField.js +11 -0
- package/dist/PathField.d.ts +28 -0
- package/dist/PathField.js +32 -0
- package/dist/Pill.d.ts +12 -0
- package/dist/Pill.js +5 -0
- package/dist/ProgressBar.d.ts +14 -0
- package/dist/ProgressBar.js +6 -0
- package/dist/RowMark.d.ts +5 -0
- package/dist/RowMark.js +6 -0
- package/dist/Select.d.ts +12 -6
- package/dist/Select.js +21 -15
- package/dist/Selector.d.ts +15 -11
- package/dist/Selector.js +11 -6
- package/dist/SidebarRow.d.ts +10 -2
- package/dist/SidebarRow.js +8 -3
- package/dist/Slider.d.ts +1 -1
- package/dist/Slider.js +3 -1
- package/dist/SubCard.d.ts +1 -1
- package/dist/SubCard.js +1 -1
- package/dist/Table.d.ts +14 -0
- package/dist/Table.js +6 -0
- package/dist/TextField.d.ts +23 -0
- package/dist/TextField.js +11 -0
- package/dist/Toast.d.ts +5 -2
- package/dist/Toast.js +9 -4
- package/dist/Toggle.d.ts +5 -4
- package/dist/Toggle.js +7 -2
- package/dist/Tree.d.ts +20 -0
- package/dist/Tree.js +59 -0
- package/dist/Window.d.ts +43 -0
- package/dist/Window.js +45 -0
- package/dist/fieldName.d.ts +4 -0
- package/dist/fieldName.js +9 -0
- package/dist/glyphs.d.ts +5 -0
- package/dist/glyphs.js +5 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +23 -0
- package/package.json +2 -2
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { takePageHue } from "@glimstone/core";
|
|
3
|
+
import { IconTipButton } from "./IconTipButton.js";
|
|
4
|
+
const reach = (e) => takePageHue(e.currentTarget);
|
|
5
|
+
export function IconButton({ tip, glyph, pressed, absent, className, ...rest }) {
|
|
6
|
+
if (absent)
|
|
7
|
+
return _jsx("span", { className: "glim-icon-btn-gap", "aria-hidden": "true" });
|
|
8
|
+
return (_jsx(IconTipButton, { ...rest, tip: tip, ariaPressed: pressed, className: `glim-btn-bare glim-icon-btn ${className ?? ""}`.trim(), onPointerEnter: reach, onFocusCapture: reach, children: glyph }));
|
|
9
|
+
}
|
package/dist/IconTipButton.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { CSSProperties, ReactNode } from "react";
|
|
2
|
-
export
|
|
1
|
+
import type { ButtonHTMLAttributes, CSSProperties, ReactNode } from "react";
|
|
2
|
+
export interface IconTipButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children" | "type"> {
|
|
3
3
|
/** The hover and focus explanation, and the button's `aria-label`. */
|
|
4
4
|
tip: string;
|
|
5
|
-
onClick?: () => void;
|
|
6
5
|
disabled?: boolean;
|
|
7
6
|
className?: string;
|
|
8
7
|
/** `aria-pressed` for a trigger that toggles rather than acts once. Omitted,
|
|
@@ -14,5 +13,8 @@ export declare function IconTipButton({ tip, onClick, disabled, className, style
|
|
|
14
13
|
/** Inline style, so a hued Badge can set its `--item-hue*` properties. */
|
|
15
14
|
style?: CSSProperties;
|
|
16
15
|
children: ReactNode;
|
|
16
|
+
/** Makes it a link. A disabled one stays a disabled button. */
|
|
17
|
+
href?: string;
|
|
17
18
|
type?: "button" | "submit";
|
|
18
|
-
}
|
|
19
|
+
}
|
|
20
|
+
export declare function IconTipButton({ tip, disabled, className, style, children, href, type, ariaPressed, ariaExpanded, ...rest }: IconTipButtonProps): import("react").JSX.Element;
|
package/dist/IconTipButton.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useTipBubble } from "./useTipBubble.js";
|
|
3
|
-
|
|
4
|
-
// a `.glim-bubble` tooltip rather than the native `title=` balloon. `tip` is
|
|
5
|
-
// required because an icon-only button has no other way to say what it does.
|
|
6
|
-
//
|
|
7
|
-
// Unlike Button, this control has no label to hide: a bare glyph in a box the
|
|
8
|
-
// caller sizes, with no width stage, no tone fill and no place in the label
|
|
9
|
-
// mode engine.
|
|
10
|
-
export function IconTipButton({ tip, onClick, disabled, className, style, children, type = "button", ariaPressed, ariaExpanded, }) {
|
|
3
|
+
export function IconTipButton({ tip, disabled, className, style, children, href, type = "button", ariaPressed, ariaExpanded, ...rest }) {
|
|
11
4
|
const tooltip = useTipBubble(tip, disabled);
|
|
12
|
-
|
|
5
|
+
const Element = (href && !disabled ? "a" : "button");
|
|
6
|
+
const own = href && !disabled ? { href } : { type, disabled };
|
|
7
|
+
return (_jsxs(_Fragment, { children: [tooltip.wrap(_jsx(Element, { ...rest, ...own, ref: tooltip.ref, "aria-label": tip, "aria-pressed": ariaPressed, "aria-expanded": ariaExpanded, "aria-describedby": tooltip.describedBy, ...tooltip.handlers, className: className, style: style, children: children })), tooltip.bubble] }));
|
|
13
8
|
}
|
package/dist/Kbd.d.ts
ADDED
package/dist/Kbd.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// A key or a key combination as it is written on the keys, such as "Ctrl+K".
|
|
3
|
+
// The words are the app's, so a German app writes "Strg".
|
|
4
|
+
export function Kbd({ children, className }) {
|
|
5
|
+
return _jsx("kbd", { className: className ? `glim-kbd ${className}` : "glim-kbd", children: children });
|
|
6
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from "react";
|
|
2
|
+
export interface ListRowProps extends Omit<HTMLAttributes<HTMLDivElement>, "children"> {
|
|
3
|
+
name: string;
|
|
4
|
+
/** More about the row, drawn as an "(i)" beside the name. */
|
|
5
|
+
tip?: string | null;
|
|
6
|
+
/** Sets the name in monospace, for a path. */
|
|
7
|
+
mono?: boolean;
|
|
8
|
+
/** The glyph at the row's start, which fills with the accent while the row is reached. */
|
|
9
|
+
tile?: ReactNode;
|
|
10
|
+
/** What stands at the row's end at rest. */
|
|
11
|
+
badges?: ReactNode;
|
|
12
|
+
/** The buttons that come in on hover and focus. A press on one does not open the row. */
|
|
13
|
+
actions?: ReactNode;
|
|
14
|
+
className?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function ListRow({ name, tip, mono, tile, badges, actions, className, onClick, onKeyDown, ...rest }: ListRowProps): import("react").JSX.Element;
|
package/dist/ListRow.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { InfoBubble } from "./InfoBubble.js";
|
|
3
|
+
const stay = (e) => e.stopPropagation();
|
|
4
|
+
export function ListRow({ name, tip, mono, tile, badges, actions, className, onClick, onKeyDown, ...rest }) {
|
|
5
|
+
function keys(e) {
|
|
6
|
+
onKeyDown?.(e);
|
|
7
|
+
if (!onClick || e.target !== e.currentTarget || (e.key !== "Enter" && e.key !== " "))
|
|
8
|
+
return;
|
|
9
|
+
e.preventDefault();
|
|
10
|
+
e.currentTarget.click();
|
|
11
|
+
}
|
|
12
|
+
const classes = ["glim-list-row", onClick && "glim-list-row--opens", className].filter(Boolean).join(" ");
|
|
13
|
+
return (_jsxs("div", { role: "group", "aria-label": name, tabIndex: onClick ? 0 : undefined, ...rest, onClick: onClick, onKeyDown: keys, className: classes, children: [tile && _jsx("span", { className: "glim-list-row-tile", children: tile }), _jsxs("span", { className: mono ? "glim-list-row-name glim-list-row-name--mono" : "glim-list-row-name", children: [_jsx("span", { className: "glim-list-row-title", children: name }), tip && (_jsx("span", { className: "glim-list-row-tip", onClick: stay, children: _jsx(InfoBubble, { tip: tip }) }))] }), badges && _jsx("span", { className: "glim-list-row-badges", children: badges }), actions && (_jsx("span", { className: "glim-list-row-actions", onClick: stay, children: actions }))] }));
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Ref } from "react";
|
|
2
|
+
import { type MenuEntry } from "./ContextMenu.tsx";
|
|
3
|
+
export interface MenuBarMenu {
|
|
4
|
+
label: string;
|
|
5
|
+
items: MenuEntry[];
|
|
6
|
+
/** The id of the open menu, for a caller or a script that looks for it. */
|
|
7
|
+
id?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface MenuBarHandle {
|
|
10
|
+
/** Opens a menu by its index and puts the focus on its first row. */
|
|
11
|
+
open: (index: number) => void;
|
|
12
|
+
}
|
|
13
|
+
export interface MenuBarProps {
|
|
14
|
+
/** The bar's accessible name, such as "Menu". */
|
|
15
|
+
label: string;
|
|
16
|
+
menus: MenuBarMenu[];
|
|
17
|
+
ref?: Ref<MenuBarHandle>;
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function MenuBar({ label, menus, ref, className }: MenuBarProps): import("react").JSX.Element;
|
package/dist/MenuBar.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// The menu bar of a desktop-style app: a row of words, each opening its menu
|
|
3
|
+
// below it. While one is open the pointer and the arrow keys move between
|
|
4
|
+
// them, as in a desktop program. The app opens the first one on F10 through
|
|
5
|
+
// the ref, since which key does it is the app's keymap.
|
|
6
|
+
import { useImperativeHandle, useRef, useState } from "react";
|
|
7
|
+
import { ContextMenu } from "./ContextMenu.js";
|
|
8
|
+
export function MenuBar({ label, menus, ref, className }) {
|
|
9
|
+
const buttons = useRef([]);
|
|
10
|
+
const [open, setOpen] = useState(null);
|
|
11
|
+
const [stop, setStop] = useState(0);
|
|
12
|
+
const count = menus.length;
|
|
13
|
+
function show(at) {
|
|
14
|
+
const button = buttons.current[at];
|
|
15
|
+
if (!button)
|
|
16
|
+
return;
|
|
17
|
+
button.focus();
|
|
18
|
+
setStop(at);
|
|
19
|
+
const r = button.getBoundingClientRect();
|
|
20
|
+
setOpen({ at, x: r.left, y: r.bottom + 6 });
|
|
21
|
+
}
|
|
22
|
+
useImperativeHandle(ref, () => ({ open: show }));
|
|
23
|
+
function keys(e, at) {
|
|
24
|
+
const rtl = getComputedStyle(e.currentTarget).direction === "rtl";
|
|
25
|
+
const step = { ArrowRight: rtl ? -1 : 1, ArrowLeft: rtl ? 1 : -1 }[e.key];
|
|
26
|
+
if (step !== undefined) {
|
|
27
|
+
e.preventDefault();
|
|
28
|
+
const next = (at + step + count) % count;
|
|
29
|
+
setStop(next);
|
|
30
|
+
buttons.current[next]?.focus();
|
|
31
|
+
}
|
|
32
|
+
else if (e.key === "ArrowDown") {
|
|
33
|
+
e.preventDefault();
|
|
34
|
+
show(at);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return (_jsxs("div", { role: "menubar", "aria-label": label, className: className ? `glim-menubar ${className}` : "glim-menubar", children: [menus.map((m, i) => (_jsx("button", { ref: (el) => {
|
|
38
|
+
buttons.current[i] = el;
|
|
39
|
+
}, type: "button", role: "menuitem", "aria-haspopup": "menu", "aria-expanded": open?.at === i, tabIndex: i === stop ? 0 : -1, className: "glim-menubar-item", onClick: () => (open?.at === i ? setOpen(null) : show(i)), onMouseEnter: () => open && open.at !== i && show(i), onKeyDown: (e) => keys(e, i), onFocus: () => setStop(i), children: m.label }, i))), open && menus[open.at] && (_jsx(ContextMenu, { x: open.x, y: open.y, items: menus[open.at].items, label: menus[open.at].label, id: menus[open.at].id, opener: buttons.current[open.at], onClose: () => setOpen(null), onStep: (d) => show((open.at + d + count) % count) }, open.at))] }));
|
|
40
|
+
}
|
package/dist/Meter.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type MeterSize } from "@glimstone/core";
|
|
2
|
+
export type { MeterSize } from "@glimstone/core";
|
|
3
|
+
export interface MeterProps {
|
|
4
|
+
/** From 0 to 1. Without it the meter shows stripes while the level is still being read. */
|
|
5
|
+
value?: number | null;
|
|
6
|
+
/** The accessible name, such as the disk's. */
|
|
7
|
+
label: string;
|
|
8
|
+
/** `small` sits beside a row's name, `medium` is as wide as its column. */
|
|
9
|
+
size?: MeterSize;
|
|
10
|
+
/** From here on the fill is the fault colour. */
|
|
11
|
+
threshold?: number;
|
|
12
|
+
/** Slim and grey, for a footer line or a dense list. Inside a button it takes the accent when the button is reached. */
|
|
13
|
+
quiet?: boolean;
|
|
14
|
+
/** The level in words, such as "120 GB free of 4 TB": read out, and shown in the bubble. */
|
|
15
|
+
valueText?: string;
|
|
16
|
+
className?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function Meter({ value, label, size, threshold, quiet, valueText, className }: MeterProps): import("react").JSX.Element;
|
package/dist/Meter.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { meterView } from "@glimstone/core";
|
|
3
|
+
import { useTipBubble } from "./useTipBubble.js";
|
|
4
|
+
export function Meter({ value, label, size = "medium", threshold, quiet, valueText, className }) {
|
|
5
|
+
const view = meterView(value, { size, threshold, quiet });
|
|
6
|
+
const tip = useTipBubble(valueText);
|
|
7
|
+
const busy = view.percent === null;
|
|
8
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: tip.ref, ...tip.handlers, role: busy ? "progressbar" : "meter", "aria-label": label, "aria-valuemin": busy ? undefined : 0, "aria-valuemax": busy ? undefined : 100, "aria-valuenow": view.percent ?? undefined, "aria-valuetext": valueText, "aria-busy": busy || undefined, className: className ? `${view.className} ${className}` : view.className, children: _jsx("span", { className: "glim-meter-fill", style: view.width ? { width: view.width } : undefined }) }), tip.bubble] }));
|
|
9
|
+
}
|
package/dist/NumberField.d.ts
CHANGED
|
@@ -13,4 +13,4 @@ export interface NumberFieldProps extends Omit<InputHTMLAttributes<HTMLInputElem
|
|
|
13
13
|
className?: string;
|
|
14
14
|
ref?: Ref<HTMLInputElement>;
|
|
15
15
|
}
|
|
16
|
-
export declare function NumberField({ className, ref, ...rest }: NumberFieldProps): import("react").JSX.Element;
|
|
16
|
+
export declare function NumberField({ className, ref, "aria-label": ariaLabel, ...rest }: NumberFieldProps): import("react").JSX.Element;
|
package/dist/NumberField.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useRef } from "react";
|
|
3
3
|
import { attachNumberSteppers, syncNumberSteppers } from "@glimstone/core";
|
|
4
|
-
|
|
4
|
+
import { useFieldName } from "./fieldName.js";
|
|
5
|
+
export function NumberField({ className = "", ref, "aria-label": ariaLabel, ...rest }) {
|
|
6
|
+
const name = useFieldName(ariaLabel);
|
|
5
7
|
const own = useRef(null);
|
|
6
8
|
useEffect(() => attachNumberSteppers(own.current), []);
|
|
7
9
|
// A value the app sets fires no input event, so the arrows look again.
|
|
8
10
|
useEffect(() => {
|
|
9
11
|
syncNumberSteppers(own.current);
|
|
10
12
|
}, [rest.value, rest.min, rest.max, rest.step, rest.disabled, rest.readOnly]);
|
|
11
|
-
return (_jsx("span", { className: "glim-num-wrap", children: _jsx("input", { ...rest, ref: (el) => {
|
|
13
|
+
return (_jsx("span", { className: "glim-num-wrap", children: _jsx("input", { ...rest, "aria-label": name, ref: (el) => {
|
|
12
14
|
own.current = el;
|
|
13
15
|
if (typeof ref === "function")
|
|
14
16
|
ref(el);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type InputHTMLAttributes, type Ref } from "react";
|
|
2
|
+
import { type FieldWidth } from "@glimstone/core";
|
|
3
|
+
export interface PasswordFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "width"> {
|
|
4
|
+
width?: FieldWidth;
|
|
5
|
+
/** Attributes for the eye, such as a data hook. */
|
|
6
|
+
eyeAttrs?: Record<string, string>;
|
|
7
|
+
/** The eye's name and bubble while the secret is hidden, and once it shows. */
|
|
8
|
+
text?: {
|
|
9
|
+
show: string;
|
|
10
|
+
hide: string;
|
|
11
|
+
};
|
|
12
|
+
/** Classes for the wrapper, which carries the field's width. */
|
|
13
|
+
className?: string;
|
|
14
|
+
ref?: Ref<HTMLInputElement>;
|
|
15
|
+
}
|
|
16
|
+
export declare function PasswordField({ width, eyeAttrs, text, className, ref, disabled, "aria-label": ariaLabel, ...rest }: PasswordFieldProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { fieldWidthClass } from "@glimstone/core";
|
|
4
|
+
import { useFieldName } from "./fieldName.js";
|
|
5
|
+
import { IconEye, IconEyeOff } from "./glyphs.js";
|
|
6
|
+
import { IconTipButton } from "./IconTipButton.js";
|
|
7
|
+
export function PasswordField({ width, eyeAttrs, text = { show: "Show", hide: "Hide" }, className, ref, disabled, "aria-label": ariaLabel, ...rest }) {
|
|
8
|
+
const [shown, setShown] = useState(false);
|
|
9
|
+
const name = useFieldName(ariaLabel);
|
|
10
|
+
return (_jsxs("span", { className: ["glim-secret", fieldWidthClass(width), className].filter(Boolean).join(" "), children: [_jsx("input", { autoComplete: "current-password", spellCheck: false, ...rest, "aria-label": name, ref: ref, disabled: disabled, type: shown ? "text" : "password", className: "glim-input" }), _jsx(IconTipButton, { ...eyeAttrs, tip: shown ? text.hide : text.show, className: "glim-secret-eye", disabled: disabled, onClick: () => setShown(!shown), children: shown ? _jsx(IconEyeOff, {}) : _jsx(IconEye, {}) })] }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type InputHTMLAttributes, type ReactNode, type Ref } from "react";
|
|
2
|
+
import { type FieldWidth } from "@glimstone/core";
|
|
3
|
+
export interface PathFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "value" | "onChange" | "type" | "width"> {
|
|
4
|
+
value: string;
|
|
5
|
+
/** Called with the path as it is typed and as the picker answers. */
|
|
6
|
+
onChange: (path: string) => void;
|
|
7
|
+
/** Handed the path in the field. Answers with a path, or with nothing when the person left. */
|
|
8
|
+
pick: (current: string) => string | null | undefined | Promise<string | null | undefined>;
|
|
9
|
+
/** Called with a path the picker answered with, after onChange. */
|
|
10
|
+
onPicked?: (path: string) => void;
|
|
11
|
+
/** The accessible name. Inside a FieldRow the row gives it. */
|
|
12
|
+
label?: string;
|
|
13
|
+
width?: FieldWidth;
|
|
14
|
+
/** The button's words. */
|
|
15
|
+
text?: {
|
|
16
|
+
pick: string;
|
|
17
|
+
};
|
|
18
|
+
/** The button's glyph, an open folder unless set, such as a file for a picker of files. */
|
|
19
|
+
glyph?: ReactNode;
|
|
20
|
+
/** Shows the button's glyph alone, as it does by itself with less than 20rem of room. */
|
|
21
|
+
compact?: boolean;
|
|
22
|
+
/** Attributes for the button, such as a data hook. */
|
|
23
|
+
buttonAttrs?: Record<string, string>;
|
|
24
|
+
/** Classes for the wrapper, which carries the width. */
|
|
25
|
+
className?: string;
|
|
26
|
+
ref?: Ref<HTMLInputElement>;
|
|
27
|
+
}
|
|
28
|
+
export declare function PathField({ value, onChange, pick, onPicked, label, width, text, glyph, compact, buttonAttrs, className, style, disabled, ref, ...rest }: PathFieldProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { fieldWidthClass, PATH_ROOM_PX } from "@glimstone/core";
|
|
4
|
+
import { Button } from "./Button.js";
|
|
5
|
+
import { useFieldName } from "./fieldName.js";
|
|
6
|
+
import { IconFolderOpen } from "./glyphs.js";
|
|
7
|
+
export function PathField({ value, onChange, pick, onPicked, label, width, text = { pick: "Choose" }, glyph = _jsx(IconFolderOpen, {}), compact = false, buttonAttrs, className, style, disabled, ref, ...rest }) {
|
|
8
|
+
const name = useFieldName(label);
|
|
9
|
+
const own = useRef(null);
|
|
10
|
+
const box = useRef(null);
|
|
11
|
+
const [tight, setTight] = useState(false);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const watcher = new ResizeObserver(([entry]) => setTight(entry.contentRect.width < PATH_ROOM_PX));
|
|
14
|
+
watcher.observe(box.current);
|
|
15
|
+
return () => watcher.disconnect();
|
|
16
|
+
}, []);
|
|
17
|
+
async function ask() {
|
|
18
|
+
const answer = await pick(value);
|
|
19
|
+
own.current?.focus();
|
|
20
|
+
if (!answer)
|
|
21
|
+
return;
|
|
22
|
+
onChange(answer);
|
|
23
|
+
onPicked?.(answer);
|
|
24
|
+
}
|
|
25
|
+
return (_jsxs("span", { ref: box, className: ["glim-path", fieldWidthClass(width), className].filter(Boolean).join(" "), style: style, children: [_jsx("input", { spellCheck: false, autoComplete: "off", "aria-label": name, ...rest, ref: (el) => {
|
|
26
|
+
own.current = el;
|
|
27
|
+
if (typeof ref === "function")
|
|
28
|
+
ref(el);
|
|
29
|
+
else if (ref)
|
|
30
|
+
ref.current = el;
|
|
31
|
+
}, type: "text", value: value, disabled: disabled, onChange: (e) => onChange(e.target.value), className: "glim-input glim-input--mono" }), _jsx(Button, { ...buttonAttrs, variant: "icon", label: text.pick, labelKey: null, glyph: glyph, compact: compact || tight, disabled: disabled, onClick: ask })] }));
|
|
32
|
+
}
|
package/dist/Pill.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { type PillTone } from "@glimstone/core";
|
|
3
|
+
export type { PillTone } from "@glimstone/core";
|
|
4
|
+
export interface PillProps {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
/** `state` lifts a word that says what the row is doing; the other three
|
|
7
|
+
* wash the pill in their state colour. */
|
|
8
|
+
tone?: PillTone;
|
|
9
|
+
/** Extra classes, such as `glim-num` for figures that line up in a column. */
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function Pill({ children, tone, className }: PillProps): import("react").JSX.Element;
|
package/dist/Pill.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { pillClassName } from "@glimstone/core";
|
|
3
|
+
export function Pill({ children, tone = "neutral", className }) {
|
|
4
|
+
return _jsx("span", { className: className ? `${pillClassName(tone)} ${className}` : pillClassName(tone), children: children });
|
|
5
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ProgressBarProps {
|
|
2
|
+
/** From 0 to 1. Without it the bar runs indeterminate, while the work has no measure yet. */
|
|
3
|
+
value?: number | null;
|
|
4
|
+
/** The accessible name, such as what is being copied. */
|
|
5
|
+
label: string;
|
|
6
|
+
/** The work waits: the fill takes the waiting tone and the sheen stops. */
|
|
7
|
+
paused?: boolean;
|
|
8
|
+
/** The work stopped on an error: the fill takes the fault colour. */
|
|
9
|
+
failed?: boolean;
|
|
10
|
+
/** The progress in words, such as "1.2 GB of 4 GB", read out instead of the percentage. */
|
|
11
|
+
valueText?: string;
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function ProgressBar({ value, label, paused, failed, valueText, className }: ProgressBarProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { progressView } from "@glimstone/core";
|
|
3
|
+
export function ProgressBar({ value, label, paused, failed, valueText, className }) {
|
|
4
|
+
const view = progressView(value, { paused, failed });
|
|
5
|
+
return (_jsx("span", { role: "progressbar", "aria-label": label, "aria-valuemin": view.percent === null ? undefined : 0, "aria-valuemax": view.percent === null ? undefined : 100, "aria-valuenow": view.percent ?? undefined, "aria-valuetext": valueText, className: className ? `${view.className} ${className}` : view.className, children: _jsx("span", { className: "glim-progress-fill", style: view.width ? { width: view.width } : undefined }) }));
|
|
6
|
+
}
|
package/dist/RowMark.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { IconCheck } from "./glyphs.js";
|
|
3
|
+
export function RowMark({ on, className }) {
|
|
4
|
+
const classes = ["glim-rowmark", on && "glim-rowmark--on", className].filter(Boolean).join(" ");
|
|
5
|
+
return (_jsx("span", { className: classes, "aria-hidden": "true", children: _jsx(IconCheck, {}) }));
|
|
6
|
+
}
|
package/dist/Select.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { type ReactNode, type Ref } from "react";
|
|
2
|
-
import { type SelectChoice, type SelectEntry as Entry, type SelectRun, type SelectSize, type SelectSubmenu as Submenu, type SelectWidth } from "@glimstone/core";
|
|
2
|
+
import { type SelectChoice, type SelectEntry as Entry, type SelectRows, type SelectRun, type SelectSize, type SelectSubmenu as Submenu, type SelectWidth } from "@glimstone/core";
|
|
3
3
|
export type SelectOption<T extends string = string> = SelectChoice<T, ReactNode>;
|
|
4
4
|
export type SelectSubmenu<T extends string = string> = Submenu<T, ReactNode>;
|
|
5
5
|
export type SelectEntry<T extends string = string> = Entry<T, ReactNode>;
|
|
6
6
|
export type SelectGroup<T extends string = string> = SelectRun<T, ReactNode>;
|
|
7
|
-
export type { SelectSize, SelectWidth } from "@glimstone/core";
|
|
7
|
+
export type { SelectRows, SelectSize, SelectWidth } from "@glimstone/core";
|
|
8
8
|
export interface SelectProps<T extends string = string> {
|
|
9
|
-
/** The field's name, always the accessible name. */
|
|
10
|
-
label
|
|
9
|
+
/** The field's name, always the accessible name. Inside a FieldRow the row gives it and draws the words. */
|
|
10
|
+
label?: string;
|
|
11
11
|
/** Draw the label off screen, for a settings row that names the field at its start. */
|
|
12
12
|
hideLabel?: boolean;
|
|
13
13
|
/** Every choice, in list order, for a list without groups. */
|
|
@@ -19,13 +19,19 @@ export interface SelectProps<T extends string = string> {
|
|
|
19
19
|
onChange: (value: T) => void;
|
|
20
20
|
/** Shown while the value is null. */
|
|
21
21
|
placeholder?: string;
|
|
22
|
-
/** Defaults to `fill` for a field and to `steady` for the smaller sizes. */
|
|
22
|
+
/** Defaults to `fill` for a field and to `steady` for the smaller sizes and inside a FieldRow. */
|
|
23
23
|
width?: SelectWidth;
|
|
24
24
|
size?: SelectSize;
|
|
25
|
+
/** `menu` draws the open list with a context menu's rows, so an app with both shows one kind of menu row. */
|
|
26
|
+
rows?: SelectRows;
|
|
25
27
|
/** Lets a long value run onto a second line instead of ending in an ellipsis, for one whose end says as much as its start, such as a path. */
|
|
26
28
|
wrap?: boolean;
|
|
27
29
|
/** The trigger's id, for a `<label htmlFor>` outside the select. */
|
|
28
30
|
id?: string;
|
|
31
|
+
/** Attributes for the trigger, such as a data hook that says the value. */
|
|
32
|
+
triggerAttrs?: Record<string, string>;
|
|
33
|
+
/** The open list's id. */
|
|
34
|
+
listId?: string;
|
|
29
35
|
/** The trigger's own node, for a caller that hands it the focus. */
|
|
30
36
|
ref?: Ref<HTMLButtonElement>;
|
|
31
37
|
disabled?: boolean;
|
|
@@ -38,4 +44,4 @@ export interface SelectProps<T extends string = string> {
|
|
|
38
44
|
/** Classes for the trigger, for a size the call site needs. */
|
|
39
45
|
className?: string;
|
|
40
46
|
}
|
|
41
|
-
export declare function Select<T extends string = string>({ size, width, wrap, className, options, groups, ...rest }: SelectProps<T>): import("react").JSX.Element;
|
|
47
|
+
export declare function Select<T extends string = string>({ size, rows, label, hideLabel, width, wrap, className, options, groups, ...rest }: SelectProps<T>): import("react").JSX.Element;
|
package/dist/Select.js
CHANGED
|
@@ -3,16 +3,20 @@ import { useEffect, useId, useRef } from "react";
|
|
|
3
3
|
import * as menu from "@zag-js/menu";
|
|
4
4
|
import * as select from "@zag-js/select";
|
|
5
5
|
import { normalizeProps, Portal, useMachine } from "@zag-js/react";
|
|
6
|
-
import { closeOnPageMove, defaultWidth, enableWheelStep, faceLabels, flattenRuns, hasSubmenu, homeRow, isSubmenu, pageDir, SELECT_POSITIONING,
|
|
6
|
+
import { closeOnPageMove, defaultWidth, enableWheelStep, faceLabels, flattenRuns, hasSubmenu, homeRow, isSubmenu, pageDir, SELECT_POSITIONING, selectRootClass, selectRowParts, selectTriggerClass, shake as shakeOnce, wheelValue, } from "@glimstone/core";
|
|
7
|
+
import { useFieldName } from "./fieldName.js";
|
|
7
8
|
import { IconCheck, IconExpand } from "./glyphs.js";
|
|
8
9
|
import { usePortalHue } from "./portalHue.js";
|
|
9
10
|
import { useTipBubble } from "./useTipBubble.js";
|
|
10
|
-
export function Select({ size = "field",
|
|
11
|
+
export function Select({ size = "field", rows = "list", label, hideLabel, width, wrap = false, className = "", options, groups, ...rest }) {
|
|
12
|
+
const name = useFieldName(label);
|
|
13
|
+
const fromRow = label === undefined;
|
|
14
|
+
const shared = { label: name ?? "", hideLabel: hideLabel || fromRow, width: width ?? (fromRow ? "steady" : defaultWidth(size)), rows };
|
|
11
15
|
const runs = groups ?? [{ entries: options ?? [] }];
|
|
12
16
|
const look = `${selectTriggerClass(size, wrap)} ${className}`.trim();
|
|
13
|
-
return hasSubmenu(runs) ? (_jsx(MenuSelect, { ...rest,
|
|
17
|
+
return hasSubmenu(runs) ? (_jsx(MenuSelect, { ...rest, ...shared, groups: runs, className: look })) : (_jsx(ListSelect, { ...rest, ...shared, groups: runs, className: look }));
|
|
14
18
|
}
|
|
15
|
-
function ListSelect({ label, hideLabel, groups, value, onChange, placeholder, width, disabled, busy, tip, shake, className, id, ref, }) {
|
|
19
|
+
function ListSelect({ label, hideLabel, groups, value, onChange, placeholder, width, rows, disabled, busy, tip, shake, className, id, triggerAttrs, listId, ref, }) {
|
|
16
20
|
const uid = useId();
|
|
17
21
|
const all = flattenRuns(groups);
|
|
18
22
|
const collection = select.collection({
|
|
@@ -23,7 +27,7 @@ function ListSelect({ label, hideLabel, groups, value, onChange, placeholder, wi
|
|
|
23
27
|
});
|
|
24
28
|
const service = useMachine(select.machine, {
|
|
25
29
|
id: uid,
|
|
26
|
-
ids:
|
|
30
|
+
ids: { trigger: id, content: listId },
|
|
27
31
|
dir: pageDir(),
|
|
28
32
|
collection,
|
|
29
33
|
value: value === null ? [] : [value],
|
|
@@ -41,21 +45,22 @@ function ListSelect({ label, hideLabel, groups, value, onChange, placeholder, wi
|
|
|
41
45
|
useEffect(() => (api.open ? closeOnPageMove(() => api.setOpen(false)) : undefined), [api.open]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
42
46
|
const hue = usePortalHue(api.open, trigger.ref);
|
|
43
47
|
const glyphs = all.some((o) => o.glyph);
|
|
48
|
+
const parts = selectRowParts(rows, glyphs);
|
|
44
49
|
const tp = api.getTriggerProps();
|
|
45
50
|
const positioner = api.getPositionerProps();
|
|
46
|
-
return (_jsxs("div", { ...api.getRootProps(), className: selectRootClass(width), children: [_jsx("label", { ...api.getLabelProps(), className: hideLabel ? "glim-sr-only" : "glim-field-label", children: label }), _jsx("div", { ...api.getControlProps(), children: trigger.tip.wrap(_jsxs("button", { ...tp, ref: trigger.attach, ...trigger.handlers(tp), "aria-busy": busy || undefined, className: className, children: [_jsx(Face, { all: all, value: value, placeholder: placeholder, width: width, glyphs: glyphs }), _jsx("span", { ...api.getIndicatorProps(), className: "glim-select-indicator", children: _jsx(IconExpand, {}) })] })) }), trigger.tip.bubble, _jsx(Portal, { children: _jsx("div", { ...positioner, style: { ...positioner.style, ...hue.style }, className: `glim-select-positioner ${hue.className}`.trim(), children: _jsx("div", { ...api.getContentProps(), className:
|
|
51
|
+
return (_jsxs("div", { ...api.getRootProps(), className: selectRootClass(width), children: [_jsx("label", { ...api.getLabelProps(), className: hideLabel ? "glim-sr-only" : "glim-field-label", children: label }), _jsx("div", { ...api.getControlProps(), children: trigger.tip.wrap(_jsxs("button", { ...triggerAttrs, ...tp, ref: trigger.attach, ...trigger.handlers(tp), "aria-busy": busy || undefined, className: className, children: [_jsx(Face, { all: all, value: value, placeholder: placeholder, width: width, glyphs: glyphs }), _jsx("span", { ...api.getIndicatorProps(), className: "glim-select-indicator", children: _jsx(IconExpand, {}) })] })) }), trigger.tip.bubble, _jsx(Portal, { children: _jsx("div", { ...positioner, style: { ...positioner.style, ...hue.style }, className: `glim-select-positioner ${hue.className}`.trim(), children: _jsx("div", { ...api.getContentProps(), className: parts.content, children: groups.map((g, gi) => {
|
|
47
52
|
const items = g.entries;
|
|
48
53
|
if (items.length === 0)
|
|
49
54
|
return null;
|
|
50
55
|
const id = `${uid}-g${gi}`;
|
|
51
|
-
return (_jsxs("div", { ...(g.heading ? api.getItemGroupProps({ id }) : {}), className: "glim-select-group", children: [g.heading && (_jsx("div", { ...api.getItemGroupLabelProps({ htmlFor: id }), className:
|
|
56
|
+
return (_jsxs("div", { ...(g.heading ? api.getItemGroupProps({ id }) : {}), className: "glim-select-group", children: [g.heading && (_jsx("div", { ...api.getItemGroupLabelProps({ htmlFor: id }), className: parts.heading, children: g.heading })), items.map((item) => (_jsxs("div", { ...api.getItemProps({ item }), className: parts.item, children: [parts.glyph && _jsx("span", { className: parts.glyph, children: item.glyph }), _jsx("span", { ...api.getItemTextProps({ item }), className: parts.label, children: item.label }), _jsx("span", { ...api.getItemIndicatorProps({ item }), className: parts.check, children: _jsx(IconCheck, {}) })] }, item.value)))] }, gi));
|
|
52
57
|
}) }) }) }), _jsx("select", { ...api.getHiddenSelectProps() })] }));
|
|
53
58
|
}
|
|
54
|
-
function MenuSelect({ label, hideLabel, groups, value, onChange, placeholder, width, disabled, busy, tip, shake, className, id, ref, }) {
|
|
59
|
+
function MenuSelect({ label, hideLabel, groups, value, onChange, placeholder, width, rows, disabled, busy, tip, shake, className, id, triggerAttrs, listId, ref, }) {
|
|
55
60
|
const uid = useId();
|
|
56
61
|
const service = useMachine(menu.machine, {
|
|
57
62
|
id: uid,
|
|
58
|
-
ids:
|
|
63
|
+
ids: { trigger: id, content: listId },
|
|
59
64
|
dir: pageDir(),
|
|
60
65
|
"aria-label": label,
|
|
61
66
|
positioning: SELECT_POSITIONING,
|
|
@@ -66,6 +71,7 @@ function MenuSelect({ label, hideLabel, groups, value, onChange, placeholder, wi
|
|
|
66
71
|
useEffect(() => (api.open ? closeOnPageMove(() => api.setOpen(false)) : undefined), [api.open]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
67
72
|
const hue = usePortalHue(api.open, trigger.ref);
|
|
68
73
|
const glyphs = all.some((o) => o.glyph);
|
|
74
|
+
const parts = selectRowParts(rows, glyphs);
|
|
69
75
|
const subId = (gi, ei) => `${uid}-sub-${gi}-${ei}`;
|
|
70
76
|
// Zag highlights on the frame after the list opens, so the home row goes one
|
|
71
77
|
// frame later still.
|
|
@@ -92,14 +98,14 @@ function MenuSelect({ label, hideLabel, groups, value, onChange, placeholder, wi
|
|
|
92
98
|
fn?.(e);
|
|
93
99
|
};
|
|
94
100
|
const positioner = api.getPositionerProps();
|
|
95
|
-
return (_jsxs("div", { className: selectRootClass(width), children: [!hideLabel && (_jsx("span", { "aria-hidden": "true", className: "glim-field-label", children: label })), _jsx("div", { children: trigger.tip.wrap(_jsxs("button", { ...tp, ref: trigger.attach, ...trigger.handlers(tp), onPointerDown: hold(tp.onPointerDown), onClick: hold(tp.onClick), onKeyDown: hold(tp.onKeyDown), disabled: disabled, "data-disabled": disabled ? "" : undefined, "data-readonly": busy ? "" : undefined, "aria-busy": busy || undefined, "aria-label": `${label}: ${text}`, className: className, children: [_jsx(Face, { all: all, value: value, placeholder: placeholder, width: width, glyphs: glyphs }), _jsx("span", { ...api.getIndicatorProps(), className: "glim-select-indicator", children: _jsx(IconExpand, {}) })] })) }), trigger.tip.bubble, _jsx(Portal, { children: _jsx("div", { ...positioner, style: { ...positioner.style, ...hue.style }, className: `glim-select-positioner ${hue.className}`.trim(), children: _jsx("div", { ...api.getContentProps(), className:
|
|
101
|
+
return (_jsxs("div", { className: selectRootClass(width), children: [!hideLabel && (_jsx("span", { "aria-hidden": "true", className: "glim-field-label", children: label })), _jsx("div", { children: trigger.tip.wrap(_jsxs("button", { ...triggerAttrs, ...tp, ref: trigger.attach, ...trigger.handlers(tp), onPointerDown: hold(tp.onPointerDown), onClick: hold(tp.onClick), onKeyDown: hold(tp.onKeyDown), disabled: disabled, "data-disabled": disabled ? "" : undefined, "data-readonly": busy ? "" : undefined, "aria-busy": busy || undefined, "aria-label": `${label}: ${text}`, className: className, children: [_jsx(Face, { all: all, value: value, placeholder: placeholder, width: width, glyphs: glyphs }), _jsx("span", { ...api.getIndicatorProps(), className: "glim-select-indicator", children: _jsx(IconExpand, {}) })] })) }), trigger.tip.bubble, _jsx(Portal, { children: _jsx("div", { ...positioner, style: { ...positioner.style, ...hue.style }, className: `glim-select-positioner ${hue.className}`.trim(), children: _jsx("div", { ...api.getContentProps(), className: parts.content, children: groups.map((g, gi) => {
|
|
96
102
|
if (g.entries.length === 0)
|
|
97
103
|
return null;
|
|
98
104
|
const id = `g${gi}`;
|
|
99
|
-
return (_jsxs("div", { ...(g.heading ? api.getItemGroupProps({ id }) : {}), className: "glim-select-group", children: [g.heading && (_jsx("div", { ...api.getItemGroupLabelProps({ htmlFor: id }), className:
|
|
105
|
+
return (_jsxs("div", { ...(g.heading ? api.getItemGroupProps({ id }) : {}), className: "glim-select-group", children: [g.heading && (_jsx("div", { ...api.getItemGroupLabelProps({ htmlFor: id }), className: parts.heading, children: g.heading })), g.entries.map((e, ei) => isSubmenu(e) ? (_jsx(SubmenuList, { parent: service, parentApi: api, triggerId: subId(gi, ei), entry: e, value: value, onChange: onChange, parts: parts, hue: hue }, `s${ei}`)) : (_jsx(Choice, { api: api, option: e, value: value, onChange: onChange, parts: parts }, e.value)))] }, gi));
|
|
100
106
|
}) }) }) })] }));
|
|
101
107
|
}
|
|
102
|
-
function SubmenuList({ parent, parentApi, triggerId, entry, value, onChange,
|
|
108
|
+
function SubmenuList({ parent, parentApi, triggerId, entry, value, onChange, parts, hue, }) {
|
|
103
109
|
const service = useMachine(menu.machine, {
|
|
104
110
|
id: useId(),
|
|
105
111
|
ids: { trigger: triggerId },
|
|
@@ -112,9 +118,9 @@ function SubmenuList({ parent, parentApi, triggerId, entry, value, onChange, gly
|
|
|
112
118
|
api.setParent(parent);
|
|
113
119
|
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
114
120
|
const positioner = api.getPositionerProps();
|
|
115
|
-
return (_jsxs(_Fragment, { children: [_jsxs("div", { ...parentApi.getTriggerItemProps(api), className:
|
|
121
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { ...parentApi.getTriggerItemProps(api), className: parts.item, children: [parts.glyph && _jsx("span", { className: parts.glyph, children: entry.glyph }), _jsx("span", { className: parts.label, children: entry.label }), _jsx("span", { "aria-hidden": "true", className: parts.caret, children: _jsx(IconExpand, {}) })] }), _jsx(Portal, { children: _jsx("div", { ...positioner, style: { ...positioner.style, ...hue.style }, className: `glim-select-positioner ${hue.className}`.trim(), children: _jsx("div", { ...api.getContentProps(), className: parts.content, children: entry.options.map((o) => (_jsx(Choice, { api: api, option: o, value: value, onChange: onChange, parts: parts }, o.value))) }) }) })] }));
|
|
116
122
|
}
|
|
117
|
-
function Choice({ api, option, value, onChange,
|
|
123
|
+
function Choice({ api, option, value, onChange, parts, }) {
|
|
118
124
|
const checked = option.value === value;
|
|
119
125
|
const item = {
|
|
120
126
|
type: "radio",
|
|
@@ -127,7 +133,7 @@ function Choice({ api, option, value, onChange, glyphs, }) {
|
|
|
127
133
|
onChange(option.value);
|
|
128
134
|
},
|
|
129
135
|
};
|
|
130
|
-
return (_jsxs("div", { ...api.getOptionItemProps(item), className:
|
|
136
|
+
return (_jsxs("div", { ...api.getOptionItemProps(item), className: parts.item, children: [parts.glyph && _jsx("span", { className: parts.glyph, children: option.glyph }), _jsx("span", { ...api.getItemTextProps(item), className: parts.label, children: option.label }), _jsx("span", { "aria-hidden": "true", "data-state": checked ? "checked" : "unchecked", className: parts.check, children: _jsx(IconCheck, {}) })] }));
|
|
131
137
|
}
|
|
132
138
|
function Face({ all, value, placeholder, width, glyphs, }) {
|
|
133
139
|
const { text, labels } = faceLabels(all, value, placeholder, width);
|
package/dist/Selector.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { type ReactNode } from "react";
|
|
|
2
2
|
import { type SelectMode, type SelectorActivation, type SelectorOrientation, type SelectorSize, type SelectorVariant } from "@glimstone/core";
|
|
3
3
|
export type { SelectMode, SelectorActivation, SelectorOrientation, SelectorSize, SelectorVariant } from "@glimstone/core";
|
|
4
4
|
export { selectorTabId } from "@glimstone/core";
|
|
5
|
-
export interface SelectorItem {
|
|
6
|
-
/** Stable id, handed back by onChange. */
|
|
7
|
-
id:
|
|
5
|
+
export interface SelectorItem<V extends string | number = string> {
|
|
6
|
+
/** Stable id, handed back by onChange as it stands here. */
|
|
7
|
+
id: V;
|
|
8
8
|
label: string;
|
|
9
9
|
/** Shown before the label; in a tab strip it is tinted with its tab's hue. */
|
|
10
10
|
glyph?: ReactNode;
|
|
@@ -20,17 +20,21 @@ export interface SelectorItem {
|
|
|
20
20
|
href?: string;
|
|
21
21
|
/** Tiles only: a page with nothing on it yet, dimmed rather than hidden. */
|
|
22
22
|
dim?: boolean;
|
|
23
|
+
/** Attributes for the item's own segment, such as a data hook. */
|
|
24
|
+
attrs?: Record<string, string>;
|
|
23
25
|
}
|
|
24
|
-
export interface SelectorProps<M extends SelectMode = "one"> {
|
|
25
|
-
items: SelectorItem[];
|
|
26
|
-
/** The accessible name of the strip, such as "Sort" or "Settings pages". */
|
|
27
|
-
label
|
|
26
|
+
export interface SelectorProps<M extends SelectMode = "one", V extends string | number = string> {
|
|
27
|
+
items: SelectorItem<V>[];
|
|
28
|
+
/** The accessible name of the strip, such as "Sort" or "Settings pages". Inside a FieldRow the row gives it. */
|
|
29
|
+
label?: string;
|
|
28
30
|
/** `one` picks a value, `many` toggles any number of them. Default `one`. */
|
|
29
31
|
select?: M;
|
|
30
32
|
/** The chosen id, or the chosen ids for `many`. */
|
|
31
|
-
value: M extends "many" ? readonly
|
|
33
|
+
value: M extends "many" ? readonly V[] : V | null;
|
|
32
34
|
/** Called with the new id, or the new list for `many`. */
|
|
33
|
-
onChange: (next: M extends "many" ?
|
|
35
|
+
onChange: (next: M extends "many" ? V[] : V) => void;
|
|
36
|
+
/** Called on every press and every arrow key that chooses, before the choice changes, also one on the segment already chosen. */
|
|
37
|
+
onPress?: (id: V) => void;
|
|
34
38
|
/** `vertical` is the column of tiles beside a settings area's pages. */
|
|
35
39
|
orientation?: SelectorOrientation;
|
|
36
40
|
size?: SelectorSize;
|
|
@@ -42,7 +46,7 @@ export interface SelectorProps<M extends SelectMode = "one"> {
|
|
|
42
46
|
* floor where the row has room; the page-level picker. */
|
|
43
47
|
equalWidth?: boolean;
|
|
44
48
|
/** Hug the segments instead of spanning the box, for a strip that shares a
|
|
45
|
-
* toolbar row. */
|
|
49
|
+
* toolbar row, as it does inside a FieldRow. */
|
|
46
50
|
inline?: boolean;
|
|
47
51
|
/** Keep every segment on one row, for page tabs: once the labels do not fit
|
|
48
52
|
* together every segment shows its glyph alone. */
|
|
@@ -64,4 +68,4 @@ export interface SelectorProps<M extends SelectMode = "one"> {
|
|
|
64
68
|
panelId?: string;
|
|
65
69
|
className?: string;
|
|
66
70
|
}
|
|
67
|
-
export declare function Selector<M extends SelectMode = "one">({ items, label, select, value, onChange, orientation, size, variant, activation, equalWidth, inline, fit, pairsOnPhone, buttonHeight, hue, hueOffset, disabled, panelId, className, }: SelectorProps<M>): import("react").JSX.Element;
|
|
71
|
+
export declare function Selector<M extends SelectMode = "one", V extends string | number = string>({ items, label, select, value, onChange, onPress, orientation, size, variant, activation, equalWidth, inline: ownInline, fit, pairsOnPhone, buttonHeight, hue, hueOffset, disabled, panelId, className, }: SelectorProps<M, V>): import("react").JSX.Element;
|