@sero-ai/ui 0.1.0

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 (113) hide show
  1. package/.turbo/turbo-typecheck.log +4 -0
  2. package/components.json +18 -0
  3. package/package.json +70 -0
  4. package/src/components/ai-elements/agent.tsx +142 -0
  5. package/src/components/ai-elements/artifact.tsx +149 -0
  6. package/src/components/ai-elements/attachments.tsx +427 -0
  7. package/src/components/ai-elements/audio-player.tsx +232 -0
  8. package/src/components/ai-elements/canvas.tsx +26 -0
  9. package/src/components/ai-elements/chain-of-thought.tsx +223 -0
  10. package/src/components/ai-elements/checkpoint.tsx +72 -0
  11. package/src/components/ai-elements/code-block.tsx +555 -0
  12. package/src/components/ai-elements/commit.tsx +449 -0
  13. package/src/components/ai-elements/confirmation.tsx +173 -0
  14. package/src/components/ai-elements/connection.tsx +28 -0
  15. package/src/components/ai-elements/context.tsx +410 -0
  16. package/src/components/ai-elements/controls.tsx +19 -0
  17. package/src/components/ai-elements/conversation.tsx +167 -0
  18. package/src/components/ai-elements/edge.tsx +144 -0
  19. package/src/components/ai-elements/environment-variables.tsx +325 -0
  20. package/src/components/ai-elements/file-tree.tsx +298 -0
  21. package/src/components/ai-elements/image.tsx +25 -0
  22. package/src/components/ai-elements/inline-citation.tsx +294 -0
  23. package/src/components/ai-elements/jsx-preview.tsx +250 -0
  24. package/src/components/ai-elements/message.tsx +359 -0
  25. package/src/components/ai-elements/mic-selector.tsx +372 -0
  26. package/src/components/ai-elements/model-selector.tsx +214 -0
  27. package/src/components/ai-elements/node.tsx +72 -0
  28. package/src/components/ai-elements/open-in-chat.tsx +367 -0
  29. package/src/components/ai-elements/package-info.tsx +235 -0
  30. package/src/components/ai-elements/panel.tsx +16 -0
  31. package/src/components/ai-elements/persona.tsx +280 -0
  32. package/src/components/ai-elements/plan.tsx +144 -0
  33. package/src/components/ai-elements/prompt-input.tsx +1341 -0
  34. package/src/components/ai-elements/queue.tsx +275 -0
  35. package/src/components/ai-elements/reasoning.tsx +229 -0
  36. package/src/components/ai-elements/sandbox.tsx +133 -0
  37. package/src/components/ai-elements/schema-display.tsx +473 -0
  38. package/src/components/ai-elements/shimmer.tsx +78 -0
  39. package/src/components/ai-elements/snippet.tsx +141 -0
  40. package/src/components/ai-elements/sources.tsx +78 -0
  41. package/src/components/ai-elements/speech-input.tsx +324 -0
  42. package/src/components/ai-elements/stack-trace.tsx +531 -0
  43. package/src/components/ai-elements/suggestion.tsx +58 -0
  44. package/src/components/ai-elements/task.tsx +88 -0
  45. package/src/components/ai-elements/terminal.tsx +277 -0
  46. package/src/components/ai-elements/test-results.tsx +497 -0
  47. package/src/components/ai-elements/tool.tsx +174 -0
  48. package/src/components/ai-elements/toolbar.tsx +17 -0
  49. package/src/components/ai-elements/transcription.tsx +126 -0
  50. package/src/components/ai-elements/voice-selector.tsx +525 -0
  51. package/src/components/ai-elements/web-preview.tsx +282 -0
  52. package/src/components/ui/accordion.tsx +64 -0
  53. package/src/components/ui/alert-dialog.tsx +196 -0
  54. package/src/components/ui/alert.tsx +66 -0
  55. package/src/components/ui/aspect-ratio.tsx +11 -0
  56. package/src/components/ui/avatar.tsx +107 -0
  57. package/src/components/ui/badge.tsx +48 -0
  58. package/src/components/ui/breadcrumb.tsx +109 -0
  59. package/src/components/ui/button-group.tsx +83 -0
  60. package/src/components/ui/button.tsx +64 -0
  61. package/src/components/ui/calendar.tsx +218 -0
  62. package/src/components/ui/card.tsx +92 -0
  63. package/src/components/ui/carousel.tsx +239 -0
  64. package/src/components/ui/chart.tsx +355 -0
  65. package/src/components/ui/checkbox.tsx +32 -0
  66. package/src/components/ui/collapsible.tsx +31 -0
  67. package/src/components/ui/combobox.tsx +310 -0
  68. package/src/components/ui/command.tsx +184 -0
  69. package/src/components/ui/context-menu.tsx +252 -0
  70. package/src/components/ui/dialog.tsx +158 -0
  71. package/src/components/ui/direction.tsx +22 -0
  72. package/src/components/ui/drawer.tsx +133 -0
  73. package/src/components/ui/dropdown-menu.tsx +257 -0
  74. package/src/components/ui/empty.tsx +104 -0
  75. package/src/components/ui/field.tsx +248 -0
  76. package/src/components/ui/form.tsx +165 -0
  77. package/src/components/ui/hover-card.tsx +42 -0
  78. package/src/components/ui/input-group.tsx +168 -0
  79. package/src/components/ui/input-otp.tsx +77 -0
  80. package/src/components/ui/input.tsx +21 -0
  81. package/src/components/ui/item.tsx +193 -0
  82. package/src/components/ui/kbd.tsx +28 -0
  83. package/src/components/ui/label.tsx +22 -0
  84. package/src/components/ui/menubar.tsx +276 -0
  85. package/src/components/ui/native-select.tsx +53 -0
  86. package/src/components/ui/navigation-menu.tsx +168 -0
  87. package/src/components/ui/pagination.tsx +127 -0
  88. package/src/components/ui/popover.tsx +87 -0
  89. package/src/components/ui/progress.tsx +31 -0
  90. package/src/components/ui/radio-group.tsx +43 -0
  91. package/src/components/ui/resizable.tsx +53 -0
  92. package/src/components/ui/scroll-area.tsx +56 -0
  93. package/src/components/ui/select.tsx +190 -0
  94. package/src/components/ui/separator.tsx +28 -0
  95. package/src/components/ui/sheet.tsx +145 -0
  96. package/src/components/ui/sidebar.tsx +724 -0
  97. package/src/components/ui/skeleton.tsx +13 -0
  98. package/src/components/ui/slider.tsx +61 -0
  99. package/src/components/ui/sonner.tsx +40 -0
  100. package/src/components/ui/spinner.tsx +16 -0
  101. package/src/components/ui/switch.tsx +33 -0
  102. package/src/components/ui/table.tsx +116 -0
  103. package/src/components/ui/tabs.tsx +91 -0
  104. package/src/components/ui/textarea.tsx +18 -0
  105. package/src/components/ui/toggle-group.tsx +83 -0
  106. package/src/components/ui/toggle.tsx +47 -0
  107. package/src/components/ui/tooltip.tsx +57 -0
  108. package/src/components/ui/tree.tsx +207 -0
  109. package/src/hooks/use-mobile.ts +17 -0
  110. package/src/index.ts +16 -0
  111. package/src/lib/utils.ts +6 -0
  112. package/src/styles/globals.css +373 -0
  113. package/tsconfig.json +18 -0
@@ -0,0 +1,275 @@
1
+ "use client";
2
+
3
+ import type { ComponentProps } from "react";
4
+
5
+ import { Button } from "../ui/button";
6
+ import {
7
+ Collapsible,
8
+ CollapsibleContent,
9
+ CollapsibleTrigger,
10
+ } from "../ui/collapsible";
11
+ import { ScrollArea } from "../ui/scroll-area";
12
+ import { cn } from "../../lib/utils";
13
+ import { ChevronDownIcon, PaperclipIcon } from "lucide-react";
14
+
15
+ export interface QueueMessagePart {
16
+ type: string;
17
+ text?: string;
18
+ url?: string;
19
+ filename?: string;
20
+ mediaType?: string;
21
+ }
22
+
23
+ export interface QueueMessage {
24
+ id: string;
25
+ parts: QueueMessagePart[];
26
+ }
27
+
28
+ export interface QueueTodo {
29
+ id: string;
30
+ title: string;
31
+ description?: string;
32
+ status?: "pending" | "completed";
33
+ }
34
+
35
+ export type QueueItemProps = ComponentProps<"li">;
36
+
37
+ export const QueueItem = ({ className, ...props }: QueueItemProps) => (
38
+ <li
39
+ className={cn(
40
+ "group flex flex-col gap-1 rounded-md px-3 py-1 text-sm transition-colors hover:bg-muted",
41
+ className
42
+ )}
43
+ {...props}
44
+ />
45
+ );
46
+
47
+ export type QueueItemIndicatorProps = ComponentProps<"span"> & {
48
+ completed?: boolean;
49
+ };
50
+
51
+ export const QueueItemIndicator = ({
52
+ completed = false,
53
+ className,
54
+ ...props
55
+ }: QueueItemIndicatorProps) => (
56
+ <span
57
+ className={cn(
58
+ "mt-0.5 inline-block size-2.5 rounded-full border",
59
+ completed
60
+ ? "border-muted-foreground/20 bg-muted-foreground/10"
61
+ : "border-muted-foreground/50",
62
+ className
63
+ )}
64
+ {...props}
65
+ />
66
+ );
67
+
68
+ export type QueueItemContentProps = ComponentProps<"span"> & {
69
+ completed?: boolean;
70
+ };
71
+
72
+ export const QueueItemContent = ({
73
+ completed = false,
74
+ className,
75
+ ...props
76
+ }: QueueItemContentProps) => (
77
+ <span
78
+ className={cn(
79
+ "line-clamp-1 grow break-words",
80
+ completed
81
+ ? "text-muted-foreground/50 line-through"
82
+ : "text-muted-foreground",
83
+ className
84
+ )}
85
+ {...props}
86
+ />
87
+ );
88
+
89
+ export type QueueItemDescriptionProps = ComponentProps<"div"> & {
90
+ completed?: boolean;
91
+ };
92
+
93
+ export const QueueItemDescription = ({
94
+ completed = false,
95
+ className,
96
+ ...props
97
+ }: QueueItemDescriptionProps) => (
98
+ <div
99
+ className={cn(
100
+ "ml-6 text-xs",
101
+ completed
102
+ ? "text-muted-foreground/40 line-through"
103
+ : "text-muted-foreground",
104
+ className
105
+ )}
106
+ {...props}
107
+ />
108
+ );
109
+
110
+ export type QueueItemActionsProps = ComponentProps<"div">;
111
+
112
+ export const QueueItemActions = ({
113
+ className,
114
+ ...props
115
+ }: QueueItemActionsProps) => (
116
+ <div className={cn("flex gap-1", className)} {...props} />
117
+ );
118
+
119
+ export type QueueItemActionProps = Omit<
120
+ ComponentProps<typeof Button>,
121
+ "variant" | "size"
122
+ >;
123
+
124
+ export const QueueItemAction = ({
125
+ className,
126
+ ...props
127
+ }: QueueItemActionProps) => (
128
+ <Button
129
+ className={cn(
130
+ "size-auto rounded p-1 text-muted-foreground opacity-0 transition-opacity hover:bg-muted-foreground/10 hover:text-foreground group-hover:opacity-100",
131
+ className
132
+ )}
133
+ size="icon"
134
+ type="button"
135
+ variant="ghost"
136
+ {...props}
137
+ />
138
+ );
139
+
140
+ export type QueueItemAttachmentProps = ComponentProps<"div">;
141
+
142
+ export const QueueItemAttachment = ({
143
+ className,
144
+ ...props
145
+ }: QueueItemAttachmentProps) => (
146
+ <div className={cn("mt-1 flex flex-wrap gap-2", className)} {...props} />
147
+ );
148
+
149
+ export type QueueItemImageProps = ComponentProps<"img">;
150
+
151
+ export const QueueItemImage = ({
152
+ className,
153
+ ...props
154
+ }: QueueItemImageProps) => (
155
+ <img
156
+ alt=""
157
+ className={cn("h-8 w-8 rounded border object-cover", className)}
158
+ height={32}
159
+ width={32}
160
+ {...props}
161
+ />
162
+ );
163
+
164
+ export type QueueItemFileProps = ComponentProps<"span">;
165
+
166
+ export const QueueItemFile = ({
167
+ children,
168
+ className,
169
+ ...props
170
+ }: QueueItemFileProps) => (
171
+ <span
172
+ className={cn(
173
+ "flex items-center gap-1 rounded border bg-muted px-2 py-1 text-xs",
174
+ className
175
+ )}
176
+ {...props}
177
+ >
178
+ <PaperclipIcon size={12} />
179
+ <span className="max-w-[100px] truncate">{children}</span>
180
+ </span>
181
+ );
182
+
183
+ export type QueueListProps = ComponentProps<typeof ScrollArea>;
184
+
185
+ export const QueueList = ({
186
+ children,
187
+ className,
188
+ ...props
189
+ }: QueueListProps) => (
190
+ <ScrollArea className={cn("mt-2 -mb-1", className)} {...props}>
191
+ <div className="max-h-40 pr-4">
192
+ <ul>{children}</ul>
193
+ </div>
194
+ </ScrollArea>
195
+ );
196
+
197
+ // QueueSection - collapsible section container
198
+ export type QueueSectionProps = ComponentProps<typeof Collapsible>;
199
+
200
+ export const QueueSection = ({
201
+ className,
202
+ defaultOpen = true,
203
+ ...props
204
+ }: QueueSectionProps) => (
205
+ <Collapsible className={cn(className)} defaultOpen={defaultOpen} {...props} />
206
+ );
207
+
208
+ // QueueSectionTrigger - section header/trigger
209
+ export type QueueSectionTriggerProps = ComponentProps<"button">;
210
+
211
+ export const QueueSectionTrigger = ({
212
+ children,
213
+ className,
214
+ ...props
215
+ }: QueueSectionTriggerProps) => (
216
+ <CollapsibleTrigger asChild>
217
+ <button
218
+ className={cn(
219
+ "group flex w-full items-center justify-between rounded-md bg-muted/40 px-3 py-2 text-left font-medium text-muted-foreground text-sm transition-colors hover:bg-muted",
220
+ className
221
+ )}
222
+ type="button"
223
+ {...props}
224
+ >
225
+ {children}
226
+ </button>
227
+ </CollapsibleTrigger>
228
+ );
229
+
230
+ // QueueSectionLabel - label content with icon and count
231
+ export type QueueSectionLabelProps = ComponentProps<"span"> & {
232
+ count?: number;
233
+ label: string;
234
+ icon?: React.ReactNode;
235
+ };
236
+
237
+ export const QueueSectionLabel = ({
238
+ count,
239
+ label,
240
+ icon,
241
+ className,
242
+ ...props
243
+ }: QueueSectionLabelProps) => (
244
+ <span className={cn("flex items-center gap-2", className)} {...props}>
245
+ <ChevronDownIcon className="size-4 transition-transform group-data-[state=closed]:-rotate-90" />
246
+ {icon}
247
+ <span>
248
+ {count} {label}
249
+ </span>
250
+ </span>
251
+ );
252
+
253
+ // QueueSectionContent - collapsible content area
254
+ export type QueueSectionContentProps = ComponentProps<
255
+ typeof CollapsibleContent
256
+ >;
257
+
258
+ export const QueueSectionContent = ({
259
+ className,
260
+ ...props
261
+ }: QueueSectionContentProps) => (
262
+ <CollapsibleContent className={cn(className)} {...props} />
263
+ );
264
+
265
+ export type QueueProps = ComponentProps<"div">;
266
+
267
+ export const Queue = ({ className, ...props }: QueueProps) => (
268
+ <div
269
+ className={cn(
270
+ "flex flex-col gap-2 rounded-xl border border-border bg-background px-3 pt-2 pb-2 shadow-xs",
271
+ className
272
+ )}
273
+ {...props}
274
+ />
275
+ );
@@ -0,0 +1,229 @@
1
+ "use client";
2
+
3
+ import type { ComponentProps, ReactNode } from "react";
4
+
5
+ import { useControllableState } from "@radix-ui/react-use-controllable-state";
6
+ import {
7
+ Collapsible,
8
+ CollapsibleContent,
9
+ CollapsibleTrigger,
10
+ } from "../ui/collapsible";
11
+ import { cn } from "../../lib/utils";
12
+ import { cjk } from "@streamdown/cjk";
13
+ import { code } from "@streamdown/code";
14
+ import { math } from "@streamdown/math";
15
+ import { mermaid } from "@streamdown/mermaid";
16
+ import { BrainIcon, ChevronDownIcon } from "lucide-react";
17
+ import {
18
+ createContext,
19
+ memo,
20
+ useCallback,
21
+ useContext,
22
+ useEffect,
23
+ useMemo,
24
+ useRef,
25
+ useState,
26
+ } from "react";
27
+ import { Streamdown } from "streamdown";
28
+
29
+ import { Shimmer } from "./shimmer";
30
+
31
+ interface ReasoningContextValue {
32
+ isStreaming: boolean;
33
+ isOpen: boolean;
34
+ setIsOpen: (open: boolean) => void;
35
+ duration: number | undefined;
36
+ }
37
+
38
+ const ReasoningContext = createContext<ReasoningContextValue | null>(null);
39
+
40
+ export const useReasoning = () => {
41
+ const context = useContext(ReasoningContext);
42
+ if (!context) {
43
+ throw new Error("Reasoning components must be used within Reasoning");
44
+ }
45
+ return context;
46
+ };
47
+
48
+ export type ReasoningProps = ComponentProps<typeof Collapsible> & {
49
+ isStreaming?: boolean;
50
+ open?: boolean;
51
+ defaultOpen?: boolean;
52
+ onOpenChange?: (open: boolean) => void;
53
+ duration?: number;
54
+ };
55
+
56
+ const AUTO_CLOSE_DELAY = 1000;
57
+ const MS_IN_S = 1000;
58
+
59
+ export const Reasoning = memo(
60
+ ({
61
+ className,
62
+ isStreaming = false,
63
+ open,
64
+ defaultOpen,
65
+ onOpenChange,
66
+ duration: durationProp,
67
+ children,
68
+ ...props
69
+ }: ReasoningProps) => {
70
+ const resolvedDefaultOpen = defaultOpen ?? isStreaming;
71
+ // Track if defaultOpen was explicitly set to false (to prevent auto-open)
72
+ const isExplicitlyClosed = defaultOpen === false;
73
+
74
+ const [isOpen, setIsOpen] = useControllableState<boolean>({
75
+ defaultProp: resolvedDefaultOpen,
76
+ onChange: onOpenChange,
77
+ prop: open,
78
+ });
79
+ const [duration, setDuration] = useControllableState<number | undefined>({
80
+ defaultProp: undefined,
81
+ prop: durationProp,
82
+ });
83
+
84
+ const hasEverStreamedRef = useRef(isStreaming);
85
+ const [hasAutoClosed, setHasAutoClosed] = useState(false);
86
+ const startTimeRef = useRef<number | null>(null);
87
+
88
+ // Track when streaming starts and compute duration
89
+ useEffect(() => {
90
+ if (isStreaming) {
91
+ hasEverStreamedRef.current = true;
92
+ if (startTimeRef.current === null) {
93
+ startTimeRef.current = Date.now();
94
+ }
95
+ } else if (startTimeRef.current !== null) {
96
+ setDuration(Math.ceil((Date.now() - startTimeRef.current) / MS_IN_S));
97
+ startTimeRef.current = null;
98
+ }
99
+ }, [isStreaming, setDuration]);
100
+
101
+ // Auto-open when streaming starts (unless explicitly closed)
102
+ useEffect(() => {
103
+ if (isStreaming && !isOpen && !isExplicitlyClosed) {
104
+ setIsOpen(true);
105
+ }
106
+ }, [isStreaming, isOpen, setIsOpen, isExplicitlyClosed]);
107
+
108
+ // Auto-close when streaming ends (once only, and only if it ever streamed)
109
+ useEffect(() => {
110
+ if (
111
+ hasEverStreamedRef.current &&
112
+ !isStreaming &&
113
+ isOpen &&
114
+ !hasAutoClosed
115
+ ) {
116
+ const timer = setTimeout(() => {
117
+ setIsOpen(false);
118
+ setHasAutoClosed(true);
119
+ }, AUTO_CLOSE_DELAY);
120
+
121
+ return () => clearTimeout(timer);
122
+ }
123
+ }, [isStreaming, isOpen, setIsOpen, hasAutoClosed]);
124
+
125
+ const handleOpenChange = useCallback(
126
+ (newOpen: boolean) => {
127
+ setIsOpen(newOpen);
128
+ },
129
+ [setIsOpen]
130
+ );
131
+
132
+ const contextValue = useMemo(
133
+ () => ({ duration, isOpen, isStreaming, setIsOpen }),
134
+ [duration, isOpen, isStreaming, setIsOpen]
135
+ );
136
+
137
+ return (
138
+ <ReasoningContext.Provider value={contextValue}>
139
+ <Collapsible
140
+ className={cn("not-prose mb-4", className)}
141
+ onOpenChange={handleOpenChange}
142
+ open={isOpen}
143
+ {...props}
144
+ >
145
+ {children}
146
+ </Collapsible>
147
+ </ReasoningContext.Provider>
148
+ );
149
+ }
150
+ );
151
+
152
+ export type ReasoningTriggerProps = ComponentProps<
153
+ typeof CollapsibleTrigger
154
+ > & {
155
+ getThinkingMessage?: (isStreaming: boolean, duration?: number) => ReactNode;
156
+ };
157
+
158
+ const defaultGetThinkingMessage = (isStreaming: boolean, duration?: number) => {
159
+ if (isStreaming || duration === 0) {
160
+ return <Shimmer duration={1}>Thinking...</Shimmer>;
161
+ }
162
+ if (duration === undefined) {
163
+ return <p>Thought for a few seconds</p>;
164
+ }
165
+ return <p>Thought for {duration} seconds</p>;
166
+ };
167
+
168
+ export const ReasoningTrigger = memo(
169
+ ({
170
+ className,
171
+ children,
172
+ getThinkingMessage = defaultGetThinkingMessage,
173
+ ...props
174
+ }: ReasoningTriggerProps) => {
175
+ const { isStreaming, isOpen, duration } = useReasoning();
176
+
177
+ return (
178
+ <CollapsibleTrigger
179
+ className={cn(
180
+ "flex w-full items-center gap-2 text-muted-foreground text-sm transition-colors hover:text-foreground",
181
+ className
182
+ )}
183
+ {...props}
184
+ >
185
+ {children ?? (
186
+ <>
187
+ <BrainIcon className="size-4" />
188
+ {getThinkingMessage(isStreaming, duration)}
189
+ <ChevronDownIcon
190
+ className={cn(
191
+ "size-4 transition-transform",
192
+ isOpen ? "rotate-180" : "rotate-0"
193
+ )}
194
+ />
195
+ </>
196
+ )}
197
+ </CollapsibleTrigger>
198
+ );
199
+ }
200
+ );
201
+
202
+ export type ReasoningContentProps = ComponentProps<
203
+ typeof CollapsibleContent
204
+ > & {
205
+ children: string;
206
+ };
207
+
208
+ const streamdownPlugins = { cjk, code, math, mermaid };
209
+
210
+ export const ReasoningContent = memo(
211
+ ({ className, children, ...props }: ReasoningContentProps) => (
212
+ <CollapsibleContent
213
+ className={cn(
214
+ "mt-4 text-sm",
215
+ "data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-muted-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",
216
+ className
217
+ )}
218
+ {...props}
219
+ >
220
+ <Streamdown plugins={streamdownPlugins}>
221
+ {children}
222
+ </Streamdown>
223
+ </CollapsibleContent>
224
+ )
225
+ );
226
+
227
+ Reasoning.displayName = "Reasoning";
228
+ ReasoningTrigger.displayName = "ReasoningTrigger";
229
+ ReasoningContent.displayName = "ReasoningContent";
@@ -0,0 +1,133 @@
1
+ "use client";
2
+
3
+ import type { ToolUIPart } from "ai";
4
+ import type { ComponentProps } from "react";
5
+
6
+ import {
7
+ Collapsible,
8
+ CollapsibleContent,
9
+ CollapsibleTrigger,
10
+ } from "../ui/collapsible";
11
+ import {
12
+ Tabs,
13
+ TabsContent,
14
+ TabsList,
15
+ TabsTrigger,
16
+ } from "../ui/tabs";
17
+ import { cn } from "../../lib/utils";
18
+ import { ChevronDownIcon, Code } from "lucide-react";
19
+
20
+ import { getStatusBadge } from "./tool";
21
+
22
+ export type SandboxRootProps = ComponentProps<typeof Collapsible>;
23
+
24
+ export const Sandbox = ({ className, ...props }: SandboxRootProps) => (
25
+ <Collapsible
26
+ className={cn(
27
+ "not-prose group mb-4 w-full overflow-hidden rounded-md border",
28
+ className
29
+ )}
30
+ defaultOpen
31
+ {...props}
32
+ />
33
+ );
34
+
35
+ export interface SandboxHeaderProps {
36
+ title?: string;
37
+ state: ToolUIPart["state"];
38
+ className?: string;
39
+ }
40
+
41
+ export const SandboxHeader = ({
42
+ className,
43
+ title,
44
+ state,
45
+ ...props
46
+ }: SandboxHeaderProps) => (
47
+ <CollapsibleTrigger
48
+ className={cn(
49
+ "flex w-full items-center justify-between gap-4 p-3",
50
+ className
51
+ )}
52
+ {...props}
53
+ >
54
+ <div className="flex items-center gap-2">
55
+ <Code className="size-4 text-muted-foreground" />
56
+ <span className="font-medium text-sm">{title}</span>
57
+ {getStatusBadge(state)}
58
+ </div>
59
+ <ChevronDownIcon className="size-4 text-muted-foreground transition-transform group-data-[state=open]:rotate-180" />
60
+ </CollapsibleTrigger>
61
+ );
62
+
63
+ export type SandboxContentProps = ComponentProps<typeof CollapsibleContent>;
64
+
65
+ export const SandboxContent = ({
66
+ className,
67
+ ...props
68
+ }: SandboxContentProps) => (
69
+ <CollapsibleContent
70
+ className={cn(
71
+ "data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",
72
+ className
73
+ )}
74
+ {...props}
75
+ />
76
+ );
77
+
78
+ export type SandboxTabsProps = ComponentProps<typeof Tabs>;
79
+
80
+ export const SandboxTabs = ({ className, ...props }: SandboxTabsProps) => (
81
+ <Tabs className={cn("w-full gap-0", className)} {...props} />
82
+ );
83
+
84
+ export type SandboxTabsBarProps = ComponentProps<"div">;
85
+
86
+ export const SandboxTabsBar = ({
87
+ className,
88
+ ...props
89
+ }: SandboxTabsBarProps) => (
90
+ <div
91
+ className={cn(
92
+ "flex w-full items-center border-border border-t border-b",
93
+ className
94
+ )}
95
+ {...props}
96
+ />
97
+ );
98
+
99
+ export type SandboxTabsListProps = ComponentProps<typeof TabsList>;
100
+
101
+ export const SandboxTabsList = ({
102
+ className,
103
+ ...props
104
+ }: SandboxTabsListProps) => (
105
+ <TabsList
106
+ className={cn("h-auto rounded-none border-0 bg-transparent p-0", className)}
107
+ {...props}
108
+ />
109
+ );
110
+
111
+ export type SandboxTabsTriggerProps = ComponentProps<typeof TabsTrigger>;
112
+
113
+ export const SandboxTabsTrigger = ({
114
+ className,
115
+ ...props
116
+ }: SandboxTabsTriggerProps) => (
117
+ <TabsTrigger
118
+ className={cn(
119
+ "rounded-none border-0 border-transparent border-b-2 px-4 py-2 font-medium text-muted-foreground text-sm transition-colors data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:text-foreground data-[state=active]:shadow-none",
120
+ className
121
+ )}
122
+ {...props}
123
+ />
124
+ );
125
+
126
+ export type SandboxTabContentProps = ComponentProps<typeof TabsContent>;
127
+
128
+ export const SandboxTabContent = ({
129
+ className,
130
+ ...props
131
+ }: SandboxTabContentProps) => (
132
+ <TabsContent className={cn("mt-0 text-sm", className)} {...props} />
133
+ );