@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.
Files changed (81) hide show
  1. package/README.md +2 -2
  2. package/dist/AngleSlider.d.ts +1 -1
  3. package/dist/AngleSlider.js +17 -4
  4. package/dist/Avatar.js +1 -1
  5. package/dist/Badge.d.ts +3 -6
  6. package/dist/Badge.js +2 -2
  7. package/dist/Card.d.ts +4 -1
  8. package/dist/Card.js +2 -2
  9. package/dist/Chart.d.ts +30 -0
  10. package/dist/Chart.js +22 -0
  11. package/dist/Checkbox.js +1 -2
  12. package/dist/ColorPicker.d.ts +3 -1
  13. package/dist/ColorPicker.js +22 -5
  14. package/dist/Combobox.js +14 -4
  15. package/dist/ConfirmDialog.js +4 -2
  16. package/dist/ContextMenu.d.ts +3 -1
  17. package/dist/ContextMenu.js +3 -3
  18. package/dist/DatePicker.js +6 -1
  19. package/dist/FieldRow.d.ts +1 -1
  20. package/dist/FieldRow.js +8 -4
  21. package/dist/FileUpload.d.ts +3 -1
  22. package/dist/FileUpload.js +6 -3
  23. package/dist/FortressPermissions.js +3 -2
  24. package/dist/HoverCard.d.ts +13 -3
  25. package/dist/HoverCard.js +3 -3
  26. package/dist/IconTipButton.d.ts +4 -1
  27. package/dist/IconTipButton.js +3 -3
  28. package/dist/InfoBubble.js +1 -1
  29. package/dist/{AboutCard.d.ts → InfoTile.d.ts} +0 -44
  30. package/dist/{AboutCard.js → InfoTile.js} +1 -28
  31. package/dist/ListRow.d.ts +19 -4
  32. package/dist/ListRow.js +15 -2
  33. package/dist/ListTable.d.ts +6 -1
  34. package/dist/ListTable.js +18 -6
  35. package/dist/Meter.d.ts +5 -1
  36. package/dist/Meter.js +8 -3
  37. package/dist/MultiSelect.js +2 -1
  38. package/dist/NotifyCard.js +1 -1
  39. package/dist/NumberField.js +2 -2
  40. package/dist/PasswordField.js +10 -4
  41. package/dist/PinInput.js +3 -3
  42. package/dist/Rating.js +9 -3
  43. package/dist/Select.js +8 -4
  44. package/dist/Selector.d.ts +5 -4
  45. package/dist/Selector.js +21 -4
  46. package/dist/SettingsNav.d.ts +41 -0
  47. package/dist/SettingsNav.js +48 -0
  48. package/dist/SignInTile.js +16 -15
  49. package/dist/SkeletonRow.d.ts +5 -1
  50. package/dist/SkeletonRow.js +3 -3
  51. package/dist/Slider.js +1 -1
  52. package/dist/StatusSummary.d.ts +16 -0
  53. package/dist/StatusSummary.js +8 -0
  54. package/dist/SubCard.d.ts +6 -7
  55. package/dist/SubCard.js +4 -6
  56. package/dist/TextField.d.ts +1 -1
  57. package/dist/TextField.js +17 -6
  58. package/dist/TimePicker.d.ts +30 -0
  59. package/dist/TimePicker.js +146 -0
  60. package/dist/Timer.js +6 -1
  61. package/dist/Toast.d.ts +3 -1
  62. package/dist/Toast.js +9 -7
  63. package/dist/Toggle.js +1 -1
  64. package/dist/Tour.js +6 -3
  65. package/dist/Window.d.ts +3 -1
  66. package/dist/Window.js +2 -2
  67. package/dist/engines.d.ts +7 -1
  68. package/dist/engines.js +17 -2
  69. package/dist/fieldErrorLine.d.ts +4 -0
  70. package/dist/fieldErrorLine.js +18 -0
  71. package/dist/glyphs.d.ts +2 -0
  72. package/dist/glyphs.js +2 -0
  73. package/dist/index.d.ts +5 -2
  74. package/dist/index.js +5 -2
  75. package/dist/searchHit.d.ts +4 -0
  76. package/dist/searchHit.js +10 -0
  77. package/dist/useTipBubble.d.ts +11 -2
  78. package/dist/useTipBubble.js +14 -10
  79. package/package.json +3 -3
  80. package/dist/DropdownListbox.d.ts +0 -22
  81. package/dist/DropdownListbox.js +0 -190
package/README.md CHANGED
@@ -54,14 +54,14 @@ needs none of them.
54
54
  | `Combobox` | A field that filters a long list as somebody types |
55
55
  | `MultiSelect` | Several picks from a list, kept as tags in the field; a long list filters as somebody types |
56
56
  | `Slider` | A value on a range, with the value in words beside the label |
57
- | `DropdownListbox` | Deprecated, use `Select` |
58
57
  | `ConfirmDialog` + `useConfirm` | The confirm surface for a destructive action, and the hook that gives it a portal, Escape, the Tab trap and focus back to the control that asked |
59
58
  | `ToastViewport` | Transient feedback; the queue is the core's `toastEngine` |
60
59
  | `InfoBubble`, `IconTipButton` | The "(i)" explanation and the hover name on an icon-only control |
61
60
  | `InfoTile` | The Info tile with its Version, Help and About cards, each also on its own |
62
61
  | `ReadmeButton` | The button in the shape of the README's, with its segments |
63
62
  | `CryptoDonateDialog`, `CoffeeDialog`, `PaypalDialog` | The three windows to give |
64
- | `Selector` | The one horizontal selector: tabs, filter bars, segmented pickers, one value or many, and with `orientation="vertical"` the column of tiles beside a settings area's pages |
63
+ | `Selector` | The one horizontal selector: tabs, filter bars, segmented pickers, one value or many, and with `orientation="vertical"` a column of tiles |
64
+ | `SettingsNav` | The pages of a settings area as a light list in groups beside the page, and on a phone a list that leads to each page |
65
65
  | `NumberField` | A number with its two steppers inside the field and the wheel while it has focus |
66
66
  | `SidebarRow` | One row of the rail: glyph, words by the label mode, the current page and a count |
67
67
  | `EmptyState` | What a list, table or panel shows when it holds nothing |
@@ -3,7 +3,7 @@ export interface AngleSliderProps {
3
3
  value: number;
4
4
  onChange: (value: number) => void;
5
5
  step?: number;
6
- /** The angles that carry a tick on the dial. */
6
+ /** The angles that carry a tick on the dial. A tick on a quarter is longer. */
7
7
  marks?: number[];
8
8
  disabled?: boolean;
9
9
  }
@@ -1,10 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useId } from "react";
2
+ import { useId, useRef } from "react";
3
3
  import * as angleSlider from "@zag-js/angle-slider";
4
4
  import { normalizeProps, useMachine } from "@zag-js/react";
5
- import { pageDir } from "@glimstone/core";
5
+ import { ANGLE_MARKS, angleKeyTarget, pageDir } from "@glimstone/core";
6
6
  import { useFieldName } from "./fieldName.js";
7
- export function AngleSlider({ label, value, onChange, step = 1, marks = [0, 90, 180, 270], disabled = false }) {
7
+ export function AngleSlider({ label, value, onChange, step = 15, marks = ANGLE_MARKS, disabled = false }) {
8
8
  const name = useFieldName(label);
9
9
  const service = useMachine(angleSlider.machine, {
10
10
  id: useId(),
@@ -15,5 +15,18 @@ export function AngleSlider({ label, value, onChange, step = 1, marks = [0, 90,
15
15
  onValueChange: (d) => onChange(d.value),
16
16
  });
17
17
  const api = angleSlider.connect(service, normalizeProps);
18
- return (_jsxs("div", { "data-glim": "AngleSlider", ...api.getRootProps(), className: "glim-angle", children: [_jsx("label", { ...api.getLabelProps(), className: label === undefined ? "glim-sr-only" : "glim-field-label", children: name }), _jsxs("div", { className: "glim-angle-body", children: [_jsxs("div", { ...api.getControlProps(), className: "glim-angle-dial", children: [_jsx("div", { ...api.getMarkerGroupProps(), className: "glim-angle-marks", children: marks.map((mark) => (_jsx("span", { ...api.getMarkerProps({ value: mark }), className: "glim-angle-mark" }, mark))) }), _jsx("div", { ...api.getThumbProps(), "aria-valuetext": `${api.value}°`, className: "glim-angle-thumb" })] }), _jsx("div", { ...api.getValueTextProps(), className: "glim-angle-value glim-num", children: `${api.value}°` })] }), _jsx("input", { ...api.getHiddenInputProps() })] }));
18
+ // Zag sends End to 359 whatever the step, so Home and End are answered here.
19
+ const thumb = api.getThumbProps();
20
+ const onKeyDown = (e) => {
21
+ const to = angleKeyTarget(e.key, step);
22
+ if (to === undefined)
23
+ return thumb.onKeyDown?.(e);
24
+ e.preventDefault();
25
+ api.setValue(to);
26
+ };
27
+ // A turn past 0° would spring the long way round, so that step lands at once.
28
+ const last = useRef(api.value);
29
+ const across = Math.abs(api.value - last.current) > 180;
30
+ last.current = api.value;
31
+ return (_jsxs("div", { "data-glim": "AngleSlider", ...api.getRootProps(), className: "glim-angle", children: [_jsx("label", { ...api.getLabelProps(), className: label === undefined ? "glim-sr-only" : "glim-field-label", children: name }), _jsx("div", { className: "glim-angle-body", children: _jsxs("div", { ...api.getControlProps(), className: "glim-angle-dial", children: [_jsx("div", { ...api.getMarkerGroupProps(), className: "glim-angle-marks", children: marks.map((mark) => (_jsx("span", { ...api.getMarkerProps({ value: mark }), "data-quarter": mark % 90 === 0 ? "" : undefined, className: "glim-angle-mark" }, mark))) }), _jsx("div", { ...thumb, onKeyDown: onKeyDown, "aria-valuetext": `${api.value}°`, "data-across": across ? "" : undefined, className: "glim-angle-thumb", children: _jsx("span", { className: "glim-angle-hand" }) }), _jsx("div", { ...api.getValueTextProps(), className: "glim-angle-value glim-num", children: `${api.value}°` })] }) }), _jsx("input", { ...api.getHiddenInputProps() })] }));
19
32
  }
package/dist/Avatar.js CHANGED
@@ -6,6 +6,6 @@ import { avatarView, initials, pageDir } from "@glimstone/core";
6
6
  export function Avatar({ name, src, size = "md", hueIndex }) {
7
7
  const service = useMachine(avatar.machine, { id: useId(), dir: pageDir() });
8
8
  const api = avatar.connect(service, normalizeProps);
9
- const view = avatarView({ size, hueIndex });
9
+ const view = avatarView({ size, hueIndex, name });
10
10
  return (_jsxs("span", { "data-glim": "Avatar", ...api.getRootProps(), role: "img", "aria-label": name, className: view.className, style: view.style, children: [src && _jsx("img", { ...api.getImageProps(), src: src, alt: "", className: "glim-avatar-image" }), _jsx("span", { ...api.getFallbackProps(), "aria-hidden": "true", className: "glim-avatar-fallback", children: initials(name) })] }));
11
11
  }
package/dist/Badge.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { ReactNode } from "react";
2
- import { type BadgeForm, type BadgeShape, type BadgeSize, type BadgeTone, type NotchInset } from "@glimstone/core";
3
- export type { BadgeForm, BadgeShape, BadgeSize, BadgeTone, NotchInset } from "@glimstone/core";
2
+ import { type BadgeForm, type BadgeSize, type BadgeTone, type NotchInset } from "@glimstone/core";
3
+ export type { BadgeForm, BadgeSize, BadgeTone, NotchInset } from "@glimstone/core";
4
4
  export interface BadgeProps {
5
5
  children: ReactNode;
6
6
  /** Status colour. Defaults to the neutral chip. */
@@ -11,9 +11,6 @@ export interface BadgeProps {
11
11
  /** The corners: rounded, square, pill or circle. Without it they follow the
12
12
  * shape setting. */
13
13
  form?: BadgeForm;
14
- /** @deprecated Use `form`. Only "circle" has an effect: it makes the badge
15
- * icon-only. Removed in 5.0.0. */
16
- shape?: BadgeShape;
17
14
  /** Render as a <button> or a real <a href>, with the same box as a span. */
18
15
  as?: "span" | "button" | "a";
19
16
  onClick?: () => void;
@@ -49,4 +46,4 @@ export interface BadgeProps {
49
46
  * badge in normal flow is a `tone="heading"` badge at another size. */
50
47
  inFlow?: boolean;
51
48
  }
52
- export declare function Badge({ children, tone, size, form, shape, as, onClick, disabled, title, ariaLabel, href, target, rel, wrap, className, hueIndex, tip, insetStart, inFlow, }: BadgeProps): import("react").JSX.Element;
49
+ export declare function Badge({ children, tone, size, form, as, onClick, disabled, title, ariaLabel, href, target, rel, wrap, className, hueIndex, tip, insetStart, inFlow, }: BadgeProps): import("react").JSX.Element;
package/dist/Badge.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { badgeClassName, hueVars } from "@glimstone/core";
3
3
  import { IconTipButton } from "./IconTipButton.js";
4
- export function Badge({ children, tone = "neutral", size = "medium", form, shape, as = "span", onClick, disabled, title, ariaLabel, href, target, rel, wrap, className, hueIndex, tip, insetStart, inFlow, }) {
4
+ export function Badge({ children, tone = "neutral", size = "medium", form, as = "span", onClick, disabled, title, ariaLabel, href, target, rel, wrap, className, hueIndex, tip, insetStart, inFlow, }) {
5
5
  // No rainbow subscription: Badge holds no hooks so a test can call it as a
6
6
  // plain function, and hueVars points at the root's colours, so a palette
7
7
  // change reaches the badge without a render.
@@ -16,7 +16,7 @@ export function Badge({ children, tone = "neutral", size = "medium", form, shape
16
16
  const classes = [
17
17
  hueOn && "glim-hue",
18
18
  isNotchHue && "glim-notch-hue",
19
- badgeClassName({ tone, size, form, shape, wrap, iconOnly: tip !== undefined, inFlow, insetStart, action: as !== "span" }),
19
+ badgeClassName({ tone, size, form, wrap, iconOnly: tip !== undefined, inFlow, insetStart, action: as !== "span" }),
20
20
  className,
21
21
  ]
22
22
  .filter(Boolean)
package/dist/Card.d.ts CHANGED
@@ -12,7 +12,7 @@ import type { ReactNode } from "react";
12
12
  *
13
13
  * A card with neither `title` nor `hint` draws no heading.
14
14
  */
15
- export declare function Card({ title, drawn, hint, children, hueIndex, nested, ...data }: {
15
+ export declare function Card({ title, drawn, hint, action, children, hueIndex, nested, ...data }: {
16
16
  /** The section name. Omit it where a control inside already carries the same
17
17
  * name; the badge still renders to keep the card's hue notch. */
18
18
  title?: string;
@@ -21,6 +21,9 @@ export declare function Card({ title, drawn, hint, children, hueIndex, nested, .
21
21
  /** One line saying what this whole card does, drawn as an "(i)" beside the
22
22
  * title. */
23
23
  hint?: string;
24
+ /** One control for the whole card, such as an icon button or a status
25
+ * badge, at the end of the top edge level with the notch. */
26
+ action?: ReactNode;
24
27
  children: ReactNode;
25
28
  /** This card's position in the rainbow, counted across the cards visible on
26
29
  * the active tab. Omit it for a tab's only card. */
package/dist/Card.js CHANGED
@@ -15,6 +15,6 @@ import { InfoBubble } from "./InfoBubble.js";
15
15
  *
16
16
  * A card with neither `title` nor `hint` draws no heading.
17
17
  */
18
- export function Card({ title, drawn, hint, children, hueIndex, nested, ...data }) {
19
- return (_jsxs("div", { "data-glim": "Card", "data-glim-title": title, ...data, className: `glim-panel glim-notch-card${nested ? " glim-panel--nested" : ""}${hueIndex !== undefined ? " glim-hue" : ""}`, style: hueIndex !== undefined ? hueVars(hueIndex) : undefined, children: [(title || drawn || hint) && (_jsx("h2", { className: "glim-panel-heading", children: _jsxs(Badge, { tone: "heading", size: "heading", wrap: true, hueIndex: hueIndex, children: [drawn ?? title, hint && _jsx(InfoBubble, { tip: hint, onAccent: true })] }) })), children] }));
18
+ export function Card({ title, drawn, hint, action, children, hueIndex, nested, ...data }) {
19
+ return (_jsxs("div", { "data-glim": "Card", "data-glim-title": title, ...data, className: `glim-panel glim-notch-card${nested ? " glim-panel--nested" : ""}${hueIndex !== undefined ? " glim-hue" : ""}`, style: hueIndex !== undefined ? hueVars(hueIndex) : undefined, children: [(title || drawn || hint) && (_jsx("h2", { className: "glim-panel-heading", children: _jsxs(Badge, { tone: "heading", size: "heading", wrap: true, hueIndex: hueIndex, children: [drawn ?? title, hint && _jsx(InfoBubble, { tip: hint, onAccent: true })] }) })), action && _jsx("div", { className: "glim-panel-action", children: action }), children] }));
20
20
  }
@@ -0,0 +1,30 @@
1
+ import { type ChartKind, type ChartRow, type ChartSeries } from "@glimstone/core";
2
+ export type { ChartKind, ChartRow, ChartSeries } from "@glimstone/core";
3
+ export interface ChartProps {
4
+ data: readonly ChartRow[];
5
+ /** The field that names each point on the x axis, such as "day". */
6
+ x: string;
7
+ series: readonly ChartSeries[];
8
+ /** What the chart shows, for a screen reader. */
9
+ label: string;
10
+ kind?: ChartKind;
11
+ height?: number;
12
+ /** How a figure reads on the axis and in the tooltip. */
13
+ format?: (n: number) => string;
14
+ /** The legend under the plot, shown where there is more than one series. */
15
+ legend?: boolean;
16
+ }
17
+ export declare function Chart({ data, x, series, label, kind, height, format, legend }: ChartProps): import("react").JSX.Element;
18
+ export declare function ChartLegend({ series }: {
19
+ series: readonly ChartSeries[];
20
+ }): import("react").JSX.Element;
21
+ export interface SparklineProps {
22
+ values: readonly number[];
23
+ /** What the line shows, for a screen reader. */
24
+ label: string;
25
+ color?: string;
26
+ width?: number;
27
+ height?: number;
28
+ }
29
+ /** A small line of the last values, beside a figure, without axes or a tooltip. */
30
+ export declare function Sparkline({ values, label, color, width, height }: SparklineProps): import("react").JSX.Element;
package/dist/Chart.js ADDED
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useLayoutEffect, useRef, useState } from "react";
3
+ import { chartIndexAt, chartLayout, chartTooltip, chartTooltipPlace, seriesColor, sparkline, watchChartFrame, } from "@glimstone/core";
4
+ export function Chart({ data, x, series, label, kind = "bar", height = 200, format, legend = true }) {
5
+ const box = useRef(null);
6
+ const [frame, setFrame] = useState({ width: 0, radius: 4 });
7
+ useLayoutEffect(() => watchChartFrame(box.current, setFrame), []);
8
+ const [hover, setHover] = useState(null);
9
+ const layout = chartLayout({ data, x, series, kind, width: frame.width, height, radius: frame.radius, format });
10
+ const tip = hover === null ? null : { ...chartTooltip(data, x, series, hover, format), ...chartTooltipPlace(layout, hover) };
11
+ const move = (e) => setHover(chartIndexAt(layout, e.clientX - e.currentTarget.getBoundingClientRect().left));
12
+ return (_jsxs("div", { "data-glim": "Chart", className: "glim-chart", children: [_jsxs("div", { ref: box, className: "glim-chart-plot", style: { height }, children: [frame.width > 0 && (_jsxs("svg", { width: frame.width, height: height, role: "img", "aria-label": label, onPointerMove: move, onPointerLeave: () => setHover(null), children: [layout.ticks.map((t) => (_jsxs("g", { children: [_jsx("line", { x1: layout.plot.left, x2: layout.plot.left + layout.plot.width, y1: t.y, y2: t.y, className: "glim-chart-grid" }), _jsx("text", { x: layout.plot.left - 8, y: t.y, dy: "0.32em", textAnchor: "end", className: "glim-chart-tick", children: t.text })] }, t.value))), hover !== null &&
13
+ (kind === "bar" ? (_jsx("rect", { x: layout.plot.left + layout.band * hover, y: layout.plot.top, width: layout.band, height: layout.plot.height, className: "glim-chart-cursor" })) : (_jsx("line", { x1: layout.centres[hover], x2: layout.centres[hover], y1: layout.plot.top, y2: layout.plot.top + layout.plot.height, className: "glim-chart-cursor-line" }))), layout.bars.map((b) => (_jsx("path", { className: "glim-chart-bar", d: b.d, fill: b.color }, b.key))), layout.lines.map((l) => (_jsxs("g", { children: [kind === "area" && _jsx("path", { d: l.area, fill: l.color, className: "glim-chart-area" }), _jsx("polyline", { points: l.points, fill: "none", stroke: l.color, strokeWidth: 2, strokeLinejoin: "round", strokeLinecap: "round" }), hover !== null && _jsx("circle", { cx: l.dots[hover].x, cy: l.dots[hover].y, r: 4, fill: l.color, className: "glim-chart-dot" })] }, l.key))), layout.labels.map((l, i) => (_jsx("text", { x: l.x, y: height - 6, textAnchor: "middle", className: "glim-chart-tick", children: l.text }, i)))] })), tip && (_jsxs("div", { className: "glim-chart-tooltip", "aria-hidden": "true", style: { left: tip.left, top: tip.top, translate: tip.flip ? "calc(-100% - 12px) 0" : "12px 0" }, children: [_jsx("div", { className: "glim-chart-tooltip-title", children: tip.title }), tip.rows.map((r) => (_jsxs("div", { className: "glim-chart-tooltip-row", children: [_jsx("span", { className: "glim-chart-swatch", style: { background: r.color } }), _jsx("span", { children: r.label }), _jsx("span", { className: "glim-chart-tooltip-value glim-num", children: r.value })] }, r.label)))] }))] }), legend && series.length > 1 && _jsx(ChartLegend, { series: series })] }));
14
+ }
15
+ export function ChartLegend({ series }) {
16
+ return (_jsx("ul", { "data-glim": "ChartLegend", className: "glim-chart-legend", children: series.map((s, i) => (_jsxs("li", { children: [_jsx("span", { className: "glim-chart-swatch", style: { background: seriesColor(s, i) } }), s.label] }, s.key))) }));
17
+ }
18
+ /** A small line of the last values, beside a figure, without axes or a tooltip. */
19
+ export function Sparkline({ values, label, color = "var(--chart-1)", width = 96, height = 28 }) {
20
+ const line = sparkline(values, width, height);
21
+ return (_jsxs("svg", { "data-glim": "Sparkline", className: "glim-sparkline", width: width, height: height, role: "img", "aria-label": label, children: [_jsx("path", { d: line.area, fill: color, className: "glim-chart-area" }), _jsx("polyline", { points: line.points, fill: "none", stroke: color, strokeWidth: 1.5, strokeLinejoin: "round", strokeLinecap: "round" }), _jsx("circle", { cx: line.last[0], cy: line.last[1], r: 2.5, fill: color })] }));
22
+ }
package/dist/Checkbox.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { IconCheck } from "./glyphs.js";
3
2
  export function Checkbox({ checked, onChange, label, hideLabel = false, slim = false, disabled, className }) {
4
3
  const bare = hideLabel || slim;
5
4
  const classes = ["glim-checkbox", slim && "glim-checkbox--slim", className].filter(Boolean).join(" ");
6
- return (_jsxs("button", { "data-glim": "Checkbox", type: "button", role: "checkbox", "aria-checked": checked, "aria-label": bare ? label : undefined, disabled: disabled, onClick: () => onChange(!checked), onKeyDown: (e) => e.key === "Enter" && e.preventDefault(), className: classes, children: [_jsx("span", { className: "glim-checkbox-box", "aria-hidden": "true", children: _jsx(IconCheck, {}) }), !bare && _jsx("span", { children: label })] }));
5
+ return (_jsxs("button", { "data-glim": "Checkbox", type: "button", role: "checkbox", "aria-checked": checked, "aria-label": bare ? label : undefined, disabled: disabled, onClick: () => onChange(!checked), onKeyDown: (e) => e.key === "Enter" && e.preventDefault(), className: classes, children: [_jsx("span", { className: "glim-checkbox-box", "aria-hidden": "true", children: _jsx("svg", { viewBox: "0 0 14 14", width: "14", height: "14", fill: "none", className: "glim-mark", children: _jsx("path", { d: "M3 7.4 5.7 10 11 4.2", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", pathLength: 1, strokeDasharray: 1, strokeDashoffset: checked ? 0 : 1, className: "glim-checkbox-tick" }) }) }), !bare && _jsx("span", { children: label })] }));
7
6
  }
@@ -14,8 +14,10 @@ export interface ColorPickerProps {
14
14
  onClose?: () => void;
15
15
  /** The names a colour is matched against, nearest in OKLab. `false` shows none. */
16
16
  names?: readonly ColorName[] | false;
17
+ /** The ready colours under the hue bar, as `#rrggbb`. The page's rainbow unless given, and `false` shows none. */
18
+ swatches?: string[] | false;
17
19
  /** The words, read when the picker opens. */
18
20
  text?: Partial<ColorPickerPanelText>;
19
21
  className?: string;
20
22
  }
21
- export declare function ColorPicker({ value, onApply, onInput, anchor, onClose, names, text, className }: ColorPickerProps): import("react").JSX.Element;
23
+ export declare function ColorPicker({ value, onApply, onInput, anchor, onClose, names, swatches, text, className }: ColorPickerProps): import("react").JSX.Element;
@@ -1,16 +1,19 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useLayoutEffect, useRef, useState } from "react";
3
3
  import { createPortal } from "react-dom";
4
- import { COLOR_NAMES_DE, COLOR_PICKER_TEXT, colorPicker, floatColorPicker, nearestColorName, normalizeHex, portalTarget, } from "@glimstone/core";
4
+ import { canPickFromScreen, COLOR_NAMES_DE, COLOR_PICKER_TEXT, colorPicker, floatColorPicker, MARKS, nearestColorName, normalizeHex, pickFromScreen, rainbowSwatches, portalTarget, } from "@glimstone/core";
5
5
  import { Button } from "./Button.js";
6
- import { IconCheck } from "./glyphs.js";
7
- export function ColorPicker({ value, onApply, onInput, anchor, onClose, names = COLOR_NAMES_DE, text, className }) {
6
+ import { IconButton } from "./IconButton.js";
7
+ import { IconCheck, MarkSvg } from "./glyphs.js";
8
+ export function ColorPicker({ value, onApply, onInput, anchor, onClose, names = COLOR_NAMES_DE, swatches, text, className }) {
8
9
  const words = { ...COLOR_PICKER_TEXT, ...text };
9
10
  const panel = useRef(null);
10
11
  const host = useRef(null);
11
12
  const widget = useRef(null);
12
13
  const [draft, setDraft] = useState(() => normalizeHex(value) ?? "#000000");
13
14
  const [typed, setTyped] = useState(draft);
15
+ const [ready, setReady] = useState([]);
16
+ const [dropper] = useState(canPickFromScreen);
14
17
  const latest = useRef({ onInput, onClose });
15
18
  useLayoutEffect(() => {
16
19
  latest.current = { onInput, onClose };
@@ -55,7 +58,17 @@ export function ColorPicker({ value, onApply, onInput, anchor, onClose, names =
55
58
  apply();
56
59
  }
57
60
  }
58
- const body = (_jsxs("div", { "data-glim": "ColorPicker", ref: panel, className: ["glim-picker-panel", anchor && "glim-picker-panel--float", className].filter(Boolean).join(" "), style: { "--glim-picker-colour": draft }, onKeyDown: onKeyDown, children: [_jsx("div", { ref: host, style: { display: "contents" } }), _jsxs("div", { className: "glim-picker-foot", children: [_jsx("span", { className: "glim-picker-swatch", "aria-hidden": "true" }), name !== null && _jsx("span", { className: "glim-picker-name", children: name }), _jsx("input", { className: "glim-picker-hex", value: typed, maxLength: 7, spellCheck: false, "aria-label": words.hex, onChange: (e) => {
61
+ useLayoutEffect(() => {
62
+ setReady(swatches === false ? [] : (swatches ?? rainbowSwatches()).flatMap((c) => normalizeHex(c) ?? []));
63
+ }, [swatches]);
64
+ /** A colour from a ready swatch or from the screen, taken as a drag on the square would be. */
65
+ function take(hex) {
66
+ setDraft(hex);
67
+ setTyped(hex);
68
+ widget.current?.setValue(hex);
69
+ onInput?.(hex);
70
+ }
71
+ const body = (_jsxs("div", { "data-glim": "ColorPicker", ref: panel, className: ["glim-picker-panel", anchor && "glim-picker-panel--float", className].filter(Boolean).join(" "), style: { "--glim-picker-colour": draft }, onKeyDown: onKeyDown, children: [_jsx("div", { ref: host, style: { display: "contents" } }), ready.length > 0 && (_jsx("div", { role: "group", "aria-label": words.swatches, className: "glim-picker-swatches", children: ready.map((hex) => (_jsx("button", { type: "button", "aria-label": hex, "aria-pressed": hex === draft, className: "glim-picker-preset", style: { "--glim-preset": hex }, onClick: () => take(hex) }, hex))) })), _jsxs("div", { className: "glim-picker-foot", children: [_jsx("span", { className: "glim-picker-swatch", "aria-hidden": "true" }), name !== null && _jsx("span", { className: "glim-picker-name", children: name }), _jsx("input", { className: "glim-picker-hex", value: typed, maxLength: 7, spellCheck: false, "aria-label": words.hex, onChange: (e) => {
59
72
  setTyped(e.target.value);
60
73
  const hex = normalizeHex(e.target.value);
61
74
  if (!hex)
@@ -63,6 +76,10 @@ export function ColorPicker({ value, onApply, onInput, anchor, onClose, names =
63
76
  setDraft(hex);
64
77
  widget.current?.setValue(hex);
65
78
  onInput?.(hex);
66
- } })] }), _jsx("div", { className: "glim-picker-actions", children: _jsx(Button, { label: words.apply, labelKey: "apply", glyph: _jsx(IconCheck, {}), tone: "accent", onClick: apply }) })] }));
79
+ } }), dropper && (_jsx(IconButton, { tip: words.eyedropper, glyph: _jsx(MarkSvg, { mark: MARKS.eyedropper, className: "glim-mark" }), onClick: async () => {
80
+ const hex = await pickFromScreen();
81
+ if (hex)
82
+ take(hex);
83
+ } }))] }), _jsx("div", { className: "glim-picker-actions", children: _jsx(Button, { label: words.apply, labelKey: "apply", glyph: _jsx(IconCheck, {}), tone: "accent", onClick: apply }) })] }));
67
84
  return anchor ? createPortal(body, portalTarget()) : body;
68
85
  }
package/dist/Combobox.js CHANGED
@@ -5,9 +5,11 @@ import * as combobox from "@zag-js/combobox";
5
5
  import { useFieldName } from "./fieldName.js";
6
6
  import { normalizeProps, Portal, useMachine } from "@zag-js/react";
7
7
  import { IconCheck, IconExpand } from "./glyphs.js";
8
+ import { SearchHit } from "./searchHit.js";
8
9
  export function Combobox({ label, hideLabel, options, value, onChange, placeholder, empty, toggleLabel, disabled }) {
9
10
  const name = useFieldName(label);
10
11
  const [shown, setShown] = useState(options);
12
+ const [query, setQuery] = useState("");
11
13
  const collection = combobox.collection({
12
14
  items: shown,
13
15
  itemToValue: (o) => o.value,
@@ -23,13 +25,21 @@ export function Combobox({ label, hideLabel, options, value, onChange, placehold
23
25
  positioning: { sameWidth: true, gutter: 6 },
24
26
  // Typing opens the list after the filter has run, so only a close may put
25
27
  // the full list back.
26
- onOpenChange: ({ open }) => !open && setShown(options),
27
- onInputValueChange: ({ inputValue }) => {
28
- const q = inputValue.toLocaleLowerCase();
28
+ onOpenChange: ({ open }) => {
29
+ if (open)
30
+ return;
31
+ setShown(options);
32
+ setQuery("");
33
+ },
34
+ onInputValueChange: ({ inputValue, reason }) => {
35
+ // Picking an item writes its label into the field, which is no search.
36
+ const typed = reason === "input-change" ? inputValue : "";
37
+ const q = typed.toLocaleLowerCase();
38
+ setQuery(typed);
29
39
  setShown(options.filter((o) => o.label.toLocaleLowerCase().includes(q)));
30
40
  },
31
41
  onValueChange: (d) => onChange(d.value[0] ?? ""),
32
42
  });
33
43
  const api = combobox.connect(service, normalizeProps);
34
- return (_jsxs("div", { "data-glim": "Combobox", ...api.getRootProps(), className: "glim-combobox", children: [_jsx("label", { ...api.getLabelProps(), className: hideLabel || label === undefined ? "glim-sr-only" : "glim-field-label", children: name }), _jsxs("div", { ...api.getControlProps(), className: "glim-combobox-control", children: [_jsx("input", { ...api.getInputProps(), className: "glim-combobox-input" }), _jsx("button", { ...api.getTriggerProps(), "aria-label": toggleLabel, className: "glim-combobox-toggle", children: _jsx("span", { className: "glim-select-indicator", "data-state": api.open ? "open" : "closed", children: _jsx(IconExpand, {}) }) })] }), _jsx(Portal, { container: { current: portalTarget() }, children: _jsx("div", { ...api.getPositionerProps(), className: "glim-select-positioner", children: _jsxs("ul", { ...api.getContentProps(), className: "glim-select-content", children: [shown.length === 0 && _jsx("li", { className: "glim-select-empty", children: empty }), shown.map((item) => (_jsxs("li", { ...api.getItemProps({ item }), className: "glim-select-item", children: [_jsx("span", { ...api.getItemTextProps({ item }), children: item.label }), _jsx("span", { ...api.getItemIndicatorProps({ item }), className: "glim-select-check", children: _jsx(IconCheck, {}) })] }, item.value)))] }) }) })] }));
44
+ return (_jsxs("div", { "data-glim": "Combobox", ...api.getRootProps(), className: "glim-combobox", children: [_jsx("label", { ...api.getLabelProps(), className: hideLabel || label === undefined ? "glim-sr-only" : "glim-field-label", children: name }), _jsxs("div", { ...api.getControlProps(), className: "glim-combobox-control", children: [_jsx("input", { ...api.getInputProps(), className: "glim-combobox-input" }), _jsx("button", { ...api.getTriggerProps(), "aria-label": toggleLabel, className: "glim-combobox-toggle", children: _jsx("span", { className: "glim-select-indicator", "data-state": api.open ? "open" : "closed", children: _jsx(IconExpand, {}) }) })] }), _jsx(Portal, { container: { current: portalTarget() }, children: _jsx("div", { ...api.getPositionerProps(), className: "glim-select-positioner", children: _jsxs("ul", { ...api.getContentProps(), className: "glim-select-content", children: [shown.length === 0 && _jsx("li", { className: "glim-select-empty", children: empty }), shown.map((item) => (_jsxs("li", { ...api.getItemProps({ item }), className: "glim-select-item", children: [_jsx("span", { ...api.getItemTextProps({ item }), "data-search": query ? "" : undefined, children: _jsx(SearchHit, { label: item.label, query: query }) }), _jsx("span", { ...api.getItemIndicatorProps({ item }), className: "glim-select-check", children: _jsx(IconCheck, {}) })] }, item.value)))] }) }) })] }));
35
45
  }
@@ -1,12 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { leaveBehind, splitQuestion } from "@glimstone/core";
2
3
  import { Badge } from "./Badge.js";
3
4
  import { Button } from "./Button.js";
4
5
  import { IconCancel, IconClose } from "./glyphs.js";
5
6
  export function ConfirmDialog({ title, message, confirmLabel, confirmLabelKey, confirmGlyph, extra, cancelLabel, closeLabel, onConfirm, onCancel, ref, }) {
6
- return (_jsx("div", { className: "glim-modal-backdrop", onClick: (e) => {
7
+ const { question, detail } = splitQuestion(message);
8
+ return (_jsx("div", { ref: leaveBehind, className: "glim-modal-backdrop", onClick: (e) => {
7
9
  if (e.target === e.currentTarget)
8
10
  onCancel();
9
- }, children: _jsxs("div", { "data-glim": "ConfirmDialog", "data-glim-title": title, ref: ref, role: "dialog", "aria-modal": "true", "aria-labelledby": "confirmdialog-title", "aria-describedby": "confirmdialog-message", className: "glim-modal-card", children: [_jsxs("div", { className: "glim-modal-head", children: [_jsx("h2", { id: "confirmdialog-title", className: "glim-modal-title", children: _jsx(Badge, { tone: "heading", size: "heading", wrap: true, children: title }) }), closeLabel !== undefined && (_jsx(Button, { label: closeLabel, labelKey: "common.close", glyph: _jsx(IconClose, {}), tone: "neutral", onClick: onCancel, className: "glim-modal-close" }))] }), _jsxs("div", { className: "glim-modal-body", children: [_jsx("p", { id: "confirmdialog-message", className: "glim-modal-text", children: message }), extra !== undefined && _jsx("div", { className: "glim-modal-extra", children: extra })] }), _jsxs("div", { className: "glim-modal-foot", children: [_jsx(Button, { label: cancelLabel, labelKey: "common.cancel", glyph: _jsx(IconCancel, {}), tone: "neutral", autoFocus: true, onClick: onCancel }), _jsx(Button, { label: confirmLabel,
11
+ }, children: _jsxs("div", { "data-glim": "ConfirmDialog", "data-glim-title": title, ref: ref, role: "dialog", "aria-modal": "true", "aria-labelledby": "confirmdialog-title", "aria-describedby": "confirmdialog-message", className: "glim-modal-card glim-window--small", children: [_jsxs("div", { className: "glim-modal-head", children: [_jsx("h2", { id: "confirmdialog-title", className: "glim-modal-title", children: _jsx(Badge, { tone: "heading", size: "heading", wrap: true, children: title }) }), closeLabel !== undefined && (_jsx(Button, { label: closeLabel, labelKey: "common.close", glyph: _jsx(IconClose, {}), tone: "neutral", onClick: onCancel, className: "glim-modal-close" }))] }), _jsxs("div", { className: "glim-modal-body", children: [_jsxs("div", { id: "confirmdialog-message", children: [_jsx("p", { className: "glim-modal-question", children: question }), detail && _jsx("p", { className: "glim-modal-text", children: detail })] }), extra !== undefined && _jsx("div", { className: "glim-modal-extra", children: extra })] }), _jsxs("div", { className: "glim-modal-foot", children: [_jsx(Button, { label: cancelLabel, labelKey: "common.cancel", glyph: _jsx(IconCancel, {}), tone: "neutral", autoFocus: true, onClick: onCancel }), _jsx(Button, { label: confirmLabel,
10
12
  // `null` means no key: the action being confirmed has no fixed one.
11
13
  labelKey: confirmLabelKey ?? null, glyph: confirmGlyph,
12
14
  // Not red ("Destructive and confirmable actions"): the dialog's
@@ -10,6 +10,8 @@ export interface ContextMenuProps {
10
10
  items: MenuEntry[];
11
11
  /** Stand the menu on the point instead, for a menu opened from a bar at the bottom. */
12
12
  above?: boolean;
13
+ /** Line the menu's end edge up with the point, for a menu opened from a button at a row's end (`menuPointUnder()`). */
14
+ end?: boolean;
13
15
  /** The menu's accessible name. */
14
16
  label?: string;
15
17
  /** The menu element's id, for a caller or a script that looks for it. */
@@ -24,4 +26,4 @@ export interface ContextMenuProps {
24
26
  /** Opens with the focus on the last row, as ArrowUp on a menu bar's word asks. */
25
27
  fromEnd?: boolean;
26
28
  }
27
- export declare function ContextMenu({ x, y, items, above, label, id, opener, onClose, onStep, fromEnd }: ContextMenuProps): import("react").JSX.Element;
29
+ export declare function ContextMenu({ x, y, items, above, end, label, id, opener, onClose, onStep, fromEnd }: ContextMenuProps): import("react").JSX.Element;
@@ -28,7 +28,7 @@ function Rows({ entries, openAt, onPick, }) {
28
28
  return (_jsxs("button", { type: "button", role: view.role, tabIndex: -1, "aria-checked": view.role === "menuitem" ? undefined : entry.checked, "aria-haspopup": entry.sub ? "menu" : undefined, "aria-expanded": entry.sub ? openAt === i : undefined, disabled: entry.disabled, className: view.current ? "glim-menu-item glim-menu-item--current" : "glim-menu-item", "data-row": i, onClick: () => onPick(i), children: [view.lead === "box" ? (_jsx("span", { className: "glim-checkbox-box", "aria-hidden": "true", children: _jsx(IconCheck, {}) })) : view.lead === "dot" ? (_jsx("span", { className: "glim-menu-dot", style: { backgroundColor: entry.color }, "aria-hidden": "true" })) : (_jsx("span", { className: "glim-menu-glyph", "aria-hidden": "true", children: view.lead === "glyph" && entry.glyph })), _jsx("span", { className: "glim-menu-label", children: entry.label }), view.end === "submenu" && (_jsx("span", { className: "glim-menu-end glim-menu-caret", "aria-hidden": "true", children: _jsx(IconExpand, {}) })), view.end === "tick" && (_jsx("span", { className: "glim-menu-end glim-menu-tick", "aria-hidden": "true", children: _jsx(IconCheck, {}) })), view.end === "shortcut" && _jsx(Kbd, { className: "glim-menu-end", children: entry.shortcut }), view.end === "count" && _jsx("span", { className: "glim-menu-end glim-menu-count glim-num", children: entry.count })] }, i));
29
29
  });
30
30
  }
31
- export function ContextMenu({ x, y, items, above = false, label, id, opener, onClose, onStep, fromEnd = false }) {
31
+ export function ContextMenu({ x, y, items, above = false, end = false, label, id, opener, onClose, onStep, fromEnd = false }) {
32
32
  const menu = useRef(null);
33
33
  const subMenu = useRef(null);
34
34
  const [asker] = useState(focusedAsker);
@@ -52,8 +52,8 @@ export function ContextMenu({ x, y, items, above = false, label, id, opener, onC
52
52
  };
53
53
  useLayoutEffect(() => {
54
54
  const el = menu.current;
55
- setPos(placeMenu(x, y, { width: el.offsetWidth, height: el.offsetHeight }, viewport(), above));
56
- }, [x, y, above]);
55
+ setPos(placeMenu(x, y, { width: el.offsetWidth, height: el.offsetHeight }, viewport(), above, end, getComputedStyle(el).direction === "rtl"));
56
+ }, [x, y, above, end]);
57
57
  useLayoutEffect(() => {
58
58
  const release = claimMenu(finish);
59
59
  const outside = closeMenuOutside(() => [menu.current, subMenu.current, latest.current.opener], () => finish(false));
@@ -34,6 +34,11 @@ export function DatePicker({ label, value, onChange, min, max, locale, disabled
34
34
  const hue = usePortalHue(api.open, triggerRef);
35
35
  const positioner = api.getPositionerProps();
36
36
  const months = api.getMonthsGrid({ columns: 4, format: "short" });
37
+ // Which way the month turned, so the new one slides in from that side.
38
+ const month = api.visibleRange.start.toString();
39
+ const seen = useRef({ month });
40
+ if (seen.current.month !== month)
41
+ seen.current = { month, turn: month > seen.current.month ? "next" : "prev" };
37
42
  const years = api.getYearsGrid({ columns: 4 });
38
- return (_jsxs("div", { "data-glim": "DatePicker", ...api.getRootProps(), className: "glim-date", children: [_jsx("label", { ...api.getLabelProps(), className: label === undefined ? "glim-sr-only" : "glim-field-label", children: name }), _jsx("div", { ...api.getControlProps(), className: "glim-date-control", children: _jsxs("button", { ...api.getTriggerProps(), ref: triggerRef, className: "glim-input glim-date-trigger", children: [_jsx("span", { className: value ? "glim-date-value" : "glim-date-value glim-date-value--empty", children: shown }), _jsx(IconCalendar, {})] }) }), _jsx(Portal, { container: { current: portalTarget() }, children: _jsx("div", { ...positioner, style: { ...positioner.style, ...hue.style }, className: `glim-date-positioner ${hue.className}`.trim(), children: _jsxs("div", { ...api.getContentProps(), className: "glim-date-panel", children: [_jsxs("div", { ...api.getViewProps({ view: "day" }), hidden: api.view !== "day", children: [_jsxs("div", { ...api.getViewControlProps({ view: "day" }), className: "glim-date-head", children: [_jsx("button", { ...api.getPrevTriggerProps({ view: "day" }), className: "glim-date-step", children: _jsx(IconBack, {}) }), _jsx("button", { ...api.getViewTriggerProps({ view: "day" }), className: "glim-date-title", children: api.visibleRangeText.start }), _jsx("button", { ...api.getNextTriggerProps({ view: "day" }), className: "glim-date-step", children: _jsx(IconForward, {}) })] }), _jsxs("table", { ...api.getTableProps({ view: "day" }), className: "glim-date-grid", children: [_jsx("thead", { ...api.getTableHeadProps({ view: "day" }), children: _jsx("tr", { ...api.getTableRowProps({ view: "day" }), children: api.weekDays.map((day, i) => (_jsx("th", { scope: "col", "aria-label": day.long, className: "glim-date-weekday", children: day.narrow }, i))) }) }), _jsx("tbody", { ...api.getTableBodyProps({ view: "day" }), children: api.weeks.map((week, i) => (_jsx("tr", { ...api.getTableRowProps({ view: "day" }), children: week.map((day, j) => (_jsx("td", { ...api.getDayTableCellProps({ value: day }), children: _jsx("div", { ...api.getDayTableCellTriggerProps({ value: day }), className: "glim-date-cell glim-num", children: day.day }) }, j))) }, i))) })] })] }), _jsxs("div", { ...api.getViewProps({ view: "month" }), hidden: api.view !== "month", children: [_jsxs("div", { ...api.getViewControlProps({ view: "month" }), className: "glim-date-head", children: [_jsx("button", { ...api.getPrevTriggerProps({ view: "month" }), className: "glim-date-step", children: _jsx(IconBack, {}) }), _jsx("button", { ...api.getViewTriggerProps({ view: "month" }), className: "glim-date-title", children: api.visibleRange.start.year }), _jsx("button", { ...api.getNextTriggerProps({ view: "month" }), className: "glim-date-step", children: _jsx(IconForward, {}) })] }), _jsx("table", { ...api.getTableProps({ view: "month", columns: 4 }), className: "glim-date-grid", children: _jsx("tbody", { ...api.getTableBodyProps({ view: "month" }), children: months.map((row, i) => (_jsx("tr", { ...api.getTableRowProps(), children: row.map((month, j) => (_jsx("td", { ...api.getMonthTableCellProps({ ...month, columns: 4 }), children: _jsx("div", { ...api.getMonthTableCellTriggerProps({ ...month, columns: 4 }), className: "glim-date-cell glim-date-cell--wide", children: month.label }) }, j))) }, i))) }) })] }), _jsxs("div", { ...api.getViewProps({ view: "year" }), hidden: api.view !== "year", children: [_jsxs("div", { ...api.getViewControlProps({ view: "year" }), className: "glim-date-head", children: [_jsx("button", { ...api.getPrevTriggerProps({ view: "year" }), className: "glim-date-step", children: _jsx(IconBack, {}) }), _jsx("span", { className: "glim-date-title glim-num", children: `${api.getDecade().start} - ${api.getDecade().end}` }), _jsx("button", { ...api.getNextTriggerProps({ view: "year" }), className: "glim-date-step", children: _jsx(IconForward, {}) })] }), _jsx("table", { ...api.getTableProps({ view: "year", columns: 4 }), className: "glim-date-grid", children: _jsx("tbody", { ...api.getTableBodyProps({ view: "year" }), children: years.map((row, i) => (_jsx("tr", { ...api.getTableRowProps({ view: "year" }), children: row.map((year, j) => (_jsx("td", { ...api.getYearTableCellProps({ ...year, columns: 4 }), children: _jsx("div", { ...api.getYearTableCellTriggerProps({ ...year, columns: 4 }), className: "glim-date-cell glim-date-cell--wide glim-num", children: year.label }) }, j))) }, i))) }) })] })] }) }) })] }));
43
+ return (_jsxs("div", { "data-glim": "DatePicker", ...api.getRootProps(), className: "glim-date", children: [_jsx("label", { ...api.getLabelProps(), className: label === undefined ? "glim-sr-only" : "glim-field-label", children: name }), _jsx("div", { ...api.getControlProps(), className: "glim-date-control", children: _jsxs("button", { ...api.getTriggerProps(), ref: triggerRef, className: "glim-input glim-date-trigger", children: [_jsx("span", { className: value ? "glim-date-value" : "glim-date-value glim-date-value--empty", children: shown }), _jsx(IconCalendar, {})] }) }), _jsx(Portal, { container: { current: portalTarget() }, children: _jsx("div", { ...positioner, style: { ...positioner.style, ...hue.style }, className: `glim-date-positioner ${hue.className}`.trim(), children: _jsxs("div", { ...api.getContentProps(), className: "glim-date-panel", children: [_jsxs("div", { ...api.getViewProps({ view: "day" }), hidden: api.view !== "day", children: [_jsxs("div", { ...api.getViewControlProps({ view: "day" }), className: "glim-date-head", children: [_jsx("button", { ...api.getPrevTriggerProps({ view: "day" }), className: "glim-date-step", children: _jsx(IconBack, {}) }), _jsx("button", { ...api.getViewTriggerProps({ view: "day" }), className: "glim-date-title", children: api.visibleRangeText.start }), _jsx("button", { ...api.getNextTriggerProps({ view: "day" }), className: "glim-date-step", children: _jsx(IconForward, {}) })] }), _jsxs("table", { ...api.getTableProps({ view: "day" }), className: "glim-date-grid", children: [_jsx("thead", { ...api.getTableHeadProps({ view: "day" }), children: _jsx("tr", { ...api.getTableRowProps({ view: "day" }), children: api.weekDays.map((day, i) => (_jsx("th", { scope: "col", "aria-label": day.long, className: "glim-date-weekday", children: day.narrow }, i))) }) }), _jsx("tbody", { ...api.getTableBodyProps({ view: "day" }), "data-turn": seen.current.turn, children: api.weeks.map((week, i) => (_jsx("tr", { ...api.getTableRowProps({ view: "day" }), children: week.map((day, j) => (_jsx("td", { ...api.getDayTableCellProps({ value: day }), children: _jsx("div", { ...api.getDayTableCellTriggerProps({ value: day }), className: "glim-date-cell glim-num", children: day.day }) }, j))) }, i))) }, month)] })] }), _jsxs("div", { ...api.getViewProps({ view: "month" }), hidden: api.view !== "month", children: [_jsxs("div", { ...api.getViewControlProps({ view: "month" }), className: "glim-date-head", children: [_jsx("button", { ...api.getPrevTriggerProps({ view: "month" }), className: "glim-date-step", children: _jsx(IconBack, {}) }), _jsx("button", { ...api.getViewTriggerProps({ view: "month" }), className: "glim-date-title", children: api.visibleRange.start.year }), _jsx("button", { ...api.getNextTriggerProps({ view: "month" }), className: "glim-date-step", children: _jsx(IconForward, {}) })] }), _jsx("table", { ...api.getTableProps({ view: "month", columns: 4 }), className: "glim-date-grid", children: _jsx("tbody", { ...api.getTableBodyProps({ view: "month" }), children: months.map((row, i) => (_jsx("tr", { ...api.getTableRowProps(), children: row.map((month, j) => (_jsx("td", { ...api.getMonthTableCellProps({ ...month, columns: 4 }), children: _jsx("div", { ...api.getMonthTableCellTriggerProps({ ...month, columns: 4 }), className: "glim-date-cell glim-date-cell--wide", children: month.label }) }, j))) }, i))) }) })] }), _jsxs("div", { ...api.getViewProps({ view: "year" }), hidden: api.view !== "year", children: [_jsxs("div", { ...api.getViewControlProps({ view: "year" }), className: "glim-date-head", children: [_jsx("button", { ...api.getPrevTriggerProps({ view: "year" }), className: "glim-date-step", children: _jsx(IconBack, {}) }), _jsx("span", { className: "glim-date-title glim-num", children: `${api.getDecade().start} - ${api.getDecade().end}` }), _jsx("button", { ...api.getNextTriggerProps({ view: "year" }), className: "glim-date-step", children: _jsx(IconForward, {}) })] }), _jsx("table", { ...api.getTableProps({ view: "year", columns: 4 }), className: "glim-date-grid", children: _jsx("tbody", { ...api.getTableBodyProps({ view: "year" }), children: years.map((row, i) => (_jsx("tr", { ...api.getTableRowProps({ view: "year" }), children: row.map((year, j) => (_jsx("td", { ...api.getYearTableCellProps({ ...year, columns: 4 }), children: _jsx("div", { ...api.getYearTableCellTriggerProps({ ...year, columns: 4 }), className: "glim-date-cell glim-date-cell--wide glim-num", children: year.label }) }, j))) }, i))) }) })] })] }) }) })] }));
39
44
  }
@@ -17,4 +17,4 @@ export interface FieldRowProps extends Omit<HTMLAttributes<HTMLDivElement>, "chi
17
17
  children?: ReactNode;
18
18
  className?: string;
19
19
  }
20
- export declare function FieldRow({ label, drawn, hint, value, tone, wide, children, className, ...rest }: FieldRowProps): import("react").JSX.Element;
20
+ export declare function FieldRow({ label, drawn, hint, value, tone, wide, children, className, onClick, ...rest }: FieldRowProps): import("react").JSX.Element;
package/dist/FieldRow.js CHANGED
@@ -1,13 +1,17 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useContext, useRef } from "react";
3
- import { pressRowControl } from "@glimstone/core";
2
+ import { useContext, useEffect, useRef } from "react";
3
+ import { pressRowControl, pressRowSwitch, watchRowStack } from "@glimstone/core";
4
4
  import { FieldRowContext, FieldRowGroupContext } from "./fieldName.js";
5
5
  import { InfoBubble } from "./InfoBubble.js";
6
6
  import { Pill } from "./Pill.js";
7
- export function FieldRow({ label, drawn, hint, value, tone, wide, children, className, ...rest }) {
7
+ export function FieldRow({ label, drawn, hint, value, tone, wide, children, className, onClick, ...rest }) {
8
8
  const row = useRef(null);
9
9
  const inGroup = useContext(FieldRowGroupContext);
10
+ useEffect(() => watchRowStack(row.current), []);
10
11
  const control = children ??
11
12
  (value !== undefined && (_jsx(Pill, { className: "glim-num", tone: tone, children: value })));
12
- return (_jsx(FieldRowContext.Provider, { value: label, children: _jsxs("div", { "data-glim": "FieldRow", ...rest, ref: row, className: ["glim-field-row", wide && "glim-field-row--wide", className].filter(Boolean).join(" "), children: [_jsxs("span", { className: "glim-field-row-name", children: [_jsx("span", { className: "glim-field-row-label", onClick: () => pressRowControl(row.current), children: drawn ?? label }), hint && _jsx(InfoBubble, { tip: hint })] }), inGroup ? _jsx("span", { className: "glim-field-row-controls", children: control }) : control] }) }));
13
+ return (_jsx(FieldRowContext.Provider, { value: label, children: _jsxs("div", { "data-glim": "FieldRow", "data-press": "", ...rest, ref: row, onClick: (e) => {
14
+ onClick?.(e);
15
+ pressRowSwitch(row.current, e.target);
16
+ }, className: ["glim-field-row", wide && "glim-field-row--wide", className].filter(Boolean).join(" "), children: [_jsxs("span", { className: "glim-field-row-name", children: [_jsx("span", { className: "glim-field-row-label", onClick: () => pressRowControl(row.current), children: drawn ?? label }), hint && _jsx(InfoBubble, { tip: hint })] }), inGroup ? _jsx("span", { className: "glim-field-row-controls", children: control }) : control] }) }));
13
17
  }
@@ -10,6 +10,8 @@ export interface FileUploadProps {
10
10
  /** The largest file it takes, in bytes. */
11
11
  maxFileSize?: number;
12
12
  disabled?: boolean;
13
+ /** How far a file has gone up, from 0 to 1, while the app sends it. Its row fills with it. */
14
+ progress?: (file: File) => number | undefined;
13
15
  text?: Partial<FileUploadText>;
14
16
  }
15
- export declare function FileUpload({ label, value, onChange, accept, maxFiles, maxFileSize, disabled, text }: FileUploadProps): import("react").JSX.Element;
17
+ export declare function FileUpload({ label, value, onChange, accept, maxFiles, maxFileSize, disabled, progress, text }: FileUploadProps): import("react").JSX.Element;
@@ -2,10 +2,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useId } from "react";
3
3
  import * as fileUpload from "@zag-js/file-upload";
4
4
  import { normalizeProps, useMachine } from "@zag-js/react";
5
- import { FILE_UPLOAD_TEXT, formatFileSize, pageDir } from "@glimstone/core";
5
+ import { FILE_UPLOAD_TEXT, formatFileSize, pageDir, uploadProgressView } from "@glimstone/core";
6
6
  import { IconButton } from "./IconButton.js";
7
7
  import { IconClose, IconUpload } from "./glyphs.js";
8
- export function FileUpload({ label, value, onChange, accept, maxFiles = 1, maxFileSize, disabled = false, text }) {
8
+ export function FileUpload({ label, value, onChange, accept, maxFiles = 1, maxFileSize, disabled = false, progress, text }) {
9
9
  const words = { ...FILE_UPLOAD_TEXT, ...text };
10
10
  const service = useMachine(fileUpload.machine, {
11
11
  id: useId(),
@@ -19,5 +19,8 @@ export function FileUpload({ label, value, onChange, accept, maxFiles = 1, maxFi
19
19
  translations: { dropzone: words.drop, deleteFile: (file) => words.remove(file.name) },
20
20
  });
21
21
  const api = fileUpload.connect(service, normalizeProps);
22
- return (_jsxs("div", { "data-glim": "FileUpload", ...api.getRootProps(), className: "glim-upload", children: [_jsx("label", { ...api.getLabelProps(), className: "glim-field-label", children: label }), _jsxs("div", { ...api.getDropzoneProps(), className: "glim-upload-drop", children: [_jsx(IconUpload, {}), _jsx("span", { className: "glim-upload-words", children: words.drop })] }), _jsx("input", { ...api.getHiddenInputProps() }), api.acceptedFiles.length > 0 && (_jsx("ul", { ...api.getItemGroupProps(), className: "glim-upload-files", children: api.acceptedFiles.map((file) => (_jsxs("li", { ...api.getItemProps({ file }), className: "glim-upload-file", children: [_jsx("span", { ...api.getItemNameProps({ file }), className: "glim-upload-name", children: file.name }), _jsx("span", { ...api.getItemSizeTextProps({ file }), className: "glim-upload-size glim-num", children: formatFileSize(file.size) }), _jsx(IconButton, { tip: words.remove(file.name), glyph: _jsx(IconClose, {}), onClick: () => api.deleteFile(file) })] }, `${file.name}-${file.size}`))) })), api.rejectedFiles.map(({ file, errors }) => (_jsx("p", { className: "glim-field-error", children: words.refused(file.name, errors[0]) }, `${file.name}-${file.size}`)))] }));
22
+ return (_jsxs("div", { "data-glim": "FileUpload", ...api.getRootProps(), className: "glim-upload", children: [_jsx("label", { ...api.getLabelProps(), className: "glim-field-label", children: label }), _jsxs("div", { ...api.getDropzoneProps(), className: "glim-upload-drop", children: [_jsx(IconUpload, {}), _jsx("span", { className: "glim-upload-words", children: words.drop })] }), _jsx("input", { ...api.getHiddenInputProps() }), api.acceptedFiles.length > 0 && (_jsx("ul", { ...api.getItemGroupProps(), className: "glim-upload-files", children: api.acceptedFiles.map((file) => {
23
+ const sent = uploadProgressView(progress?.(file));
24
+ return (_jsxs("li", { ...api.getItemProps({ file }), "aria-busy": sent.state === "sending" ? true : undefined, "data-progress": sent.state, style: sent.share === undefined ? undefined : { "--glim-upload-progress": sent.share }, className: "glim-upload-file", children: [_jsx("span", { ...api.getItemNameProps({ file }), className: "glim-upload-name", children: file.name }), _jsx("span", { ...api.getItemSizeTextProps({ file }), className: "glim-upload-size glim-num", children: formatFileSize(file.size) }), _jsx(IconButton, { tip: words.remove(file.name), glyph: _jsx(IconClose, {}), onClick: () => api.deleteFile(file) })] }, `${file.name}-${file.size}`));
25
+ }) })), api.rejectedFiles.map(({ file, errors }) => (_jsx("p", { className: "glim-field-error", children: words.refused(file.name, errors[0]) }, `${file.name}-${file.size}`)))] }));
23
26
  }
@@ -2,9 +2,10 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
2
2
  import { useState } from "react";
3
3
  import { fill, MARKS, permissionsWith, shake } from "@glimstone/core";
4
4
  import { Card } from "./Card.js";
5
+ import { EmptyState } from "./EmptyState.js";
5
6
  import { Selector } from "./Selector.js";
6
7
  import { Toggle } from "./Toggle.js";
7
- import { MarkSvg } from "./glyphs.js";
8
+ import { glyphFor, MarkSvg } from "./glyphs.js";
8
9
  /** What one app may do at another, a switch for each, all on unless switched off. */
9
10
  export function FortressPermissions({ text, app, apps, permissions, onPermission, notify, hueIndex, extra }) {
10
11
  const [filter, setFilter] = useState("all");
@@ -27,7 +28,7 @@ export function FortressPermissions({ text, app, apps, permissions, onPermission
27
28
  if (toggle)
28
29
  shake(toggle);
29
30
  }
30
- return (_jsx(Card, { "data-glim": "FortressPermissions", title: text.permissions, hint: text.permissionsAbout, hueIndex: hueIndex, children: permissions.length === 0 ? (_jsx("p", { className: "glim-fortress-sub", children: text.noPermissions })) : (_jsxs(_Fragment, { children: [narrows && (_jsx(Selector, { label: text.permissions, inline: true, activation: "manual", value: filter, onChange: setFilter, items: [
31
+ return (_jsx(Card, { "data-glim": "FortressPermissions", title: text.permissions, hint: text.permissionsAbout, hueIndex: hueIndex, children: permissions.length === 0 ? (_jsx(EmptyState, { nested: true, glyph: glyphFor("link"), title: text.noPermissions })) : (_jsxs(_Fragment, { children: [narrows && (_jsx(Selector, { label: text.permissions, inline: true, activation: "manual", value: filter, onChange: setFilter, items: [
31
32
  { id: "all", label: `${text.all} ${permissions.length}` },
32
33
  { id: "with", label: `${fill(text.withApp, { app: app.name })} ${mine.length}` },
33
34
  ] })), _jsx("ul", { className: "glim-permissions", children: shown.map((p) => (_jsxs("li", { className: `glim-permission${p.on ? " glim-permission--on" : ""}`, "data-permission": p.id, children: [_jsxs("span", { className: "glim-permission-pair", "aria-hidden": "true", children: [logo(p.from), _jsx(MarkSvg, { mark: MARKS.expand, className: "glim-permission-arrow" }), _jsx("span", { className: "glim-permission-to", children: p.to.map(logo) })] }), _jsxs("span", { className: "glim-permission-text", children: [_jsx("span", { className: "glim-permission-title", children: p.title }), p.detail && _jsx("span", { className: "glim-fortress-sub", children: p.detail }), extra?.(p)] }), _jsx(Toggle, { label: p.title, hideLabel: true, checked: p.on, onChange: () => flip(p) })] }, p.id))) })] })) }));
@@ -1,4 +1,6 @@
1
1
  import { type ReactNode } from "react";
2
+ import { type HoverCardFact } from "@glimstone/core";
3
+ export type { HoverCardFact } from "@glimstone/core";
2
4
  export interface HoverCardProps {
3
5
  /** The link's words. */
4
6
  label: string;
@@ -6,7 +8,15 @@ export interface HoverCardProps {
6
8
  /** How long the pointer rests before the card opens, and after it leaves before it closes, in ms. */
7
9
  openDelay?: number;
8
10
  closeDelay?: number;
9
- /** Draws the card. */
10
- content: () => ReactNode;
11
+ /** A glyph or an avatar for the card's head, in a 40px tile. */
12
+ media?: ReactNode;
13
+ /** The head's name. */
14
+ title?: string;
15
+ /** One quiet line under the name, such as an address or a state. */
16
+ meta?: string;
17
+ /** Up to three figures under the head, each a name and a value. */
18
+ facts?: readonly HoverCardFact[];
19
+ /** Draws the card's body below the head, or the whole card without one. */
20
+ content?: () => ReactNode;
11
21
  }
12
- export declare function HoverCard({ label, href, openDelay, closeDelay, content }: HoverCardProps): import("react").JSX.Element;
22
+ export declare function HoverCard({ label, href, openDelay, closeDelay, media, title, meta, facts, content }: HoverCardProps): import("react").JSX.Element;
package/dist/HoverCard.js CHANGED
@@ -2,9 +2,9 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
2
2
  import { useId, useRef } from "react";
3
3
  import * as hoverCard from "@zag-js/hover-card";
4
4
  import { normalizeProps, Portal, useMachine } from "@zag-js/react";
5
- import { pageDir, portalTarget } from "@glimstone/core";
5
+ import { hoverCardFacts, pageDir, portalTarget } from "@glimstone/core";
6
6
  import { usePortalHue } from "./portalHue.js";
7
- export function HoverCard({ label, href, openDelay = 600, closeDelay = 300, content }) {
7
+ export function HoverCard({ label, href, openDelay = 400, closeDelay = 150, media, title, meta, facts, content }) {
8
8
  const service = useMachine(hoverCard.machine, {
9
9
  id: useId(),
10
10
  dir: pageDir(),
@@ -16,5 +16,5 @@ export function HoverCard({ label, href, openDelay = 600, closeDelay = 300, cont
16
16
  const triggerRef = useRef(null);
17
17
  const hue = usePortalHue(api.open, triggerRef);
18
18
  const positioner = api.getPositionerProps();
19
- return (_jsxs(_Fragment, { children: [_jsx("a", { "data-glim": "HoverCard", ...api.getTriggerProps(), ref: triggerRef, href: href, className: "glim-hovercard-link", children: label }), api.open && (_jsx(Portal, { container: { current: portalTarget() }, children: _jsx("div", { ...positioner, style: { ...positioner.style, ...hue.style }, className: `glim-hovercard-positioner ${hue.className}`.trim(), children: _jsx("div", { ...api.getContentProps(), className: "glim-hovercard", children: content() }) }) }))] }));
19
+ return (_jsxs(_Fragment, { children: [_jsx("a", { "data-glim": "HoverCard", ...api.getTriggerProps(), ref: triggerRef, href: href, className: "glim-hovercard-link", children: label }), api.open && (_jsx(Portal, { container: { current: portalTarget() }, children: _jsx("div", { ...positioner, style: { ...positioner.style, ...hue.style }, className: `glim-hovercard-positioner ${hue.className}`.trim(), children: _jsxs("div", { ...api.getContentProps(), className: "glim-hovercard", children: [(media || title) && (_jsxs("div", { className: "glim-hovercard-head", children: [media && _jsx("span", { className: "glim-hovercard-media", children: media }), _jsxs("span", { className: "glim-hovercard-names", children: [title && _jsx("strong", { className: "glim-hovercard-title", children: title }), meta && _jsx("span", { className: "glim-hovercard-meta", children: meta })] })] })), hoverCardFacts(facts).length > 0 && (_jsx("dl", { className: "glim-hovercard-facts", children: hoverCardFacts(facts).map((f) => (_jsxs("div", { className: "glim-hovercard-fact", children: [_jsx("dt", { children: f.label }), _jsx("dd", { className: "glim-num", children: f.value })] }, f.label))) })), content?.()] }) }) }))] }));
20
20
  }