Skip to content

Commit 0b9b779

Browse files
authored
Merge pull request #11 from ut-code/re-design
chatboxの表示非表示の切り替えの実装及び、出力用のchatbubbleを作成した。
2 parents 0ebb489 + c07defe commit 0b9b779

File tree

1 file changed

+49
-95
lines changed

1 file changed

+49
-95
lines changed

app/[docs_id]/chatForm.tsx

Lines changed: 49 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export function ChatForm() {
1010
const [inputValue, setInputValue] = useState("");
1111
const [response, setResponse] = useState("");
1212
const [isLoading, setIsLoading] = useState(false);
13+
const [isFormVisible, setIsFormVisible] = useState(false);
1314

1415
const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
1516
e.preventDefault();
@@ -42,119 +43,72 @@ export function ChatForm() {
4243
};
4344
return (
4445
<>
45-
<style jsx>{`
46-
/* 簡単なCSSで見た目を整える(オプション) */
47-
.form-container {
48-
background-color: white;
49-
border-radius: 10px;
50-
box-shadow: 0 4px 8px rgba(67, 204, 216, 0.86);
51-
padding: 20px;
52-
width: 90%;
53-
max-width: 1000px;
54-
display: flex;
55-
flex-direction: column;
56-
}
57-
.input-area {
58-
border: 1px solid #ccc;
59-
border-radius: 8px;
60-
padding: 5px 15 px;
61-
margin-bottom: 15px;
62-
min-height: 150px; /* 入力欄の高さ */
63-
display: flex;
64-
}
65-
.text-input {
66-
border: none;
67-
outline: none;
68-
flex-grow: 1;
69-
font-size: 16px;
70-
resize: none; /* テキストエリアのリサイズを無効化 */
71-
overflow: auto;
72-
padding: 10px;
73-
}
74-
.controls {
75-
display: flex;
76-
align-items: center;
77-
justify-content: space-between;
78-
}
79-
.left-icons button {
80-
background: none;
81-
border: none;
82-
font-size: 24px;
83-
cursor: pointer;
84-
color: #555;
85-
margin-right: 15px;
86-
padding: 5px;
87-
}
88-
.left-icons button:hover {
89-
color: #000;
90-
}
91-
.left-icons span {
92-
font-size: 14px;
93-
vertical-align: middle;
94-
margin-left: 5px;
95-
color: #555;
96-
}
97-
.right-controls {
98-
display: flex;
99-
align-items: center;
100-
}
101-
.voice-icon button {
102-
background: none;
103-
border: none;
104-
font-size: 24px;
105-
cursor: pointer;
106-
color: #555;
107-
margin-right: 15px;
108-
padding: 5px;
109-
}
110-
.voice-icon button:hover {
111-
color: #000;
112-
}
113-
.send-button {
114-
background-color: #007bff; /* 青色の送信ボタン */
115-
color: white;
116-
border: none;
117-
border-radius: 50%; /* 丸いボタン */
118-
width: 40px;
119-
height: 40px;
120-
display: flex;
121-
justify-content: center;
122-
align-items: center;
123-
font-size: 20px;
124-
cursor: pointer;
125-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
126-
transition: background-color 0.3s ease;
127-
}
128-
.send-button:hover {
129-
background-color: #0056b3;
130-
}
131-
`}</style>
132-
133-
<form className="form-container" onSubmit={handleSubmit}>
134-
<div className="input-area">
46+
{isFormVisible && (
47+
<form className="border border-2 border-primary shadow-xl p-6 rounded-lg bg-base-100" style={{width:"100%", textAlign:"center", boxShadow:"-moz-initial"}} onSubmit={handleSubmit}>
48+
<h2 className="text-xl font-bold mb-4 text-left relative -top-2 font-mono h-2">
49+
AIへ質問
50+
</h2>
51+
<div className="input-area" style={{height:"80px"}}>
13552
<textarea
136-
className="text-input"
53+
className="textarea textarea-white textarea-md"
13754
placeholder="質問を入力してください"
55+
style={{width: "100%", height: "110px", resize: "none"}}
13856
value={inputValue}
13957
onChange={(e) => setInputValue(e.target.value)}
14058
disabled={isLoading}
14159
></textarea>
14260
</div>
143-
<div className="controls">
144-
<div className="left-icons"></div>
61+
<br />
62+
<div className="controls" style={{position:"relative", top:"22px", display:"flex", alignItems:"center", justifyContent:"space-between"}}>
63+
<div className="left-icons">
64+
<button
65+
className="btn btn-soft btn-secondary rounded-full"
66+
onClick={() => setIsFormVisible(false)}
67+
>
68+
69+
閉じる
70+
</button>
71+
</div>
14572
<div className="right-controls">
14673
<button
14774
type="submit"
148-
className="send-button"
75+
className="btn btn-soft btn-circle btn-primary rounded-full"
14976
title="送信"
77+
style={{marginTop:"10px"}}
15078
disabled={isLoading}
15179
>
15280
<span className="icon"></span>
15381
</button>
15482
</div>
15583
</div>
15684
</form>
157-
{response && <div className="response-container">{response}</div>}
85+
)}
86+
{!isFormVisible && (
87+
<button
88+
className="btn btn-soft btn-secondary rounded-full"
89+
onClick={() => setIsFormVisible(true)}
90+
>
91+
チャットを開く
92+
</button>
93+
)}
94+
95+
{response && (
96+
<article>
97+
<h3 className="text-lg font-semibold mb-2">AIの回答</h3>
98+
<div className="chat chat-start">
99+
<div className="chat-bubble chat-bubble-primary">
100+
<div className="response-container">{response}</div>
101+
</div>
102+
</div>
103+
</article>
104+
)}
105+
106+
{isLoading && (
107+
<div className="mt-2 text-l text-gray-500 animate-pulse">
108+
AIが考え中です…
109+
</div>
110+
)}
111+
158112
</>
159113
);
160114
}

0 commit comments

Comments
 (0)