@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,821 @@
1
+ import {
2
+ useEffect,
3
+ useId,
4
+ useState,
5
+ type CSSProperties,
6
+ type ReactNode,
7
+ } from 'react';
8
+ import { ArrowDown, ArrowUp, ArrowUpDown } from 'lucide-react';
9
+
10
+ import { cn } from '../lib/utils';
11
+ import { ErrorState } from './error-state';
12
+ import {
13
+ Pager,
14
+ SortControl,
15
+ type CollectionPage,
16
+ type PagerLabels,
17
+ } from './collection-controls';
18
+ import { Popover, PopoverContent, PopoverTrigger } from './ui/popover';
19
+ import { Label } from './ui/label';
20
+ import { Button } from './ui/button';
21
+ import {
22
+ DropdownMenu,
23
+ DropdownMenuTrigger,
24
+ DropdownMenuContent,
25
+ DropdownMenuCheckboxItem,
26
+ } from './ui/dropdown-menu';
27
+ import { Checkbox } from './ui/checkbox';
28
+ import { Skeleton } from './ui/skeleton';
29
+ import {
30
+ Table,
31
+ TableBody,
32
+ TableCaption,
33
+ TableCell,
34
+ TableHead,
35
+ TableHeader,
36
+ TableFooter,
37
+ TableRow,
38
+ } from './ui/table';
39
+
40
+ export type DataTableColumn<Row> = {
41
+ key: string;
42
+ header: ReactNode;
43
+ /** Shown before the header, such as an icon for the column's type. */
44
+ icon?: ReactNode;
45
+ cell: (row: Row) => ReactNode;
46
+ /** The column the query sorts by when this header is clicked; the header is not sortable without it. */
47
+ sortKey?: string;
48
+ /** `number`: right-aligned tabular digits. */
49
+ align?: 'number';
50
+ className?: string;
51
+ /** Full text for a value that the cell truncates; exposed in a keyboard/touch disclosure. */
52
+ fullText?: (row: Row) => string;
53
+ /** Text label for a header rendered as an icon or other React content. */
54
+ label?: string;
55
+ /** Fill remaining space or keep short metadata/actions at their intrinsic width. */
56
+ layout?: 'fill' | 'content';
57
+ /** False keeps a column visible; the record title also stays visible. */
58
+ hideable?: boolean;
59
+ };
60
+
61
+ export type DataTableSort = { column: string; ascending: boolean };
62
+
63
+ export type DataTablePage = CollectionPage;
64
+
65
+ export type RowKeyValue = string | number;
66
+
67
+ export type DataTableProps<Row> = {
68
+ columns: DataTableColumn<Row>[];
69
+ rows: Row[] | undefined;
70
+ rowKey: (row: Row) => RowKeyValue;
71
+ /** Shown in one full-width cell when there are no rows. */
72
+ empty: ReactNode;
73
+ /** Rows on the table stay while new ones load; with no rows, a skeleton appears after a short wait. */
74
+ loading?: boolean;
75
+ /** Shown instead of the table. */
76
+ error?: { message: string } | null;
77
+ caption?: ReactNode;
78
+ /** The sort the rows are in; sortable headers show it and ask for the next one. */
79
+ sort?: DataTableSort | null;
80
+ onSortChange?: (sort: DataTableSort) => void;
81
+ /** The keys of the selected rows; a checkbox column appears when `onSelectedChange` is set. */
82
+ selected?: ReadonlySet<RowKeyValue>;
83
+ onSelectedChange?: (selected: Set<RowKeyValue>) => void;
84
+ /** Opens a record from its explicit button or a click on non-interactive row content. */
85
+ onRowClick?: (row: Row) => void;
86
+ /** A real link for record navigation, including modified click and open in a new tab. */
87
+ rowHref?: (row: Row) => string;
88
+ rowLabel?: (row: Row) => string;
89
+ /** Which column names the record in the stacked layout. */
90
+ titleColumn?: string;
91
+ onRetry?: () => void;
92
+ labels?: Partial<PagerLabels> & {
93
+ selectPage?: string;
94
+ selectRow?: (name: string) => string;
95
+ open?: (name: string) => string;
96
+ fullValue?: (name: string) => string;
97
+ retry?: string;
98
+ retrying?: string;
99
+ sort?: string;
100
+ choose?: string;
101
+ ascending?: string;
102
+ descending?: string;
103
+ columns?: string;
104
+ scrollRegion?: string;
105
+ };
106
+ /** A footer with the range shown and previous and next buttons. */
107
+ page?: DataTablePage;
108
+ /**
109
+ * `grid`: cell borders, a compact header and a first column that stays in view on a horizontal
110
+ * scroll. `default`: rows with a line between them.
111
+ */
112
+ variant?: 'default' | 'grid';
113
+ density?: 'default' | 'compact' | 'dense';
114
+ pageGutter?: boolean;
115
+ /** Pins headings in the scroll owner; grid tables need fillHeight for vertical scrolling. */
116
+ stickyHeader?: boolean;
117
+ stickyHeaderTop?: string;
118
+ /** Fills a parent with a definite height; the table owns the scrolling pane. */
119
+ fillHeight?: boolean;
120
+ columnVisibility?: Readonly<Record<string, boolean>>;
121
+ onColumnVisibilityChange?: (visibility: Record<string, boolean>) => void;
122
+ /** A last row under the table, such as the number of rows. */
123
+ footer?: ReactNode;
124
+ };
125
+
126
+ const LOADING_ROWS = 3;
127
+ const SKELETON_DELAY_MS = 300;
128
+
129
+ /** True once `on` has held for `delay` ms, so a quick load shows no flash. */
130
+ function useAfterDelay(on: boolean, delay: number): boolean {
131
+ const [late, setLate] = useState(false);
132
+ useEffect(() => {
133
+ if (!on) {
134
+ setLate(false);
135
+ return;
136
+ }
137
+ const timer = setTimeout(() => setLate(true), delay);
138
+ return () => clearTimeout(timer);
139
+ }, [on, delay]);
140
+ return on && late;
141
+ }
142
+
143
+ function SortIcon({
144
+ direction,
145
+ }: {
146
+ direction: 'ascending' | 'descending' | 'none';
147
+ }) {
148
+ if (direction === 'ascending') return <ArrowUp className="size-3.5" />;
149
+ if (direction === 'descending') return <ArrowDown className="size-3.5" />;
150
+ return <ArrowUpDown className="size-3.5 opacity-50" />;
151
+ }
152
+
153
+ /**
154
+ * A table of rows, with its loading, empty and error states. Sorting and paging only report what
155
+ * the reader asked for: the caller reads that sort and page from OAIZ.
156
+ */
157
+ export function DataTable<Row>({
158
+ columns: allColumns,
159
+ rows,
160
+ rowKey,
161
+ empty,
162
+ loading = false,
163
+ error,
164
+ caption,
165
+ sort,
166
+ onSortChange,
167
+ selected,
168
+ onSelectedChange,
169
+ onRowClick,
170
+ rowHref,
171
+ rowLabel,
172
+ titleColumn,
173
+ onRetry,
174
+ labels,
175
+ page,
176
+ variant = 'default',
177
+ density,
178
+ pageGutter,
179
+ stickyHeader = true,
180
+ stickyHeaderTop = '0px',
181
+ fillHeight = false,
182
+ columnVisibility,
183
+ onColumnVisibilityChange,
184
+ footer,
185
+ }: DataTableProps<Row>) {
186
+ const tableId = useId();
187
+ const titleKey =
188
+ allColumns.find((column) => column.key === titleColumn)?.key ??
189
+ allColumns[0]?.key;
190
+ const canHide = (column: DataTableColumn<Row>) =>
191
+ column.key !== titleKey && column.hideable !== false;
192
+ const columns = allColumns.filter(
193
+ (column) => !canHide(column) || columnVisibility?.[column.key] !== false,
194
+ );
195
+ const columnName = (column: DataTableColumn<Row>) =>
196
+ column.label ??
197
+ (typeof column.header === 'string' && column.header
198
+ ? column.header
199
+ : column.key);
200
+ const columnLayout = (column: DataTableColumn<Row>) =>
201
+ column.layout === 'fill'
202
+ ? 'mobile:w-full mobile:max-w-0'
203
+ : column.layout === 'content'
204
+ ? 'mobile:w-px mobile:whitespace-nowrap'
205
+ : undefined;
206
+ const titleIndex = Math.max(
207
+ 0,
208
+ columns.findIndex((column) => column.key === titleColumn),
209
+ );
210
+ const noRows = rows === undefined || rows.length === 0;
211
+ const waiting = loading && noRows;
212
+ const showSkeleton = useAfterDelay(waiting, SKELETON_DELAY_MS);
213
+
214
+ if (error) {
215
+ return (
216
+ <ErrorState
217
+ error={error}
218
+ onRetry={onRetry}
219
+ retrying={loading}
220
+ labels={labels}
221
+ />
222
+ );
223
+ }
224
+
225
+ const selectable = onSelectedChange !== undefined;
226
+ const chosen = selected ?? new Set<RowKeyValue>();
227
+ const shownKeys = (rows ?? []).map(rowKey);
228
+ const chosenShown = shownKeys.filter((key) => chosen.has(key)).length;
229
+ const allChosen =
230
+ shownKeys.length > 0 && chosenShown === shownKeys.length
231
+ ? true
232
+ : chosenShown > 0
233
+ ? 'indeterminate'
234
+ : false;
235
+ const width = columns.length + (selectable ? 1 : 0);
236
+ const grid = variant === 'grid';
237
+ const rowDensity = density ?? (grid ? 'compact' : 'default');
238
+ const cellHeight =
239
+ rowDensity === 'dense'
240
+ ? 'h-9 py-1'
241
+ : rowDensity === 'compact'
242
+ ? 'h-11 py-inline'
243
+ : 'py-inset';
244
+ // The first and last cells meet the page gutter: a default table sits inside it, a grid fills the
245
+ // page edge to edge.
246
+ const edgeCell =
247
+ (pageGutter ?? grid)
248
+ ? grid
249
+ ? 'first:pl-page last:pr-page'
250
+ : 'mobile:first:pl-page mobile:last:pr-page'
251
+ : 'mobile:first:pl-0 mobile:last:pr-0';
252
+ const gridCheckboxWidth = 'w-[calc(var(--spacing-page)+1.75rem)]';
253
+ // Grid cells keep one line; a wide table scrolls sideways instead.
254
+ const gridCell =
255
+ grid && 'whitespace-nowrap border-r border-b last:border-r-0';
256
+ // On a phone the default variant stacks each row: the first column as its title, then the other
257
+ // columns as muted, aligned columns under it. A last column without a header, such as a row's menu,
258
+ // sits at the end of the title's line, and any other such column on its own line. The grid variant
259
+ // scrolls sideways instead.
260
+ const stackedTable = !grid && 'max-mobile:block';
261
+ const stackedHead = !grid && 'max-mobile:sr-only';
262
+ const stackedBody = !grid && 'max-mobile:block';
263
+ const stackedRow =
264
+ !grid &&
265
+ cn(
266
+ 'max-mobile:grid max-mobile:grid-cols-[var(--stacked-columns)] max-mobile:items-baseline max-mobile:gap-x-stack max-mobile:gap-y-0.5 max-mobile:py-inline',
267
+ pageGutter && 'max-mobile:px-page',
268
+ );
269
+ const stackedCell =
270
+ !grid &&
271
+ cn(
272
+ 'max-mobile:block max-mobile:h-auto max-mobile:min-w-0 max-mobile:break-words max-mobile:py-1',
273
+ pageGutter && 'max-mobile:px-0',
274
+ );
275
+ const stackedFullWidth = !grid && 'max-mobile:col-span-full';
276
+ const lastColumn = columns[columns.length - 1];
277
+ const stackedControls =
278
+ !grid &&
279
+ !selectable &&
280
+ columns.length > 1 &&
281
+ columns.length - 1 !== titleIndex &&
282
+ (typeof lastColumn?.header !== 'string' || !lastColumn.header)
283
+ ? columns.length - 1
284
+ : -1;
285
+ // A row's first figure sits beside its name, so the details below it stay in line. Controls take
286
+ // that place when the row has them.
287
+ const stackedFigure =
288
+ grid || selectable || stackedControls > 0
289
+ ? -1
290
+ : columns.findIndex(
291
+ (column, index) => index !== titleIndex && column.align === 'number',
292
+ );
293
+ const stackedDetails = Math.min(
294
+ 2,
295
+ Math.max(
296
+ 1,
297
+ columns.filter(
298
+ (column, index) =>
299
+ index !== titleIndex &&
300
+ index !== stackedFigure &&
301
+ typeof column.header === 'string' &&
302
+ column.header,
303
+ ).length,
304
+ ),
305
+ );
306
+ const stackedColumns = {
307
+ '--stacked-columns': [
308
+ 'minmax(0,1.6fr)',
309
+ ...Array<string>(stackedDetails - 1).fill('minmax(0,1fr)'),
310
+ ].join(' '),
311
+ } as CSSProperties;
312
+ const stackedDetail =
313
+ 'max-mobile:text-xs max-mobile:text-muted-foreground max-mobile:[&>span]:text-xs';
314
+ const stackedTitleWithFigure = 'max-mobile:row-start-1 max-mobile:pr-24';
315
+ const stackedFigureCell =
316
+ 'max-mobile:col-span-full max-mobile:row-start-1 max-mobile:justify-self-end max-mobile:text-sm';
317
+ const stackedControlsCell =
318
+ 'max-mobile:col-span-full max-mobile:row-start-1 max-mobile:justify-self-end max-mobile:self-start max-mobile:overflow-visible';
319
+ // The checkbox column and the first column stay in view on a horizontal scroll.
320
+ const stickyCell =
321
+ 'sticky z-10 bg-background group-hover/row:bg-[color-mix(in_srgb,var(--color-muted)_50%,var(--color-background))] group-data-[state=selected]/row:bg-muted';
322
+ const sticky = (index: number) =>
323
+ grid &&
324
+ index === 0 &&
325
+ cn(
326
+ stickyCell,
327
+ selectable ? 'left-[calc(var(--spacing-page)+1.75rem)]' : 'left-0',
328
+ );
329
+ const stickyCheckbox = grid && cn(stickyCell, 'left-0');
330
+
331
+ const toggle = (key: RowKeyValue, on: boolean) => {
332
+ const next = new Set(chosen);
333
+ if (on) next.add(key);
334
+ else next.delete(key);
335
+ onSelectedChange?.(next);
336
+ };
337
+ const toggleAll = (on: boolean) => {
338
+ const next = new Set(chosen);
339
+ for (const key of shownKeys) {
340
+ if (on) next.add(key);
341
+ else next.delete(key);
342
+ }
343
+ onSelectedChange?.(next);
344
+ };
345
+
346
+ return (
347
+ <div
348
+ className={cn(
349
+ 'flex min-w-0 flex-col gap-inline',
350
+ fillHeight && 'h-full min-h-0',
351
+ )}
352
+ style={stackedColumns}
353
+ >
354
+ {onColumnVisibilityChange && (
355
+ <div className="flex justify-end">
356
+ <DropdownMenu>
357
+ <DropdownMenuTrigger asChild>
358
+ <Button type="button" variant="outline" size="sm">
359
+ {labels?.columns ?? 'Columns'}
360
+ </Button>
361
+ </DropdownMenuTrigger>
362
+ <DropdownMenuContent
363
+ align="end"
364
+ aria-label={labels?.columns ?? 'Columns'}
365
+ >
366
+ {allColumns.map((column) => (
367
+ <DropdownMenuCheckboxItem
368
+ key={column.key}
369
+ checked={
370
+ !canHide(column) || columnVisibility?.[column.key] !== false
371
+ }
372
+ disabled={!canHide(column)}
373
+ onSelect={(event) => event.preventDefault()}
374
+ onCheckedChange={(checked) =>
375
+ onColumnVisibilityChange({
376
+ ...columnVisibility,
377
+ [column.key]: checked === true,
378
+ })
379
+ }
380
+ >
381
+ {columnName(column)}
382
+ </DropdownMenuCheckboxItem>
383
+ ))}
384
+ </DropdownMenuContent>
385
+ </DropdownMenu>
386
+ </div>
387
+ )}
388
+ {!grid && !noRows && (
389
+ <div
390
+ className={cn(
391
+ 'flex flex-wrap items-center gap-stack mobile:hidden',
392
+ pageGutter && 'px-page py-inline',
393
+ )}
394
+ >
395
+ {selectable && (
396
+ <Label className="flex items-center gap-inline">
397
+ <Checkbox
398
+ aria-label={
399
+ labels?.selectPage ?? 'Select all rows on this page'
400
+ }
401
+ checked={allChosen}
402
+ onCheckedChange={(state) => toggleAll(state === true)}
403
+ />
404
+ {labels?.selectPage ?? 'Select all rows on this page'}
405
+ </Label>
406
+ )}
407
+ {onSortChange && columns.some((column) => column.sortKey) && (
408
+ <SortControl
409
+ options={columns
410
+ .filter((column) => column.sortKey)
411
+ .map((column) => ({
412
+ value: column.sortKey!,
413
+ label:
414
+ column.label ??
415
+ (typeof column.header === 'string'
416
+ ? column.header
417
+ : column.key),
418
+ }))}
419
+ value={sort}
420
+ onChange={onSortChange}
421
+ labels={labels}
422
+ />
423
+ )}
424
+ </div>
425
+ )}
426
+ <div
427
+ role={fillHeight ? 'region' : 'group'}
428
+ aria-label={
429
+ labels?.scrollRegion ??
430
+ (typeof caption === 'string' ? caption : 'Table records')
431
+ }
432
+ tabIndex={0}
433
+ className={cn(
434
+ 'min-w-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
435
+ fillHeight || grid ? 'overflow-auto' : 'overflow-visible',
436
+ fillHeight && 'min-h-0 flex-1',
437
+ )}
438
+ >
439
+ <Table
440
+ containerClassName="overflow-visible"
441
+ aria-busy={loading}
442
+ data-testid="data-table"
443
+ data-variant={variant}
444
+ data-density={rowDensity}
445
+ className={cn(
446
+ grid && 'border-separate border-spacing-0',
447
+ stackedTable,
448
+ )}
449
+ >
450
+ {caption !== undefined && (
451
+ <TableCaption className="sr-only">{caption}</TableCaption>
452
+ )}
453
+ <TableHeader
454
+ className={cn(
455
+ stackedHead,
456
+ stickyHeader &&
457
+ (grid
458
+ ? 'sticky z-30 bg-background'
459
+ : 'mobile:sticky mobile:z-30 mobile:bg-background'),
460
+ noRows && !waiting && 'hidden',
461
+ )}
462
+ style={stickyHeader ? { top: stickyHeaderTop } : undefined}
463
+ >
464
+ <TableRow className={cn(grid && 'hover:bg-transparent')}>
465
+ {selectable && (
466
+ <TableHead
467
+ id={`${tableId}-selection`}
468
+ scope="col"
469
+ className={cn(
470
+ 'h-auto px-inset py-inline',
471
+ edgeCell,
472
+ grid
473
+ ? cn('z-20 border-b border-r', gridCheckboxWidth)
474
+ : 'w-10',
475
+ stickyCheckbox,
476
+ )}
477
+ >
478
+ {!grid && (
479
+ <span className="mobile:hidden">
480
+ {labels?.selectPage ?? 'Select all rows on this page'}
481
+ </span>
482
+ )}
483
+ <Checkbox
484
+ aria-label={
485
+ labels?.selectPage ?? 'Select all rows on this page'
486
+ }
487
+ className={!grid ? 'max-mobile:hidden' : undefined}
488
+ checked={allChosen}
489
+ disabled={shownKeys.length === 0}
490
+ onCheckedChange={(state) => toggleAll(state === true)}
491
+ />
492
+ </TableHead>
493
+ )}
494
+ {columns.map((column, index) => {
495
+ const direction =
496
+ sort && column.sortKey === sort.column
497
+ ? sort.ascending
498
+ ? 'ascending'
499
+ : 'descending'
500
+ : 'none';
501
+ return (
502
+ <TableHead
503
+ key={column.key}
504
+ id={`${tableId}-${column.key}`}
505
+ scope="col"
506
+ aria-label={column.label}
507
+ aria-sort={column.sortKey ? direction : undefined}
508
+ className={cn(
509
+ 'h-auto px-inset py-inline text-xs font-medium',
510
+ edgeCell,
511
+ grid &&
512
+ 'whitespace-nowrap border-b border-r last:border-r-0',
513
+ column.align === 'number' && 'text-right',
514
+ sticky(index),
515
+ grid && index === 0 && 'z-20',
516
+ columnLayout(column),
517
+ column.className,
518
+ )}
519
+ >
520
+ <span className="inline-flex items-center gap-1.5">
521
+ {!column.header && (
522
+ <span className="sr-only">
523
+ {column.label ?? column.key}
524
+ </span>
525
+ )}
526
+ {!grid && column.sortKey && onSortChange && (
527
+ <span className="mobile:hidden">{column.header}</span>
528
+ )}
529
+ {column.icon && (
530
+ <span
531
+ aria-hidden="true"
532
+ className="flex text-muted-foreground [&_svg]:size-3.5"
533
+ >
534
+ {column.icon}
535
+ </span>
536
+ )}
537
+ {column.sortKey && onSortChange ? (
538
+ <Button
539
+ variant="plain"
540
+ size="xs"
541
+ type="button"
542
+ aria-label={column.label}
543
+ className={cn(
544
+ !grid && 'max-mobile:hidden',
545
+ '-mx-1 h-auto min-h-6 gap-1 px-1 hover:text-foreground',
546
+ )}
547
+ onClick={() =>
548
+ onSortChange({
549
+ column: column.sortKey!,
550
+ ascending: direction !== 'ascending',
551
+ })
552
+ }
553
+ >
554
+ {column.header}
555
+ <SortIcon direction={direction} />
556
+ </Button>
557
+ ) : (
558
+ column.header
559
+ )}
560
+ </span>
561
+ </TableHead>
562
+ );
563
+ })}
564
+ </TableRow>
565
+ </TableHeader>
566
+ <TableBody className={cn(stackedBody)}>
567
+ {waiting ? (
568
+ showSkeleton &&
569
+ Array.from({ length: LOADING_ROWS }, (_, index) => (
570
+ <TableRow key={index} className={cn(stackedRow)}>
571
+ {Array.from({ length: width }, (_, cell) => (
572
+ <TableCell
573
+ key={cell}
574
+ className={cn(
575
+ cellHeight,
576
+ 'px-inset',
577
+ edgeCell,
578
+ gridCell,
579
+ stackedCell,
580
+ )}
581
+ >
582
+ <Skeleton className="h-4 w-full" />
583
+ </TableCell>
584
+ ))}
585
+ </TableRow>
586
+ ))
587
+ ) : noRows ? (
588
+ <TableRow className={cn(stackedRow)}>
589
+ <TableCell
590
+ colSpan={width}
591
+ className={cn(
592
+ cellHeight,
593
+ stackedCell,
594
+ stackedFullWidth,
595
+ 'px-inset text-center text-muted-foreground',
596
+ grid && 'border-b',
597
+ )}
598
+ >
599
+ {empty}
600
+ </TableCell>
601
+ </TableRow>
602
+ ) : (
603
+ rows!.map((row) => {
604
+ const key = rowKey(row);
605
+ const isChosen = chosen.has(key);
606
+ return (
607
+ <TableRow
608
+ key={key}
609
+ data-testid="data-table-row"
610
+ data-state={isChosen ? 'selected' : undefined}
611
+ className={cn(
612
+ 'group/row',
613
+ grid && 'border-0',
614
+ stackedRow,
615
+ onRowClick &&
616
+ 'cursor-pointer focus-visible:bg-muted focus-visible:outline-none',
617
+ )}
618
+ onClick={
619
+ onRowClick
620
+ ? (event) => {
621
+ if (
622
+ !event.currentTarget.contains(
623
+ event.target as Node,
624
+ )
625
+ )
626
+ return;
627
+ if (
628
+ (event.target as Element).closest(
629
+ 'button, a, input, select, textarea, [role="checkbox"], [contenteditable="true"]',
630
+ )
631
+ )
632
+ return;
633
+ onRowClick(row);
634
+ }
635
+ : undefined
636
+ }
637
+ >
638
+ {selectable && (
639
+ <TableCell
640
+ headers={`${tableId}-selection`}
641
+ className={cn(
642
+ cellHeight,
643
+ 'px-inset',
644
+ edgeCell,
645
+ grid ? gridCheckboxWidth : 'w-10',
646
+ gridCell,
647
+ stickyCheckbox,
648
+ stackedCell,
649
+ stackedFullWidth,
650
+ )}
651
+ onClick={(event) => event.stopPropagation()}
652
+ >
653
+ <Checkbox
654
+ className={!grid ? 'max-mobile:size-6' : undefined}
655
+ aria-label={
656
+ labels?.selectRow?.(
657
+ rowLabel?.(row) ?? String(key),
658
+ ) ?? `Select ${rowLabel?.(row) ?? String(key)}`
659
+ }
660
+ checked={isChosen}
661
+ onCheckedChange={(state) =>
662
+ toggle(key, state === true)
663
+ }
664
+ />
665
+ </TableCell>
666
+ )}
667
+ {columns.map((column, index) => (
668
+ <TableCell
669
+ key={column.key}
670
+ headers={`${tableId}-${column.key}`}
671
+ className={cn(
672
+ cellHeight,
673
+ 'px-inset',
674
+ edgeCell,
675
+ gridCell,
676
+ column.align === 'number' &&
677
+ 'text-right tabular-nums',
678
+ sticky(index),
679
+ stackedCell,
680
+ !grid &&
681
+ index === titleIndex &&
682
+ 'max-mobile:font-medium max-mobile:col-span-full max-mobile:-order-1',
683
+ (index === titleIndex ||
684
+ !column.header ||
685
+ typeof column.header !== 'string') &&
686
+ stackedFullWidth,
687
+ !grid &&
688
+ index !== titleIndex &&
689
+ index !== stackedFigure &&
690
+ stackedDetail,
691
+ index === titleIndex &&
692
+ (stackedFigure >= 0 || stackedControls >= 0) &&
693
+ stackedTitleWithFigure,
694
+ index === stackedFigure && stackedFigureCell,
695
+ index === stackedControls && stackedControlsCell,
696
+ columnLayout(column),
697
+ column.className,
698
+ !grid &&
699
+ column.align !== 'number' &&
700
+ 'max-mobile:text-left',
701
+ )}
702
+ >
703
+ {!grid && (column.label || column.header) && (
704
+ <span
705
+ aria-hidden="true"
706
+ className="block text-xs font-normal text-muted-foreground mobile:hidden"
707
+ >
708
+ {column.label ?? column.header}
709
+ </span>
710
+ )}
711
+ <div
712
+ className={
713
+ index === titleIndex && (rowHref || onRowClick)
714
+ ? 'flex min-w-0 items-center gap-2'
715
+ : 'contents'
716
+ }
717
+ >
718
+ <div
719
+ className={
720
+ index === titleIndex && (rowHref || onRowClick)
721
+ ? 'min-w-0 flex-1'
722
+ : 'contents'
723
+ }
724
+ >
725
+ {column.cell(row)}
726
+ </div>
727
+ {rowHref && index === titleIndex && (
728
+ <a
729
+ href={rowHref(row)}
730
+ aria-label={
731
+ labels?.open?.(
732
+ rowLabel?.(row) ?? String(key),
733
+ ) ?? `Open ${rowLabel?.(row) ?? String(key)}`
734
+ }
735
+ className="inline-flex shrink-0 min-h-6 min-w-6 items-center justify-center rounded-sm underline focus-visible:ring-2 focus-visible:ring-ring"
736
+ >
737
+ ↗
738
+ </a>
739
+ )}
740
+ {index === titleIndex && onRowClick && !rowHref && (
741
+ <Button
742
+ variant="plain"
743
+ size="icon-xs"
744
+ type="button"
745
+ className="shrink-0 min-h-6 min-w-6 rounded-sm px-1 text-xs underline focus-visible:ring-2 focus-visible:ring-ring"
746
+ onClick={() => onRowClick(row)}
747
+ aria-label={
748
+ labels?.open?.(
749
+ rowLabel?.(row) ?? String(key),
750
+ ) ?? `Open ${rowLabel?.(row) ?? String(key)}`
751
+ }
752
+ >
753
+ ↗
754
+ </Button>
755
+ )}
756
+ </div>
757
+ {column.fullText && (
758
+ <Popover>
759
+ <PopoverTrigger asChild>
760
+ <Button
761
+ variant="plain"
762
+ size="icon-xs"
763
+ type="button"
764
+ className="ml-1 min-h-6 min-w-6 rounded-sm text-xs underline"
765
+ aria-label={
766
+ labels?.fullValue?.(
767
+ column.label ??
768
+ (typeof column.header === 'string'
769
+ ? column.header
770
+ : column.key),
771
+ ) ??
772
+ `Show full ${column.label ?? (typeof column.header === 'string' ? column.header : column.key)}`
773
+ }
774
+ >
775
+ …
776
+ </Button>
777
+ </PopoverTrigger>
778
+ <PopoverContent
779
+ aria-label={
780
+ labels?.fullValue?.(
781
+ column.label ??
782
+ (typeof column.header === 'string'
783
+ ? column.header
784
+ : column.key),
785
+ ) ??
786
+ `Full ${column.label ?? (typeof column.header === 'string' ? column.header : column.key)}`
787
+ }
788
+ className="max-w-[90vw] break-words"
789
+ >
790
+ {column.fullText(row)}
791
+ </PopoverContent>
792
+ </Popover>
793
+ )}
794
+ </TableCell>
795
+ ))}
796
+ </TableRow>
797
+ );
798
+ })
799
+ )}
800
+ </TableBody>
801
+ {footer !== undefined && (
802
+ <TableFooter>
803
+ <TableRow>
804
+ <TableCell
805
+ colSpan={width}
806
+ className={cn(
807
+ 'px-inset py-inline text-xs text-muted-foreground',
808
+ !grid && 'border-t',
809
+ )}
810
+ >
811
+ {footer}
812
+ </TableCell>
813
+ </TableRow>
814
+ </TableFooter>
815
+ )}
816
+ </Table>
817
+ </div>
818
+ {page && <Pager page={page} loading={loading} labels={labels} />}
819
+ </div>
820
+ );
821
+ }