Skip to content

Commit 1b59e7c

Browse files
authored
Styling improvements to AI Chat Followup questions (#3444)
1 parent 32d6f58 commit 1b59e7c

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

.changeset/red-eagles-build.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Styling improvements to AI Chat Followup questions

packages/gitbook/src/components/AIChat/AIChat.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import AIChatIcon from './AIChatIcon';
1616
import { AIChatInput } from './AIChatInput';
1717
import { AIChatMessages } from './AIChatMessages';
1818
import AIChatSuggestedQuestions from './AIChatSuggestedQuestions';
19-
import { AIChatFollowupSuggestions } from './AiChatFollowupSuggestions';
2019

2120
export function AIChat() {
2221
const chat = useAIChatState();
@@ -169,19 +168,19 @@ export function AIChatWindow(props: { chat: AIChatState }) {
169168
) : null}
170169
</div>
171170
) : (
172-
<AIChatMessages chat={chat} lastUserMessageRef={lastUserMessageRef} />
171+
<AIChatMessages
172+
chat={chat}
173+
chatController={chatController}
174+
lastUserMessageRef={lastUserMessageRef}
175+
/>
173176
)}
174177
</div>
175178
<div
176179
ref={inputRef}
177180
className="absolute inset-x-0 bottom-0 mr-2 flex flex-col gap-4 bg-gradient-to-b from-transparent to-50% to-tint-base/9 p-4 pr-2"
178181
>
179182
{/* Display an error banner when something went wrong. */}
180-
{chat.error ? (
181-
<AIChatError chatController={chatController} />
182-
) : (
183-
<AIChatFollowupSuggestions chat={chat} chatController={chatController} />
184-
)}
183+
{chat.error ? <AIChatError chatController={chatController} /> : null}
185184

186185
<AIChatInput
187186
value={input}

packages/gitbook/src/components/AIChat/AIChatMessages.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import { tcls } from '@/lib/tailwind';
22
import { AIMessageRole } from '@gitbook/api';
33
import type React from 'react';
4-
import type { AIChatState } from '../AI/useAIChat';
4+
import type { AIChatController, AIChatState } from '../AI/useAIChat';
5+
import { AIChatFollowupSuggestions } from './AiChatFollowupSuggestions';
56

67
export function AIChatMessages(props: {
78
chat: AIChatState;
9+
chatController: AIChatController;
810
lastUserMessageRef?: React.RefObject<HTMLDivElement>;
911
}) {
10-
const { chat, lastUserMessageRef } = props;
12+
const { chat, chatController, lastUserMessageRef } = props;
1113

1214
return (
1315
<>
1416
{chat.messages.map((message, index) => {
17+
const isLastMessage = index === chat.messages.length - 1;
1518
const isLastUserMessage =
1619
message.role === AIMessageRole.User &&
1720
index === chat.messages.map((m) => m.role).lastIndexOf(AIMessageRole.User);
@@ -23,8 +26,9 @@ export function AIChatMessages(props: {
2326
message.content ? 'animate-[fadeIn_500ms_both]' : '',
2427
'shrink-0',
2528
'last:min-h-[calc(100%-5rem)]',
29+
'flex flex-col gap-6',
2630
message.role === AIMessageRole.User
27-
? 'max-w-[80%] self-end rounded-md bg-tint px-4 py-2'
31+
? 'max-w-[80%] self-end circular-corners:rounded-2xl rounded-corners:rounded-md bg-tint px-4 py-2'
2832
: ''
2933
)}
3034
style={{
@@ -48,6 +52,12 @@ export function AIChatMessages(props: {
4852
))}
4953
</div>
5054
) : null}
55+
{isLastMessage ? (
56+
<AIChatFollowupSuggestions
57+
chat={chat}
58+
chatController={chatController}
59+
/>
60+
) : null}
5161
</div>
5262
);
5363
})}

packages/gitbook/src/components/AIChat/AiChatFollowupSuggestions.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ export function AIChatFollowupSuggestions(props: {
1515
}
1616

1717
return (
18-
<div className="flex flex-row flex-wrap justify-end gap-2 pt-8">
18+
<div className="mt-auto flex flex-row flex-wrap justify-end gap-2">
1919
{chat.followUpSuggestions.map((suggestion, index) => (
2020
<Button
2121
key={index}
2222
onClick={() => {
2323
chatController.postMessage({ message: suggestion });
2424
}}
2525
label={suggestion}
26-
className="max-w-full animate-[present_500ms_both] whitespace-normal text-right"
27-
size="small"
28-
variant="secondary"
26+
className="max-w-[80%] animate-[present_500ms_both] whitespace-normal text-left ring-1 ring-tint-subtle"
27+
size="medium"
28+
variant="blank"
2929
style={{
3030
animationDelay: `${250 + Math.min(index * 50, 150)}ms`,
3131
}}

0 commit comments

Comments
 (0)