@cloudbase/agent-react-ui 0.0.23
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.
- package/README.md +135 -0
- package/components.json +21 -0
- package/dist/index.css +4241 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.mts +59 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +2169 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2182 -0
- package/dist/index.mjs.map +1 -0
- package/example/.env.sample +2 -0
- package/example/App.tsx +368 -0
- package/example/app.css +1 -0
- package/example/index.html +12 -0
- package/example/main.tsx +9 -0
- package/example/vite.config.ts +34 -0
- package/package.json +75 -0
- package/postcss.config.cjs +3 -0
- package/src/components/ai-elements/agent.tsx +140 -0
- package/src/components/ai-elements/artifact.tsx +147 -0
- package/src/components/ai-elements/attachments.tsx +421 -0
- package/src/components/ai-elements/audio-player.tsx +228 -0
- package/src/components/ai-elements/canvas.tsx +22 -0
- package/src/components/ai-elements/chain-of-thought.tsx +228 -0
- package/src/components/ai-elements/checkpoint.tsx +71 -0
- package/src/components/ai-elements/code-block.tsx +532 -0
- package/src/components/ai-elements/commit.tsx +448 -0
- package/src/components/ai-elements/confirmation.tsx +176 -0
- package/src/components/ai-elements/connection.tsx +28 -0
- package/src/components/ai-elements/context.tsx +408 -0
- package/src/components/ai-elements/controls.tsx +18 -0
- package/src/components/ai-elements/conversation.tsx +100 -0
- package/src/components/ai-elements/edge.tsx +140 -0
- package/src/components/ai-elements/environment-variables.tsx +295 -0
- package/src/components/ai-elements/file-tree.tsx +258 -0
- package/src/components/ai-elements/image.tsx +24 -0
- package/src/components/ai-elements/inline-citation.tsx +287 -0
- package/src/components/ai-elements/message.tsx +336 -0
- package/src/components/ai-elements/mic-selector.tsx +370 -0
- package/src/components/ai-elements/model-selector.tsx +211 -0
- package/src/components/ai-elements/node.tsx +71 -0
- package/src/components/ai-elements/open-in-chat.tsx +365 -0
- package/src/components/ai-elements/package-info.tsx +233 -0
- package/src/components/ai-elements/panel.tsx +15 -0
- package/src/components/ai-elements/persona.tsx +270 -0
- package/src/components/ai-elements/plan.tsx +142 -0
- package/src/components/ai-elements/prompt-input.tsx +1263 -0
- package/src/components/ai-elements/queue.tsx +274 -0
- package/src/components/ai-elements/reasoning.tsx +193 -0
- package/src/components/ai-elements/sandbox.tsx +126 -0
- package/src/components/ai-elements/schema-display.tsx +458 -0
- package/src/components/ai-elements/shimmer.tsx +64 -0
- package/src/components/ai-elements/snippet.tsx +139 -0
- package/src/components/ai-elements/sources.tsx +77 -0
- package/src/components/ai-elements/speech-input.tsx +301 -0
- package/src/components/ai-elements/stack-trace.tsx +482 -0
- package/src/components/ai-elements/suggestion.tsx +53 -0
- package/src/components/ai-elements/task.tsx +87 -0
- package/src/components/ai-elements/terminal.tsx +261 -0
- package/src/components/ai-elements/test-results.tsx +485 -0
- package/src/components/ai-elements/tool.tsx +174 -0
- package/src/components/ai-elements/toolbar.tsx +16 -0
- package/src/components/ai-elements/transcription.tsx +124 -0
- package/src/components/ai-elements/voice-selector.tsx +479 -0
- package/src/components/ai-elements/web-preview.tsx +263 -0
- package/src/components/chat/Chat.tsx +178 -0
- package/src/components/chat/Input.tsx +98 -0
- package/src/components/chat/Message.tsx +276 -0
- package/src/components/chat/index.ts +2 -0
- package/src/components/index.ts +1 -0
- package/src/components/ui/accordion.tsx +64 -0
- package/src/components/ui/alert.tsx +66 -0
- package/src/components/ui/avatar.tsx +107 -0
- package/src/components/ui/badge.tsx +48 -0
- package/src/components/ui/button-group.tsx +83 -0
- package/src/components/ui/button.tsx +64 -0
- package/src/components/ui/card.tsx +92 -0
- package/src/components/ui/carousel.tsx +239 -0
- package/src/components/ui/collapsible.tsx +31 -0
- package/src/components/ui/command.tsx +184 -0
- package/src/components/ui/dialog.tsx +158 -0
- package/src/components/ui/dropdown-menu.tsx +257 -0
- package/src/components/ui/hover-card.tsx +42 -0
- package/src/components/ui/input-group.tsx +168 -0
- package/src/components/ui/input.tsx +21 -0
- package/src/components/ui/popover.tsx +87 -0
- package/src/components/ui/progress.tsx +31 -0
- package/src/components/ui/scroll-area.tsx +56 -0
- package/src/components/ui/select.tsx +190 -0
- package/src/components/ui/separator.tsx +28 -0
- package/src/components/ui/spinner.tsx +16 -0
- package/src/components/ui/switch.tsx +33 -0
- package/src/components/ui/tabs.tsx +91 -0
- package/src/components/ui/textarea.tsx +18 -0
- package/src/components/ui/tooltip.tsx +61 -0
- package/src/css/global.css +123 -0
- package/src/css/index.css +1 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-copy-to-clipboard.ts +31 -0
- package/src/index.ts +4 -0
- package/src/lib/utils.ts +6 -0
- package/src/locales/context.ts +8 -0
- package/src/locales/hooks.ts +20 -0
- package/src/locales/index.ts +3 -0
- package/src/locales/langs/en.ts +17 -0
- package/src/locales/langs/index.ts +12 -0
- package/src/locales/langs/zh-cn.ts +18 -0
- package/tsconfig.json +21 -0
- package/tsup.config.ts +21 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Button } from "@/components/ui/button";
|
|
4
|
+
import {
|
|
5
|
+
Tooltip,
|
|
6
|
+
TooltipContent,
|
|
7
|
+
TooltipProvider,
|
|
8
|
+
TooltipTrigger,
|
|
9
|
+
} from "@/components/ui/tooltip";
|
|
10
|
+
import { cn } from "@/lib/utils";
|
|
11
|
+
import { type LucideIcon, XIcon } from "lucide-react";
|
|
12
|
+
import type { ComponentProps, HTMLAttributes } from "react";
|
|
13
|
+
|
|
14
|
+
export type ArtifactProps = HTMLAttributes<HTMLDivElement>;
|
|
15
|
+
|
|
16
|
+
export const Artifact = ({ className, ...props }: ArtifactProps) => (
|
|
17
|
+
<div
|
|
18
|
+
className={cn(
|
|
19
|
+
"flex flex-col overflow-hidden rounded-lg border bg-background shadow-sm",
|
|
20
|
+
className
|
|
21
|
+
)}
|
|
22
|
+
{...props}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export type ArtifactHeaderProps = HTMLAttributes<HTMLDivElement>;
|
|
27
|
+
|
|
28
|
+
export const ArtifactHeader = ({
|
|
29
|
+
className,
|
|
30
|
+
...props
|
|
31
|
+
}: ArtifactHeaderProps) => (
|
|
32
|
+
<div
|
|
33
|
+
className={cn(
|
|
34
|
+
"flex items-center justify-between border-b bg-muted/50 px-4 py-3",
|
|
35
|
+
className
|
|
36
|
+
)}
|
|
37
|
+
{...props}
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
export type ArtifactCloseProps = ComponentProps<typeof Button>;
|
|
42
|
+
|
|
43
|
+
export const ArtifactClose = ({
|
|
44
|
+
className,
|
|
45
|
+
children,
|
|
46
|
+
size = "sm",
|
|
47
|
+
variant = "ghost",
|
|
48
|
+
...props
|
|
49
|
+
}: ArtifactCloseProps) => (
|
|
50
|
+
<Button
|
|
51
|
+
className={cn(
|
|
52
|
+
"size-8 p-0 text-muted-foreground hover:text-foreground",
|
|
53
|
+
className
|
|
54
|
+
)}
|
|
55
|
+
size={size}
|
|
56
|
+
type="button"
|
|
57
|
+
variant={variant}
|
|
58
|
+
{...props}
|
|
59
|
+
>
|
|
60
|
+
{children ?? <XIcon className="size-4" />}
|
|
61
|
+
<span className="sr-only">Close</span>
|
|
62
|
+
</Button>
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
export type ArtifactTitleProps = HTMLAttributes<HTMLParagraphElement>;
|
|
66
|
+
|
|
67
|
+
export const ArtifactTitle = ({ className, ...props }: ArtifactTitleProps) => (
|
|
68
|
+
<p
|
|
69
|
+
className={cn("font-medium text-foreground text-sm", className)}
|
|
70
|
+
{...props}
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
export type ArtifactDescriptionProps = HTMLAttributes<HTMLParagraphElement>;
|
|
75
|
+
|
|
76
|
+
export const ArtifactDescription = ({
|
|
77
|
+
className,
|
|
78
|
+
...props
|
|
79
|
+
}: ArtifactDescriptionProps) => (
|
|
80
|
+
<p className={cn("text-muted-foreground text-sm", className)} {...props} />
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
export type ArtifactActionsProps = HTMLAttributes<HTMLDivElement>;
|
|
84
|
+
|
|
85
|
+
export const ArtifactActions = ({
|
|
86
|
+
className,
|
|
87
|
+
...props
|
|
88
|
+
}: ArtifactActionsProps) => (
|
|
89
|
+
<div className={cn("flex items-center gap-1", className)} {...props} />
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
export type ArtifactActionProps = ComponentProps<typeof Button> & {
|
|
93
|
+
tooltip?: string;
|
|
94
|
+
label?: string;
|
|
95
|
+
icon?: LucideIcon;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const ArtifactAction = ({
|
|
99
|
+
tooltip,
|
|
100
|
+
label,
|
|
101
|
+
icon: Icon,
|
|
102
|
+
children,
|
|
103
|
+
className,
|
|
104
|
+
size = "sm",
|
|
105
|
+
variant = "ghost",
|
|
106
|
+
...props
|
|
107
|
+
}: ArtifactActionProps) => {
|
|
108
|
+
const button = (
|
|
109
|
+
<Button
|
|
110
|
+
className={cn(
|
|
111
|
+
"size-8 p-0 text-muted-foreground hover:text-foreground",
|
|
112
|
+
className
|
|
113
|
+
)}
|
|
114
|
+
size={size}
|
|
115
|
+
type="button"
|
|
116
|
+
variant={variant}
|
|
117
|
+
{...props}
|
|
118
|
+
>
|
|
119
|
+
{Icon ? <Icon className="size-4" /> : children}
|
|
120
|
+
<span className="sr-only">{label || tooltip}</span>
|
|
121
|
+
</Button>
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
if (tooltip) {
|
|
125
|
+
return (
|
|
126
|
+
<TooltipProvider>
|
|
127
|
+
<Tooltip>
|
|
128
|
+
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
|
129
|
+
<TooltipContent>
|
|
130
|
+
<p>{tooltip}</p>
|
|
131
|
+
</TooltipContent>
|
|
132
|
+
</Tooltip>
|
|
133
|
+
</TooltipProvider>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return button;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export type ArtifactContentProps = HTMLAttributes<HTMLDivElement>;
|
|
141
|
+
|
|
142
|
+
export const ArtifactContent = ({
|
|
143
|
+
className,
|
|
144
|
+
...props
|
|
145
|
+
}: ArtifactContentProps) => (
|
|
146
|
+
<div className={cn("flex-1 overflow-auto p-4", className)} {...props} />
|
|
147
|
+
);
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Button } from "@/components/ui/button";
|
|
4
|
+
import {
|
|
5
|
+
HoverCard,
|
|
6
|
+
HoverCardContent,
|
|
7
|
+
HoverCardTrigger,
|
|
8
|
+
} from "@/components/ui/hover-card";
|
|
9
|
+
import { cn } from "@/lib/utils";
|
|
10
|
+
import type { FileUIPart, SourceDocumentUIPart } from "ai";
|
|
11
|
+
import {
|
|
12
|
+
FileTextIcon,
|
|
13
|
+
GlobeIcon,
|
|
14
|
+
ImageIcon,
|
|
15
|
+
Music2Icon,
|
|
16
|
+
PaperclipIcon,
|
|
17
|
+
VideoIcon,
|
|
18
|
+
XIcon,
|
|
19
|
+
} from "lucide-react";
|
|
20
|
+
import type { ComponentProps, HTMLAttributes, ReactNode } from "react";
|
|
21
|
+
import { createContext, useContext, useMemo } from "react";
|
|
22
|
+
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// Types
|
|
25
|
+
// ============================================================================
|
|
26
|
+
|
|
27
|
+
export type AttachmentData =
|
|
28
|
+
| (FileUIPart & { id: string })
|
|
29
|
+
| (SourceDocumentUIPart & { id: string });
|
|
30
|
+
|
|
31
|
+
export type AttachmentMediaCategory =
|
|
32
|
+
| "image"
|
|
33
|
+
| "video"
|
|
34
|
+
| "audio"
|
|
35
|
+
| "document"
|
|
36
|
+
| "source"
|
|
37
|
+
| "unknown";
|
|
38
|
+
|
|
39
|
+
export type AttachmentVariant = "grid" | "inline" | "list";
|
|
40
|
+
|
|
41
|
+
// ============================================================================
|
|
42
|
+
// Utility Functions
|
|
43
|
+
// ============================================================================
|
|
44
|
+
|
|
45
|
+
export const getMediaCategory = (
|
|
46
|
+
data: AttachmentData
|
|
47
|
+
): AttachmentMediaCategory => {
|
|
48
|
+
if (data.type === "source-document") {
|
|
49
|
+
return "source";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const mediaType = data.mediaType ?? "";
|
|
53
|
+
|
|
54
|
+
if (mediaType.startsWith("image/")) {
|
|
55
|
+
return "image";
|
|
56
|
+
}
|
|
57
|
+
if (mediaType.startsWith("video/")) {
|
|
58
|
+
return "video";
|
|
59
|
+
}
|
|
60
|
+
if (mediaType.startsWith("audio/")) {
|
|
61
|
+
return "audio";
|
|
62
|
+
}
|
|
63
|
+
if (mediaType.startsWith("application/") || mediaType.startsWith("text/")) {
|
|
64
|
+
return "document";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return "unknown";
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const getAttachmentLabel = (data: AttachmentData): string => {
|
|
71
|
+
if (data.type === "source-document") {
|
|
72
|
+
return data.title || data.filename || "Source";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const category = getMediaCategory(data);
|
|
76
|
+
return data.filename || (category === "image" ? "Image" : "Attachment");
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// ============================================================================
|
|
80
|
+
// Contexts
|
|
81
|
+
// ============================================================================
|
|
82
|
+
|
|
83
|
+
interface AttachmentsContextValue {
|
|
84
|
+
variant: AttachmentVariant;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const AttachmentsContext = createContext<AttachmentsContextValue | null>(null);
|
|
88
|
+
|
|
89
|
+
interface AttachmentContextValue {
|
|
90
|
+
data: AttachmentData;
|
|
91
|
+
mediaCategory: AttachmentMediaCategory;
|
|
92
|
+
onRemove?: () => void;
|
|
93
|
+
variant: AttachmentVariant;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const AttachmentContext = createContext<AttachmentContextValue | null>(null);
|
|
97
|
+
|
|
98
|
+
// ============================================================================
|
|
99
|
+
// Hooks
|
|
100
|
+
// ============================================================================
|
|
101
|
+
|
|
102
|
+
export const useAttachmentsContext = () =>
|
|
103
|
+
useContext(AttachmentsContext) ?? { variant: "grid" as const };
|
|
104
|
+
|
|
105
|
+
export const useAttachmentContext = () => {
|
|
106
|
+
const ctx = useContext(AttachmentContext);
|
|
107
|
+
if (!ctx) {
|
|
108
|
+
throw new Error("Attachment components must be used within <Attachment>");
|
|
109
|
+
}
|
|
110
|
+
return ctx;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// ============================================================================
|
|
114
|
+
// Attachments - Container
|
|
115
|
+
// ============================================================================
|
|
116
|
+
|
|
117
|
+
export type AttachmentsProps = HTMLAttributes<HTMLDivElement> & {
|
|
118
|
+
variant?: AttachmentVariant;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const Attachments = ({
|
|
122
|
+
variant = "grid",
|
|
123
|
+
className,
|
|
124
|
+
children,
|
|
125
|
+
...props
|
|
126
|
+
}: AttachmentsProps) => {
|
|
127
|
+
const contextValue = useMemo(() => ({ variant }), [variant]);
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<AttachmentsContext.Provider value={contextValue}>
|
|
131
|
+
<div
|
|
132
|
+
className={cn(
|
|
133
|
+
"flex items-start",
|
|
134
|
+
variant === "list" ? "flex-col gap-2" : "flex-wrap gap-2",
|
|
135
|
+
variant === "grid" && "ml-auto w-fit",
|
|
136
|
+
className
|
|
137
|
+
)}
|
|
138
|
+
{...props}
|
|
139
|
+
>
|
|
140
|
+
{children}
|
|
141
|
+
</div>
|
|
142
|
+
</AttachmentsContext.Provider>
|
|
143
|
+
);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// ============================================================================
|
|
147
|
+
// Attachment - Item
|
|
148
|
+
// ============================================================================
|
|
149
|
+
|
|
150
|
+
export type AttachmentProps = HTMLAttributes<HTMLDivElement> & {
|
|
151
|
+
data: AttachmentData;
|
|
152
|
+
onRemove?: () => void;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export const Attachment = ({
|
|
156
|
+
data,
|
|
157
|
+
onRemove,
|
|
158
|
+
className,
|
|
159
|
+
children,
|
|
160
|
+
...props
|
|
161
|
+
}: AttachmentProps) => {
|
|
162
|
+
const { variant } = useAttachmentsContext();
|
|
163
|
+
const mediaCategory = getMediaCategory(data);
|
|
164
|
+
|
|
165
|
+
const contextValue = useMemo<AttachmentContextValue>(
|
|
166
|
+
() => ({ data, mediaCategory, onRemove, variant }),
|
|
167
|
+
[data, mediaCategory, onRemove, variant]
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<AttachmentContext.Provider value={contextValue}>
|
|
172
|
+
<div
|
|
173
|
+
className={cn(
|
|
174
|
+
"group relative",
|
|
175
|
+
variant === "grid" && "size-24 overflow-hidden rounded-lg",
|
|
176
|
+
variant === "inline" && [
|
|
177
|
+
"flex h-8 cursor-pointer select-none items-center gap-1.5",
|
|
178
|
+
"rounded-md border border-border px-1.5",
|
|
179
|
+
"font-medium text-sm transition-all",
|
|
180
|
+
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
181
|
+
],
|
|
182
|
+
variant === "list" && [
|
|
183
|
+
"flex w-full items-center gap-3 rounded-lg border p-3",
|
|
184
|
+
"hover:bg-accent/50",
|
|
185
|
+
],
|
|
186
|
+
className
|
|
187
|
+
)}
|
|
188
|
+
{...props}
|
|
189
|
+
>
|
|
190
|
+
{children}
|
|
191
|
+
</div>
|
|
192
|
+
</AttachmentContext.Provider>
|
|
193
|
+
);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// ============================================================================
|
|
197
|
+
// AttachmentPreview - Media preview
|
|
198
|
+
// ============================================================================
|
|
199
|
+
|
|
200
|
+
export type AttachmentPreviewProps = HTMLAttributes<HTMLDivElement> & {
|
|
201
|
+
fallbackIcon?: ReactNode;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export const AttachmentPreview = ({
|
|
205
|
+
fallbackIcon,
|
|
206
|
+
className,
|
|
207
|
+
...props
|
|
208
|
+
}: AttachmentPreviewProps) => {
|
|
209
|
+
const { data, mediaCategory, variant } = useAttachmentContext();
|
|
210
|
+
|
|
211
|
+
const iconSize = variant === "inline" ? "size-3" : "size-4";
|
|
212
|
+
|
|
213
|
+
const renderImage = (
|
|
214
|
+
url: string,
|
|
215
|
+
filename: string | undefined,
|
|
216
|
+
isGrid: boolean
|
|
217
|
+
) =>
|
|
218
|
+
isGrid ? (
|
|
219
|
+
<img
|
|
220
|
+
alt={filename || "Image"}
|
|
221
|
+
className="size-full object-cover"
|
|
222
|
+
height={96}
|
|
223
|
+
src={url}
|
|
224
|
+
width={96}
|
|
225
|
+
/>
|
|
226
|
+
) : (
|
|
227
|
+
<img
|
|
228
|
+
alt={filename || "Image"}
|
|
229
|
+
className="size-full rounded object-cover"
|
|
230
|
+
height={20}
|
|
231
|
+
src={url}
|
|
232
|
+
width={20}
|
|
233
|
+
/>
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
const renderIcon = (Icon: typeof ImageIcon) => (
|
|
237
|
+
<Icon className={cn(iconSize, "text-muted-foreground")} />
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
const renderContent = () => {
|
|
241
|
+
if (mediaCategory === "image" && data.type === "file" && data.url) {
|
|
242
|
+
return renderImage(data.url, data.filename, variant === "grid");
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (mediaCategory === "video" && data.type === "file" && data.url) {
|
|
246
|
+
return <video className="size-full object-cover" muted src={data.url} />;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const iconMap: Record<AttachmentMediaCategory, typeof ImageIcon> = {
|
|
250
|
+
image: ImageIcon,
|
|
251
|
+
video: VideoIcon,
|
|
252
|
+
audio: Music2Icon,
|
|
253
|
+
source: GlobeIcon,
|
|
254
|
+
document: FileTextIcon,
|
|
255
|
+
unknown: PaperclipIcon,
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const Icon = iconMap[mediaCategory];
|
|
259
|
+
return fallbackIcon ?? renderIcon(Icon);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
return (
|
|
263
|
+
<div
|
|
264
|
+
className={cn(
|
|
265
|
+
"flex shrink-0 items-center justify-center overflow-hidden",
|
|
266
|
+
variant === "grid" && "size-full bg-muted",
|
|
267
|
+
variant === "inline" && "size-5 rounded bg-background",
|
|
268
|
+
variant === "list" && "size-12 rounded bg-muted",
|
|
269
|
+
className
|
|
270
|
+
)}
|
|
271
|
+
{...props}
|
|
272
|
+
>
|
|
273
|
+
{renderContent()}
|
|
274
|
+
</div>
|
|
275
|
+
);
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
// ============================================================================
|
|
279
|
+
// AttachmentInfo - Name and type display
|
|
280
|
+
// ============================================================================
|
|
281
|
+
|
|
282
|
+
export type AttachmentInfoProps = HTMLAttributes<HTMLDivElement> & {
|
|
283
|
+
showMediaType?: boolean;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
export const AttachmentInfo = ({
|
|
287
|
+
showMediaType = false,
|
|
288
|
+
className,
|
|
289
|
+
...props
|
|
290
|
+
}: AttachmentInfoProps) => {
|
|
291
|
+
const { data, variant } = useAttachmentContext();
|
|
292
|
+
const label = getAttachmentLabel(data);
|
|
293
|
+
|
|
294
|
+
if (variant === "grid") {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return (
|
|
299
|
+
<div className={cn("min-w-0 flex-1", className)} {...props}>
|
|
300
|
+
<span className="block truncate">{label}</span>
|
|
301
|
+
{showMediaType && data.mediaType && (
|
|
302
|
+
<span className="block truncate text-muted-foreground text-xs">
|
|
303
|
+
{data.mediaType}
|
|
304
|
+
</span>
|
|
305
|
+
)}
|
|
306
|
+
</div>
|
|
307
|
+
);
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
// ============================================================================
|
|
311
|
+
// AttachmentRemove - Remove button
|
|
312
|
+
// ============================================================================
|
|
313
|
+
|
|
314
|
+
export type AttachmentRemoveProps = ComponentProps<typeof Button> & {
|
|
315
|
+
label?: string;
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
export const AttachmentRemove = ({
|
|
319
|
+
label = "Remove",
|
|
320
|
+
className,
|
|
321
|
+
children,
|
|
322
|
+
...props
|
|
323
|
+
}: AttachmentRemoveProps) => {
|
|
324
|
+
const { onRemove, variant } = useAttachmentContext();
|
|
325
|
+
|
|
326
|
+
if (!onRemove) {
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return (
|
|
331
|
+
<Button
|
|
332
|
+
aria-label={label}
|
|
333
|
+
className={cn(
|
|
334
|
+
variant === "grid" && [
|
|
335
|
+
"absolute top-2 right-2 size-6 rounded-full p-0",
|
|
336
|
+
"bg-background/80 backdrop-blur-sm",
|
|
337
|
+
"opacity-0 transition-opacity group-hover:opacity-100",
|
|
338
|
+
"hover:bg-background",
|
|
339
|
+
"[&>svg]:size-3",
|
|
340
|
+
],
|
|
341
|
+
variant === "inline" && [
|
|
342
|
+
"size-5 rounded p-0",
|
|
343
|
+
"opacity-0 transition-opacity group-hover:opacity-100",
|
|
344
|
+
"[&>svg]:size-2.5",
|
|
345
|
+
],
|
|
346
|
+
variant === "list" && ["size-8 shrink-0 rounded p-0", "[&>svg]:size-4"],
|
|
347
|
+
className
|
|
348
|
+
)}
|
|
349
|
+
onClick={(e) => {
|
|
350
|
+
e.stopPropagation();
|
|
351
|
+
onRemove();
|
|
352
|
+
}}
|
|
353
|
+
type="button"
|
|
354
|
+
variant="ghost"
|
|
355
|
+
{...props}
|
|
356
|
+
>
|
|
357
|
+
{children ?? <XIcon />}
|
|
358
|
+
<span className="sr-only">{label}</span>
|
|
359
|
+
</Button>
|
|
360
|
+
);
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
// ============================================================================
|
|
364
|
+
// AttachmentHoverCard - Hover preview
|
|
365
|
+
// ============================================================================
|
|
366
|
+
|
|
367
|
+
export type AttachmentHoverCardProps = ComponentProps<typeof HoverCard>;
|
|
368
|
+
|
|
369
|
+
export const AttachmentHoverCard = ({
|
|
370
|
+
openDelay = 0,
|
|
371
|
+
closeDelay = 0,
|
|
372
|
+
...props
|
|
373
|
+
}: AttachmentHoverCardProps) => (
|
|
374
|
+
<HoverCard closeDelay={closeDelay} openDelay={openDelay} {...props} />
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
export type AttachmentHoverCardTriggerProps = ComponentProps<
|
|
378
|
+
typeof HoverCardTrigger
|
|
379
|
+
>;
|
|
380
|
+
|
|
381
|
+
export const AttachmentHoverCardTrigger = (
|
|
382
|
+
props: AttachmentHoverCardTriggerProps
|
|
383
|
+
) => <HoverCardTrigger {...props} />;
|
|
384
|
+
|
|
385
|
+
export type AttachmentHoverCardContentProps = ComponentProps<
|
|
386
|
+
typeof HoverCardContent
|
|
387
|
+
>;
|
|
388
|
+
|
|
389
|
+
export const AttachmentHoverCardContent = ({
|
|
390
|
+
align = "start",
|
|
391
|
+
className,
|
|
392
|
+
...props
|
|
393
|
+
}: AttachmentHoverCardContentProps) => (
|
|
394
|
+
<HoverCardContent
|
|
395
|
+
align={align}
|
|
396
|
+
className={cn("w-auto p-2", className)}
|
|
397
|
+
{...props}
|
|
398
|
+
/>
|
|
399
|
+
);
|
|
400
|
+
|
|
401
|
+
// ============================================================================
|
|
402
|
+
// AttachmentEmpty - Empty state
|
|
403
|
+
// ============================================================================
|
|
404
|
+
|
|
405
|
+
export type AttachmentEmptyProps = HTMLAttributes<HTMLDivElement>;
|
|
406
|
+
|
|
407
|
+
export const AttachmentEmpty = ({
|
|
408
|
+
className,
|
|
409
|
+
children,
|
|
410
|
+
...props
|
|
411
|
+
}: AttachmentEmptyProps) => (
|
|
412
|
+
<div
|
|
413
|
+
className={cn(
|
|
414
|
+
"flex items-center justify-center p-4 text-muted-foreground text-sm",
|
|
415
|
+
className
|
|
416
|
+
)}
|
|
417
|
+
{...props}
|
|
418
|
+
>
|
|
419
|
+
{children ?? "No attachments"}
|
|
420
|
+
</div>
|
|
421
|
+
);
|