File size: 883 Bytes
5400cf3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import { useState } from 'react'
import '../styles/chatinput.css' // Make sure file is named exactly like this
function ChatInput({ onSend }: { onSend: (msg: string) => void }) {
const [input, setInput] = useState('')
const handleKey = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter' && input.trim()) {
onSend(input)
setInput('')
}
}
return (
<div className="chat-input-wrapper">
<input
className="chat-input"
type="text"
placeholder="Ask something..."
value={input}
onChange={(e) => setInput(e.target.value)}
onKeyDown={handleKey}
/>
<button className="send-button" onClick={handleSend}>
Send
</button>
</div>
)
function handleSend() {
if (input.trim()) {
onSend(input)
setInput('')
}
}
}
export default ChatInput |