bolt.diy/app/components/chat/FilePreview.tsx

36 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-11-19 00:55:28 +00:00
import React from 'react';
interface FilePreviewProps {
2024-11-30 03:02:35 +00:00
files: File[];
imageDataList: string[];
onRemove: (index: number) => void;
2024-11-19 00:55:28 +00:00
}
const FilePreview: React.FC<FilePreviewProps> = ({ files, imageDataList, onRemove }) => {
2024-11-30 03:02:35 +00:00
if (!files || files.length === 0) {
return null;
}
2024-11-19 00:55:28 +00:00
2024-11-30 03:02:35 +00:00
return (
<div className="flex flex-row overflow-x-auto -mt-2">
2024-11-30 03:02:35 +00:00
{files.map((file, index) => (
<div key={file.name + file.size} className="mr-2 relative">
{imageDataList[index] && (
<div className="relative pt-4 pr-4">
2024-11-30 03:02:35 +00:00
<img src={imageDataList[index]} alt={file.name} className="max-h-20" />
<button
onClick={() => onRemove(index)}
className="absolute top-1 right-1 z-10 bg-black rounded-full w-5 h-5 shadow-md hover:bg-gray-900 transition-colors flex items-center justify-center"
2024-11-30 03:02:35 +00:00
>
<div className="i-ph:x w-3 h-3 text-gray-200" />
2024-11-30 03:02:35 +00:00
</button>
</div>
)}
2024-11-19 00:55:28 +00:00
</div>
2024-11-30 03:02:35 +00:00
))}
</div>
);
2024-11-19 00:55:28 +00:00
};
export default FilePreview;