import { useRef } from "react"; interface ImagePickerProps { src: string | null; alt?: string; size?: number; borderRadius?: number; onChange: (file: File) => void; uploading?: boolean; accept?: string; } export function ImagePicker({ src, alt = "", size = 80, borderRadius = 8, onChange, uploading = false, accept = "image/jpeg,image/png,image/gif,image/webp", }: ImagePickerProps) { const inputRef = useRef(null); const sizeStyle = { width: size, height: size, borderRadius }; const handleChange = (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (file) onChange(file); e.target.value = ""; }; return (
!uploading && inputRef.current?.click()} title={src ? "Change image" : "Add image"} role="button" tabIndex={0} onKeyDown={(e) => { if (e.key === "Enter" || e.key === " ") inputRef.current?.click(); }} > {src ? ( {alt} ) : (
+
)}
{uploading ? "…" : "✎"}
); }