import { useState, useRef, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { Sparkles, Send, X, Lightbulb } from 'lucide-react'; interface AISuggestionBarProps { suggestions: string[]; onSuggestionClick: (suggestion: string) => void; onSubmit: (text: string) => void; placeholder?: string; } export function AISuggestionBar({ suggestions, onSuggestionClick, onSubmit, placeholder = "输入你的想法,或点击预设词条获取 AI 建议..." }: AISuggestionBarProps) { const [inputText, setInputText] = useState(''); const [isFocused, setIsFocused] = useState(false); const [showSuggestions, setShowSuggestions] = useState(false); const inputRef = useRef(null); // 自动调整输入框高度 useEffect(() => { if (inputRef.current) { inputRef.current.style.height = 'auto'; inputRef.current.style.height = `${inputRef.current.scrollHeight}px`; } }, [inputText]); // 处理提交 const handleSubmit = () => { if (inputText.trim()) { onSubmit(inputText.trim()); setInputText(''); if (inputRef.current) { inputRef.current.style.height = 'auto'; } } }; // 处理回车提交 const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSubmit(); } }; return (
{/* 智能预设词条 */} {showSuggestions && (
智能预设词条
{suggestions.map((suggestion, index) => ( onSuggestionClick(suggestion)} > {suggestion} ))}
)}
{/* 输入区域 */}