import PropTypes from "prop-types"; import cn from "classnames"; import { useEffect, useRef, useState } from "react"; import { PlusIcon } from "../Icons"; export const TextInputIcon = ({ className, icon, placeholder, onChange }) => { const inputRef = useRef(); const [focused, setFocused] = useState(false); const [value, setValue] = useState(""); useEffect(() => { onChange(value); }, [value, onChange]); return (
{icon}
setFocused(true)} onBlur={() => setFocused(false)} onChange={(event) => setValue(event.target.value)} placeholder={placeholder} className="focus:outline-none bg-transparent placeholder:text-palette-400" /> {value && ( setValue("")} /> )}
); }; TextInputIcon.propTypes = { /** * Icon to place in text input */ icon: PropTypes.element.isRequired, /** * Input placeholder */ placeholder: PropTypes.string, /** * Function to be called whenever value changes */ onChange: PropTypes.func.isRequired, };