import clsx from "clsx" import { ArrowUpIcon, FileIcon, ImageIcon, PlusIcon, XIcon } from "lucide-react" import { motion, useAnimate } from "motion/react" import { useEffect, useRef, useState } from "react" import { Button, Menu, MenuItem, MenuTrigger, Popover } from "react-aria-components" export function ChatBox({ className, validate, onSubmit, }: { className?: string validate?: (value: string) => boolean onSubmit: (email: string) => void disabled?: boolean }) { const [scope, animate] = useAnimate() const [shouldShowInvalid, setShouldShowInvalid] = useState(false) const clearInvalidStateTimeout = useRef | null>(null) useEffect( () => () => { if (clearInvalidStateTimeout.current) { clearTimeout(clearInvalidStateTimeout.current) } }, [], ) function showInvalidState() { animate(scope.current, { x: [0, -6, 6, -4, 4, -2, 2, 0] }, { duration: 0.4, ease: "easeOut" }) if (clearInvalidStateTimeout.current) { clearTimeout(clearInvalidStateTimeout.current) } setShouldShowInvalid(true) clearInvalidStateTimeout.current = setTimeout(() => { setShouldShowInvalid(false) }, 500) } const onFormSubmit = (e: React.FormEvent) => { e.preventDefault() const formData = new FormData(e.currentTarget) const email = formData.get("liame") if (typeof email === "string") { const trimmed = email.trim() if (trimmed.length === 0) { showInvalidState() } else if (validate && !validate(trimmed)) { showInvalidState() } else { onSubmit(trimmed) e.currentTarget.reset() } } } return (
) } function AttachmentMenu() { return ( {}} > Photos {}} > Files ) }