- Support image (JPEG/PNG/GIF/WebP, max 5MB) and document uploads - Images sent as multimodal content blocks to Claude SDK - Documents saved to temp dir for Claude's Read tool - Emerald capsule badges in input for attached files - Drag-and-drop, paste, and file picker support via PromptInput - Chat display: image thumbnails with lightbox, file cards - Lightbox uses Radix Dialog with prev/next navigation - File metadata embedded in message content as HTML comments - Compatible with existing slash command badge system Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
87 lines
2.7 KiB
TypeScript
87 lines
2.7 KiB
TypeScript
'use client';
|
|
|
|
import { useState, useCallback } from 'react';
|
|
import { ChevronLeftIcon, ChevronRightIcon } from 'lucide-react';
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogTitle,
|
|
} from '@/components/ui/dialog';
|
|
|
|
interface LightboxImage {
|
|
src: string;
|
|
alt: string;
|
|
}
|
|
|
|
interface ImageLightboxProps {
|
|
images: LightboxImage[];
|
|
initialIndex: number;
|
|
open: boolean;
|
|
onOpenChange: (open: boolean) => void;
|
|
}
|
|
|
|
export function ImageLightbox({ images, initialIndex, open, onOpenChange }: ImageLightboxProps) {
|
|
const [currentIndex, setCurrentIndex] = useState(initialIndex);
|
|
|
|
const goToPrev = useCallback(() => {
|
|
setCurrentIndex((prev) => (prev > 0 ? prev - 1 : images.length - 1));
|
|
}, [images.length]);
|
|
|
|
const goToNext = useCallback(() => {
|
|
setCurrentIndex((prev) => (prev < images.length - 1 ? prev + 1 : 0));
|
|
}, [images.length]);
|
|
|
|
// Reset index when dialog opens with a new initialIndex
|
|
const handleOpenChange = useCallback((newOpen: boolean) => {
|
|
if (newOpen) {
|
|
setCurrentIndex(initialIndex);
|
|
}
|
|
onOpenChange(newOpen);
|
|
}, [initialIndex, onOpenChange]);
|
|
|
|
if (images.length === 0) return null;
|
|
|
|
const current = images[currentIndex];
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={handleOpenChange}>
|
|
<DialogContent
|
|
className="max-w-[95vw] max-h-[95vh] p-0 border-none bg-black/90 shadow-none sm:max-w-[95vw]"
|
|
showCloseButton
|
|
>
|
|
<DialogTitle className="sr-only">Image preview</DialogTitle>
|
|
<div className="relative flex items-center justify-center min-h-[50vh]">
|
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
<img
|
|
src={current.src}
|
|
alt={current.alt}
|
|
className="max-w-[90vw] max-h-[90vh] object-contain"
|
|
/>
|
|
|
|
{images.length > 1 && (
|
|
<>
|
|
<button
|
|
type="button"
|
|
onClick={goToPrev}
|
|
className="absolute left-2 top-1/2 -translate-y-1/2 rounded-full bg-black/50 p-2 text-white hover:bg-black/70 transition"
|
|
>
|
|
<ChevronLeftIcon className="h-6 w-6" />
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={goToNext}
|
|
className="absolute right-2 top-1/2 -translate-y-1/2 rounded-full bg-black/50 p-2 text-white hover:bg-black/70 transition"
|
|
>
|
|
<ChevronRightIcon className="h-6 w-6" />
|
|
</button>
|
|
<div className="absolute bottom-3 left-1/2 -translate-x-1/2 text-white/70 text-sm">
|
|
{currentIndex + 1} / {images.length}
|
|
</div>
|
|
</>
|
|
)}
|
|
</div>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|