'use client'; import { useEffect, useState } from 'react'; import type { AttachmentView } from '@/lib/types'; /** * 添付ファイル一覧表示。画像はサムネイル(クリックでLightbox)、 * それ以外はダウンロードリンク。チャット/掲示板で共通利用。 */ export function AttachmentList({ attachments, }: { attachments: AttachmentView[]; }) { const [lightbox, setLightbox] = useState(null); useEffect(() => { if (!lightbox) return; function onKey(e: KeyboardEvent) { if (e.key === 'Escape') setLightbox(null); } window.addEventListener('keydown', onKey); return () => window.removeEventListener('keydown', onKey); }, [lightbox]); if (attachments.length === 0) return null; return ( <> {lightbox && (
setLightbox(null)} data-testid="attachment-lightbox" > {lightbox.originalName} e.stopPropagation()} />
)} ); }