import { type FormEvent, useEffect, useRef } from "react"; import { Button, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@ace/ui"; type Props = { open: boolean; name: string; title?: string; label?: string; onSave: (name: string) => void; onCancel: () => void; }; export function Rename( { open, name, title = "Rename tab", label = "Tab name", onSave, onCancel }: Props, ) { const input = useRef(null); useEffect(() => { if (!open) return; const frame = requestAnimationFrame(() => { const node = input.current; if (!node) return; node.value = name; node.focus(); node.select(); }); return () => cancelAnimationFrame(frame); }, [open, name]); function save(event: FormEvent) { event.preventDefault(); onSave(input.current?.value ?? name); } return ( (next ? undefined : onCancel())}>
{title} Set a custom tab name.
); }