2025-09-21 11:02:31 -07:00
|
|
|
import Image from "next/image";
|
|
|
|
|
import type { Attachment } from "@/lib/types";
|
|
|
|
|
import { Loader } from "./elements/loader";
|
|
|
|
|
import { CrossSmallIcon } from "./icons";
|
|
|
|
|
import { Button } from "./ui/button";
|
2024-10-11 18:00:22 +05:30
|
|
|
|
|
|
|
|
export const PreviewAttachment = ({
|
|
|
|
|
attachment,
|
|
|
|
|
isUploading = false,
|
2025-08-28 14:15:36 +01:00
|
|
|
onRemove,
|
2024-10-11 18:00:22 +05:30
|
|
|
}: {
|
|
|
|
|
attachment: Attachment;
|
|
|
|
|
isUploading?: boolean;
|
2025-08-28 14:15:36 +01:00
|
|
|
onRemove?: () => void;
|
2024-10-11 18:00:22 +05:30
|
|
|
}) => {
|
|
|
|
|
const { name, url, contentType } = attachment;
|
|
|
|
|
|
|
|
|
|
return (
|
2025-09-10 16:59:48 +01:00
|
|
|
<div
|
2025-09-21 12:03:29 +01:00
|
|
|
className="group relative size-16 overflow-hidden rounded-lg border bg-muted"
|
2025-09-21 11:02:31 -07:00
|
|
|
data-testid="input-attachment-preview"
|
2025-09-10 16:59:48 +01:00
|
|
|
>
|
2025-09-21 11:02:31 -07:00
|
|
|
{contentType?.startsWith("image") ? (
|
2025-09-08 21:02:06 +01:00
|
|
|
<Image
|
2025-09-21 11:02:31 -07:00
|
|
|
alt={name ?? "An image attachment"}
|
2025-09-21 12:03:29 +01:00
|
|
|
className="size-full object-cover"
|
|
|
|
|
height={64}
|
2025-09-21 11:02:31 -07:00
|
|
|
src={url}
|
|
|
|
|
width={64}
|
2025-08-28 14:15:36 +01:00
|
|
|
/>
|
|
|
|
|
) : (
|
2025-09-10 16:59:48 +01:00
|
|
|
<div className="flex size-full items-center justify-center text-muted-foreground text-xs">
|
2025-08-28 14:15:36 +01:00
|
|
|
File
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2024-10-11 18:00:22 +05:30
|
|
|
|
2025-08-28 14:15:36 +01:00
|
|
|
{isUploading && (
|
2025-10-31 20:06:16 -04:00
|
|
|
<div
|
2025-11-29 13:02:24 +00:00
|
|
|
className="absolute inset-0 flex items-center justify-center bg-black/50"
|
|
|
|
|
data-testid="input-attachment-loader"
|
|
|
|
|
>
|
2025-08-28 14:15:36 +01:00
|
|
|
<Loader size={16} />
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{onRemove && !isUploading && (
|
|
|
|
|
<Button
|
2025-09-21 11:02:31 -07:00
|
|
|
className="absolute top-0.5 right-0.5 size-4 rounded-full p-0 opacity-0 transition-opacity group-hover:opacity-100"
|
2025-08-28 14:15:36 +01:00
|
|
|
onClick={onRemove}
|
|
|
|
|
size="sm"
|
|
|
|
|
variant="destructive"
|
|
|
|
|
>
|
|
|
|
|
<CrossSmallIcon size={8} />
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
|
2025-09-10 16:59:48 +01:00
|
|
|
<div className="absolute inset-x-0 bottom-0 truncate bg-linear-to-t from-black/80 to-transparent px-1 py-0.5 text-[10px] text-white">
|
2025-08-28 14:15:36 +01:00
|
|
|
{name}
|
2024-10-11 18:00:22 +05:30
|
|
|
</div>
|
2024-10-24 16:35:51 -04:00
|
|
|
</div>
|
2024-10-11 18:00:22 +05:30
|
|
|
);
|
|
|
|
|
};
|