import type { FC } from 'react' import { useState } from 'react' import { useTranslation } from 'react-i18next' import Button from '@/app/components/base/button' import type { ImageFile } from '@/types/app' import { TransferMethod } from '@/types/app' type ImageLinkInputProps = { onUpload: (imageFile: ImageFile) => void disabled?: boolean } const regex = /^(https?|ftp):\/\// const ImageLinkInput: FC = ({ onUpload, disabled, }) => { const { t } = useTranslation() const [imageLink, setImageLink] = useState('') const handleClick = () => { if (disabled) return const imageFile = { type: TransferMethod.remote_url, _id: `${Date.now()}`, fileId: '', progress: regex.test(imageLink) ? 0 : -1, url: imageLink, } onUpload(imageFile) } return (
setImageLink(e.target.value)} placeholder={t('common.imageUploader.pasteImageLinkInputPlaceholder') || ''} />
) } export default ImageLinkInput