import { useState, useRef, useEffect } from "react"; import { PROMPTS, THEME } from "../constants"; interface PromptInputProps { onPromptChange: (prompt: string) => void; defaultPrompt?: string; } export default function PromptInput({ onPromptChange, defaultPrompt = PROMPTS.default, }: PromptInputProps) { const [prompt, setPrompt] = useState(defaultPrompt); const [showSuggestions, setShowSuggestions] = useState(false); const inputRef = useRef(null); const containerRef = useRef(null); const resizeTextarea = () => { if (inputRef.current) { inputRef.current.style.height = "auto"; const newHeight = Math.min(inputRef.current.scrollHeight, 200); inputRef.current.style.height = `${newHeight}px`; } }; useEffect(() => { onPromptChange(prompt); resizeTextarea(); }, [prompt, onPromptChange]); const handleInputFocus = () => setShowSuggestions(true); const handleInputClick = () => setShowSuggestions(true); const handleInputBlur = (e: React.FocusEvent) => { // Small delay to allow click events on suggestions to fire requestAnimationFrame(() => { if ( !e.relatedTarget || !containerRef.current?.contains(e.relatedTarget as Node) ) { setShowSuggestions(false); } }); }; const handleSuggestionClick = (suggestion: string) => { setPrompt(suggestion); setShowSuggestions(false); inputRef.current?.focus(); }; const clearInput = () => { setPrompt(""); inputRef.current?.focus(); }; const handleInputChange = (e: React.ChangeEvent) => { setPrompt(e.target.value); }; return (
{/* Suggestions Panel */}
{/* Header */}
Prompt Library
{/* List */}
    {PROMPTS.suggestions.map((suggestion, index) => (
  • e.preventDefault()} // Prevent blur onClick={() => handleSuggestionClick(suggestion)} className="px-4 py-2.5 cursor-pointer flex items-start gap-3 transition-colors hover:bg-[var(--mistral-beige-light)] group/item" > {`>`} {suggestion}
  • ))}
{/* Input Container */}
{/* Label Badge */}
Prompt