2026-07-28 10:05:08 +07:00
|
|
|
"use client";
|
|
|
|
|
|
2026-08-14 10:49:44 +07:00
|
|
|
import type { AttachmentRef } from "@/lib/types";
|
|
|
|
|
import { cn } from "@/lib/utils";
|
2026-07-28 10:05:08 +07:00
|
|
|
|
2026-08-03 05:08:08 +07:00
|
|
|
export function AttachmentsGrid({
|
|
|
|
|
attachments,
|
2026-08-14 10:49:44 +07:00
|
|
|
onOpen,
|
|
|
|
|
}: {
|
|
|
|
|
attachments: AttachmentRef[];
|
|
|
|
|
onOpen: (url: string) => void;
|
|
|
|
|
}) {
|
2026-07-28 10:05:08 +07:00
|
|
|
if (attachments.length === 0) return null;
|
2026-08-14 10:49:44 +07:00
|
|
|
const images = attachments.filter((a) => /image/i.test(a.contentType ?? ""));
|
|
|
|
|
if (images.length === 0) return null;
|
2026-07-28 10:05:08 +07:00
|
|
|
return (
|
2026-08-14 10:49:44 +07:00
|
|
|
<div className="mt-2 grid grid-cols-2 gap-2 sm:grid-cols-3">
|
|
|
|
|
{images.map((a, i) => (
|
|
|
|
|
<button
|
|
|
|
|
key={`${a.url}-${i}`}
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => onOpen(a.url)}
|
|
|
|
|
className="group relative aspect-video overflow-hidden rounded-[var(--radius-r-control)] border border-[var(--color-hairline)]"
|
|
|
|
|
>
|
|
|
|
|
<img
|
|
|
|
|
src={a.url}
|
|
|
|
|
alt={a.name}
|
|
|
|
|
loading="lazy"
|
|
|
|
|
className="size-full object-cover transition-transform duration-200 group-hover:scale-105"
|
|
|
|
|
/>
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
2026-07-28 10:05:08 +07:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|