mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-02-12 01:01:50 +01:00
chatbox component
This commit is contained in:
parent
1edba03389
commit
fa0c2791c5
46
frontend/app/view/chatview/chatbox.tsx
Normal file
46
frontend/app/view/chatview/chatbox.tsx
Normal file
@ -0,0 +1,46 @@
|
||||
// ChatBox Component
|
||||
import { EmojiPalette } from "@/app/element/emojipalette";
|
||||
import { Input } from "@/app/element/input";
|
||||
import { InputDecoration } from "@/app/element/inputdecoration";
|
||||
import React, { useRef, useState } from "react";
|
||||
|
||||
interface ChatBoxProps {
|
||||
onSendMessage: (message: string) => void;
|
||||
}
|
||||
|
||||
const ChatBox: React.FC<ChatBoxProps> = ({ onSendMessage }) => {
|
||||
const [message, setMessage] = useState("");
|
||||
const anchorRef = useRef<HTMLButtonElement>(null);
|
||||
const scopeRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const handleInputChange = (value: string) => {
|
||||
setMessage(value);
|
||||
};
|
||||
|
||||
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
if (event.key === "Enter" && message.trim() !== "") {
|
||||
onSendMessage(message);
|
||||
setMessage("");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div ref={scopeRef} className="chatbox">
|
||||
<Input
|
||||
value={message}
|
||||
onChange={handleInputChange}
|
||||
onKeyDown={handleKeyDown}
|
||||
placeholder="Type a message..."
|
||||
decoration={{
|
||||
endDecoration: (
|
||||
<InputDecoration>
|
||||
<EmojiPalette scopeRef={scopeRef} className="emoji-palette" />
|
||||
</InputDecoration>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export { ChatBox };
|
Loading…
Reference in New Issue
Block a user