@blackbelt-technology/pi-dashboard-client-utils 0.5.4 → 0.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blackbelt-technology/pi-dashboard-client-utils",
3
- "version": "0.5.4",
3
+ "version": "0.6.1",
4
4
  "description": "Small reusable React components, hooks, and helpers shared between the pi-dashboard shell and dashboard plugins. Per-subpath exports; no markdown stack.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -25,13 +25,25 @@
25
25
  "types": "./src/DialogPortal.tsx",
26
26
  "default": "./src/DialogPortal.tsx"
27
27
  },
28
+ "./escape-stack": {
29
+ "types": "./src/escape-stack.ts",
30
+ "default": "./src/escape-stack.ts"
31
+ },
28
32
  "./Popover": {
29
33
  "types": "./src/Popover.tsx",
30
34
  "default": "./src/Popover.tsx"
31
35
  },
32
- "./ConfirmDialog": {
33
- "types": "./src/ConfirmDialog.tsx",
34
- "default": "./src/ConfirmDialog.tsx"
36
+ "./Dialog": {
37
+ "types": "./src/Dialog.tsx",
38
+ "default": "./src/Dialog.tsx"
39
+ },
40
+ "./Confirm": {
41
+ "types": "./src/Confirm.tsx",
42
+ "default": "./src/Confirm.tsx"
43
+ },
44
+ "./useFocusTrap": {
45
+ "types": "./src/useFocusTrap.ts",
46
+ "default": "./src/useFocusTrap.ts"
35
47
  },
36
48
  "./SearchableSelectDialog": {
37
49
  "types": "./src/SearchableSelectDialog.tsx",
@@ -77,6 +89,22 @@
77
89
  "types": "./src/StatusPill.tsx",
78
90
  "default": "./src/StatusPill.tsx"
79
91
  },
92
+ "./EmptyState": {
93
+ "types": "./src/EmptyState.tsx",
94
+ "default": "./src/EmptyState.tsx"
95
+ },
96
+ "./Skeleton": {
97
+ "types": "./src/Skeleton.tsx",
98
+ "default": "./src/Skeleton.tsx"
99
+ },
100
+ "./focusRing": {
101
+ "types": "./src/focusRing.ts",
102
+ "default": "./src/focusRing.ts"
103
+ },
104
+ "./statusPresentation": {
105
+ "types": "./src/statusPresentation.ts",
106
+ "default": "./src/statusPresentation.ts"
107
+ },
80
108
  "./minimal-chat": {
81
109
  "types": "./src/minimal-chat/index.ts",
82
110
  "default": "./src/minimal-chat/index.ts"
@@ -90,7 +118,7 @@
90
118
  "react-dom": ">=18.0.0"
91
119
  },
92
120
  "dependencies": {
93
- "@blackbelt-technology/pi-dashboard-shared": "^0.5.4",
121
+ "@blackbelt-technology/pi-dashboard-shared": "^0.6.1",
94
122
  "@mdi/js": "^7.4.47",
95
123
  "@mdi/react": "^1.6.1"
96
124
  },
package/src/AGENTS.md ADDED
@@ -0,0 +1,25 @@
1
+ # DOX — packages/client-utils/src
2
+
3
+ Files in this directory. One row per source file.
4
+
5
+ | File | Purpose |
6
+ |------|---------|
7
+ | `ActionList.tsx` | `ui:action-list` primitive. Exports `ActionList({ actions })` — horizontal row of MDI-icon + label buttons. `ExtendedActionItem` carries `dataAction` (pluginId/sessionId/action/payload) dispatched via `sendPluginAction`, or classical `onClick`. `IconByKey` lazy-imports `@mdi/js` and looks up path by export-name key. |
8
+ | `agent-card-utils.ts` | Shared helpers for agent card rendering. Exports `formatTokens`, `formatDuration`, `AgentCardStatus` type, `StatusIconDef`, `statusIconDefs` (pending/running/complete/error/blocked/stopped/background → MDI icon + color), `getStatusIcon`. Used by `FlowAgentCard` and `AgentToolRenderer`. |
9
+ | `AgentCardShell.tsx` | Exports `AgentCardShell` — reusable card container with status-colored border, header row (status icon + name + optional `headerRight`), optional `stats` line, clickable/selected states. `getStatusIcon` drives icon + border color. Consumers pass tool-specific content as children. |
10
+ | `Confirm.tsx` | Confirm preset over Dialog (size sm). Props `{open,onClose,title,message,body?,intent?,confirmLabel?,cancelLabel?,onConfirm,testId?}`. Action → onConfirm only (no auto-close); cancel/Esc/overlay → onClose. Replaces legacy ConfirmDialog. See change: unify-dialog-system. |
11
+ | `Dialog.tsx` | Unified modal shell. Props `{open,onClose,title?,icon?,size?,testId?,ariaLabel?,children}`. Owns DialogPortal, overlay `bg-black/60`, Esc via shared escape-stack (`useEscapeDismiss(open,onClose)` — onClose fires on Escape only when topmost registered layer; overlay opened above consumes it first), click-outside, focus trap (useFocusTrap), `role="dialog"`/`aria-modal`/`aria-labelledby`, `z-[60]`, size sm/md/lg → max-w-sm/md/lg, `max-h-[80vh]`. Renders standard ✕ close button (absolute top-right, testId `<testId>-close`) on every dialog incl. flush/headerless. Static subcomponents `Dialog.Footer`/`Dialog.Cancel`/`Dialog.Action` (intent primary\|danger\|neutral). See change: unify-dialog-system. |
12
+ | `DialogPortal.tsx` | Exports `DialogPortal` — `createPortal` to `document.body`. Hides body scroll (`overflow: hidden`) on mount, restores prior value on unmount. |
13
+ | `EmptyState.tsx` | EmptyState primitive. Props `{title, body?, icon?, action?, secondaryAction?}`. Single `action` prop enforces one-primary-CTA. Renders NN/g empty-state pattern: value-framed heading, optional body, ≤1 primary CTA, ≤1 secondary escape-hatch. data-empty-state markers. See change: extend-client-utils-state-feedback-primitives. |
14
+ | `escape-stack.ts` | Shared escape-dismiss stack. Single module-stable `document`-bubble `keydown` listener + LIFO registry; Escape invokes `onEscape` of topmost registered layer only, then `preventDefault`+`stopImmediatePropagation`; guards `e.repeat`+`e.defaultPrevented`. Attach-once/never-detach (early-returns on empty). Exports `useEscapeDismiss(active,onEscape)` (`useId`-stable id, ref-backed onEscape, remove-by-id), `registerEscapeLayer`/`unregisterEscapeLayer`, `__resetEscapeStack` (test-only, prod no-op). See change: fix-stacked-escape-closes-layers. |
15
+ | `focusRing.ts` | Exports `focusRing` = "focus-ring" className string. Points at `.focus-ring` utility in packages/client/src/index.css (:focus-visible, 2px outline, 2px offset, var(--focus-ring) color). Replaces ad-hoc focus:outline-none + 1px border. WCAG 2.2 §2.4.7/§2.4.11. See change: extend-client-utils-state-feedback-primitives. |
16
+ | `Popover.tsx` | `ui:popover` primitive. Exports `Popover`, `PopoverProps`, `computePopoverPosition` (pure). Anchors floating panel to `anchorEl`'s rect; flips above on bottom overflow, shifts left on right overflow; recomputes on resize/scroll. Dismisses on outside mousedown or Escape. Body portal, not modal/scroll-lock/tooltip. |
17
+ | `SearchableSelectDialog.tsx` | Exports `SearchableSelectDialog`, `SelectOption`. Filterable list inside `Dialog` (size `sm`). Arrow/Enter/Esc keyboard nav, scrolls selected into view, optional badge. Used for single-select choices. |
18
+ | `Skeleton.tsx` | Skeleton primitive for content-layout loads. Props `{variant=text\|card\|bubble\|row, count?}`. Honors prefers-reduced-motion via useMediaQuery (static, no animate-pulse). aria-hidden. data-skeleton / data-skeleton-item / data-static markers. See change: extend-client-utils-state-feedback-primitives. |
19
+ | `StatusPill.tsx` | `ui:status-pill` primitive. Exports `StatusPill({ state, text, icon?, tooltip? })` — state-tinted pill. `STATE_STYLE_DARK`/`STATE_STYLE_LIGHT` palettes keyed by `UiStatusPillState` (running/success/info/warn/error/muted). `useIsLightTheme` observes `data-theme` attr. `IconByKey` lazy-imports `@mdi/js`. |
20
+ | `statusPresentation.ts` | `statusPresentation(kind)` maps StatusKind (done\|current\|todo\|error) to `{glyph, tokenVar, label}`. Glyph = mandatory non-hue channel (✓ done, ▸ current, ○ todo, ✕ error). tokenVar references semantic --status-* / --text-muted token. `statusAriaLabel(name, kind)` returns "Name, label". WCAG 2.2 §1.4.1. Consumed by composer ArtifactChip + board BoardStatePill. See change: extend-client-utils-state-feedback-primitives. |
21
+ | `useFocusTrap.ts` | `useFocusTrap(ref,open)` hook. Stores prev activeElement, focuses first focusable child on open, traps Tab/Shift+Tab, restores focus on close. See change: unify-dialog-system. |
22
+ | `useMediaQuery.ts` | Reactive CSS media-query hook. Returns match boolean. Guards missing window.matchMedia (returns false). See change: extend-client-utils-state-feedback-primitives. |
23
+ | `useMobile.tsx` | Exports `MobileProvider` + `useMobile`. `MobileContext` provides boolean: viewport `max-width: 767px` OR `max-height: 599px` (catches landscape phones). Backed by `useMediaQuery`. |
24
+ | `useZoomPan.ts` | Exports `useZoomPan`, `ZoomPanState`, `UseZoomPanOptions`. State `{ scale, translateX, translateY }`. Wheel zoom centered on cursor, pointer drag pan (deferred capture past `DRAG_THRESHOLD` so clicks reach children), pinch zoom, double-click reset, `zoomIn`/`zoomOut`/`reset` controls. Clamp `minScale`/`maxScale`. Used by `MermaidBlock`, `FlowGraph`. |
25
+ | `ZoomControls.tsx` | Exports `ZoomControls({ onZoomIn, onZoomOut, onReset, scale })` — top-right overlay buttons (zoom in/out/reset) using MDI icons, percent readout when `scale !== 1`. Shared by `MermaidBlock` and `FlowGraph`. Stops pointer propagation. |
@@ -0,0 +1,58 @@
1
+ import React, { type ReactNode } from "react";
2
+ import { Dialog, type DialogIntent } from "./Dialog.js";
3
+
4
+ interface ConfirmProps {
5
+ open: boolean;
6
+ onClose: () => void;
7
+ title: string;
8
+ message: string;
9
+ /** Optional rich content rendered between the message and the footer. */
10
+ body?: ReactNode;
11
+ intent?: DialogIntent;
12
+ confirmLabel?: string;
13
+ cancelLabel?: string;
14
+ onConfirm: () => void;
15
+ testId?: string;
16
+ }
17
+
18
+ /**
19
+ * Thin preset over `Dialog` for the common title-message-confirm-cancel
20
+ * shape. Delegates all chrome (portal, overlay, focus, ARIA, dismissal) to
21
+ * `Dialog`. `onConfirm` does NOT auto-close — the caller controls dismissal.
22
+ *
23
+ * See change: unify-dialog-system (design.md D7).
24
+ */
25
+ export function Confirm({
26
+ open,
27
+ onClose,
28
+ title,
29
+ message,
30
+ body,
31
+ intent = "primary",
32
+ confirmLabel = "Confirm",
33
+ cancelLabel = "Cancel",
34
+ onConfirm,
35
+ testId,
36
+ }: ConfirmProps) {
37
+ return (
38
+ <Dialog open={open} onClose={onClose} title={title} size="sm" testId={testId}>
39
+ <p className="text-sm text-[var(--text-secondary)]">{message}</p>
40
+ {body}
41
+ <Dialog.Footer>
42
+ <Dialog.Cancel
43
+ onClick={onClose}
44
+ testId={testId ? `${testId}-cancel` : undefined}
45
+ >
46
+ {cancelLabel}
47
+ </Dialog.Cancel>
48
+ <Dialog.Action
49
+ onClick={onConfirm}
50
+ intent={intent}
51
+ testId={testId ? `${testId}-action` : undefined}
52
+ >
53
+ {confirmLabel}
54
+ </Dialog.Action>
55
+ </Dialog.Footer>
56
+ </Dialog>
57
+ );
58
+ }
package/src/Dialog.tsx ADDED
@@ -0,0 +1,194 @@
1
+ import React, {
2
+ useId,
3
+ useRef,
4
+ type ReactNode,
5
+ } from "react";
6
+ import { mdiClose } from "@mdi/js";
7
+ import { Icon } from "@mdi/react";
8
+ import { DialogPortal } from "./DialogPortal.js";
9
+ import { useEscapeDismiss } from "./escape-stack.js";
10
+ import { useFocusTrap } from "./useFocusTrap.js";
11
+
12
+ export type DialogSize = "sm" | "md" | "lg" | "full";
13
+ export type DialogIntent = "primary" | "danger" | "neutral";
14
+
15
+ interface DialogProps {
16
+ open: boolean;
17
+ onClose: () => void;
18
+ title?: string;
19
+ /** Optional leading icon (mdi path string) rendered in the header. */
20
+ icon?: string;
21
+ size?: DialogSize;
22
+ testId?: string;
23
+ /** Used for aria-label when no `title` is given. */
24
+ ariaLabel?: string;
25
+ /** Edge-to-edge body: drop the inner padding + clip overflow so a
26
+ * self-framed child (e.g. a chat/detail view with its own header) fills
27
+ * the dialog as a single window. See change:
28
+ * improve-flow-graph-dialog-and-card-interaction. */
29
+ flush?: boolean;
30
+ children: ReactNode;
31
+ }
32
+
33
+ const SIZE_MAX_W: Record<DialogSize, string> = {
34
+ sm: "max-w-sm",
35
+ md: "max-w-md",
36
+ lg: "max-w-lg",
37
+ full: "max-w-[95vw]",
38
+ };
39
+
40
+ // `full` gets a taller cap (near-fullscreen wide stage, e.g. horizontal flow
41
+ // graphs); sm/md/lg keep the 80vh column cap. See change:
42
+ // improve-flow-graph-dialog-and-card-interaction.
43
+ const SIZE_MAX_H: Record<DialogSize, string> = {
44
+ sm: "max-h-[80vh]",
45
+ md: "max-h-[80vh]",
46
+ lg: "max-h-[80vh]",
47
+ full: "max-h-[92vh]",
48
+ };
49
+
50
+ export function Dialog({
51
+ open,
52
+ onClose,
53
+ title,
54
+ icon,
55
+ size = "md",
56
+ testId,
57
+ ariaLabel,
58
+ flush = false,
59
+ children,
60
+ }: DialogProps) {
61
+ const containerRef = useRef<HTMLDivElement>(null);
62
+ const titleId = useId();
63
+
64
+ useFocusTrap(containerRef, open);
65
+
66
+ // Escape dismissal routes through the shared escape-stack: onClose fires only
67
+ // when this dialog is the topmost registered layer, so an overlay opened above
68
+ // it consumes the Escape first. See change: fix-stacked-escape-closes-layers.
69
+ useEscapeDismiss(open, onClose);
70
+
71
+ if (!open) return null;
72
+
73
+ const hasHeader = Boolean(title || icon);
74
+
75
+ return (
76
+ <DialogPortal>
77
+ <div className="fixed inset-0 z-[60] flex items-center justify-center">
78
+ <div
79
+ className="absolute inset-0 bg-black/60"
80
+ onClick={onClose}
81
+ data-testid={testId ? `${testId}-overlay` : undefined}
82
+ />
83
+ <div
84
+ ref={containerRef}
85
+ role="dialog"
86
+ aria-modal="true"
87
+ aria-labelledby={title ? titleId : undefined}
88
+ aria-label={!title ? ariaLabel : undefined}
89
+ tabIndex={-1}
90
+ data-testid={testId}
91
+ className={`relative w-full mx-4 ${SIZE_MAX_W[size]} ${SIZE_MAX_H[size]} ${flush ? "overflow-hidden" : "overflow-y-auto p-5 space-y-4"} bg-[var(--bg-primary)] border border-[var(--border-primary)] rounded-lg shadow-xl focus:outline-none`}
92
+ >
93
+ {/* Standard close affordance on every dialog (Escape + backdrop also
94
+ close). Absolutely positioned so it works for both headered and
95
+ `flush` (headerless) dialogs. */}
96
+ <button
97
+ type="button"
98
+ onClick={onClose}
99
+ aria-label="Close"
100
+ data-testid={testId ? `${testId}-close` : undefined}
101
+ className="absolute top-3 right-3 z-10 flex items-center justify-center w-7 h-7 rounded text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-surface)] transition-colors"
102
+ >
103
+ <Icon path={mdiClose} size={0.8} />
104
+ </button>
105
+ {hasHeader && (
106
+ <div className="flex items-center gap-3 pr-8">
107
+ {icon && (
108
+ <div className="flex-shrink-0 flex items-center justify-center w-9 h-9 rounded-md bg-[var(--accent-primary)]/15 text-[var(--accent-primary)]">
109
+ <Icon path={icon} size={0.85} />
110
+ </div>
111
+ )}
112
+ {title && (
113
+ <h3
114
+ id={titleId}
115
+ className="text-base font-semibold text-[var(--text-primary)]"
116
+ >
117
+ {title}
118
+ </h3>
119
+ )}
120
+ </div>
121
+ )}
122
+ {children}
123
+ </div>
124
+ </div>
125
+ </DialogPortal>
126
+ );
127
+ }
128
+
129
+ // ── Footer composition ───────────────────────────────────────────────────
130
+
131
+ function DialogFooter({ children }: { children: ReactNode }) {
132
+ return (
133
+ <div className="flex justify-end items-center gap-2 pt-1">{children}</div>
134
+ );
135
+ }
136
+
137
+ interface DialogCancelProps {
138
+ onClick: () => void;
139
+ children?: ReactNode;
140
+ testId?: string;
141
+ }
142
+
143
+ function DialogCancel({ onClick, children = "Cancel", testId }: DialogCancelProps) {
144
+ return (
145
+ <button
146
+ type="button"
147
+ onClick={onClick}
148
+ data-testid={testId}
149
+ className="text-xs px-3 py-1.5 rounded border border-[var(--border-primary)] text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors"
150
+ >
151
+ {children}
152
+ </button>
153
+ );
154
+ }
155
+
156
+ const INTENT_CLASS: Record<DialogIntent, string> = {
157
+ primary:
158
+ "bg-[var(--accent-primary)] text-white hover:opacity-90 border border-transparent",
159
+ danger: "bg-red-600 text-white hover:bg-red-500 border border-transparent",
160
+ neutral:
161
+ "bg-transparent border border-[var(--border-primary)] text-[var(--text-secondary)] hover:text-[var(--text-primary)]",
162
+ };
163
+
164
+ interface DialogActionProps {
165
+ onClick: () => void;
166
+ intent?: DialogIntent;
167
+ disabled?: boolean;
168
+ children: ReactNode;
169
+ testId?: string;
170
+ }
171
+
172
+ function DialogAction({
173
+ onClick,
174
+ intent = "primary",
175
+ disabled,
176
+ children,
177
+ testId,
178
+ }: DialogActionProps) {
179
+ return (
180
+ <button
181
+ type="button"
182
+ onClick={onClick}
183
+ disabled={disabled}
184
+ data-testid={testId}
185
+ className={`text-xs px-3 py-1.5 rounded transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${INTENT_CLASS[intent]}`}
186
+ >
187
+ {children}
188
+ </button>
189
+ );
190
+ }
191
+
192
+ Dialog.Footer = DialogFooter;
193
+ Dialog.Cancel = DialogCancel;
194
+ Dialog.Action = DialogAction;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * EmptyState primitive — encodes the NN/g empty-state pattern: a value-framed
3
+ * heading, optional body / shape-of-success slot, at most ONE primary CTA, and
4
+ * at most one secondary (escape-hatch) action.
5
+ *
6
+ * The single `action` prop (not an array) enforces one-primary-CTA by
7
+ * construction — a consumer cannot supply more than one primary action. Bare
8
+ * inline empty `<p>` strings can't satisfy this shape, so adopting `EmptyState`
9
+ * upgrades copy by construction.
10
+ *
11
+ * Rule: NN/g empty-state; H8 one primary action; Von Restorff.
12
+ * See change: extend-client-utils-state-feedback-primitives.
13
+ */
14
+ import type React from "react";
15
+
16
+ export interface EmptyStateAction {
17
+ label: string;
18
+ onClick: () => void;
19
+ testId?: string;
20
+ }
21
+
22
+ export interface EmptyStateProps {
23
+ /** Value-framed heading naming what lives here once populated. */
24
+ title: string;
25
+ /** Optional supporting copy (shape of success). */
26
+ body?: React.ReactNode;
27
+ /** Optional ghost/illustration slot. */
28
+ icon?: React.ReactNode;
29
+ /** At most one primary CTA. */
30
+ action?: EmptyStateAction;
31
+ /** At most one secondary escape-hatch action. */
32
+ secondaryAction?: EmptyStateAction;
33
+ className?: string;
34
+ }
35
+
36
+ export function EmptyState({
37
+ title,
38
+ body,
39
+ icon,
40
+ action,
41
+ secondaryAction,
42
+ className,
43
+ }: EmptyStateProps) {
44
+ return (
45
+ <div
46
+ data-empty-state=""
47
+ className={
48
+ "flex flex-col items-center justify-center text-center gap-2 px-4 py-6 text-[var(--text-tertiary)]" +
49
+ (className ? ` ${className}` : "")
50
+ }
51
+ >
52
+ {icon ? (
53
+ <div aria-hidden="true" className="opacity-60">
54
+ {icon}
55
+ </div>
56
+ ) : null}
57
+ <p className="text-sm font-medium text-[var(--text-secondary)]">{title}</p>
58
+ {body ? <div className="text-xs text-[var(--text-tertiary)] max-w-xs">{body}</div> : null}
59
+ {action || secondaryAction ? (
60
+ <div className="flex items-center gap-2 mt-1">
61
+ {action ? (
62
+ <button
63
+ type="button"
64
+ data-empty-state-action="primary"
65
+ data-testid={action.testId}
66
+ onClick={action.onClick}
67
+ className="focus-ring text-xs font-medium px-3 py-1.5 rounded-md bg-[var(--accent-primary)] text-white hover:opacity-90"
68
+ >
69
+ {action.label}
70
+ </button>
71
+ ) : null}
72
+ {secondaryAction ? (
73
+ <button
74
+ type="button"
75
+ data-empty-state-action="secondary"
76
+ data-testid={secondaryAction.testId}
77
+ onClick={secondaryAction.onClick}
78
+ className="focus-ring text-xs font-medium px-3 py-1.5 rounded-md text-[var(--text-secondary)] hover:text-[var(--text-primary)]"
79
+ >
80
+ {secondaryAction.label}
81
+ </button>
82
+ ) : null}
83
+ </div>
84
+ ) : null}
85
+ </div>
86
+ );
87
+ }
@@ -1,5 +1,5 @@
1
1
  import React, { useState, useRef, useEffect, useMemo } from "react";
2
- import { DialogPortal } from "./DialogPortal.js";
2
+ import { Dialog } from "./Dialog.js";
3
3
 
4
4
  export interface SelectOption {
5
5
  value: string;
@@ -66,19 +66,13 @@ export function SearchableSelectDialog({
66
66
  if (filtered[selectedIndex]) {
67
67
  onSelect(filtered[selectedIndex].value);
68
68
  }
69
- } else if (e.key === "Escape") {
70
- onCancel();
71
69
  }
72
70
  };
73
71
 
74
72
  return (
75
- <DialogPortal>
76
- <div className="fixed inset-0 z-[60] flex items-center justify-center">
77
- <div className="absolute inset-0 bg-[var(--bg-overlay)]" onClick={onCancel} />
78
- <div className="relative bg-[var(--bg-secondary)] rounded-xl border border-[var(--border-subtle)] shadow-2xl w-[90vw] max-w-sm overflow-hidden">
79
- {/* Header */}
80
- <div className="px-3 pt-3 pb-2">
81
- <div className="text-sm font-medium text-[var(--text-primary)] mb-2">{title}</div>
73
+ <Dialog open onClose={onCancel} title={title} size="sm">
74
+ {/* Search */}
75
+ <div>
82
76
  <input
83
77
  ref={inputRef}
84
78
  type="text"
@@ -123,11 +117,9 @@ export function SearchableSelectDialog({
123
117
  </div>
124
118
 
125
119
  {/* Footer hint */}
126
- <div className="px-3 py-1.5 border-t border-[var(--border-subtle)] text-[10px] text-[var(--text-muted)]">
120
+ <div className="pt-1.5 border-t border-[var(--border-subtle)] text-[10px] text-[var(--text-muted)]">
127
121
  ↑↓ navigate · Enter select · Esc cancel
128
122
  </div>
129
- </div>
130
- </div>
131
- </DialogPortal>
123
+ </Dialog>
132
124
  );
133
125
  }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Skeleton primitive — content-shaped loading placeholder for content-layout
3
+ * loads (chat history, board, lists). Spinners stay for short blocking actions
4
+ * only.
5
+ *
6
+ * Honors `prefers-reduced-motion: reduce` by rendering a static placeholder
7
+ * with no shimmer animation. Per-content variants keep placeholder shape close
8
+ * to the real content so there is no layout shift (CLS) on swap.
9
+ *
10
+ * Rule: NN/g skeleton-screens; response-times; Doherty.
11
+ * See change: extend-client-utils-state-feedback-primitives.
12
+ */
13
+ import { useMediaQuery } from "./useMediaQuery.js";
14
+
15
+ export type SkeletonVariant = "text" | "card" | "bubble" | "row";
16
+
17
+ export interface SkeletonProps {
18
+ variant?: SkeletonVariant;
19
+ /** How many placeholder rows to render. Default 1. */
20
+ count?: number;
21
+ className?: string;
22
+ }
23
+
24
+ const VARIANT_CLASS: Record<SkeletonVariant, string> = {
25
+ text: "h-3 w-2/3 rounded",
26
+ card: "h-24 w-full rounded-lg",
27
+ bubble: "h-14 w-3/4 rounded-2xl",
28
+ row: "h-8 w-full rounded-md",
29
+ };
30
+
31
+ export function Skeleton({ variant = "text", count = 1, className }: SkeletonProps) {
32
+ const reducedMotion = useMediaQuery("(prefers-reduced-motion: reduce)");
33
+ const n = Number.isFinite(count) ? Math.max(1, Math.floor(count)) : 1;
34
+ const items = Array.from({ length: n });
35
+ const motionClass = reducedMotion ? "" : "animate-pulse";
36
+ return (
37
+ <div
38
+ data-skeleton={variant}
39
+ data-static={reducedMotion ? "true" : undefined}
40
+ aria-hidden="true"
41
+ className={`flex flex-col gap-2${className ? ` ${className}` : ""}`}
42
+ >
43
+ {items.map((_, i) => (
44
+ <div
45
+ key={i}
46
+ data-skeleton-item=""
47
+ className={`bg-[var(--bg-surface)] ${motionClass} ${VARIANT_CLASS[variant]}`}
48
+ />
49
+ ))}
50
+ </div>
51
+ );
52
+ }
@@ -4,8 +4,8 @@
4
4
  * Registered as `ui:status-pill` in the primitive registry. Plugins emit
5
5
  * `{primitive: "ui:status-pill", props: {state, text, icon?}}`.
6
6
  *
7
- * Mirrors the badge style from honcho-plugin's HonchoBadge so plugins
8
- * migrating to intent rendering get visual parity. See change:
7
+ * Provides a consistent badge style so plugins migrating to intent
8
+ * rendering get visual parity. See change:
9
9
  * adopt-server-driven-intent-rendering.
10
10
  */
11
11
  import React, { useEffect, useState } from "react";
@@ -0,0 +1,105 @@
1
+ import { describe, it, expect, afterEach, vi } from "vitest";
2
+ import { render, cleanup, fireEvent } from "@testing-library/react";
3
+ import React from "react";
4
+ import { Confirm } from "../Confirm.js";
5
+
6
+ afterEach(() => cleanup());
7
+
8
+ describe("Confirm", () => {
9
+ it("renders title and message", () => {
10
+ const { getByText, baseElement } = render(
11
+ <Confirm
12
+ open
13
+ onClose={() => {}}
14
+ onConfirm={() => {}}
15
+ title="Forget workspace?"
16
+ message="This cannot be undone."
17
+ testId="c"
18
+ />,
19
+ );
20
+ expect(getByText("Forget workspace?")).toBeTruthy();
21
+ expect(getByText("This cannot be undone.")).toBeTruthy();
22
+ const container = baseElement.querySelector("[data-testid='c']")!;
23
+ expect(container.getAttribute("aria-labelledby")).toBeTruthy();
24
+ });
25
+
26
+ it("renders optional body node", () => {
27
+ const { getByTestId } = render(
28
+ <Confirm
29
+ open
30
+ onClose={() => {}}
31
+ onConfirm={() => {}}
32
+ title="t"
33
+ message="m"
34
+ body={<ul data-testid="files" />}
35
+ />,
36
+ );
37
+ expect(getByTestId("files")).toBeTruthy();
38
+ });
39
+
40
+ it("uses default labels", () => {
41
+ const { getByText } = render(
42
+ <Confirm open onClose={() => {}} onConfirm={() => {}} title="t" message="m" />,
43
+ );
44
+ expect(getByText("Confirm")).toBeTruthy();
45
+ expect(getByText("Cancel")).toBeTruthy();
46
+ });
47
+
48
+ it("uses custom labels", () => {
49
+ const { getByText } = render(
50
+ <Confirm
51
+ open
52
+ onClose={() => {}}
53
+ onConfirm={() => {}}
54
+ title="t"
55
+ message="m"
56
+ confirmLabel="Forget"
57
+ cancelLabel="Keep"
58
+ />,
59
+ );
60
+ expect(getByText("Forget")).toBeTruthy();
61
+ expect(getByText("Keep")).toBeTruthy();
62
+ });
63
+
64
+ it("maps danger intent to action button class", () => {
65
+ const { baseElement } = render(
66
+ <Confirm
67
+ open
68
+ onClose={() => {}}
69
+ onConfirm={() => {}}
70
+ title="t"
71
+ message="m"
72
+ intent="danger"
73
+ testId="c"
74
+ />,
75
+ );
76
+ expect(
77
+ baseElement.querySelector("[data-testid='c-action']")!.className,
78
+ ).toContain("bg-red-600");
79
+ });
80
+
81
+ it("action calls onConfirm only; cancel/Esc call onClose only", () => {
82
+ const onConfirm = vi.fn();
83
+ const onClose = vi.fn();
84
+ const { baseElement } = render(
85
+ <Confirm
86
+ open
87
+ onClose={onClose}
88
+ onConfirm={onConfirm}
89
+ title="t"
90
+ message="m"
91
+ testId="c"
92
+ />,
93
+ );
94
+ fireEvent.click(baseElement.querySelector("[data-testid='c-action']")!);
95
+ expect(onConfirm).toHaveBeenCalledTimes(1);
96
+ expect(onClose).not.toHaveBeenCalled();
97
+
98
+ fireEvent.click(baseElement.querySelector("[data-testid='c-cancel']")!);
99
+ expect(onClose).toHaveBeenCalledTimes(1);
100
+
101
+ fireEvent.keyDown(document, { key: "Escape" });
102
+ expect(onClose).toHaveBeenCalledTimes(2);
103
+ expect(onConfirm).toHaveBeenCalledTimes(1);
104
+ });
105
+ });