@oaiz/app-kit 0.0.0-stage → 0.1.4128

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 +143 -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,403 @@
1
+ import {
2
+ useEffect,
3
+ useRef,
4
+ useState,
5
+ type ReactNode,
6
+ type RefObject,
7
+ } from 'react';
8
+ import { Command, defaultFilter } from 'cmdk';
9
+ import { ChevronRight, Search } from 'lucide-react';
10
+
11
+ import { cn } from '../lib/utils';
12
+ import {
13
+ Dialog,
14
+ DialogContent,
15
+ DialogDescription,
16
+ DialogTitle,
17
+ } from './ui/dialog';
18
+ import { Text } from './ui/text';
19
+
20
+ export type CommandPaletteItem = {
21
+ id: string;
22
+ label: string;
23
+ /** More words that find the item, such as a record's other fields. */
24
+ keywords?: string[];
25
+ icon?: ReactNode;
26
+ /** The key that runs it outside the palette, shown at the right, such as "C". */
27
+ shortcut?: string;
28
+ /** Muted text after the label, such as a record's type or domain. */
29
+ hint?: ReactNode;
30
+ /** Shown in the preview pane while the item is active; the pane appears when any item has one. */
31
+ preview?: ReactNode;
32
+ /** Runs the item and closes the palette. */
33
+ onSelect?: () => void;
34
+ /** Opens a page of these items instead, such as "Change status…" → each status. */
35
+ items?: CommandPaletteItem[];
36
+ };
37
+
38
+ export type CommandPaletteGroup = {
39
+ heading: string;
40
+ items: CommandPaletteItem[];
41
+ /** The caller read these items for the search text, so the palette shows them without matching again. */
42
+ searched?: boolean;
43
+ };
44
+
45
+ export type CommandPaletteProps = {
46
+ open: boolean;
47
+ onOpenChange: (open: boolean) => void;
48
+ groups: CommandPaletteGroup[];
49
+ placeholder?: string;
50
+ empty?: ReactNode;
51
+ /** What the actions act on, shown above the search, such as the focused issue. */
52
+ context?: ReactNode;
53
+ /** Reports the search text, so the caller can read matching records from OAIZ. */
54
+ onSearchChange?: (search: string) => void;
55
+ labels?: Partial<{
56
+ title: string;
57
+ description: string;
58
+ more: string;
59
+ preview: string;
60
+ noPreview: string;
61
+ navigate: string;
62
+ open: string;
63
+ run: string;
64
+ back: string;
65
+ close: string;
66
+ }>;
67
+ };
68
+
69
+ /**
70
+ * True while the reader types in a field or a dialog or menu is open, where single-key shortcuts
71
+ * must not fire.
72
+ */
73
+ function typing(target: EventTarget | null): boolean {
74
+ if (
75
+ document.querySelector(
76
+ '[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"]',
77
+ )
78
+ ) {
79
+ return true;
80
+ }
81
+ if (!(target instanceof HTMLElement)) return false;
82
+ return (
83
+ target.isContentEditable ||
84
+ ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName)
85
+ );
86
+ }
87
+
88
+ /**
89
+ * Calls `handler` when `key` is pressed anywhere on the page. With `mod`, it needs ⌘ on macOS or
90
+ * Ctrl elsewhere. Character shortcuts need focus inside `scope`; without a scope they require Alt.
91
+ * Composition, handled keys, text fields and open overlays keep their own input.
92
+ */
93
+ export function useHotkey(
94
+ key: string,
95
+ handler: () => void,
96
+ options: {
97
+ mod?: boolean;
98
+ enabled?: boolean;
99
+ scope?: RefObject<HTMLElement | null>;
100
+ } = {},
101
+ ) {
102
+ const latest = useRef(handler);
103
+ latest.current = handler;
104
+ const mod = options.mod ?? false;
105
+ const enabled = options.enabled ?? true;
106
+ const scope = options.scope;
107
+ useEffect(() => {
108
+ if (!enabled) return;
109
+ function onKeyDown(event: KeyboardEvent) {
110
+ if (
111
+ event.defaultPrevented ||
112
+ event.isComposing ||
113
+ event.key.toLowerCase() !== key.toLowerCase()
114
+ )
115
+ return;
116
+ const pressed = event.metaKey || event.ctrlKey;
117
+ if (mod) {
118
+ if (!pressed || event.altKey) return;
119
+ } else {
120
+ if (pressed || typing(event.target)) return;
121
+ if (scope) {
122
+ if (
123
+ event.altKey ||
124
+ !(event.target instanceof Node) ||
125
+ !scope.current?.contains(event.target)
126
+ )
127
+ return;
128
+ } else if (key.length === 1 && !event.altKey) return;
129
+ }
130
+ event.preventDefault();
131
+ latest.current();
132
+ }
133
+ document.addEventListener('keydown', onKeyDown);
134
+ return () => document.removeEventListener('keydown', onKeyDown);
135
+ }, [key, mod, enabled, scope]);
136
+ }
137
+
138
+ /**
139
+ * A searchable list of actions and records in a dialog, as ⌘K opens. Arrow
140
+ * keys move and Enter runs the item. An item with `items` opens a page of them; Backspace in an
141
+ * empty search goes back. While searching, page items also match, as "Change status › Done".
142
+ * Open it with `useHotkey('k', …, { mod: true })`.
143
+ */
144
+ export function CommandPalette({
145
+ open,
146
+ onOpenChange,
147
+ groups,
148
+ placeholder = 'Type a command or search…',
149
+ empty = 'No results.',
150
+ context,
151
+ onSearchChange,
152
+ labels,
153
+ }: CommandPaletteProps) {
154
+ const [pages, setPages] = useState<CommandPaletteItem[]>([]);
155
+ const [search, setSearch] = useState('');
156
+ const [active, setActive] = useState('');
157
+ const page = pages[pages.length - 1];
158
+ const searchListener = useRef(onSearchChange);
159
+ searchListener.current = onSearchChange;
160
+ const changeSearch = (next: string) => {
161
+ setSearch(next);
162
+ searchListener.current?.(next);
163
+ };
164
+
165
+ // Each opening starts on the first page with an empty search, however the palette was closed.
166
+ useEffect(() => {
167
+ if (!open) {
168
+ setPages([]);
169
+ setSearch('');
170
+ searchListener.current?.('');
171
+ }
172
+ }, [open]);
173
+
174
+ function run(item: CommandPaletteItem) {
175
+ if (item.items) {
176
+ setPages((current) => [...current, item]);
177
+ changeSearch('');
178
+ return;
179
+ }
180
+ onOpenChange(false);
181
+ item.onSelect?.();
182
+ }
183
+
184
+ const shown: CommandPaletteGroup[] = page
185
+ ? [{ heading: page.label.replace(/…$/, ''), items: page.items ?? [] }]
186
+ : groups;
187
+ // While searching the first page, the items of every page match too.
188
+ const nested: CommandPaletteItem[] =
189
+ !page && search.trim() !== ''
190
+ ? groups.flatMap((group) =>
191
+ group.items.flatMap((parent) =>
192
+ (parent.items ?? []).map((child) => ({
193
+ ...child,
194
+ id: `${parent.id}/${child.id}`,
195
+ label: `${parent.label.replace(/…$/, '')} › ${child.label}`,
196
+ })),
197
+ ),
198
+ )
199
+ : [];
200
+ const all = [...shown.flatMap((group) => group.items), ...nested];
201
+ const activeItem = all.find((item) => valueOf(item) === active);
202
+ const withPreview = all.some((item) => item.preview !== undefined);
203
+
204
+ return (
205
+ <Dialog open={open} onOpenChange={onOpenChange}>
206
+ <DialogContent
207
+ showCloseButton={false}
208
+ overlayClassName="bg-black/20"
209
+ className={cn(
210
+ // A phone docks it at the top, so the keyboard opens below the results.
211
+ 'top-[15%] translate-y-0 gap-0 overflow-hidden p-0 max-mobile:top-0',
212
+ withPreview ? 'max-w-3xl' : 'max-w-xl',
213
+ )}
214
+ >
215
+ <DialogTitle className="sr-only">
216
+ {labels?.title ?? 'Command palette'}
217
+ </DialogTitle>
218
+ <DialogDescription className="sr-only">
219
+ {labels?.description ??
220
+ 'Search for an action or a record, then press Enter.'}
221
+ </DialogDescription>
222
+ <Command
223
+ label={labels?.title ?? 'Command palette'}
224
+ filter={score}
225
+ value={active}
226
+ onValueChange={setActive}
227
+ className="flex flex-col"
228
+ onKeyDown={(event) => {
229
+ if (event.key === 'Backspace' && search === '' && page) {
230
+ event.preventDefault();
231
+ setPages((current) => current.slice(0, -1));
232
+ }
233
+ }}
234
+ >
235
+ {context && !page && (
236
+ <div className="px-inset pt-inset">
237
+ <span className="inline-flex max-w-full items-center gap-1 truncate rounded-md bg-muted px-2 py-1 text-xs text-muted-foreground">
238
+ {context}
239
+ </span>
240
+ </div>
241
+ )}
242
+ <div className="flex items-center gap-inline border-b px-stack">
243
+ <Search
244
+ aria-hidden="true"
245
+ className="size-4 shrink-0 text-muted-foreground"
246
+ />
247
+ {page && (
248
+ <span className="shrink-0 rounded-sm bg-muted px-1.5 py-0.5 text-xs text-muted-foreground">
249
+ {page.label.replace(/…$/, '')}
250
+ </span>
251
+ )}
252
+ <Command.Input
253
+ autoFocus
254
+ value={search}
255
+ onValueChange={changeSearch}
256
+ placeholder={
257
+ page ? `${page.label.replace(/…$/, '')}…` : placeholder
258
+ }
259
+ // 16px text on a phone keeps iOS from zooming into the field.
260
+ className="h-12 w-full bg-transparent text-base outline-none placeholder:text-muted-foreground mobile:text-sm"
261
+ />
262
+ </div>
263
+ <div className="flex min-h-0">
264
+ <Command.List className="max-h-96 min-w-0 flex-1 overflow-y-auto p-inline">
265
+ <Command.Empty className="py-section text-center text-sm text-muted-foreground">
266
+ <div role="option" aria-disabled="true" aria-selected="false">
267
+ {empty}
268
+ </div>
269
+ </Command.Empty>
270
+ {shown.map((group) => (
271
+ <Command.Group
272
+ key={group.heading}
273
+ heading={group.heading}
274
+ className={GROUP}
275
+ >
276
+ {group.items.map((item) => (
277
+ <Item
278
+ key={item.id}
279
+ item={item}
280
+ onRun={run}
281
+ searched={group.searched}
282
+ />
283
+ ))}
284
+ </Command.Group>
285
+ ))}
286
+ {nested.length > 0 && (
287
+ <Command.Group
288
+ heading={labels?.more ?? 'More actions'}
289
+ className={GROUP}
290
+ >
291
+ {nested.map((item) => (
292
+ <Item key={item.id} item={item} onRun={run} />
293
+ ))}
294
+ </Command.Group>
295
+ )}
296
+ </Command.List>
297
+ {withPreview && (
298
+ <aside
299
+ aria-label={labels?.preview ?? 'Preview'}
300
+ className="hidden w-72 shrink-0 overflow-y-auto border-l p-stack text-sm mobile:block"
301
+ >
302
+ {activeItem?.preview ?? (
303
+ <span className="text-muted-foreground">
304
+ {labels?.noPreview ?? 'No preview'}
305
+ </span>
306
+ )}
307
+ </aside>
308
+ )}
309
+ </div>
310
+ <footer className="flex items-center gap-stack border-t px-stack py-2 text-xs text-muted-foreground pointer-coarse:hidden">
311
+ <span className="flex items-center gap-1">
312
+ <Key>↑</Key>
313
+ <Key>↓</Key>
314
+ {labels?.navigate ?? 'Navigate'}
315
+ </span>
316
+ <span className="flex items-center gap-1">
317
+ <Key>↵</Key>
318
+ {activeItem?.items
319
+ ? (labels?.open ?? 'Open')
320
+ : (labels?.run ?? 'Run')}
321
+ </span>
322
+ {page && (
323
+ <span className="flex items-center gap-1">
324
+ <Key>⌫</Key>
325
+ {labels?.back ?? 'Back'}
326
+ </span>
327
+ )}
328
+ <span className="ml-auto flex items-center gap-1">
329
+ <Key>Esc</Key>
330
+ {labels?.close ?? 'Close'}
331
+ </span>
332
+ </footer>
333
+ </Command>
334
+ </DialogContent>
335
+ </Dialog>
336
+ );
337
+ }
338
+
339
+ const GROUP =
340
+ '[&_[cmdk-group-heading]]:px-inline [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground';
341
+
342
+ const valueOf = (item: CommandPaletteItem) => `${item.label} ${item.id}`;
343
+
344
+ const SEARCHED = 'oaiz:searched';
345
+
346
+ /** Ranks items by the search text, and never hides an item of a group the caller searched. */
347
+ function score(value: string, search: string, keywords: string[] = []): number {
348
+ const words = keywords.filter((word) => word !== SEARCHED);
349
+ const match = defaultFilter(value, search, words);
350
+ return words.length === keywords.length ? match : Math.max(match, 0.01);
351
+ }
352
+
353
+ function Key({ children }: { children: ReactNode }) {
354
+ return (
355
+ <kbd className="inline-flex h-5 min-w-5 items-center justify-center rounded-sm bg-muted px-1 font-sans text-xs text-muted-foreground">
356
+ {children}
357
+ </kbd>
358
+ );
359
+ }
360
+
361
+ function Item({
362
+ item,
363
+ onRun,
364
+ searched,
365
+ }: {
366
+ item: CommandPaletteItem;
367
+ onRun: (item: CommandPaletteItem) => void;
368
+ searched?: boolean;
369
+ }) {
370
+ return (
371
+ <Command.Item
372
+ value={valueOf(item)}
373
+ keywords={searched ? [...(item.keywords ?? []), SEARCHED] : item.keywords}
374
+ onSelect={() => onRun(item)}
375
+ className="flex h-9 cursor-pointer items-center gap-inline rounded-sm px-inline text-sm text-foreground max-mobile:h-11 data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground"
376
+ >
377
+ {item.icon && (
378
+ <span className="flex size-4 shrink-0 items-center justify-center text-muted-foreground [&_svg]:size-4">
379
+ {item.icon}
380
+ </span>
381
+ )}
382
+ <span className="min-w-0 truncate">{item.label}</span>
383
+ {item.hint && (
384
+ <Text as="span" size="xs" variant="muted" className="min-w-0 truncate">
385
+ {item.hint}
386
+ </Text>
387
+ )}
388
+ <span className="ml-auto flex shrink-0 items-center gap-1">
389
+ {item.shortcut && (
390
+ <kbd className="rounded-sm border bg-muted px-1.5 font-mono text-xs text-muted-foreground pointer-coarse:hidden">
391
+ {item.shortcut}
392
+ </kbd>
393
+ )}
394
+ {item.items && (
395
+ <ChevronRight
396
+ aria-hidden="true"
397
+ className="size-3.5 text-muted-foreground"
398
+ />
399
+ )}
400
+ </span>
401
+ </Command.Item>
402
+ );
403
+ }
@@ -0,0 +1,123 @@
1
+ import { useRef, useState, type ReactNode } from 'react';
2
+ import { Alert, AlertDescription } from './ui/alert';
3
+ import {
4
+ AlertDialog,
5
+ AlertDialogCancel,
6
+ AlertDialogContent,
7
+ AlertDialogDescription,
8
+ AlertDialogFooter,
9
+ AlertDialogHeader,
10
+ AlertDialogTitle,
11
+ AlertDialogTrigger,
12
+ } from './ui/alert-dialog';
13
+ import { Button } from './ui/button';
14
+
15
+ export type ConfirmActionProps = {
16
+ title: ReactNode;
17
+ description: ReactNode;
18
+ confirmLabel: string;
19
+ cancelLabel?: string;
20
+ pendingLabel?: string;
21
+ errorLabel?: string;
22
+ onConfirm: () => unknown;
23
+ /** Supply a button element; controlled consumers can instead pass open/onOpenChange. */
24
+ trigger?: ReactNode;
25
+ open?: boolean;
26
+ onOpenChange?: (open: boolean) => void;
27
+ destructive?: boolean;
28
+ };
29
+
30
+ export function ConfirmAction({
31
+ title,
32
+ description,
33
+ confirmLabel,
34
+ cancelLabel = 'Cancel',
35
+ pendingLabel = 'Working…',
36
+ errorLabel = 'The action failed. Try again.',
37
+ onConfirm,
38
+ trigger,
39
+ open: controlledOpen,
40
+ onOpenChange,
41
+ destructive = false,
42
+ }: ConfirmActionProps) {
43
+ const [internalOpen, setInternalOpen] = useState(false);
44
+ const [pending, setPending] = useState(false);
45
+ const [error, setError] = useState<string | null>(null);
46
+ const inFlight = useRef(false);
47
+ const origin = useRef<HTMLElement | null>(null);
48
+ const open = controlledOpen ?? internalOpen;
49
+ function changeOpen(next: boolean) {
50
+ if (inFlight.current) return;
51
+ setInternalOpen(next);
52
+ setError(null);
53
+ onOpenChange?.(next);
54
+ }
55
+ async function confirm() {
56
+ if (inFlight.current) return;
57
+ inFlight.current = true;
58
+ setPending(true);
59
+ setError(null);
60
+ try {
61
+ await onConfirm();
62
+ inFlight.current = false;
63
+ changeOpen(false);
64
+ } catch (failure) {
65
+ setError(failure instanceof Error ? failure.message : errorLabel);
66
+ } finally {
67
+ inFlight.current = false;
68
+ setPending(false);
69
+ }
70
+ }
71
+ return (
72
+ <AlertDialog open={open} onOpenChange={changeOpen}>
73
+ {trigger && <AlertDialogTrigger asChild>{trigger}</AlertDialogTrigger>}
74
+ <AlertDialogContent
75
+ onOpenAutoFocus={() => {
76
+ origin.current =
77
+ document.activeElement instanceof HTMLElement
78
+ ? document.activeElement
79
+ : null;
80
+ }}
81
+ onCloseAutoFocus={(event) => {
82
+ if (
83
+ !trigger &&
84
+ origin.current?.isConnected &&
85
+ origin.current !== document.body
86
+ ) {
87
+ event.preventDefault();
88
+ origin.current.focus();
89
+ }
90
+ }}
91
+ aria-busy={pending}
92
+ onEscapeKeyDown={(event) => {
93
+ if (inFlight.current) event.preventDefault();
94
+ }}
95
+ >
96
+ <AlertDialogHeader>
97
+ <AlertDialogTitle>{title}</AlertDialogTitle>
98
+ <AlertDialogDescription>{description}</AlertDialogDescription>
99
+ </AlertDialogHeader>
100
+ {error && (
101
+ <Alert variant="destructive">
102
+ <AlertDescription>{error}</AlertDescription>
103
+ </Alert>
104
+ )}
105
+ <AlertDialogFooter>
106
+ <AlertDialogCancel asChild>
107
+ <Button type="button" variant="outline" disabled={pending}>
108
+ {cancelLabel}
109
+ </Button>
110
+ </AlertDialogCancel>
111
+ <Button
112
+ type="button"
113
+ variant={destructive ? 'destructive' : 'default'}
114
+ disabled={pending}
115
+ onClick={() => void confirm()}
116
+ >
117
+ {pending ? pendingLabel : confirmLabel}
118
+ </Button>
119
+ </AlertDialogFooter>
120
+ </AlertDialogContent>
121
+ </AlertDialog>
122
+ );
123
+ }