import React, { useContext } from 'react' import { InputProps } from 'antd/lib/input' import { Input, Upload } from 'antd' import { usePrefix, IconWidget } from '@pind/designable-react' import { SettingsFormContext } from '../../shared/context' import cls from 'classnames' import './styles.less' export interface ImageInputProps extends Omit { value?: string onChange?: (value: string) => void } export const ImageInput: React.FC = ({ className, style, ...props }) => { const prefix = usePrefix('image-input') const context = useContext(SettingsFormContext) return (
{ props.onChange?.(e?.target?.['value']) }} prefix={ null} maxCount={1} onChange={(params: any) => { const response = params.file?.response const url = response?.url || response?.downloadURL || response?.imageURL || response?.thumbUrl if (!url) return props.onChange?.(url) }} > } />
) } export const BackgroundImageInput: React.FC = (props) => { const addBgValue = (value: any) => { if (/url\([^)]+\)/.test(value)) { return value } return `url(${value})` } const removeBgValue = (value: any) => { const matched = String(value).match(/url\(\s*([^)]+)\s*\)/) if (matched?.[1]) { return matched?.[1] } return value } return ( { props.onChange?.(addBgValue(url)) }} /> ) }