"use client"; import React, { useRef, useState } from "react"; import { CloseOutlined } from '@ant-design/icons'; import { theme } from "antd"; interface BAImagePickerProps { onChange: (files: File[]) => void; accept?: string; disabled?: boolean; uploadText?: string; value?: string; } const BAImagePicker: React.FC = ({ onChange, accept = "image/*", disabled = false, uploadText = "Select Image", value }) => { const { token } = theme.useToken(); const [image, setImage] = useState<{ file: File; url: string } | null>(null); const inputRef = useRef(null); const handleFiles = (files: FileList | null) => { if (!files || files.length === 0) return; const file = files[0]; const imgObj = { file, url: URL.createObjectURL(file) }; setImage(imgObj); onChange([file]); }; const handleRemove = () => { setImage(null); onChange([]); }; return (
handleFiles(e.target.files)} />
inputRef.current?.click()} style={{ display: "flex", gap: 8, marginTop: 8, width: 100, height: 100 }} > {image ? (
preview
) : value ? ( preview-value ) : ( {uploadText} )}
); }; export default BAImagePicker;