@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,622 @@
1
+ import { useId, useRef, useState, type CSSProperties, type ReactNode } from 'react';
2
+ import { Menu, Search } from 'lucide-react';
3
+
4
+ import { useTheme, type ThemeChoice } from '../hooks/use-theme';
5
+ import { cn } from '../lib/utils';
6
+ import {
7
+ CommandPalette,
8
+ useHotkey,
9
+ type CommandPaletteGroup,
10
+ } from './command-palette';
11
+ import { Avatar, AvatarFallback } from './ui/avatar';
12
+ import { BottomNavigation, BottomNavigationItem } from './ui/bottom-navigation';
13
+ import { Button } from './ui/button';
14
+ import {
15
+ DropdownMenu,
16
+ DropdownMenuContent,
17
+ DropdownMenuItem,
18
+ DropdownMenuLabel,
19
+ DropdownMenuRadioGroup,
20
+ DropdownMenuRadioItem,
21
+ DropdownMenuSeparator,
22
+ DropdownMenuTrigger,
23
+ } from './ui/dropdown-menu';
24
+ import { Heading } from './ui/heading';
25
+ import {
26
+ Sheet,
27
+ SheetContent,
28
+ SheetDescription,
29
+ SheetHeader,
30
+ SheetTitle,
31
+ } from './ui/sheet';
32
+ import { Text } from './ui/text';
33
+
34
+ export type AppShellNavItem = {
35
+ key: string;
36
+ label: ReactNode;
37
+ icon?: ReactNode;
38
+ /** A number after the label, such as open items. */
39
+ count?: number;
40
+ active?: boolean;
41
+ /** A link target; without it the item is a button that calls `onSelect`. */
42
+ href?: string;
43
+ onSelect?: () => void;
44
+ };
45
+
46
+ export type AppShellNavSection = {
47
+ key: string;
48
+ /** A small heading above the section's items. */
49
+ label?: ReactNode;
50
+ items: AppShellNavItem[];
51
+ };
52
+
53
+ export type AppShellUser = { name?: string; email?: string };
54
+
55
+ export type AppShellMessages = {
56
+ skipToContent: string;
57
+ sidebar: string;
58
+ main: string;
59
+ navigation: string;
60
+ navigationDescription: string;
61
+ openNavigation: string;
62
+ search: string;
63
+ goTo: string;
64
+ account: string;
65
+ theme: string;
66
+ light: string;
67
+ dark: string;
68
+ system: string;
69
+ signOut: string;
70
+ };
71
+ const SHELL_MESSAGES: AppShellMessages = {
72
+ skipToContent: 'Skip to main content',
73
+ sidebar: 'Sidebar',
74
+ main: 'Main',
75
+ navigation: 'Navigation',
76
+ navigationDescription: "The app's pages",
77
+ openNavigation: 'Open navigation',
78
+ search: 'Search',
79
+ goTo: 'Go to',
80
+ account: 'Account',
81
+ theme: 'Theme',
82
+ light: 'Light',
83
+ dark: 'Dark',
84
+ system: 'Match system',
85
+ signOut: 'Sign out',
86
+ };
87
+
88
+ export type AppShellProps = {
89
+ appName: ReactNode;
90
+ logo?: ReactNode;
91
+ nav: AppShellNavSection[];
92
+ /** The page title in the header. */
93
+ title?: ReactNode;
94
+ /** Buttons at the right of the header. */
95
+ actions?: ReactNode;
96
+ /** `narrow` holds the bar and the page to one centred column, for a short table, a feed or a form. */
97
+ width?: 'full' | 'narrow';
98
+ user?: AppShellUser;
99
+ /** More user menu items, above Sign out. */
100
+ userMenu?: ReactNode;
101
+ onSignOut?: () => unknown;
102
+ /**
103
+ * The app's actions and records. The shell mounts the command palette with them and with a Go to
104
+ * group of the nav items, opens it with ⌘K and shows the search button.
105
+ */
106
+ commands?: CommandPaletteGroup[];
107
+ /** Reports the palette's search text, so the caller can read matching records from OAIZ. */
108
+ onCommandSearch?: (search: string) => void;
109
+ /** A search button that shows ⌘K for a palette the app holds itself; `commands` replaces it. */
110
+ onSearch?: () => void;
111
+ /** Sets the page in a rounded panel beside the sidebar, as in Linear. */
112
+ inset?: boolean;
113
+ /** Uses the sidebar primary/foreground pair for a contrasting navigation surface. */
114
+ sidebarAppearance?: 'default' | 'inverted';
115
+ /**
116
+ * How a phone or narrow window reaches the nav: `menu` opens it from a button in the header;
117
+ * `tabs` shows up to five nav items as a tab bar at the bottom, within reach of the thumb, and
118
+ * the menu only when there are more.
119
+ */
120
+ phoneNav?: 'menu' | 'tabs';
121
+ children: ReactNode;
122
+ messages?: Partial<AppShellMessages>;
123
+ /** Stable main target for consumer-owned route focus. The app owns document.title. */
124
+ mainId?: string;
125
+ };
126
+
127
+ const INVERTED_SIDEBAR = {
128
+ '--role-sidebar': 'var(--role-sidebar-primary)',
129
+ '--role-sidebar-foreground': 'var(--role-sidebar-primary-foreground)',
130
+ '--role-sidebar-accent':
131
+ 'color-mix(in oklch, var(--role-sidebar-primary-foreground) 14%, var(--role-sidebar-primary))',
132
+ '--role-sidebar-accent-foreground': 'var(--role-sidebar-primary-foreground)',
133
+ '--role-sidebar-selected':
134
+ 'color-mix(in oklch, var(--role-sidebar-primary-foreground) 22%, var(--role-sidebar-primary))',
135
+ '--role-sidebar-border':
136
+ 'color-mix(in oklch, var(--role-sidebar-primary-foreground) 25%, var(--role-sidebar-primary))',
137
+ '--role-sidebar-ring': 'var(--role-sidebar-primary-foreground)',
138
+ } as CSSProperties;
139
+
140
+ function initials(user: AppShellUser): string {
141
+ const source = user.name || user.email || '';
142
+ const words = source.split(/[\s@.]+/).filter(Boolean);
143
+ return (
144
+ words
145
+ .slice(0, 2)
146
+ .map((word) => word[0]!.toUpperCase())
147
+ .join('') || '?'
148
+ );
149
+ }
150
+
151
+ function NavList({
152
+ nav,
153
+ onNavigate,
154
+ }: {
155
+ nav: AppShellNavSection[];
156
+ onNavigate?: () => void;
157
+ }) {
158
+ return (
159
+ <div className="flex flex-col gap-stack">
160
+ {nav.map((section) => (
161
+ <div key={section.key} className="flex flex-col gap-1">
162
+ {section.label && (
163
+ <Text
164
+ size="xs"
165
+ variant="inherit"
166
+ weight="medium"
167
+ className="px-inline"
168
+ >
169
+ {section.label}
170
+ </Text>
171
+ )}
172
+ <ul className="flex flex-col gap-1">
173
+ {section.items.map((item) => {
174
+ const className = cn(
175
+ 'flex w-full items-center gap-inline rounded-md px-inline py-1.5 text-left max-mobile:py-inset text-sm text-sidebar-foreground transition-colors duration-fast ease-move hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sidebar-ring focus-visible:ring-inset focus-visible:ring-offset-0',
176
+ item.active &&
177
+ 'bg-sidebar-selected font-medium text-sidebar-accent-foreground',
178
+ );
179
+ const content = (
180
+ <>
181
+ {item.icon && (
182
+ <span className="flex size-4 shrink-0 items-center justify-center [&_svg]:size-4">
183
+ {item.icon}
184
+ </span>
185
+ )}
186
+ <span className="min-w-0 flex-1 truncate">{item.label}</span>
187
+ {item.count !== undefined && (
188
+ <Text
189
+ as="span"
190
+ size="xs"
191
+ className="tabular-nums"
192
+ variant="inherit"
193
+ >
194
+ {item.count}
195
+ </Text>
196
+ )}
197
+ </>
198
+ );
199
+ const select = () => {
200
+ item.onSelect?.();
201
+ onNavigate?.();
202
+ };
203
+ return (
204
+ <li key={item.key}>
205
+ {item.href !== undefined ? (
206
+ <a
207
+ href={item.href}
208
+ aria-current={item.active ? 'page' : undefined}
209
+ className={className}
210
+ onClick={select}
211
+ >
212
+ {content}
213
+ </a>
214
+ ) : (
215
+ <Button variant="plain" size={null}
216
+ type="button"
217
+ aria-current={item.active ? 'page' : undefined}
218
+ className={className}
219
+ onClick={select}
220
+ >
221
+ {content}
222
+ </Button>
223
+ )}
224
+ </li>
225
+ );
226
+ })}
227
+ </ul>
228
+ </div>
229
+ ))}
230
+ </div>
231
+ );
232
+ }
233
+
234
+ /** With `iconOnPhone`, a phone shows the search icon alone, so a narrow header keeps room for its title. */
235
+ function SearchButton({
236
+ onSearch,
237
+ iconOnPhone = false,
238
+ label,
239
+ className,
240
+ }: {
241
+ onSearch: () => void;
242
+ iconOnPhone?: boolean;
243
+ label: string;
244
+ className?: string;
245
+ }) {
246
+ return (
247
+ <Button variant="plain" size={null}
248
+ type="button"
249
+ onClick={onSearch}
250
+ className={cn(
251
+ 'flex h-8 items-center gap-inline rounded-md border bg-background px-inline text-sm text-muted-foreground shadow-xs transition-colors duration-fast hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
252
+ iconOnPhone &&
253
+ 'max-mobile:w-8 max-mobile:justify-center max-mobile:px-0',
254
+ className,
255
+ )}
256
+ >
257
+ <Search aria-hidden="true" className="size-3.5" />
258
+ <span className={cn(iconOnPhone && 'max-mobile:sr-only')}>{label}</span>
259
+ <kbd
260
+ className={cn(
261
+ 'ml-auto font-sans text-xs',
262
+ iconOnPhone && 'max-mobile:hidden',
263
+ )}
264
+ >
265
+ ⌘K
266
+ </kbd>
267
+ </Button>
268
+ );
269
+ }
270
+
271
+ function navCommands(
272
+ nav: AppShellNavSection[],
273
+ heading: string,
274
+ ): CommandPaletteGroup {
275
+ return {
276
+ heading,
277
+ items: nav
278
+ .flatMap((section) => section.items)
279
+ .flatMap((item) =>
280
+ typeof item.label === 'string'
281
+ ? [
282
+ {
283
+ id: `nav:${item.key}`,
284
+ label: item.label,
285
+ icon: item.icon,
286
+ onSelect: () => {
287
+ item.onSelect?.();
288
+ if (item.href !== undefined)
289
+ window.location.assign(item.href);
290
+ },
291
+ },
292
+ ]
293
+ : [],
294
+ ),
295
+ };
296
+ }
297
+
298
+ function Brand({
299
+ appName,
300
+ logo,
301
+ onSearch,
302
+ searchLabel,
303
+ }: {
304
+ appName: ReactNode;
305
+ logo?: ReactNode;
306
+ onSearch?: () => void;
307
+ searchLabel: string;
308
+ }) {
309
+ return (
310
+ <div className="flex flex-col gap-inline">
311
+ <div className="flex h-10 items-center gap-inline px-inline">
312
+ {logo}
313
+ <Text size="sm" weight="semibold" variant="inherit" className="truncate">
314
+ {appName}
315
+ </Text>
316
+ </div>
317
+ {onSearch && (
318
+ <SearchButton
319
+ onSearch={onSearch}
320
+ label={searchLabel}
321
+ className="border-sidebar-border bg-sidebar text-sidebar-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-sidebar-ring focus-visible:ring-offset-sidebar"
322
+ />
323
+ )}
324
+ </div>
325
+ );
326
+ }
327
+
328
+ /**
329
+ * The frame of an app: a sidebar with the app name and sections of navigation, and a header with
330
+ * the page title, actions and the user menu. Below the `half` breakpoint the sidebar opens as a
331
+ * sheet from a header button. With fewer than two nav items there is nothing to navigate: the app
332
+ * name moves to the header and no sidebar is drawn.
333
+ */
334
+ export function AppShell({
335
+ appName,
336
+ logo,
337
+ nav,
338
+ title,
339
+ actions,
340
+ width = 'full',
341
+ user,
342
+ userMenu,
343
+ onSignOut,
344
+ commands,
345
+ onCommandSearch,
346
+ onSearch,
347
+ inset = false,
348
+ sidebarAppearance = 'default',
349
+ phoneNav = 'menu',
350
+ children,
351
+ messages: overrides,
352
+ mainId,
353
+ }: AppShellProps) {
354
+ const sidebarStyle =
355
+ sidebarAppearance === 'inverted' ? INVERTED_SIDEBAR : undefined;
356
+ const messages = { ...SHELL_MESSAGES, ...overrides };
357
+ const generatedMainId = useId();
358
+ const contentId = mainId ?? generatedMainId;
359
+ const mainRef = useRef<HTMLElement>(null);
360
+ const menuRef = useRef<HTMLButtonElement>(null);
361
+ const [navOpen, setNavOpen] = useState(false);
362
+ const [paletteOpen, setPaletteOpen] = useState(false);
363
+ const theme = useTheme();
364
+ const navItems = nav.flatMap((section) => section.items);
365
+ const hasSidebar = navItems.length > 1;
366
+ const tabs = phoneNav === 'tabs' && hasSidebar && navItems.length <= 5;
367
+ const search = commands ? () => setPaletteOpen(true) : onSearch;
368
+ useHotkey('k', () => setPaletteOpen((open) => !open), {
369
+ mod: true,
370
+ enabled: commands !== undefined,
371
+ });
372
+
373
+ return (
374
+ <div
375
+ className={cn(
376
+ 'flex h-svh text-foreground',
377
+ inset
378
+ ? sidebarAppearance === 'inverted' ? 'bg-sidebar-primary' : 'bg-sidebar'
379
+ : 'bg-background',
380
+ )}
381
+ >
382
+ <a
383
+ href={`#${contentId}`}
384
+ onClick={() => mainRef.current?.focus()}
385
+ className="sr-only z-50 rounded-md bg-background p-inline text-foreground shadow-md focus:not-sr-only focus:fixed focus:left-2 focus:top-2 focus:ring-2 focus:ring-ring"
386
+ >
387
+ {messages.skipToContent}
388
+ </a>
389
+ {commands && (
390
+ <CommandPalette
391
+ open={paletteOpen}
392
+ onOpenChange={setPaletteOpen}
393
+ groups={[...commands, navCommands(nav, messages.goTo)]}
394
+ onSearchChange={onCommandSearch}
395
+ />
396
+ )}
397
+ {hasSidebar && (
398
+ <aside
399
+ aria-label={messages.sidebar}
400
+ style={sidebarStyle}
401
+ className={cn(
402
+ 'hidden w-sidebar shrink-0 flex-col gap-stack border-sidebar-border bg-sidebar p-inline text-sidebar-foreground half:flex',
403
+ !inset && 'border-r',
404
+ )}
405
+ >
406
+ <Brand
407
+ appName={appName}
408
+ logo={logo}
409
+ onSearch={search}
410
+ searchLabel={messages.search}
411
+ />
412
+ <nav
413
+ aria-label={messages.main}
414
+ className="min-h-0 flex-1 overflow-y-auto"
415
+ >
416
+ <NavList nav={nav} />
417
+ </nav>
418
+ </aside>
419
+ )}
420
+ <Sheet open={hasSidebar && navOpen} onOpenChange={setNavOpen}>
421
+ <SheetContent
422
+ side="left"
423
+ style={sidebarStyle}
424
+ onCloseAutoFocus={(event) => {
425
+ event.preventDefault();
426
+ menuRef.current?.focus();
427
+ }}
428
+ className="w-sidebar border-sidebar-border bg-sidebar p-inline text-sidebar-foreground [&>button]:ring-offset-sidebar [&>button]:focus:ring-sidebar-ring [&>button[data-state=open]]:bg-sidebar-accent"
429
+ >
430
+ <SheetHeader className="sr-only">
431
+ <SheetTitle>{messages.navigation}</SheetTitle>
432
+ <SheetDescription>
433
+ {messages.navigationDescription}
434
+ </SheetDescription>
435
+ </SheetHeader>
436
+ <Brand
437
+ appName={appName}
438
+ searchLabel={messages.search}
439
+ logo={logo}
440
+ onSearch={
441
+ search &&
442
+ (() => {
443
+ setNavOpen(false);
444
+ search();
445
+ })
446
+ }
447
+ />
448
+ <nav aria-label={messages.main}>
449
+ <NavList nav={nav} onNavigate={() => setNavOpen(false)} />
450
+ </nav>
451
+ </SheetContent>
452
+ </Sheet>
453
+ <div
454
+ className={cn(
455
+ 'flex min-w-0 flex-1 flex-col bg-background',
456
+ inset &&
457
+ 'half:my-inline half:mr-inline half:overflow-hidden half:rounded-lg half:border half:shadow-xs',
458
+ )}
459
+ >
460
+ <header
461
+ className={cn(
462
+ 'flex h-11 shrink-0 items-center gap-inline border-b',
463
+ width === 'narrow'
464
+ ? 'px-[max(var(--spacing-page),calc((100%-48rem)/2))]'
465
+ : 'px-page',
466
+ )}
467
+ >
468
+ {hasSidebar && !tabs && (
469
+ <Button
470
+ variant="ghost"
471
+ size="icon"
472
+ className="half:hidden"
473
+ ref={menuRef}
474
+ aria-label={messages.openNavigation}
475
+ onClick={() => setNavOpen(true)}
476
+ >
477
+ <Menu />
478
+ </Button>
479
+ )}
480
+ <div className="flex min-w-0 flex-1 items-center gap-inline">
481
+ {!hasSidebar && logo}
482
+ {!hasSidebar &&
483
+ (title ? (
484
+ <>
485
+ <Text
486
+ size="sm"
487
+ variant="muted"
488
+ className="truncate max-mobile:hidden"
489
+ >
490
+ {appName}
491
+ </Text>
492
+ <span
493
+ aria-hidden="true"
494
+ className="text-sm text-muted-foreground max-mobile:hidden"
495
+ >
496
+ /
497
+ </span>
498
+ </>
499
+ ) : (
500
+ <Heading
501
+ level={1}
502
+ size="md"
503
+ weight="semibold"
504
+ className="truncate"
505
+ >
506
+ {appName}
507
+ </Heading>
508
+ ))}
509
+ {title && (
510
+ <Heading
511
+ level={1}
512
+ size="md"
513
+ weight="semibold"
514
+ className="truncate"
515
+ >
516
+ {title}
517
+ </Heading>
518
+ )}
519
+ </div>
520
+ {!hasSidebar && search && (
521
+ <SearchButton
522
+ onSearch={search}
523
+ label={messages.search}
524
+ iconOnPhone
525
+ className="w-40"
526
+ />
527
+ )}
528
+ {actions && (
529
+ <div className="flex items-center gap-inline">{actions}</div>
530
+ )}
531
+ {user && (
532
+ <DropdownMenu>
533
+ <DropdownMenuTrigger asChild>
534
+ <Button
535
+ variant="ghost"
536
+ size="icon"
537
+ shape="pill"
538
+ aria-label={messages.account}
539
+ >
540
+ <Avatar className="size-7">
541
+ <AvatarFallback className="text-xs">
542
+ {initials(user)}
543
+ </AvatarFallback>
544
+ </Avatar>
545
+ </Button>
546
+ </DropdownMenuTrigger>
547
+ <DropdownMenuContent align="end" className="min-w-48">
548
+ <DropdownMenuLabel className="flex flex-col">
549
+ {user.name && <span>{user.name}</span>}
550
+ {user.email && (
551
+ <span className="font-normal text-muted-foreground">
552
+ {user.email}
553
+ </span>
554
+ )}
555
+ </DropdownMenuLabel>
556
+ {userMenu}
557
+ <DropdownMenuSeparator />
558
+ <DropdownMenuLabel>{messages.theme}</DropdownMenuLabel>
559
+ <DropdownMenuRadioGroup
560
+ value={theme.choice}
561
+ onValueChange={(value) =>
562
+ theme.setChoice(value as ThemeChoice)
563
+ }
564
+ >
565
+ <DropdownMenuRadioItem value="light">
566
+ {messages.light}
567
+ </DropdownMenuRadioItem>
568
+ <DropdownMenuRadioItem value="dark">
569
+ {messages.dark}
570
+ </DropdownMenuRadioItem>
571
+ <DropdownMenuRadioItem value="system">
572
+ {messages.system}
573
+ </DropdownMenuRadioItem>
574
+ </DropdownMenuRadioGroup>
575
+ {onSignOut && (
576
+ <>
577
+ <DropdownMenuSeparator />
578
+ <DropdownMenuItem onSelect={() => void onSignOut()}>
579
+ {messages.signOut}
580
+ </DropdownMenuItem>
581
+ </>
582
+ )}
583
+ </DropdownMenuContent>
584
+ </DropdownMenu>
585
+ )}
586
+ </header>
587
+ <main
588
+ id={contentId}
589
+ ref={mainRef}
590
+ tabIndex={-1}
591
+ className="min-h-0 flex-1 overflow-y-auto outline-none"
592
+ >
593
+ {width === 'narrow' ? (
594
+ <div className="mx-auto h-full max-w-[calc(48rem+2*var(--layout-page-gutter))] p-[var(--layout-page-gutter)] [--spacing-page:0px]">
595
+ {children}
596
+ </div>
597
+ ) : (
598
+ children
599
+ )}
600
+ </main>
601
+ {tabs && (
602
+ <BottomNavigation aria-label={messages.main} className="half:hidden">
603
+ {navItems.map((item) => (
604
+ <BottomNavigationItem
605
+ key={item.key}
606
+ icon={item.icon}
607
+ label={item.label}
608
+ selected={item.active}
609
+ aria-current={item.active ? 'page' : undefined}
610
+ badge={item.count}
611
+ asChild={item.href !== undefined}
612
+ onClick={item.href === undefined ? item.onSelect : undefined}
613
+ >
614
+ {item.href !== undefined ? <a href={item.href} /> : undefined}
615
+ </BottomNavigationItem>
616
+ ))}
617
+ </BottomNavigation>
618
+ )}
619
+ </div>
620
+ </div>
621
+ );
622
+ }
@@ -0,0 +1,47 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ import { cn } from '../lib/utils';
4
+ import { STATUS_DOT_TONES, type StatusDotTone } from './status-dot';
5
+
6
+ export type BarListItem = {
7
+ key: string;
8
+ label: ReactNode;
9
+ /** Sets the length of the bar. */
10
+ amount: number;
11
+ /** How the amount reads; the amount when omitted. */
12
+ value?: ReactNode;
13
+ /** The tone the same value has in its `StatusDot`. */
14
+ tone?: StatusDotTone;
15
+ };
16
+
17
+ export type BarListProps = {
18
+ items: BarListItem[];
19
+ 'aria-label'?: string;
20
+ };
21
+
22
+ /** Amounts to compare, one bar to a row. On a phone the bar takes its own full-width line. */
23
+ export function BarList({ items, 'aria-label': label }: BarListProps) {
24
+ const largest = Math.max(0, ...items.map((item) => item.amount)) || 1;
25
+ return (
26
+ <ul
27
+ aria-label={label}
28
+ className="grid grid-cols-[minmax(0,8rem)_1fr_auto] gap-x-stack gap-y-inline max-mobile:grid-cols-[minmax(0,1fr)_auto]"
29
+ >
30
+ {items.map((item) => (
31
+ <li
32
+ key={item.key}
33
+ className="col-span-full grid grid-cols-subgrid items-center text-sm max-mobile:gap-y-1"
34
+ >
35
+ <span className="truncate">{item.label}</span>
36
+ <span className="h-1.5 rounded-sm bg-muted max-mobile:col-span-full max-mobile:row-start-2">
37
+ <span
38
+ className={cn('block h-full rounded-sm', item.tone ? STATUS_DOT_TONES[item.tone] : 'bg-primary')}
39
+ style={{ width: `${(Math.max(item.amount, 0) / largest) * 100}%` }}
40
+ />
41
+ </span>
42
+ <span className="text-right tabular-nums">{item.value ?? item.amount}</span>
43
+ </li>
44
+ ))}
45
+ </ul>
46
+ );
47
+ }