Skip to content

Commit 0d6cd83

Browse files
koki-developclaude
andcommitted
feat: implement basic chat UI component
- Create App component with message list and input field - Use Static component for message history - Support user input with ink-text-input - Simple echo response for demonstration πŸ€– Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 61b638e commit 0d6cd83

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

β€Žsrc/App.tsxβ€Ž

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { Box, Static, Text } from "ink";
2+
import TextInput from "ink-text-input";
3+
import type React from "react";
4+
import { useState } from "react";
5+
6+
interface Message {
7+
id: number;
8+
text: string;
9+
sender: "user" | "assistant";
10+
}
11+
12+
export const App: React.FC = () => {
13+
const [messages, setMessages] = useState<Message[]>([
14+
{
15+
id: 1,
16+
text: "γ“γ‚“γ«γ‘γ―οΌδ½•γ‹γŠζ‰‹δΌγ„γ§γγ‚‹γ“γ¨γ―γ‚γ‚ŠγΎγ™γ‹οΌŸ",
17+
sender: "assistant",
18+
},
19+
]);
20+
const [input, setInput] = useState("");
21+
22+
const handleSubmit = () => {
23+
if (input.trim() === "") return;
24+
25+
const newMessage: Message = {
26+
id: messages.length + 1,
27+
text: input,
28+
sender: "user",
29+
};
30+
31+
setMessages([...messages, newMessage]);
32+
setInput("");
33+
34+
// シンプルγͺεΏœη­”γ‚’θΏ½εŠ 
35+
setTimeout(() => {
36+
const response: Message = {
37+
id: messages.length + 2,
38+
text: `γ€Œ${input}γ€γ«γ€γ„γ¦γŠη­”γˆγ—γΎγ™γ€‚`,
39+
sender: "assistant",
40+
};
41+
setMessages((prev) => [...prev, response]);
42+
}, 500);
43+
};
44+
45+
return (
46+
<Box flexDirection="column">
47+
<Static items={messages}>
48+
{(message) => (
49+
<Box key={message.id} marginBottom={1}>
50+
<Text color={message.sender === "user" ? "cyan" : "green"}>
51+
{message.sender === "user" ? "あγͺた" : "γ‚’γ‚·γ‚Ήγ‚Ώγƒ³γƒˆ"}:{" "}
52+
{message.text}
53+
</Text>
54+
</Box>
55+
)}
56+
</Static>
57+
<Box>
58+
<Text color="yellow">ε…₯εŠ›: </Text>
59+
<TextInput value={input} onChange={setInput} onSubmit={handleSubmit} />
60+
</Box>
61+
</Box>
62+
);
63+
};

0 commit comments

Comments
Β (0)