import React, { useCallback, useRef, useState } from "react" import SendIcon from "../../fundamentals/icons/send-icon" import EmojiPicker from "../emoji-picker" type NoteInputProps = { onSubmit: (note: string | undefined) => void } const NoteInput: React.FC = ({ onSubmit }) => { const [note, setNote] = useState(undefined) const inputRef = useRef(null) const handleAddEmoji = (emoji: string) => { setNote(`${note ? note : ""}${emoji}`) } const handleSubmit = () => { if (onSubmit && note) { onSubmit(note) setNote("") } } const onKeyDownHandler = useCallback( (event) => { switch (event.key) { case "Enter": event.preventDefault() event.stopPropagation() handleSubmit() inputRef.current?.blur() break case "Esc": case "Escape": inputRef.current?.blur() break default: break } }, [note, setNote, onSubmit] ) return (
inputRef.current?.focus()} >
setNote(e.target.value)} className="inter-base-regular placeholder:text-grey-40 flex-grow bg-transparent focus:outline-none" ref={inputRef} id="note-input" autoComplete="off" onKeyDown={onKeyDownHandler} />
) } export default NoteInput