mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
e550340565
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
31 lines
910 B
TypeScript
31 lines
910 B
TypeScript
import React, { useEffect } from 'react';
|
|
import { createPortal } from 'react-dom';
|
|
import { X } from 'lucide-react';
|
|
|
|
interface Props {
|
|
src: string;
|
|
alt: string;
|
|
onClose: () => void;
|
|
}
|
|
|
|
export default function CoverLightbox({ src, alt, onClose }: Props) {
|
|
useEffect(() => {
|
|
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); };
|
|
window.addEventListener('keydown', onKey);
|
|
return () => window.removeEventListener('keydown', onKey);
|
|
}, [onClose]);
|
|
|
|
return createPortal(
|
|
<div className="cover-lightbox-overlay" onClick={onClose} role="dialog" aria-modal="true" aria-label={alt}>
|
|
<button className="cover-lightbox-close" onClick={onClose} aria-label="Close"><X size={20} /></button>
|
|
<img
|
|
className="cover-lightbox-img"
|
|
src={src}
|
|
alt={alt}
|
|
onClick={e => e.stopPropagation()}
|
|
/>
|
|
</div>,
|
|
document.body
|
|
);
|
|
}
|