@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,270 @@
1
+ import * as React from 'react';
2
+ import { createPortal } from 'react-dom';
3
+ import { Slot } from '@radix-ui/react-slot';
4
+
5
+ import { cn } from '../../lib/utils';
6
+ import {
7
+ DropdownMenu,
8
+ DropdownMenuContent,
9
+ DropdownMenuTrigger,
10
+ } from './dropdown-menu';
11
+
12
+ /** How long a touch must rest before it opens the menu, as on iOS and Android. */
13
+ const LONG_PRESS_MS = 500;
14
+ /** A touch that drifts further than this is a scroll or a drag, not a press. */
15
+ const LONG_PRESS_SLOP_PX = 10;
16
+
17
+ interface ContextMenuContextValue {
18
+ openAt: (x: number, y: number) => void;
19
+ returnFocus: () => void;
20
+ }
21
+
22
+ const ContextMenuContext = React.createContext<ContextMenuContextValue | null>(
23
+ null,
24
+ );
25
+
26
+ function useContextMenuContext(component: string) {
27
+ const context = React.useContext(ContextMenuContext);
28
+ if (!context) throw new Error(`${component} must be inside <ContextMenu>`);
29
+ return context;
30
+ }
31
+
32
+ /**
33
+ * A menu that opens where the user right-clicks, long-presses, or presses the
34
+ * Menu key or Shift+F10. Its items are the `DropdownMenu` items, so a row's
35
+ * "⋯" menu and its context menu can render the same item list.
36
+ */
37
+ function ContextMenu({
38
+ children,
39
+ onOpenChange,
40
+ }: {
41
+ children?: React.ReactNode;
42
+ onOpenChange?: (open: boolean) => void;
43
+ }) {
44
+ const [open, setOpen] = React.useState(false);
45
+ // The point stays after closing so the menu does not jump while it fades.
46
+ const [point, setPoint] = React.useState<{ x: number; y: number } | null>(
47
+ null,
48
+ );
49
+ const focusOrigin = React.useRef<HTMLElement | null>(null);
50
+
51
+ const context = React.useMemo<ContextMenuContextValue>(
52
+ () => ({
53
+ openAt: (x, y) => {
54
+ focusOrigin.current =
55
+ document.activeElement instanceof HTMLElement
56
+ ? document.activeElement
57
+ : null;
58
+ setPoint({ x, y });
59
+ setOpen(true);
60
+ onOpenChange?.(true);
61
+ },
62
+ returnFocus: () => focusOrigin.current?.focus(),
63
+ }),
64
+ [onOpenChange],
65
+ );
66
+
67
+ return (
68
+ <ContextMenuContext.Provider value={context}>
69
+ <DropdownMenu
70
+ modal={false}
71
+ open={open}
72
+ onOpenChange={(next) => {
73
+ setOpen(next);
74
+ onOpenChange?.(next);
75
+ }}
76
+ >
77
+ {/* A zero-size anchor at the pointer, outside the trigger's own
78
+ markup so the trigger can be any element, including a table row. */}
79
+ {/* Mounted from the first open on, so long lists of rows do not each
80
+ add an anchor to the page. */}
81
+ {point && typeof document !== 'undefined'
82
+ ? createPortal(
83
+ <DropdownMenuTrigger asChild>
84
+ <span
85
+ aria-hidden
86
+ tabIndex={-1}
87
+ className="pointer-events-none fixed size-0"
88
+ style={{ left: point.x, top: point.y }}
89
+ />
90
+ </DropdownMenuTrigger>,
91
+ document.body,
92
+ )
93
+ : null}
94
+ {children}
95
+ </DropdownMenu>
96
+ </ContextMenuContext.Provider>
97
+ );
98
+ }
99
+
100
+ /**
101
+ * Menus and dialogs opened from inside the trigger render in portals, but React
102
+ * still bubbles their events to it. Only events from the trigger's own markup
103
+ * may open this menu.
104
+ */
105
+ function isInside(event: React.SyntheticEvent<HTMLElement>) {
106
+ return (
107
+ event.target instanceof Node && event.currentTarget.contains(event.target)
108
+ );
109
+ }
110
+
111
+ type ContextMenuTriggerProps = React.HTMLAttributes<HTMLElement> & {
112
+ asChild?: boolean;
113
+ disabled?: boolean;
114
+ };
115
+
116
+ /** The area that opens the menu. Pass `asChild` to use the child element itself. */
117
+ const ContextMenuTrigger = React.forwardRef<
118
+ HTMLElement,
119
+ ContextMenuTriggerProps
120
+ >(
121
+ (
122
+ {
123
+ asChild = false,
124
+ disabled = false,
125
+ onContextMenu,
126
+ onPointerDown,
127
+ onPointerMove,
128
+ onPointerUp,
129
+ onPointerCancel,
130
+ onClickCapture,
131
+ ...props
132
+ },
133
+ ref,
134
+ ) => {
135
+ const { openAt } = useContextMenuContext('ContextMenuTrigger');
136
+ const press = React.useRef<{
137
+ x: number;
138
+ y: number;
139
+ timer: ReturnType<typeof setTimeout>;
140
+ } | null>(null);
141
+ const openedByPress = React.useRef(false);
142
+
143
+ const cancelPress = () => {
144
+ if (press.current) clearTimeout(press.current.timer);
145
+ press.current = null;
146
+ };
147
+ React.useEffect(() => cancelPress, []);
148
+
149
+ const Component = asChild ? Slot : 'span';
150
+ return (
151
+ <Component
152
+ ref={ref}
153
+ {...props}
154
+ onContextMenu={(event: React.MouseEvent<HTMLElement>) => {
155
+ onContextMenu?.(event);
156
+ if (disabled || event.defaultPrevented || !isInside(event)) return;
157
+ event.preventDefault();
158
+ cancelPress();
159
+ // The Menu key and Shift+F10 report no pointer position.
160
+ if (event.clientX === 0 && event.clientY === 0) {
161
+ const rect = event.currentTarget.getBoundingClientRect();
162
+ openAt(rect.left + 8, rect.top + 8);
163
+ } else {
164
+ openAt(event.clientX, event.clientY);
165
+ }
166
+ }}
167
+ onPointerDown={(event: React.PointerEvent<HTMLElement>) => {
168
+ onPointerDown?.(event);
169
+ openedByPress.current = false;
170
+ if (disabled || event.pointerType !== 'touch' || !isInside(event))
171
+ return;
172
+ cancelPress();
173
+ const { clientX: x, clientY: y } = event;
174
+ press.current = {
175
+ x,
176
+ y,
177
+ timer: setTimeout(() => {
178
+ press.current = null;
179
+ openedByPress.current = true;
180
+ openAt(x, y);
181
+ }, LONG_PRESS_MS),
182
+ };
183
+ }}
184
+ onPointerMove={(event: React.PointerEvent<HTMLElement>) => {
185
+ onPointerMove?.(event);
186
+ if (
187
+ press.current &&
188
+ Math.hypot(
189
+ event.clientX - press.current.x,
190
+ event.clientY - press.current.y,
191
+ ) > LONG_PRESS_SLOP_PX
192
+ )
193
+ cancelPress();
194
+ }}
195
+ onPointerUp={(event: React.PointerEvent<HTMLElement>) => {
196
+ onPointerUp?.(event);
197
+ cancelPress();
198
+ }}
199
+ onPointerCancel={(event: React.PointerEvent<HTMLElement>) => {
200
+ onPointerCancel?.(event);
201
+ cancelPress();
202
+ }}
203
+ // Lifting the finger after a long-press must not also activate the row.
204
+ onClickCapture={(event: React.MouseEvent<HTMLElement>) => {
205
+ onClickCapture?.(event);
206
+ if (!openedByPress.current) return;
207
+ openedByPress.current = false;
208
+ event.preventDefault();
209
+ event.stopPropagation();
210
+ }}
211
+ />
212
+ );
213
+ },
214
+ );
215
+ ContextMenuTrigger.displayName = 'ContextMenuTrigger';
216
+
217
+ /** The menu surface; fill it with `DropdownMenuItem`s and separators. */
218
+ const ContextMenuContent = React.forwardRef<
219
+ React.ElementRef<typeof DropdownMenuContent>,
220
+ React.ComponentPropsWithoutRef<typeof DropdownMenuContent>
221
+ >(
222
+ (
223
+ {
224
+ className,
225
+ onCloseAutoFocus,
226
+ onClick,
227
+ onPointerDown,
228
+ onContextMenu,
229
+ ...props
230
+ },
231
+ ref,
232
+ ) => {
233
+ const { returnFocus } = useContextMenuContext('ContextMenuContent');
234
+ return (
235
+ <DropdownMenuContent
236
+ ref={ref}
237
+ align="start"
238
+ side="bottom"
239
+ sideOffset={2}
240
+ collisionPadding={8}
241
+ className={cn('min-w-48', className)}
242
+ {...props}
243
+ // The menu renders in a portal, but React still bubbles its events to
244
+ // the trigger. A click on an item must not also open or drag the row.
245
+ onClick={(event) => {
246
+ onClick?.(event);
247
+ event.stopPropagation();
248
+ }}
249
+ onPointerDown={(event) => {
250
+ onPointerDown?.(event);
251
+ event.stopPropagation();
252
+ }}
253
+ onContextMenu={(event) => {
254
+ onContextMenu?.(event);
255
+ event.preventDefault();
256
+ event.stopPropagation();
257
+ }}
258
+ onCloseAutoFocus={(event) => {
259
+ onCloseAutoFocus?.(event);
260
+ if (event.defaultPrevented) return;
261
+ event.preventDefault();
262
+ returnFocus();
263
+ }}
264
+ />
265
+ );
266
+ },
267
+ );
268
+ ContextMenuContent.displayName = 'ContextMenuContent';
269
+
270
+ export { ContextMenu, ContextMenuTrigger, ContextMenuContent };
@@ -0,0 +1,136 @@
1
+ import * as React from 'react';
2
+
3
+ import { useMediaQuery } from '../../hooks/use-media-query';
4
+ import { cn } from '../../lib/utils';
5
+
6
+ /**
7
+ * The `--ease-enter` curve from tokens.css: the count moves fast at first and
8
+ * settles slowly onto the target.
9
+ */
10
+ const EASE_ENTER = [0.16, 1, 0.3, 1] as const;
11
+
12
+ function cubicBezier(x1: number, y1: number, x2: number, y2: number) {
13
+ const coordinate = (t: number, p1: number, p2: number) =>
14
+ 3 * (1 - t) * (1 - t) * t * p1 + 3 * (1 - t) * t * t * p2 + t * t * t;
15
+ const slope = (t: number, p1: number, p2: number) =>
16
+ 3 * (1 - t) * (1 - t) * p1 +
17
+ 6 * (1 - t) * t * (p2 - p1) +
18
+ 3 * t * t * (1 - p2);
19
+
20
+ return (x: number) => {
21
+ if (x <= 0) return 0;
22
+ if (x >= 1) return 1;
23
+ let t = x;
24
+ for (let i = 0; i < 8; i++) {
25
+ const error = coordinate(t, x1, x2) - x;
26
+ const derivative = slope(t, x1, x2);
27
+ if (Math.abs(error) < 1e-5 || derivative === 0) break;
28
+ t -= error / derivative;
29
+ }
30
+ return coordinate(Math.min(1, Math.max(0, t)), y1, y2);
31
+ };
32
+ }
33
+
34
+ /** The `--ease-enter` token as a function, for animations driven from JavaScript. */
35
+ const easeEnter = cubicBezier(...EASE_ENTER);
36
+
37
+ export interface CountUpProps {
38
+ value: number;
39
+ /** Formats the target and every intermediate value. */
40
+ format: (value: number) => string;
41
+ /** Decimal places intermediate values round to before formatting. */
42
+ fractionDigits?: number;
43
+ /** Length of one count. */
44
+ durationMs?: number;
45
+ /** When false, the value renders immediately. */
46
+ animate?: boolean;
47
+ className?: string;
48
+ }
49
+
50
+ function roundTo(value: number, fractionDigits: number) {
51
+ const factor = 10 ** fractionDigits;
52
+ return Math.round(value * factor) / factor;
53
+ }
54
+
55
+ /**
56
+ * Counts from zero to `value` on mount, and from the shown value to the new
57
+ * one when `value` changes. The formatted target is laid out from the start, so
58
+ * the width never jumps, and assistive technology reads only the target; the
59
+ * counting digits are drawn over it. Under reduced motion the value renders
60
+ * statically.
61
+ */
62
+ function CountUp({
63
+ value,
64
+ format,
65
+ fractionDigits = 0,
66
+ durationMs = 1400,
67
+ animate = true,
68
+ className,
69
+ }: CountUpProps) {
70
+ const prefersReducedMotion = useMediaQuery(
71
+ '(prefers-reduced-motion: reduce)',
72
+ );
73
+ const shouldAnimate =
74
+ animate && !prefersReducedMotion && Number.isFinite(value);
75
+ // The value the count has reached; animation frames read and advance it.
76
+ const reachedRef = React.useRef(0);
77
+ const [shown, setShown] = React.useState<number | null>(
78
+ shouldAnimate && value !== 0 ? 0 : null,
79
+ );
80
+ const [previousValue, setPreviousValue] = React.useState(value);
81
+ if (value !== previousValue) {
82
+ setPreviousValue(value);
83
+ // Keep showing the reached value until the next frame counts on from it.
84
+ if (shouldAnimate) setShown(shown ?? previousValue);
85
+ }
86
+
87
+ React.useEffect(() => {
88
+ if (!shouldAnimate) {
89
+ reachedRef.current = value;
90
+ return;
91
+ }
92
+ const from = reachedRef.current;
93
+ let frame = 0;
94
+ if (from === value) {
95
+ frame = requestAnimationFrame(() => setShown(null));
96
+ return () => cancelAnimationFrame(frame);
97
+ }
98
+ let start: number | undefined;
99
+ const step = (now: number) => {
100
+ start ??= now;
101
+ const progress = Math.min(1, (now - start) / durationMs);
102
+ reachedRef.current = from + (value - from) * easeEnter(progress);
103
+ if (progress < 1) {
104
+ setShown(roundTo(reachedRef.current, fractionDigits));
105
+ frame = requestAnimationFrame(step);
106
+ } else {
107
+ reachedRef.current = value;
108
+ setShown(null);
109
+ }
110
+ };
111
+ frame = requestAnimationFrame(step);
112
+ return () => cancelAnimationFrame(frame);
113
+ }, [value, shouldAnimate, durationMs, fractionDigits]);
114
+
115
+ const counting = shouldAnimate && shown !== null;
116
+
117
+ return (
118
+ <span
119
+ className={cn('relative inline-block tabular-nums', className)}
120
+ data-testid="count-up"
121
+ data-counting={counting ? 'true' : undefined}
122
+ >
123
+ <span className={cn(counting && 'opacity-0')}>{format(value)}</span>
124
+ {counting ? (
125
+ <span
126
+ aria-hidden="true"
127
+ className="absolute inset-y-0 left-0 whitespace-nowrap"
128
+ >
129
+ {format(shown ?? value)}
130
+ </span>
131
+ ) : null}
132
+ </span>
133
+ );
134
+ }
135
+
136
+ export { CountUp, easeEnter };
@@ -0,0 +1,109 @@
1
+ import { useState, type ReactNode } from 'react';
2
+ import { ChevronRight } from 'lucide-react';
3
+
4
+ import {
5
+ Collapsible,
6
+ CollapsibleContent,
7
+ CollapsibleTrigger,
8
+ } from './collapsible';
9
+ import { cn } from '../../lib/utils';
10
+
11
+ import { Heading, type HeadingLevel } from './heading';
12
+ import { Text } from './text';
13
+ import { Button } from './button';
14
+ interface DetailDisclosureSectionProps {
15
+ title: string;
16
+ /** Outline level of the title; nest it one below the enclosing heading. */
17
+ headingLevel?: HeadingLevel;
18
+ children: ReactNode;
19
+ secondary?: ReactNode;
20
+ meta?: ReactNode;
21
+ trailing?: ReactNode;
22
+ defaultOpen?: boolean;
23
+ density?: 'default' | 'compact';
24
+ className?: string;
25
+ contentClassName?: string;
26
+ ariaLabel?: string;
27
+ /** Localized accessible name for the current disclosure action. */
28
+ getToggleLabel?: (open: boolean, title: string) => string;
29
+ testId?: string;
30
+ triggerTestId?: string;
31
+ chevronTestId?: string;
32
+ }
33
+
34
+ export function DetailDisclosureSection({
35
+ title,
36
+ headingLevel = 3,
37
+ children,
38
+ secondary,
39
+ meta,
40
+ trailing,
41
+ defaultOpen = false,
42
+ density = 'default',
43
+ className,
44
+ contentClassName,
45
+ ariaLabel = title,
46
+ getToggleLabel = (expanded, name) =>
47
+ `${expanded ? 'Collapse' : 'Expand'} ${name}`,
48
+ testId,
49
+ triggerTestId,
50
+ chevronTestId,
51
+ }: DetailDisclosureSectionProps) {
52
+ const [open, setOpen] = useState(defaultOpen);
53
+
54
+ return (
55
+ <Collapsible
56
+ open={open}
57
+ onOpenChange={setOpen}
58
+ className={cn('min-w-0', className)}
59
+ data-testid={testId}
60
+ >
61
+ <div className="flex min-w-0 items-stretch border-b border-border">
62
+ <CollapsibleTrigger asChild>
63
+ <Button
64
+ type="button"
65
+ variant="plain"
66
+ aria-label={getToggleLabel(open, ariaLabel)}
67
+ className={cn(
68
+ 'flex h-auto min-w-0 flex-1 flex-wrap justify-start gap-inline whitespace-normal px-inline text-left hover:bg-muted/50',
69
+ density === 'compact' ? 'py-inline' : 'py-inset',
70
+ )}
71
+ data-testid={triggerTestId}
72
+ >
73
+ <ChevronRight
74
+ className={cn(
75
+ 'h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-fast ease-move',
76
+ open && 'rotate-90',
77
+ )}
78
+ data-testid={chevronTestId}
79
+ />
80
+ <Heading
81
+ level={headingLevel}
82
+ size={density === 'compact' ? 'xs' : undefined}
83
+ variant="default"
84
+ className="min-w-0 [overflow-wrap:anywhere]"
85
+ >
86
+ {title}
87
+ </Heading>
88
+ {secondary ? (
89
+ <Text
90
+ as="span"
91
+ size={density === 'compact' ? 'xs' : 'sm'}
92
+ className="min-w-0 truncate"
93
+ >
94
+ {secondary}
95
+ </Text>
96
+ ) : null}
97
+ {meta ? <span className="ml-auto shrink-0">{meta}</span> : null}
98
+ </Button>
99
+ </CollapsibleTrigger>
100
+ {trailing ? (
101
+ <div className="flex shrink-0 items-center px-inline">{trailing}</div>
102
+ ) : null}
103
+ </div>
104
+ <CollapsibleContent className={contentClassName}>
105
+ {children}
106
+ </CollapsibleContent>
107
+ </Collapsible>
108
+ );
109
+ }
@@ -0,0 +1,157 @@
1
+ import * as React from 'react';
2
+ import * as DialogPrimitive from '@radix-ui/react-dialog';
3
+ import { X } from 'lucide-react';
4
+
5
+ import { cn } from '../../lib/utils';
6
+ import { Heading } from './heading';
7
+ import { Text } from './text';
8
+
9
+ const Dialog = DialogPrimitive.Root;
10
+
11
+ const DialogTrigger = DialogPrimitive.Trigger;
12
+
13
+ const DialogPortal = DialogPrimitive.Portal;
14
+
15
+ const DialogClose = DialogPrimitive.Close;
16
+
17
+ const DialogOverlay = React.forwardRef<
18
+ React.ElementRef<typeof DialogPrimitive.Overlay>,
19
+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
20
+ >(({ className, ...props }, ref) => (
21
+ <DialogPrimitive.Overlay
22
+ ref={ref}
23
+ className={cn(
24
+ 'fixed inset-0 z-50 bg-black/80 duration-normal ease-enter data-[state=closed]:ease-exit data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
25
+ className,
26
+ )}
27
+ {...props}
28
+ />
29
+ ));
30
+ DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
31
+
32
+ type DialogContentProps = React.ComponentPropsWithoutRef<
33
+ typeof DialogPrimitive.Content
34
+ > & {
35
+ motion?: 'default' | 'fade';
36
+ closeLabel?: string;
37
+ showCloseButton?: boolean;
38
+ /** Replaces parts of the overlay's look, such as a lighter backdrop. */
39
+ overlayClassName?: string;
40
+ };
41
+
42
+ const DialogContent = React.forwardRef<
43
+ React.ElementRef<typeof DialogPrimitive.Content>,
44
+ DialogContentProps
45
+ >(
46
+ (
47
+ {
48
+ className,
49
+ children,
50
+ motion = 'default',
51
+ closeLabel = 'Close',
52
+ showCloseButton = true,
53
+ overlayClassName,
54
+ ...props
55
+ },
56
+ ref,
57
+ ) => {
58
+ const motionClasses =
59
+ motion === 'fade'
60
+ ? 'duration-normal ease-enter data-[state=closed]:ease-exit data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-98 data-[state=open]:zoom-in-98'
61
+ : 'duration-normal ease-enter data-[state=closed]:ease-exit data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95';
62
+
63
+ return (
64
+ <DialogPortal>
65
+ <DialogOverlay className={overlayClassName} />
66
+ <DialogPrimitive.Content
67
+ ref={ref}
68
+ className={cn(
69
+ 'fixed left-[50%] top-[50%] z-50 grid max-h-[calc(100dvh-2rem)] w-full max-w-lg overflow-y-auto translate-x-[-50%] translate-y-[-50%] gap-stack border bg-background p-6 shadow-lg outline-none mobile:rounded-lg',
70
+ motionClasses,
71
+ className,
72
+ )}
73
+ {...props}
74
+ >
75
+ {children}
76
+ {showCloseButton ? (
77
+ <DialogPrimitive.Close
78
+ className="absolute right-stack top-stack flex h-6 w-6 items-center justify-center rounded-sm opacity-70 outline-none ring-offset-background transition-opacity duration-fast ease-move hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground"
79
+ data-testid="dialog-close-button"
80
+ >
81
+ <X className="h-4 w-4" />
82
+ <span className="sr-only">{closeLabel}</span>
83
+ </DialogPrimitive.Close>
84
+ ) : null}
85
+ </DialogPrimitive.Content>
86
+ </DialogPortal>
87
+ );
88
+ },
89
+ );
90
+ DialogContent.displayName = DialogPrimitive.Content.displayName;
91
+
92
+ const DialogHeader = ({
93
+ className,
94
+ ...props
95
+ }: React.HTMLAttributes<HTMLDivElement>) => (
96
+ <div
97
+ className={cn(
98
+ 'flex flex-col space-y-1.5 text-center mobile:text-left',
99
+ className,
100
+ )}
101
+ {...props}
102
+ />
103
+ );
104
+ DialogHeader.displayName = 'DialogHeader';
105
+
106
+ const DialogFooter = ({
107
+ className,
108
+ ...props
109
+ }: React.HTMLAttributes<HTMLDivElement>) => (
110
+ <div
111
+ className={cn(
112
+ 'flex flex-col-reverse mobile:flex-row mobile:justify-end mobile:space-x-inline',
113
+ className,
114
+ )}
115
+ {...props}
116
+ />
117
+ );
118
+ DialogFooter.displayName = 'DialogFooter';
119
+
120
+ const DialogTitle = React.forwardRef<
121
+ React.ElementRef<typeof DialogPrimitive.Title>,
122
+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
123
+ >(({ className, ...props }, ref) => (
124
+ <Heading
125
+ asChild
126
+ level={3}
127
+ size="lg"
128
+ weight="semibold"
129
+ className={cn('leading-none tracking-tight', className)}
130
+ >
131
+ <DialogPrimitive.Title ref={ref} {...props} />
132
+ </Heading>
133
+ ));
134
+ DialogTitle.displayName = DialogPrimitive.Title.displayName;
135
+
136
+ const DialogDescription = React.forwardRef<
137
+ React.ElementRef<typeof DialogPrimitive.Description>,
138
+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
139
+ >(({ className, ...props }, ref) => (
140
+ <Text asChild size="sm" variant="muted" className={className}>
141
+ <DialogPrimitive.Description ref={ref} {...props} />
142
+ </Text>
143
+ ));
144
+ DialogDescription.displayName = DialogPrimitive.Description.displayName;
145
+
146
+ export {
147
+ Dialog,
148
+ DialogPortal,
149
+ DialogOverlay,
150
+ DialogClose,
151
+ DialogTrigger,
152
+ DialogContent,
153
+ DialogHeader,
154
+ DialogFooter,
155
+ DialogTitle,
156
+ DialogDescription,
157
+ };