2026-05-07 02:41:01 +08:00
|
|
|
import { useState, useRef } from 'react';
|
|
|
|
|
import { Send } from 'lucide-react';
|
|
|
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
|
|
2026-05-07 03:22:15 +08:00
|
|
|
export function ChatInput({ onSend, disabled }: { onSend: (content: string) => void; disabled?: boolean }) {
|
2026-05-07 02:41:01 +08:00
|
|
|
const [input, setInput] = useState('');
|
|
|
|
|
const ref = useRef<HTMLTextAreaElement>(null);
|
|
|
|
|
|
|
|
|
|
const handleSend = () => {
|
|
|
|
|
if (!input.trim()) return;
|
|
|
|
|
onSend(input.trim());
|
|
|
|
|
setInput('');
|
|
|
|
|
ref.current?.focus();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleKeyDown = (e: React.KeyboardEvent) => {
|
|
|
|
|
if (e.key === 'Enter' && !e.shiftKey) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
handleSend();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2026-05-07 03:48:14 +08:00
|
|
|
<div className="p-4 border-t border-zinc-200 bg-white">
|
|
|
|
|
<div className="flex items-end gap-2 bg-zinc-50 rounded-xl border border-zinc-200 px-4 py-2.5 focus-within:border-indigo-300 transition-colors">
|
2026-05-07 02:41:01 +08:00
|
|
|
<textarea
|
|
|
|
|
ref={ref}
|
|
|
|
|
value={input}
|
|
|
|
|
onChange={(e) => setInput(e.target.value)}
|
|
|
|
|
onKeyDown={handleKeyDown}
|
|
|
|
|
rows={1}
|
2026-05-07 03:22:15 +08:00
|
|
|
placeholder={disabled ? '等待回复中...' : '输入指令...'}
|
2026-05-07 03:48:14 +08:00
|
|
|
className="flex-1 bg-transparent text-sm resize-none outline-none placeholder:text-zinc-400 text-zinc-700"
|
2026-05-07 03:22:15 +08:00
|
|
|
disabled={disabled}
|
2026-05-07 02:41:01 +08:00
|
|
|
/>
|
2026-05-07 03:48:14 +08:00
|
|
|
<Button size="icon" variant="ghost" className="h-8 w-8 text-zinc-400 hover:text-indigo-600" onClick={handleSend} disabled={disabled}>
|
|
|
|
|
<Send size={16} />
|
2026-05-07 02:41:01 +08:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|