@whity/ui 0.0.0-stage → 1.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 (205) hide show
  1. package/README.md +106 -2
  2. package/package.json +219 -4
  3. package/src/access-denied.stories.tsx +179 -0
  4. package/src/access-denied.tsx +305 -0
  5. package/src/action-proposal.tsx +338 -0
  6. package/src/actor-chip.tsx +71 -0
  7. package/src/agent-activity.tsx +163 -0
  8. package/src/agent-collaboration.stories.tsx +156 -0
  9. package/src/agent-run-status.tsx +196 -0
  10. package/src/alert-dialog.stories.tsx +45 -0
  11. package/src/alert-dialog.tsx +147 -0
  12. package/src/alert.stories.tsx +91 -0
  13. package/src/alert.tsx +89 -0
  14. package/src/app-sidebar.stories.tsx +195 -0
  15. package/src/app-sidebar.tsx +604 -0
  16. package/src/approval-queue.tsx +109 -0
  17. package/src/audience-group-picker.stories.tsx +198 -0
  18. package/src/audience-group-picker.tsx +362 -0
  19. package/src/audience-people-picker.stories.tsx +102 -0
  20. package/src/audience-people-picker.tsx +279 -0
  21. package/src/avatar-pattern.ts +138 -0
  22. package/src/avatar.tsx +125 -0
  23. package/src/badge.stories.tsx +105 -0
  24. package/src/badge.tsx +68 -0
  25. package/src/beta-warning.stories.tsx +79 -0
  26. package/src/beta-warning.tsx +189 -0
  27. package/src/bilingual-input.stories.tsx +82 -0
  28. package/src/bilingual-input.tsx +188 -0
  29. package/src/board.tsx +216 -0
  30. package/src/breadcrumb.stories.tsx +51 -0
  31. package/src/breadcrumb.tsx +90 -0
  32. package/src/built-on-whity.tsx +52 -0
  33. package/src/button.stories.tsx +87 -0
  34. package/src/button.tsx +123 -0
  35. package/src/card.stories.tsx +423 -0
  36. package/src/card.tsx +180 -0
  37. package/src/chart.stories.tsx +66 -0
  38. package/src/chart.tsx +228 -0
  39. package/src/checkbox.stories.tsx +62 -0
  40. package/src/checkbox.tsx +54 -0
  41. package/src/collapsible.stories.tsx +48 -0
  42. package/src/collapsible.tsx +34 -0
  43. package/src/color-card.stories.tsx +61 -0
  44. package/src/color-card.tsx +270 -0
  45. package/src/color-picker.stories.tsx +65 -0
  46. package/src/color-picker.tsx +425 -0
  47. package/src/column-matcher.tsx +84 -0
  48. package/src/command-palette.tsx +398 -0
  49. package/src/confirm-action.tsx +98 -0
  50. package/src/copy-block.stories.tsx +38 -0
  51. package/src/copy-block.tsx +85 -0
  52. package/src/data-table.stories.tsx +200 -0
  53. package/src/data-table.tsx +1686 -0
  54. package/src/date-picker.stories.tsx +61 -0
  55. package/src/date-picker.tsx +456 -0
  56. package/src/design-cards.stories.tsx +551 -0
  57. package/src/dialog.stories.tsx +48 -0
  58. package/src/dialog.tsx +179 -0
  59. package/src/display-preferences.tsx +50 -0
  60. package/src/documents/barcode-svg.stories.tsx +72 -0
  61. package/src/documents/barcode-svg.tsx +79 -0
  62. package/src/dropdown-menu.stories.tsx +77 -0
  63. package/src/dropdown-menu.tsx +271 -0
  64. package/src/editor/agent-panel.tsx +222 -0
  65. package/src/editor/agents.stories.tsx +81 -0
  66. package/src/editor/agents.ts +55 -0
  67. package/src/editor/behaviour.ts +279 -0
  68. package/src/editor/block-ids.ts +44 -0
  69. package/src/editor/block-list.tsx +104 -0
  70. package/src/editor/block-toolbar.tsx +490 -0
  71. package/src/editor/bubble.tsx +119 -0
  72. package/src/editor/catalogue.ts +169 -0
  73. package/src/editor/collab-rail.tsx +746 -0
  74. package/src/editor/collab.stories.tsx +207 -0
  75. package/src/editor/collab.ts +87 -0
  76. package/src/editor/contract.ts +476 -0
  77. package/src/editor/convert.ts +414 -0
  78. package/src/editor/doc-editor.stories.tsx +98 -0
  79. package/src/editor/doc-editor.tsx +1492 -0
  80. package/src/editor/editor.css +636 -0
  81. package/src/editor/extensions.ts +86 -0
  82. package/src/editor/field-bar.tsx +154 -0
  83. package/src/editor/field-picker.tsx +109 -0
  84. package/src/editor/fields.ts +100 -0
  85. package/src/editor/gutter.tsx +443 -0
  86. package/src/editor/index.ts +23 -0
  87. package/src/editor/label-sheet.tsx +289 -0
  88. package/src/editor/labels.ts +394 -0
  89. package/src/editor/link-tools.tsx +141 -0
  90. package/src/editor/node-views.tsx +461 -0
  91. package/src/editor/page-view.tsx +372 -0
  92. package/src/editor/phone.tsx +310 -0
  93. package/src/editor/plugin-block-view.tsx +230 -0
  94. package/src/editor/plugin-blocks.stories.tsx +96 -0
  95. package/src/editor/plugin-blocks.ts +52 -0
  96. package/src/editor/publish-check.tsx +201 -0
  97. package/src/editor/rich-blocks.stories.tsx +146 -0
  98. package/src/editor/sample.ts +40 -0
  99. package/src/editor/save-block-dialog.tsx +141 -0
  100. package/src/editor/saved-block-view.tsx +205 -0
  101. package/src/editor/saved-blocks.stories.tsx +105 -0
  102. package/src/editor/saved-parts.ts +192 -0
  103. package/src/editor/schema-rich.ts +156 -0
  104. package/src/editor/schema.ts +368 -0
  105. package/src/editor/services.tsx +205 -0
  106. package/src/editor/slash.ts +64 -0
  107. package/src/editor/suggesting.ts +372 -0
  108. package/src/editor/suggestions.ts +763 -0
  109. package/src/editor/table-keys.ts +66 -0
  110. package/src/editor/templates.stories.tsx +324 -0
  111. package/src/editor/toolbar.tsx +364 -0
  112. package/src/empty-state.stories.tsx +51 -0
  113. package/src/empty-state.tsx +126 -0
  114. package/src/empty-state.usage-notes.md +30 -0
  115. package/src/form.stories.tsx +112 -0
  116. package/src/form.tsx +176 -0
  117. package/src/globals.css +20 -0
  118. package/src/icon-button.tsx +85 -0
  119. package/src/icon-map.ts +335 -0
  120. package/src/icon.tsx +41 -0
  121. package/src/index.ts +90 -0
  122. package/src/input.stories.tsx +157 -0
  123. package/src/input.tsx +768 -0
  124. package/src/kpi-strip.tsx +47 -0
  125. package/src/localized-text.ts +76 -0
  126. package/src/locked-screen.stories.tsx +29 -0
  127. package/src/locked-screen.tsx +75 -0
  128. package/src/lockup.tsx +42 -0
  129. package/src/lottie.tsx +441 -0
  130. package/src/mark.tsx +62 -0
  131. package/src/math-text.stories.tsx +33 -0
  132. package/src/math-text.tsx +43 -0
  133. package/src/menu-bar.stories.tsx +198 -0
  134. package/src/menu-bar.tsx +373 -0
  135. package/src/message-thread.tsx +181 -0
  136. package/src/money/currency.ts +244 -0
  137. package/src/money/money-input.tsx +131 -0
  138. package/src/money/money.tsx +33 -0
  139. package/src/open-on-computer.tsx +150 -0
  140. package/src/otp-input.tsx +161 -0
  141. package/src/page-header.stories.tsx +95 -0
  142. package/src/page-header.tsx +122 -0
  143. package/src/page-shell.stories.tsx +42 -0
  144. package/src/page-shell.tsx +32 -0
  145. package/src/page-states.tsx +277 -0
  146. package/src/pagination.stories.tsx +45 -0
  147. package/src/pagination.tsx +98 -0
  148. package/src/paper-sheet.stories.tsx +88 -0
  149. package/src/paper-sheet.tsx +85 -0
  150. package/src/phone-tab-bar.tsx +152 -0
  151. package/src/plugin-card.stories.tsx +208 -0
  152. package/src/plugin-card.tsx +931 -0
  153. package/src/popover.stories.tsx +48 -0
  154. package/src/popover.tsx +55 -0
  155. package/src/radio-group.stories.tsx +26 -0
  156. package/src/radio-group.tsx +44 -0
  157. package/src/route-flow/editor.tsx +1087 -0
  158. package/src/route-flow/model.ts +771 -0
  159. package/src/save-bar.tsx +94 -0
  160. package/src/scope-grant.tsx +139 -0
  161. package/src/screen-too-small.stories.tsx +61 -0
  162. package/src/screen-too-small.tsx +104 -0
  163. package/src/search-field.tsx +65 -0
  164. package/src/select.stories.tsx +44 -0
  165. package/src/select.tsx +197 -0
  166. package/src/separator.stories.tsx +34 -0
  167. package/src/separator.tsx +34 -0
  168. package/src/sheet.stories.tsx +49 -0
  169. package/src/sheet.tsx +168 -0
  170. package/src/skeleton.stories.tsx +28 -0
  171. package/src/skeleton.tsx +19 -0
  172. package/src/slider.stories.tsx +78 -0
  173. package/src/slider.tsx +300 -0
  174. package/src/spinner.stories.tsx +33 -0
  175. package/src/spinner.tsx +55 -0
  176. package/src/stepper.tsx +85 -0
  177. package/src/switch.stories.tsx +42 -0
  178. package/src/switch.tsx +41 -0
  179. package/src/switcher.stories.tsx +111 -0
  180. package/src/switcher.tsx +131 -0
  181. package/src/system-state.tsx +55 -0
  182. package/src/table.stories.tsx +48 -0
  183. package/src/table.tsx +121 -0
  184. package/src/tabs.stories.tsx +74 -0
  185. package/src/tabs.tsx +90 -0
  186. package/src/tag-input.stories.tsx +67 -0
  187. package/src/tag-input.tsx +117 -0
  188. package/src/tenant-logo.tsx +63 -0
  189. package/src/tenant-switcher.stories.tsx +38 -0
  190. package/src/tenant-switcher.tsx +164 -0
  191. package/src/textarea.stories.tsx +27 -0
  192. package/src/textarea.tsx +18 -0
  193. package/src/theme-mode.ts +52 -0
  194. package/src/time-grid.tsx +163 -0
  195. package/src/time-picker.stories.tsx +62 -0
  196. package/src/time-picker.tsx +615 -0
  197. package/src/toggle-group.tsx +138 -0
  198. package/src/tooltip.stories.tsx +43 -0
  199. package/src/tooltip.tsx +73 -0
  200. package/src/top-nav.stories.tsx +58 -0
  201. package/src/top-nav.tsx +324 -0
  202. package/src/undo-bar.tsx +107 -0
  203. package/src/utils.ts +45 -0
  204. package/src/view-toggle.stories.tsx +84 -0
  205. package/src/view-toggle.tsx +110 -0
@@ -0,0 +1,398 @@
1
+ "use client"
2
+
3
+ import * as React from "react"
4
+
5
+ import { cn } from "./utils"
6
+
7
+ /**
8
+ * A searchable, keyboard-driven command list — the `/` or Ctrl-K surface.
9
+ *
10
+ * BUILT FROM PRIMITIVES RATHER THAN `cmdk`. The platform's stated selling
11
+ * point is a lean, near-zero-dependency stack (ADR 0003), and what a palette
12
+ * actually needs — filter a list, move a cursor, run a callback — is less code
13
+ * than the wiring a dependency would take. Nothing here is novel; the value is
14
+ * in not owing anyone an upgrade for it.
15
+ *
16
+ * PRESENTATIONAL AND CONTROLLED. It holds the query and the cursor, because
17
+ * those die with the dialog; it holds no notion of what a command IS. The
18
+ * caller supplies items and decides what running one means, which is what lets
19
+ * the document designer feed it a flattened menu registry while another screen
20
+ * feeds it something else entirely.
21
+ *
22
+ * COPY ARRIVES AS PROPS, with English defaults, for the reason every component
23
+ * in this package does: `@whity/ui` is published standalone and may not
24
+ * depend on the i18n feature (#758). Translating is the consumer's job.
25
+ */
26
+
27
+ export interface CommandPaletteItem {
28
+ id: string
29
+ label: string
30
+ /** Heading this item sits under. Items are shown in the order given, grouped by first appearance. */
31
+ group?: string
32
+ /** Rendered right-aligned, e.g. "Ctrl+S". Never used for matching. */
33
+ shortcut?: string
34
+ icon?: React.ReactNode
35
+ /**
36
+ * Extra words that should MATCH but need not be shown — a block's scope, an
37
+ * element's other name ("picture" finding "image").
38
+ */
39
+ keywords?: string
40
+ /**
41
+ * Shown greyed and skipped by the cursor, never hidden.
42
+ *
43
+ * A command absent from the list reads as "this editor cannot do that"; a
44
+ * command present and greyed reads as "not right now", which is the true
45
+ * statement and the one that stops somebody hunting through menus for
46
+ * something that was never going to be available.
47
+ */
48
+ disabled?: boolean
49
+ /**
50
+ * Secondary words after the label, never matched against ("$301.60 ·
51
+ * overdue"): what tells two records with similar names apart.
52
+ */
53
+ hint?: string
54
+ /**
55
+ * Shown whatever the query, and not filtered by it: the "Ask an agent" row,
56
+ * which takes the words as they are (register 2.1c).
57
+ */
58
+ always?: boolean
59
+ /** An agent row: dashed, because nothing has happened until a person approves. */
60
+ agent?: boolean
61
+ /**
62
+ * Keep the palette open after `onSelect`: picking a command that still needs
63
+ * its details (`/go` then a screen) only changes the query.
64
+ */
65
+ keepOpen?: boolean
66
+ /**
67
+ * What Tab does on this row: complete it into the query (`/ne` becomes
68
+ * `/new `). Without it, Tab leaves the palette's own keys alone.
69
+ */
70
+ onComplete?: () => void
71
+ onSelect: () => void
72
+ }
73
+
74
+ export interface CommandPaletteProps {
75
+ open: boolean
76
+ onOpenChange: (open: boolean) => void
77
+ items: CommandPaletteItem[]
78
+ placeholder?: string
79
+ emptyLabel?: string
80
+ /** Accessible name for the dialog. */
81
+ label?: string
82
+ /**
83
+ * Called as the query changes, so the caller can fetch results (records
84
+ * from search) and pass them back in `items`. Items the caller supplies
85
+ * this way are still filtered here, so return what the server matched.
86
+ */
87
+ onQueryChange?: (query: string) => void
88
+ /** The keys row at the foot. Omit to hide it. */
89
+ footer?: { move: string; open: string; close: string; complete?: string }
90
+ /**
91
+ * The query, when the caller owns it (commands rewrite it: Tab completes
92
+ * `/ne` into `/new `). Omit to let the palette keep its own. A controlled
93
+ * caller resets it on open itself.
94
+ */
95
+ query?: string
96
+ /**
97
+ * False when the caller has already chosen what matches (command mode
98
+ * parses the query itself, so a substring test here would hide `/new
99
+ * document` behind the words after it).
100
+ */
101
+ filter?: boolean
102
+ /** A chip before the input naming the mode, e.g. "Commands". */
103
+ mode?: string
104
+ /**
105
+ * Read out after the list changes ("6 results"), so a screen-reader user
106
+ * hears that typing did something. Omit for silence.
107
+ */
108
+ countLabel?: (count: number) => string
109
+ /**
110
+ * Type a slash for the person when they press the slash KEY on an empty
111
+ * box, whatever their layout: on the Arabic layout that key types "ظ", and
112
+ * `/` is how commands start.
113
+ */
114
+ slashKey?: boolean
115
+ }
116
+
117
+ /** Case-insensitive subsequence-free substring match over label + keywords. */
118
+ function matches(item: CommandPaletteItem, query: string): boolean {
119
+ if (query === "" || item.always === true) return true
120
+ const q = query.toLowerCase()
121
+ return (
122
+ item.label.toLowerCase().includes(q) ||
123
+ (item.group?.toLowerCase().includes(q) ?? false) ||
124
+ (item.keywords?.toLowerCase().includes(q) ?? false)
125
+ )
126
+ }
127
+
128
+ export function CommandPalette({
129
+ open,
130
+ onOpenChange,
131
+ items,
132
+ placeholder = "Type a command…",
133
+ emptyLabel = "No matching command",
134
+ label = "Command palette",
135
+ onQueryChange,
136
+ footer,
137
+ query: controlledQuery,
138
+ filter = true,
139
+ mode,
140
+ countLabel,
141
+ slashKey = false,
142
+ }: CommandPaletteProps) {
143
+ const [ownQuery, setOwnQuery] = React.useState("")
144
+ const query = controlledQuery ?? ownQuery
145
+ const setQuery = (next: string) => {
146
+ if (controlledQuery === undefined) setOwnQuery(next)
147
+ onQueryChange?.(next)
148
+ }
149
+ const [cursor, setCursor] = React.useState(0)
150
+ const inputRef = React.useRef<HTMLInputElement>(null)
151
+ const listRef = React.useRef<HTMLDivElement>(null)
152
+
153
+ const shown = React.useMemo(
154
+ () => (filter ? items.filter((i) => matches(i, query)) : items),
155
+ [items, query, filter]
156
+ )
157
+
158
+ // The indices the cursor may land on. A disabled item is displayed but never
159
+ // selected, so navigation skips it rather than stopping on something Enter
160
+ // would silently ignore.
161
+ const selectable = React.useMemo(
162
+ () => shown.map((item, index) => (item.disabled === true ? -1 : index)).filter((i) => i >= 0),
163
+ [shown]
164
+ )
165
+
166
+ // Reset on open, and whenever the query changes the previous cursor is
167
+ // meaningless — it pointed into a different list.
168
+ React.useEffect(() => {
169
+ if (open) {
170
+ setOwnQuery("")
171
+ setCursor(0)
172
+ // Focus after paint; the input does not exist until this renders.
173
+ const id = requestAnimationFrame(() => inputRef.current?.focus())
174
+ return () => cancelAnimationFrame(id)
175
+ }
176
+ return undefined
177
+ }, [open])
178
+
179
+ React.useEffect(() => {
180
+ setCursor(selectable[0] ?? 0)
181
+ }, [query, selectable])
182
+
183
+ // Escape at the DOCUMENT level, not only on the dialog.
184
+ //
185
+ // Focus arrives a frame late (the input does not exist until this renders),
186
+ // so an Escape pressed in that gap would reach whatever had focus before —
187
+ // in the document designer, a window handler that deselects the canvas — and
188
+ // the palette would stay open having eaten the keystroke. Rare, and exactly
189
+ // the kind of race that shows up as a flaky test rather than a bug report.
190
+ React.useEffect(() => {
191
+ if (!open) return undefined;
192
+ const onEscape = (e: KeyboardEvent) => {
193
+ if (e.key !== 'Escape') return
194
+ e.preventDefault()
195
+ e.stopPropagation()
196
+ onOpenChange(false)
197
+ }
198
+ // Capture phase: ahead of any window listener the host already has.
199
+ document.addEventListener('keydown', onEscape, true)
200
+ return () => document.removeEventListener('keydown', onEscape, true)
201
+ }, [open, onOpenChange])
202
+
203
+ // Keep the highlighted row in view when arrowing past the fold.
204
+ React.useEffect(() => {
205
+ if (!open) return
206
+ const el = listRef.current?.querySelector<HTMLElement>(`[data-index="${cursor}"]`)
207
+ el?.scrollIntoView({ block: "nearest" })
208
+ }, [cursor, open])
209
+
210
+ if (!open) return null
211
+
212
+ const step = (delta: number) => {
213
+ if (selectable.length === 0) return
214
+ const at = selectable.indexOf(cursor)
215
+ const next = at === -1 ? 0 : (at + delta + selectable.length) % selectable.length
216
+ setCursor(selectable[next])
217
+ }
218
+
219
+ const run = (item: CommandPaletteItem | undefined) => {
220
+ if (!item || item.disabled === true) return
221
+ // Close FIRST. A command that opens a dialog of its own would otherwise
222
+ // find this one still mounted and fighting it for focus.
223
+ if (item.keepOpen !== true) onOpenChange(false)
224
+ item.onSelect()
225
+ if (item.keepOpen === true) inputRef.current?.focus()
226
+ }
227
+
228
+ const onKeyDown = (e: React.KeyboardEvent) => {
229
+ if (e.key === "ArrowDown") {
230
+ e.preventDefault()
231
+ step(1)
232
+ return
233
+ }
234
+ if (e.key === "ArrowUp") {
235
+ e.preventDefault()
236
+ step(-1)
237
+ return
238
+ }
239
+ if (e.key === "Enter") {
240
+ e.preventDefault()
241
+ run(shown[cursor])
242
+ return
243
+ }
244
+ if (e.key === "Tab" && !e.shiftKey) {
245
+ const item = shown[cursor]
246
+ if (item?.onComplete !== undefined && item.disabled !== true) {
247
+ e.preventDefault()
248
+ item.onComplete()
249
+ inputRef.current?.focus()
250
+ }
251
+ return
252
+ }
253
+ if (e.key === "Home" || e.key === "End") {
254
+ if (selectable.length === 0 || query !== "") return
255
+ e.preventDefault()
256
+ setCursor(e.key === "Home" ? selectable[0] : selectable[selectable.length - 1])
257
+ return
258
+ }
259
+ if (
260
+ slashKey &&
261
+ query === "" &&
262
+ e.code === "Slash" &&
263
+ e.key !== "/" &&
264
+ !e.ctrlKey &&
265
+ !e.metaKey &&
266
+ !e.altKey
267
+ ) {
268
+ e.preventDefault()
269
+ setQuery("/")
270
+ return
271
+ }
272
+ if (e.key === "Escape") {
273
+ e.preventDefault()
274
+ onOpenChange(false)
275
+ }
276
+ // Everything else falls through to the input, including "/" — a palette
277
+ // you cannot type a slash into would be unable to search for anything
278
+ // named with one.
279
+ }
280
+
281
+ let lastGroup: string | undefined
282
+
283
+ return (
284
+ <div
285
+ className="fixed inset-0 z-50 flex items-start justify-center bg-foreground/30 px-4 pt-[12vh]"
286
+ // A backdrop click closes, matching every other dismissible surface. The
287
+ // dialog itself stops propagation below.
288
+ onMouseDown={() => onOpenChange(false)}
289
+ data-testid="command-palette-backdrop"
290
+ >
291
+ <div
292
+ role="dialog"
293
+ aria-modal="true"
294
+ aria-label={label}
295
+ className="w-full max-w-xl overflow-hidden rounded-2xl border border-border bg-popover text-popover-foreground shadow-float"
296
+ onMouseDown={(e) => e.stopPropagation()}
297
+ onKeyDown={onKeyDown}
298
+ data-testid="command-palette"
299
+ >
300
+ <div className="flex items-center gap-2 border-b border-border px-4">
301
+ {mode !== undefined && (
302
+ <span
303
+ className="shrink-0 rounded-md bg-primary-tint px-2 py-0.5 text-xs font-medium text-primary-tint-foreground"
304
+ data-testid="command-palette-mode"
305
+ >
306
+ {mode}
307
+ </span>
308
+ )}
309
+ <input
310
+ ref={inputRef}
311
+ value={query}
312
+ onChange={(e) => setQuery(e.target.value)}
313
+ placeholder={placeholder}
314
+ aria-label={label}
315
+ role="combobox"
316
+ aria-expanded
317
+ aria-controls="command-palette-list"
318
+ aria-activedescendant={shown[cursor] ? `command-item-${shown[cursor].id}` : undefined}
319
+ className="min-w-0 flex-1 bg-transparent py-3.5 text-base outline-none placeholder:text-muted-foreground"
320
+ data-testid="command-palette-input"
321
+ />
322
+ </div>
323
+ {countLabel !== undefined && (
324
+ <span className="sr-only" aria-live="polite" data-testid="command-palette-count">
325
+ {countLabel(selectable.length)}
326
+ </span>
327
+ )}
328
+
329
+ <div
330
+ ref={listRef}
331
+ id="command-palette-list"
332
+ role="listbox"
333
+ aria-label={label}
334
+ className="max-h-80 overflow-y-auto p-1"
335
+ >
336
+ {shown.length === 0 && (
337
+ <p className="px-3 py-6 text-center text-sm text-muted-foreground" data-testid="command-palette-empty">
338
+ {emptyLabel}
339
+ </p>
340
+ )}
341
+
342
+ {shown.map((item, index) => {
343
+ const header = item.group !== undefined && item.group !== lastGroup ? item.group : null
344
+ lastGroup = item.group
345
+
346
+ return (
347
+ <React.Fragment key={item.id}>
348
+ {header !== null && (
349
+ <div className="px-3 pt-3 pb-1 text-[0.8125rem] font-medium text-muted-foreground">
350
+ {header}
351
+ </div>
352
+ )}
353
+ <div
354
+ id={`command-item-${item.id}`}
355
+ role="option"
356
+ aria-selected={index === cursor}
357
+ aria-disabled={item.disabled === true}
358
+ data-index={index}
359
+ data-testid={`command-item-${item.id}`}
360
+ onMouseEnter={() => item.disabled !== true && setCursor(index)}
361
+ onClick={() => run(item)}
362
+ className={cn(
363
+ "flex cursor-pointer items-center gap-2 rounded-md px-3 py-2 text-sm",
364
+ // The selected row is the tint with text in the main colour (7.3).
365
+ index === cursor && item.disabled !== true && "bg-primary-tint text-primary-tint-foreground",
366
+ item.agent === true && "border border-dashed border-input",
367
+ item.disabled === true && "cursor-not-allowed opacity-45"
368
+ )}
369
+ >
370
+ {item.icon !== undefined && <span className="shrink-0 text-muted-foreground">{item.icon}</span>}
371
+ <span className="min-w-0 flex-1 truncate">
372
+ {item.label}
373
+ {item.hint !== undefined && (
374
+ <span className="ms-2 text-[0.8125rem] text-muted-foreground">{item.hint}</span>
375
+ )}
376
+ </span>
377
+ {item.shortcut !== undefined && (
378
+ <span className="shrink-0 text-xs text-muted-foreground">{item.shortcut}</span>
379
+ )}
380
+ </div>
381
+ </React.Fragment>
382
+ )
383
+ })}
384
+ </div>
385
+ {footer !== undefined && (
386
+ <div className="flex gap-4 border-t border-border px-4 py-2 text-[0.8125rem] text-muted-foreground">
387
+ <span><kbd className="me-1 rounded border border-border px-1 font-mono text-xs">↑↓</kbd>{footer.move}</span>
388
+ <span><kbd className="me-1 rounded border border-border px-1 font-mono text-xs">Enter</kbd>{footer.open}</span>
389
+ {footer.complete !== undefined && (
390
+ <span><kbd className="me-1 rounded border border-border px-1 font-mono text-xs">Tab</kbd>{footer.complete}</span>
391
+ )}
392
+ <span><kbd className="me-1 rounded border border-border px-1 font-mono text-xs">Esc</kbd>{footer.close}</span>
393
+ </div>
394
+ )}
395
+ </div>
396
+ </div>
397
+ )
398
+ }
@@ -0,0 +1,98 @@
1
+ import * as React from "react"
2
+
3
+ import {
4
+ AlertDialog,
5
+ AlertDialogCancel,
6
+ AlertDialogContent,
7
+ AlertDialogDescription,
8
+ AlertDialogFooter,
9
+ AlertDialogHeader,
10
+ AlertDialogTitle,
11
+ } from "./alert-dialog"
12
+ import { Button } from "./button"
13
+ import { Input } from "./input"
14
+
15
+ /**
16
+ * Confirming by how undoable an action is (docs/design/components/PatternConfirm, P.4).
17
+ *
18
+ * Tier 1, undoable, needs no dialog: act at once and show an Undo toast.
19
+ * Tier 2, hard to undo: this dialog, with the question as its title and the
20
+ * consequence as its text. Tier 3, security-sensitive or irreversible: the same
21
+ * with `typeToConfirm`, and the button stays disabled until the text matches.
22
+ *
23
+ * The confirm button repeats the verb ("Delete role"), never "OK" or "Yes".
24
+ */
25
+ export interface ConfirmActionProps {
26
+ open: boolean
27
+ onOpenChange: (open: boolean) => void
28
+ /** The question: "Delete the Branch manager role?" */
29
+ title: string
30
+ /** The consequence for people and data. */
31
+ description: React.ReactNode
32
+ /** The verb: "Delete role". */
33
+ confirmLabel: string
34
+ cancelLabel: string
35
+ onConfirm: () => void | Promise<void>
36
+ /** Tier 3: the name or email to type, and the label that asks for it. */
37
+ typeToConfirm?: { value: string; label: string }
38
+ /** Destructive unless the action only changes who can do what. */
39
+ variant?: "destructive" | "default"
40
+ }
41
+
42
+ function ConfirmAction({
43
+ open,
44
+ onOpenChange,
45
+ title,
46
+ description,
47
+ confirmLabel,
48
+ cancelLabel,
49
+ onConfirm,
50
+ typeToConfirm,
51
+ variant = "destructive",
52
+ }: ConfirmActionProps) {
53
+ const [typed, setTyped] = React.useState("")
54
+ const [busy, setBusy] = React.useState(false)
55
+
56
+ React.useEffect(() => {
57
+ if (open) setTyped("")
58
+ }, [open])
59
+
60
+ const matches = typeToConfirm === undefined || typed.trim() === typeToConfirm.value
61
+
62
+ const confirm = async () => {
63
+ setBusy(true)
64
+ try {
65
+ await onConfirm()
66
+ onOpenChange(false)
67
+ } finally {
68
+ setBusy(false)
69
+ }
70
+ }
71
+
72
+ return (
73
+ <AlertDialog open={open} onOpenChange={onOpenChange}>
74
+ <AlertDialogContent>
75
+ <AlertDialogHeader>
76
+ <AlertDialogTitle>{title}</AlertDialogTitle>
77
+ <AlertDialogDescription>{description}</AlertDialogDescription>
78
+ </AlertDialogHeader>
79
+ {typeToConfirm && (
80
+ <Input
81
+ label={typeToConfirm.label}
82
+ value={typed}
83
+ autoComplete="off"
84
+ onChange={(event) => setTyped(event.target.value)}
85
+ />
86
+ )}
87
+ <AlertDialogFooter>
88
+ <AlertDialogCancel>{cancelLabel}</AlertDialogCancel>
89
+ <Button type="button" variant={variant} disabled={!matches} loading={busy} onClick={confirm}>
90
+ {confirmLabel}
91
+ </Button>
92
+ </AlertDialogFooter>
93
+ </AlertDialogContent>
94
+ </AlertDialog>
95
+ )
96
+ }
97
+
98
+ export { ConfirmAction }
@@ -0,0 +1,38 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite"
2
+
3
+ import { CopyBlock } from "./copy-block"
4
+
5
+ const meta = {
6
+ title: "Primitives/CopyBlock",
7
+ component: CopyBlock,
8
+ tags: ["autodocs"],
9
+ } satisfies Meta<typeof CopyBlock>
10
+
11
+ export default meta
12
+ type Story = StoryObj<typeof meta>
13
+
14
+ export const Command: Story = {
15
+ args: {
16
+ value: 'claude mcp add --transport http whity "https://api.example.com/mcp" --header "Authorization: Bearer eyJ…"',
17
+ },
18
+ }
19
+
20
+ export const File: Story = {
21
+ args: {
22
+ caption: "~/.cursor/mcp.json",
23
+ multiline: true,
24
+ value: JSON.stringify(
25
+ { mcpServers: { whity: { url: "https://api.example.com/mcp", headers: { Authorization: "Bearer eyJ…" } } } },
26
+ null,
27
+ 2
28
+ ),
29
+ },
30
+ }
31
+
32
+ export const MaskedSecret: Story = {
33
+ args: {
34
+ caption: "Token",
35
+ value: "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJ4In0.signature",
36
+ display: "eyJhbGci••••••••••••",
37
+ },
38
+ }
@@ -0,0 +1,85 @@
1
+ import * as React from "react"
2
+ import { IconCheck, IconCopy } from "@tabler/icons-react"
3
+
4
+ import { Button } from "./button"
5
+ import { cn } from "./utils"
6
+
7
+ export interface CopyBlockProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onCopy"> {
8
+ /** The exact text copied, and shown unless `display` is given. */
9
+ value: string
10
+ /** What to show instead of `value` — a masked secret, say. The copy is still `value`. */
11
+ display?: string
12
+ /** A caption above the block: a file path, a field name. */
13
+ caption?: React.ReactNode
14
+ /** Render as a multi-line code block (a command or file) rather than one line. */
15
+ multiline?: boolean
16
+ copyLabel?: string
17
+ copiedLabel?: string
18
+ /** Called after a copy attempt, so the consumer can toast. */
19
+ onCopy?: (copied: boolean) => void
20
+ }
21
+
22
+ /**
23
+ * Text the user is meant to copy somewhere else — a command, a config file, a
24
+ * token — with a copy button.
25
+ *
26
+ * Shown as code: left-to-right and monospaced even in an RTL layout, because
27
+ * the text is read by a program, not a person.
28
+ */
29
+ export function CopyBlock({
30
+ value,
31
+ display,
32
+ caption,
33
+ multiline = false,
34
+ copyLabel = "Copy",
35
+ copiedLabel = "Copied",
36
+ onCopy,
37
+ className,
38
+ ...props
39
+ }: CopyBlockProps) {
40
+ const [copied, setCopied] = React.useState(false)
41
+
42
+ React.useEffect(() => {
43
+ if (!copied) return
44
+ const timer = setTimeout(() => setCopied(false), 2000)
45
+ return () => clearTimeout(timer)
46
+ }, [copied])
47
+
48
+ const copy = async () => {
49
+ try {
50
+ await navigator.clipboard.writeText(value)
51
+ setCopied(true)
52
+ onCopy?.(true)
53
+ } catch {
54
+ onCopy?.(false)
55
+ }
56
+ }
57
+
58
+ return (
59
+ <div data-slot="copy-block" className={cn("space-y-1", className)} {...props}>
60
+ {caption !== undefined && <div className="text-xs font-medium text-muted-foreground">{caption}</div>}
61
+ <div className="relative rounded-md border border-border bg-muted">
62
+ <pre
63
+ dir="ltr"
64
+ className={cn(
65
+ "overflow-x-auto py-2 ps-3 pe-12 text-start font-mono text-xs text-foreground",
66
+ multiline ? "whitespace-pre" : "whitespace-nowrap"
67
+ )}
68
+ >
69
+ <code>{display ?? value}</code>
70
+ </pre>
71
+ <Button
72
+ type="button"
73
+ variant="ghost"
74
+ size="icon-sm"
75
+ onClick={copy}
76
+ aria-label={copied ? copiedLabel : copyLabel}
77
+ title={copied ? copiedLabel : copyLabel}
78
+ className="absolute end-1.5 top-1.5"
79
+ >
80
+ {copied ? <IconCheck size={14} /> : <IconCopy size={14} />}
81
+ </Button>
82
+ </div>
83
+ </div>
84
+ )
85
+ }