import { FC, ReactNode, useEffect, useRef, useState } from "react" import classNames from "classnames" import IconClose from "../icon/IconClose" import { isUrl } from "../../lib/utils" interface Props { url: string placeholder: string tooltip: string onSubmit?: () => void onChange: (url: string) => void className?: string children?: ReactNode } const InputUrl: FC = ({ url, placeholder, tooltip, onSubmit, onChange, className, children, }) => { const [valid, setValid] = useState(url === "" || isUrl(url)) const inputRef = useRef(null) useEffect(() => { setValid(url === "" || isUrl(url)) }, [url]) return (
{ e.preventDefault() if (onSubmit) { onSubmit() } }} className={classNames("flex flex-col", className)} >
{ onChange(event.target.value) }} type={"text"} onFocus={() => inputRef.current?.select()} />
onChange("")}>
{!valid &&
Invalid url
}
) } export default InputUrl