@oaiz/app-kit 0.0.0-stage → 0.1.4130

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 (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +149 -2
  3. package/THIRD_PARTY_NOTICES.md +76 -0
  4. package/package.json +139 -4
  5. package/registry.json +1847 -0
  6. package/src/components/activity-timeline.tsx +227 -0
  7. package/src/components/app-shell.tsx +622 -0
  8. package/src/components/bar-list.tsx +47 -0
  9. package/src/components/board.tsx +700 -0
  10. package/src/components/calendar-view.tsx +1388 -0
  11. package/src/components/card-grid.tsx +462 -0
  12. package/src/components/charts.tsx +701 -0
  13. package/src/components/chat-markdown.tsx +230 -0
  14. package/src/components/chat-panel.tsx +760 -0
  15. package/src/components/code-editor.tsx +276 -0
  16. package/src/components/collection-controls.tsx +226 -0
  17. package/src/components/command-palette.tsx +403 -0
  18. package/src/components/confirm-action.tsx +123 -0
  19. package/src/components/data-table.tsx +821 -0
  20. package/src/components/date-input.tsx +429 -0
  21. package/src/components/empty-state.tsx +31 -0
  22. package/src/components/error-state.tsx +37 -0
  23. package/src/components/file-upload.tsx +595 -0
  24. package/src/components/filter-bar.tsx +415 -0
  25. package/src/components/grouped-picker.tsx +250 -0
  26. package/src/components/line-items.tsx +601 -0
  27. package/src/components/list-view.tsx +491 -0
  28. package/src/components/metrics.tsx +53 -0
  29. package/src/components/page-header.tsx +33 -0
  30. package/src/components/property-picker.tsx +546 -0
  31. package/src/components/record-detail.tsx +416 -0
  32. package/src/components/record-form.tsx +295 -0
  33. package/src/components/record-name.tsx +85 -0
  34. package/src/components/save-bar.tsx +142 -0
  35. package/src/components/sign-in.tsx +179 -0
  36. package/src/components/split-view.tsx +128 -0
  37. package/src/components/status-dot.tsx +56 -0
  38. package/src/components/stepper.tsx +153 -0
  39. package/src/components/text-diff-model.ts +111 -0
  40. package/src/components/text-diff.tsx +98 -0
  41. package/src/components/time-zone-picker.tsx +69 -0
  42. package/src/components/ui/accordion.tsx +138 -0
  43. package/src/components/ui/alert-dialog.tsx +67 -0
  44. package/src/components/ui/alert.tsx +65 -0
  45. package/src/components/ui/avatar-group.tsx +119 -0
  46. package/src/components/ui/avatar.tsx +55 -0
  47. package/src/components/ui/badge.tsx +59 -0
  48. package/src/components/ui/bottom-navigation.tsx +102 -0
  49. package/src/components/ui/breadcrumb.tsx +117 -0
  50. package/src/components/ui/button.tsx +71 -0
  51. package/src/components/ui/card.tsx +95 -0
  52. package/src/components/ui/checkbox.tsx +31 -0
  53. package/src/components/ui/collapsible.tsx +27 -0
  54. package/src/components/ui/context-menu.tsx +270 -0
  55. package/src/components/ui/count-up.tsx +136 -0
  56. package/src/components/ui/detail-disclosure-section.tsx +109 -0
  57. package/src/components/ui/dialog.tsx +157 -0
  58. package/src/components/ui/dropdown-menu.tsx +273 -0
  59. package/src/components/ui/form-field.tsx +155 -0
  60. package/src/components/ui/heading.tsx +126 -0
  61. package/src/components/ui/hover-card.tsx +45 -0
  62. package/src/components/ui/input.tsx +50 -0
  63. package/src/components/ui/label.tsx +30 -0
  64. package/src/components/ui/orb-spinner.tsx +238 -0
  65. package/src/components/ui/popover.tsx +59 -0
  66. package/src/components/ui/progress-ring.tsx +125 -0
  67. package/src/components/ui/progress.tsx +38 -0
  68. package/src/components/ui/radio-group.tsx +124 -0
  69. package/src/components/ui/resizable.tsx +48 -0
  70. package/src/components/ui/scroll-fade.tsx +98 -0
  71. package/src/components/ui/segmented-control.tsx +70 -0
  72. package/src/components/ui/select.tsx +230 -0
  73. package/src/components/ui/separator.tsx +29 -0
  74. package/src/components/ui/sheet.tsx +170 -0
  75. package/src/components/ui/shimmer-text.tsx +87 -0
  76. package/src/components/ui/shortcut.tsx +39 -0
  77. package/src/components/ui/skeleton.tsx +15 -0
  78. package/src/components/ui/slider.tsx +48 -0
  79. package/src/components/ui/switch.tsx +44 -0
  80. package/src/components/ui/table.tsx +119 -0
  81. package/src/components/ui/tabs.tsx +80 -0
  82. package/src/components/ui/text.tsx +93 -0
  83. package/src/components/ui/textarea.tsx +51 -0
  84. package/src/components/ui/toast.tsx +141 -0
  85. package/src/components/ui/toaster.tsx +40 -0
  86. package/src/components/ui/tooltip.tsx +38 -0
  87. package/src/components/ui/top-banner.tsx +108 -0
  88. package/src/components/ui/tree-view.tsx +215 -0
  89. package/src/components/ui/use-toast.tsx +184 -0
  90. package/src/components/ui/voice-orb.tsx +252 -0
  91. package/src/hooks/oaiz-chat.tsx +530 -0
  92. package/src/hooks/oaiz-data.tsx +617 -0
  93. package/src/hooks/oaiz-session.tsx +63 -0
  94. package/src/hooks/use-arrivals.ts +19 -0
  95. package/src/hooks/use-breakpoint.ts +100 -0
  96. package/src/hooks/use-media-query.ts +36 -0
  97. package/src/hooks/use-theme.ts +67 -0
  98. package/src/hooks/use-url-state.ts +77 -0
  99. package/src/lib/breakpoints.ts +81 -0
  100. package/src/lib/csp-nonce.ts +15 -0
  101. package/src/lib/format.ts +291 -0
  102. package/src/lib/speech-level.ts +118 -0
  103. package/src/lib/utils.ts +109 -0
  104. package/src/styles/oaiz/app.css +21 -0
  105. package/src/styles/oaiz/scrollbars.css +20 -0
  106. package/src/styles/oaiz/tokens.css +952 -0
  107. package/src/styles/oaiz/voice-orb.css +39 -0
@@ -0,0 +1,491 @@
1
+ import { Button } from './ui/button';
2
+ import {
3
+ useEffect,
4
+ useId,
5
+ useRef,
6
+ useState,
7
+ type KeyboardEvent,
8
+ type ReactNode,
9
+ } from 'react';
10
+ import { ChevronDown, Plus } from 'lucide-react';
11
+
12
+ import { ARRIVAL_CLASS, useArrivals } from '../hooks/use-arrivals';
13
+ import { cn } from '../lib/utils';
14
+ import { ErrorState } from './error-state';
15
+ import { Checkbox } from './ui/checkbox';
16
+ import { Collapsible, CollapsibleContent, CollapsibleTrigger } from './ui/collapsible';
17
+ import {
18
+ ContextMenu,
19
+ ContextMenuContent,
20
+ ContextMenuTrigger,
21
+ } from './ui/context-menu';
22
+ import { Skeleton } from './ui/skeleton';
23
+ import { Text } from './ui/text';
24
+
25
+ export type ListKey = string | number;
26
+
27
+ export type ListGroup<Row> = {
28
+ key: string;
29
+ title: ReactNode;
30
+ icon?: ReactNode;
31
+ rows: Row[];
32
+ };
33
+
34
+ export type ListViewProps<Row> = {
35
+ /** Rows in groups, such as issues by status; one group without a title for a flat list. */
36
+ groups: ListGroup<Row>[];
37
+ rowKey: (row: Row) => ListKey;
38
+ /** The row's accessible name, such as "OPS-12 Fix the login redirect". */
39
+ rowLabel: (row: Row) => string;
40
+ /** The row's cells after the checkbox. */
41
+ renderRow: (row: Row) => ReactNode;
42
+ /** Selected rows; a checkbox appears on each row when `onSelectedChange` is set. */
43
+ selected?: ReadonlySet<ListKey>;
44
+ onSelectedChange?: (selected: Set<ListKey>) => void;
45
+ /** Opens a row: a click, or Enter on the focused row. */
46
+ onOpen?: (row: Row) => void;
47
+ rowHref?: (row: Row) => string;
48
+ onRetry?: () => void;
49
+ labels?: {
50
+ select?: (name: string) => string;
51
+ open?: (name: string) => string;
52
+ expand?: string;
53
+ collapse?: string;
54
+ add?: (group: string) => string;
55
+ retry?: string;
56
+ retrying?: string;
57
+ };
58
+ /** All row content can be expanded without clipping, including on touch screens. */
59
+ fullRow?: (row: Row) => ReactNode;
60
+ /** The open row's key, such as the record shown beside the list; it is marked as current. */
61
+ openKey?: ListKey | null;
62
+ /** Reports the focused row, so page hotkeys such as S for status act on it. */
63
+ onFocusedChange?: (row: Row | null) => void;
64
+ /** Adds a row to a group; each group header shows a + button. */
65
+ onAddToGroup?: (groupKey: string) => void;
66
+ /** Menu items for a right-click on a row, such as `DropdownMenuItem`s. */
67
+ rowMenu?: (row: Row) => ReactNode;
68
+ /** Shown when no group has rows. */
69
+ empty: ReactNode;
70
+ loading?: boolean;
71
+ error?: { message: string } | null;
72
+ /** Opt in to Alt+J/K/X outside the list. Unmodified shortcuts stay inside the focused list. */
73
+ pageHotkeys?: boolean;
74
+ };
75
+
76
+ function typingOrOverlay(target: EventTarget | null): boolean {
77
+ if (
78
+ document.querySelector('[role="dialog"], [role="menu"], [role="listbox"]')
79
+ ) {
80
+ return true;
81
+ }
82
+ if (!(target instanceof HTMLElement)) return false;
83
+ return (
84
+ target.isContentEditable ||
85
+ ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName)
86
+ );
87
+ }
88
+
89
+ /**
90
+ * A dense, grouped list in the style of Linear. J and K (or the arrow keys) move the focus, X
91
+ * selects the focused row, Enter opens it, and a right-click opens `rowMenu`. Group headers
92
+ * collapse and show their count.
93
+ */
94
+ export function ListView<Row>({
95
+ groups,
96
+ rowKey,
97
+ rowLabel,
98
+ renderRow,
99
+ selected,
100
+ onSelectedChange,
101
+ onOpen,
102
+ rowHref,
103
+ fullRow,
104
+ onRetry,
105
+ labels,
106
+ openKey,
107
+ onFocusedChange,
108
+ onAddToGroup,
109
+ rowMenu,
110
+ empty,
111
+ loading = false,
112
+ error,
113
+ pageHotkeys = false,
114
+ }: ListViewProps<Row>) {
115
+ const listId = useId();
116
+ const [collapsed, setCollapsed] = useState<Set<string>>(new Set());
117
+ const [focused, setFocused] = useState<ListKey | null>(null);
118
+ const rowRefs = useRef(new Map<ListKey, HTMLDivElement>());
119
+ const chosen = selected ?? new Set<ListKey>();
120
+ const selectable = onSelectedChange !== undefined;
121
+
122
+ const visible = groups.flatMap((group) =>
123
+ collapsed.has(group.key) ? [] : group.rows,
124
+ );
125
+ const keys = visible.map(rowKey);
126
+ const activeKey =
127
+ focused !== null && keys.includes(focused) ? focused : (keys[0] ?? null);
128
+ // Rows that load or arrive later ease in; the rows already shown stay put.
129
+ const arrived = useArrivals(keys);
130
+ const byKey = new Map(visible.map((row) => [rowKey(row), row]));
131
+
132
+ // Keep the reported focus true when the focused row leaves the list.
133
+ const focusedRow = focused === null ? undefined : byKey.get(focused);
134
+ const lastReported = useRef<ListKey | null>(null);
135
+ useEffect(() => {
136
+ const key = focusedRow === undefined ? null : rowKey(focusedRow);
137
+ if (key !== lastReported.current) {
138
+ lastReported.current = key;
139
+ onFocusedChange?.(focusedRow ?? null);
140
+ }
141
+ });
142
+
143
+ function focusKey(key: ListKey) {
144
+ setFocused(key);
145
+ const row = rowRefs.current.get(key);
146
+ const control =
147
+ row?.querySelector<HTMLElement>('[data-row-open]') ??
148
+ row?.querySelector<HTMLElement>('button, a, input');
149
+ (control ?? row)?.focus();
150
+ }
151
+
152
+ function toggle(key: ListKey) {
153
+ const next = new Set(chosen);
154
+ if (next.has(key)) next.delete(key);
155
+ else next.add(key);
156
+ onSelectedChange?.(next);
157
+ }
158
+
159
+ function handleKey(key: string, preventDefault: () => void): boolean {
160
+ if (keys.length === 0) return false;
161
+ const index = focused === null ? -1 : keys.indexOf(focused);
162
+ if (key === 'j' || key === 'ArrowDown') {
163
+ preventDefault();
164
+ focusKey(keys[Math.min(index + 1, keys.length - 1)]!);
165
+ return true;
166
+ }
167
+ if (key === 'k' || key === 'ArrowUp') {
168
+ preventDefault();
169
+ focusKey(keys[Math.max(index - 1, 0)]!);
170
+ return true;
171
+ }
172
+ if (focused === null || index === -1) return false;
173
+ if (key === 'x' && selectable) {
174
+ preventDefault();
175
+ toggle(focused);
176
+ return true;
177
+ }
178
+ if (key === 'Enter' && onOpen) {
179
+ preventDefault();
180
+ onOpen(byKey.get(focused)!);
181
+ return true;
182
+ }
183
+ return false;
184
+ }
185
+
186
+ const handleKeyRef = useRef(handleKey);
187
+ handleKeyRef.current = handleKey;
188
+ useEffect(() => {
189
+ if (!pageHotkeys) return;
190
+ function onKeyDown(event: globalThis.KeyboardEvent) {
191
+ if (
192
+ event.defaultPrevented ||
193
+ event.isComposing ||
194
+ event.metaKey ||
195
+ event.ctrlKey ||
196
+ !event.altKey
197
+ )
198
+ return;
199
+ if (typingOrOverlay(event.target)) return;
200
+ // A focused control outside the list, such as a button or tabs, keeps Enter and the arrows.
201
+ if (
202
+ ['Enter', 'ArrowDown', 'ArrowUp'].includes(event.key) &&
203
+ event.target instanceof Element &&
204
+ event.target !== document.body &&
205
+ !document.getElementById(listId)?.contains(event.target)
206
+ ) {
207
+ return;
208
+ }
209
+ // Keys inside the list are handled on the list itself.
210
+ if (
211
+ event.target instanceof Node &&
212
+ document.getElementById(listId)?.contains(event.target)
213
+ ) {
214
+ return;
215
+ }
216
+ handleKeyRef.current(event.key, () => event.preventDefault());
217
+ }
218
+ document.addEventListener('keydown', onKeyDown);
219
+ return () => document.removeEventListener('keydown', onKeyDown);
220
+ }, [pageHotkeys, listId]);
221
+
222
+ if (error) {
223
+ return (
224
+ <ErrorState
225
+ error={error}
226
+ onRetry={onRetry}
227
+ retrying={loading}
228
+ labels={labels}
229
+ />
230
+ );
231
+ }
232
+
233
+ const total = groups.reduce((sum, group) => sum + group.rows.length, 0);
234
+
235
+ return (
236
+ <div
237
+ id={listId}
238
+ aria-busy={loading}
239
+ data-testid="list-view"
240
+ className="flex flex-col text-sm"
241
+ onKeyDown={(event: KeyboardEvent<HTMLDivElement>) => {
242
+ if (!event.currentTarget.contains(event.target as Node)) return;
243
+ if (
244
+ event.defaultPrevented ||
245
+ event.nativeEvent.isComposing ||
246
+ event.metaKey ||
247
+ event.ctrlKey ||
248
+ event.altKey
249
+ )
250
+ return;
251
+ // A control inside a row, such as a property picker, keeps its own keys.
252
+ if (
253
+ event.target instanceof HTMLElement &&
254
+ event.target.closest(
255
+ 'input, textarea, select, [contenteditable=true], button:not([data-row-open]), a:not([data-row-open])',
256
+ )
257
+ ) {
258
+ return;
259
+ }
260
+ if (event.key !== 'Enter')
261
+ handleKey(event.key, () => event.preventDefault());
262
+ }}
263
+ >
264
+ {loading ? (
265
+ Array.from({ length: 6 }, (_, index) => (
266
+ <div
267
+ key={index}
268
+ className="flex h-10 items-center gap-inline px-page"
269
+ >
270
+ <Skeleton className="h-4 w-16" />
271
+ <Skeleton className="h-4 flex-1" />
272
+ </div>
273
+ ))
274
+ ) : total === 0 ? (
275
+ typeof empty === 'string' ? (
276
+ <Text
277
+ size="sm"
278
+ variant="muted"
279
+ className="px-page py-section text-center"
280
+ >
281
+ {empty}
282
+ </Text>
283
+ ) : (
284
+ empty
285
+ )
286
+ ) : (
287
+ groups.map((group) => {
288
+ if (group.rows.length === 0) return null;
289
+ const isCollapsed = collapsed.has(group.key);
290
+ const titleId = `${listId}-${group.key}`;
291
+ return (
292
+ <section
293
+ key={group.key}
294
+ aria-labelledby={group.title ? titleId : undefined}
295
+ data-testid="list-group"
296
+ >
297
+ {group.title !== undefined && group.title !== '' && (
298
+ <header className="sticky top-0 z-10 flex h-9 items-center gap-inline bg-muted/70 px-page backdrop-blur-sm">
299
+ <Button variant="plain" size={null}
300
+ type="button"
301
+ aria-expanded={!isCollapsed}
302
+ aria-label={
303
+ isCollapsed
304
+ ? (labels?.expand ?? 'Expand group')
305
+ : (labels?.collapse ?? 'Collapse group')
306
+ }
307
+ className="-ml-1 flex size-6 items-center justify-center rounded-sm text-muted-foreground hover:bg-accent"
308
+ onClick={() =>
309
+ setCollapsed((current) => {
310
+ const next = new Set(current);
311
+ if (next.has(group.key)) next.delete(group.key);
312
+ else next.add(group.key);
313
+ return next;
314
+ })
315
+ }
316
+ >
317
+ <ChevronDown
318
+ className={cn(
319
+ 'size-3.5 transition-transform duration-fast',
320
+ isCollapsed && '-rotate-90',
321
+ )}
322
+ />
323
+ </Button>
324
+ {group.icon && (
325
+ <span aria-hidden="true" className="flex [&_svg]:size-4">
326
+ {group.icon}
327
+ </span>
328
+ )}
329
+ <span id={titleId} className="font-medium text-foreground">
330
+ {group.title}
331
+ </span>
332
+ <span className="tabular-nums text-muted-foreground">
333
+ {group.rows.length}
334
+ </span>
335
+ {onAddToGroup && (
336
+ <Button variant="plain" size={null}
337
+ type="button"
338
+ aria-label={
339
+ labels?.add?.(
340
+ typeof group.title === 'string'
341
+ ? group.title
342
+ : group.key,
343
+ ) ??
344
+ `Add to ${typeof group.title === 'string' ? group.title : group.key}`
345
+ }
346
+ className="ml-auto flex size-6 items-center justify-center rounded-sm text-muted-foreground hover:bg-accent hover:text-foreground"
347
+ onClick={() => onAddToGroup(group.key)}
348
+ >
349
+ <Plus className="size-3.5" />
350
+ </Button>
351
+ )}
352
+ </header>
353
+ )}
354
+ {!isCollapsed && (
355
+ <ul>
356
+ {group.rows.map((row) => {
357
+ const key = rowKey(row);
358
+ const isChosen = chosen.has(key);
359
+ const isFocused = activeKey === key;
360
+ const isOpen =
361
+ openKey !== undefined &&
362
+ openKey !== null &&
363
+ openKey === key;
364
+ const line = (
365
+ <div
366
+ ref={(node) => {
367
+ if (node) rowRefs.current.set(key, node);
368
+ else rowRefs.current.delete(key);
369
+ }}
370
+ data-list-row=""
371
+ data-testid="list-row"
372
+ data-focused={isFocused || undefined}
373
+ data-state={isChosen ? 'selected' : undefined}
374
+ tabIndex={-1}
375
+ data-open={isOpen || undefined}
376
+ aria-current={isOpen || undefined}
377
+ className={cn(
378
+ 'group/row flex h-11 cursor-default items-center gap-inline border-b border-border/60 px-page outline-none transition-colors duration-fast',
379
+ onOpen && 'cursor-pointer',
380
+ 'hover:bg-muted/60 data-[focused]:bg-muted data-[state=selected]:bg-accent/60',
381
+ 'relative before:absolute before:inset-y-0 before:left-0 before:w-0.5 data-[open]:bg-accent data-[open]:before:bg-primary',
382
+ )}
383
+ onFocus={() => setFocused(key)}
384
+ onClick={(event) => {
385
+ if (
386
+ !event.currentTarget.contains(event.target as Node)
387
+ )
388
+ return;
389
+ if (
390
+ (event.target as Element).closest(
391
+ 'button, a, input, select, textarea, summary, [contenteditable="true"]',
392
+ )
393
+ )
394
+ return;
395
+ setFocused(key);
396
+ if (!rowHref) onOpen?.(row);
397
+ }}
398
+ >
399
+ {selectable && (
400
+ <span
401
+ className="flex w-5 shrink-0 justify-center"
402
+ onClick={(event) => event.stopPropagation()}
403
+ >
404
+ <Checkbox
405
+ aria-label={
406
+ labels?.select?.(rowLabel(row)) ??
407
+ `Select ${rowLabel(row)}`
408
+ }
409
+ checked={isChosen}
410
+ onCheckedChange={() => toggle(key)}
411
+ />
412
+ </span>
413
+ )}
414
+ {renderRow(row)}
415
+ {rowHref ? (
416
+ <a
417
+ data-row-open=""
418
+ href={rowHref(row)}
419
+ aria-label={
420
+ labels?.open?.(rowLabel(row)) ??
421
+ `Open ${rowLabel(row)}`
422
+ }
423
+ className="ml-auto flex min-h-6 min-w-6 shrink-0 items-center justify-center rounded-sm underline focus-visible:ring-2 focus-visible:ring-ring"
424
+ >
425
+ ↗
426
+ </a>
427
+ ) : onOpen ? (
428
+ <Button variant="plain" size={null}
429
+ type="button"
430
+ data-row-open=""
431
+ onClick={() => onOpen(row)}
432
+ aria-label={
433
+ labels?.open?.(rowLabel(row)) ??
434
+ `Open ${rowLabel(row)}`
435
+ }
436
+ className="ml-auto flex min-h-6 min-w-6 shrink-0 items-center justify-center rounded-sm underline focus-visible:ring-2 focus-visible:ring-ring"
437
+ >
438
+ ↗
439
+ </Button>
440
+ ) : null}
441
+ {fullRow && (
442
+ <Collapsible
443
+ className="relative"
444
+ onClick={(event) => event.stopPropagation()}
445
+ >
446
+ <CollapsibleTrigger asChild>
447
+ <Button
448
+ variant="plain"
449
+ size={null}
450
+ className="min-h-6 min-w-6"
451
+ aria-label={rowLabel(row)}
452
+ >
453
+ …
454
+ </Button>
455
+ </CollapsibleTrigger>
456
+ <CollapsibleContent className="absolute right-0 z-20 w-72 max-w-[80vw] whitespace-normal break-words rounded-md border bg-popover p-inset text-popover-foreground shadow-md">
457
+ {fullRow(row)}
458
+ </CollapsibleContent>
459
+ </Collapsible>
460
+ )}
461
+ </div>
462
+ );
463
+ return (
464
+ <li
465
+ key={key}
466
+ className={arrived(key) ? ARRIVAL_CLASS : undefined}
467
+ >
468
+ {rowMenu ? (
469
+ <ContextMenu>
470
+ <ContextMenuTrigger asChild>
471
+ {line}
472
+ </ContextMenuTrigger>
473
+ <ContextMenuContent className="w-56">
474
+ {rowMenu(row)}
475
+ </ContextMenuContent>
476
+ </ContextMenu>
477
+ ) : (
478
+ line
479
+ )}
480
+ </li>
481
+ );
482
+ })}
483
+ </ul>
484
+ )}
485
+ </section>
486
+ );
487
+ })
488
+ )}
489
+ </div>
490
+ );
491
+ }
@@ -0,0 +1,53 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ import { CountUp } from './ui/count-up';
4
+ import { Skeleton } from './ui/skeleton';
5
+ import { Text } from './ui/text';
6
+
7
+ export type Metric = {
8
+ label: ReactNode;
9
+ /** One short line of what the value counts. */
10
+ detail?: ReactNode;
11
+ } & (
12
+ | { value: ReactNode }
13
+ /** A number that counts to each new value, written by `format`, such as `formatCurrency`. */
14
+ | { amount: number; format?: (value: number) => string }
15
+ );
16
+
17
+ const plain = (value: number) => new Intl.NumberFormat().format(value);
18
+
19
+ export type MetricsProps = {
20
+ items: Metric[];
21
+ loading?: boolean;
22
+ };
23
+
24
+ /** The figures that head a screen, as one compact row: two to a line on a phone. */
25
+ export function Metrics({ items, loading = false }: MetricsProps) {
26
+ return (
27
+ <dl aria-busy={loading} className="flex flex-wrap gap-x-section gap-y-stack max-mobile:grid max-mobile:grid-cols-2">
28
+ {items.map((item, index) => (
29
+ <div key={index} className="flex min-w-0 flex-col gap-0.5">
30
+ <Text asChild size="sm" variant="muted">
31
+ <dt className="truncate">{item.label}</dt>
32
+ </Text>
33
+ <Text asChild size="lg" weight="semibold">
34
+ <dd className="truncate tabular-nums">
35
+ {loading ? (
36
+ <Skeleton className="my-1 h-5 w-16" />
37
+ ) : 'amount' in item ? (
38
+ <CountUp value={item.amount} format={item.format ?? plain} />
39
+ ) : (
40
+ item.value
41
+ )}
42
+ </dd>
43
+ </Text>
44
+ {item.detail !== undefined && (
45
+ <Text asChild size="xs" variant="muted">
46
+ <dd className="truncate">{item.detail}</dd>
47
+ </Text>
48
+ )}
49
+ </div>
50
+ ))}
51
+ </dl>
52
+ );
53
+ }
@@ -0,0 +1,33 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ import { cn } from '../lib/utils';
4
+ import { Heading } from './ui/heading';
5
+ import { Text } from './ui/text';
6
+
7
+ export type PageHeaderProps = {
8
+ title: ReactNode;
9
+ /** One muted line under the title, such as how many records there are. */
10
+ summary?: ReactNode;
11
+ /** The page's primary action, an `sm` button. Other actions go in a menu. */
12
+ action?: ReactNode;
13
+ className?: string;
14
+ };
15
+
16
+ /** The top of a page that leaves `title` off `AppShell`: one title, its summary and one action. */
17
+ export function PageHeader({ title, summary, action, className }: PageHeaderProps) {
18
+ return (
19
+ <header className={cn('flex items-start justify-between gap-stack px-page pb-stack pt-section', className)}>
20
+ <div className="flex min-w-0 flex-col gap-1">
21
+ <Heading level={1} size="md" className="truncate">
22
+ {title}
23
+ </Heading>
24
+ {summary && (
25
+ <Text size="sm" variant="muted">
26
+ {summary}
27
+ </Text>
28
+ )}
29
+ </div>
30
+ {action && <div className="flex shrink-0 items-center gap-inline">{action}</div>}
31
+ </header>
32
+ );
33
+ }