import { Editor } from "@tiptap/core"; import { Check, Trash } from "lucide-react"; import { Dispatch, FC, SetStateAction, useEffect, useRef } from "react"; import { cn } from "../utils"; interface LinkSelectorProps { editor: Editor; isOpen: boolean; setIsOpen: Dispatch>; } export const LinkSelector: FC = ({ editor, isOpen, setIsOpen }) => { const inputRef = useRef(null); useEffect(() => { inputRef.current && inputRef.current?.focus(); }); return (
{isOpen && (
{ e.preventDefault(); const form = e.target as HTMLFormElement; const input = form.elements[0] as HTMLInputElement; editor.chain().focus().setLink({ href: input.value }).run(); setIsOpen(false); }} className="fixed top-full z-[99999] mt-1 flex w-60 overflow-hidden rounded border border-custom-border-300 bg-custom-background-100 dow-xl animate-in fade-in slide-in-from-top-1" > {editor.getAttributes("link").href ? ( ) : ( )}
)}
); };