@@ -14,11 +14,25 @@ export default function ImageCard({
1414 fallbackImageUrl,
1515 onSelect,
1616} : ImageCardProps ) {
17+ const handleDownload = ( e : React . MouseEvent ) => {
18+ e . stopPropagation ( ) ; // Prevent triggering the card selection
19+
20+ if ( image . url ) {
21+ // Create a temporary link element to trigger download
22+ const link = document . createElement ( "a" ) ;
23+ link . href = image . url ;
24+ link . download = `${ image . title || "image" } .png` ;
25+ document . body . appendChild ( link ) ;
26+ link . click ( ) ;
27+ document . body . removeChild ( link ) ;
28+ }
29+ } ;
30+
1731 return (
1832 < div
1933 onClick = { ( ) => onSelect ( image . id ) }
2034 className = { `
21- flex-shrink-0 flex flex-col gap-3 mt-2
35+ relative flex-shrink-0 flex flex-col gap-3 mt-2
2236 rounded-2xl
2337 bg-white/5 backdrop-blur-xl
2438 border-2 transition-all duration-300
@@ -35,11 +49,11 @@ export default function ImageCard({
3549 >
3650 { /* Selection Indicator */ }
3751 < div
38- className = { `absolute top-3 right-3 w-6 h-6 rounded-full flex items-center justify-center
39- ${ isSelected ? "bg-blue-600" : "bg-gray-500 " } ` }
52+ className = { `absolute top-3 right-3 w-7 h-7 rounded-full flex items-center justify-center
53+ ${ isSelected ? "bg-blue-600" : "bg-gray-600 " } ` }
4054 >
4155 < svg
42- className = { `w-4 h-4 ${ isSelected ? "text-white" : "text-gray-700 " } ` }
56+ className = { `w-4 h-4 ${ isSelected ? "text-white" : "text-gray-200 " } ` }
4357 fill = "currentColor"
4458 viewBox = "0 0 20 20"
4559 >
@@ -51,6 +65,28 @@ export default function ImageCard({
5165 </ svg >
5266 </ div >
5367
68+ { /* Download Button */ }
69+ < button
70+ onClick = { handleDownload }
71+ className = "cursor-pointer absolute top-3 left-3 w-7 h-7 bg-gray-600 hover:bg-gray-800 border border-white/10 rounded-full flex items-center justify-center transition-all duration-200 hover:scale-110 backdrop-blur-sm z-10"
72+ aria-label = "Download image"
73+ disabled = { ! image . url }
74+ >
75+ < svg
76+ className = "w-4 h-4 text-gray-200"
77+ fill = "none"
78+ stroke = "currentColor"
79+ viewBox = "0 0 24 24"
80+ >
81+ < path
82+ strokeLinecap = "round"
83+ strokeLinejoin = "round"
84+ strokeWidth = { 2 }
85+ d = "M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"
86+ />
87+ </ svg >
88+ </ button >
89+
5490 { /* Image Preview */ }
5591 < div className = "relative mt-8" >
5692 < ImagePreview imageUrl = { image . url ?? fallbackImageUrl ?? null } />
0 commit comments