1
1
import React from "react" ;
2
2
import { File , Image as ImageIcon , X as XIcon } from "lucide-react" ;
3
3
import type { Base64ContentBlock } from "@langchain/core/messages" ;
4
-
4
+ import { cn } from "@/lib/utils" ;
5
+ import Image from "next/image" ;
5
6
export interface MultimodalPreviewProps {
6
7
block : Base64ContentBlock ;
7
8
removable ?: boolean ;
@@ -14,7 +15,7 @@ export const MultimodalPreview: React.FC<MultimodalPreviewProps> = ({
14
15
block,
15
16
removable = false ,
16
17
onRemove,
17
- className = "" ,
18
+ className,
18
19
size = "md" ,
19
20
} ) => {
20
21
// Sizing
@@ -38,13 +39,13 @@ export const MultimodalPreview: React.FC<MultimodalPreviewProps> = ({
38
39
if ( size === "sm" ) imgClass = "rounded-md object-cover h-10 w-10 text-base" ;
39
40
if ( size === "lg" ) imgClass = "rounded-md object-cover h-24 w-24 text-xl" ;
40
41
return (
41
- < div
42
- className = { `relative inline-block${ className ? ` ${ className } ` : "" } ` }
43
- >
44
- < img
42
+ < div className = { cn ( "relative inline-block" , className ) } >
43
+ < Image
45
44
src = { url }
46
45
alt = { String ( block . metadata ?. name || "uploaded image" ) }
47
46
className = { imgClass }
47
+ width = { size === "sm" ? 16 : size === "md" ? 32 : 48 }
48
+ height = { size === "sm" ? 16 : size === "md" ? 32 : 48 }
48
49
/>
49
50
{ removable && (
50
51
< button
@@ -68,20 +69,24 @@ export const MultimodalPreview: React.FC<MultimodalPreviewProps> = ({
68
69
) {
69
70
const filename =
70
71
block . metadata ?. filename || block . metadata ?. name || "PDF file" ;
71
- const fileClass = `relative flex items-center gap-2 rounded-md border bg-gray-100 px-3 py-2${ className ? ` ${ className } ` : "" } ` ;
72
72
return (
73
- < div className = { fileClass } >
73
+ < div
74
+ className = { cn (
75
+ "relative flex items-center gap-2 rounded-md border bg-gray-100 px-3 py-2" ,
76
+ className
77
+ ) }
78
+ >
74
79
< File
75
- className = {
76
- "flex-shrink-0 text-teal-700 " +
77
- ( size === "sm" ? "h-5 w-5" : "h-7 w-7" )
78
- }
80
+ className = { cn (
81
+ "flex-shrink-0 text-teal-700" ,
82
+ size === "sm" ? "h-5 w-5" : "h-7 w-7"
83
+ ) }
79
84
/>
80
85
< span
81
- className = {
82
- "truncate text-sm text-gray-800 " +
83
- ( size === "sm" ? "max-w-[80px]" : "max-w-[160px]" )
84
- }
86
+ className = { cn (
87
+ "truncate text-sm text-gray-800" ,
88
+ size === "sm" ? "max-w-[80px]" : "max-w-[160px]"
89
+ ) }
85
90
>
86
91
{ String ( filename ) }
87
92
</ span >
@@ -100,9 +105,13 @@ export const MultimodalPreview: React.FC<MultimodalPreviewProps> = ({
100
105
}
101
106
102
107
// Fallback for unknown types
103
- const fallbackClass = `flex items-center gap-2 rounded-md border bg-gray-100 px-3 py-2 text-gray-500${ className ? ` ${ className } ` : "" } ` ;
104
108
return (
105
- < div className = { fallbackClass } >
109
+ < div
110
+ className = { cn (
111
+ "flex items-center gap-2 rounded-md border bg-gray-100 px-3 py-2 text-gray-500" ,
112
+ className
113
+ ) }
114
+ >
106
115
< File className = "h-5 w-5 flex-shrink-0" />
107
116
< span className = "truncate text-xs" > Unsupported file type</ span >
108
117
{ removable && (
0 commit comments