feat(ai): tint user message bubbles with theme accent for clearer turn separation (#4317)

* feat(ai): tint user message bubbles with theme accent for clearer turn separation

* fix(css): wrap global border-color reset in @layer base so user bubble border-primary utilities apply
This commit is contained in:
陈大猫 authored and GitHub committed 2026-11-25 10:37:12 +08:00
1 parent 2bf8611919
commit 040aec53b2
3 files changed
+82 -11

No files matched your search

+1 -1
View File
@@ -31,7 +31,7 @@ export const MessageContent = ({ children, className, from, ...props }: MessageC
<div
className={cn(
'ai-chat-message-content flex w-fit min-w-0 max-w-full flex-col gap-1.5 text-[13px] leading-relaxed',
'group-[.is-user]:ml-auto group-[.is-user]:overflow-hidden group-[.is-user]:rounded-lg group-[.is-user]:border group-[.is-user]:border-border/50 group-[.is-user]:bg-muted/50 group-[.is-user]:px-2.5 group-[.is-user]:py-[7px]',
'group-[.is-user]:ml-auto group-[.is-user]:overflow-hidden group-[.is-user]:rounded-lg group-[.is-user]:border group-[.is-user]:border-primary/25 group-[.is-user]:bg-primary/12 group-[.is-user]:text-foreground [.dark_&]:group-[.is-user]:border-primary/30 [.dark_&]:group-[.is-user]:bg-primary/18 group-[.is-user]:px-2.5 group-[.is-user]:py-[7px]',
'group-[.is-assistant]:w-full group-[.is-assistant]:text-foreground/90',
className,
)}
+71
View File
@@ -706,3 +706,74 @@ test('iteration limit Continue button invokes the provided send callback', async
assert.equal(continued, 1);
await act(async () => { renderer!.unmount(); });
});
test('ChatMessageList tints user prompt bubbles with theme accent while keeping assistant replies neutral', async t => {
const previousWindow = globalThis.window;
const actGlobal = globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT?: boolean };
const previousActEnvironment = actGlobal.IS_REACT_ACT_ENVIRONMENT;
globalThis.window = { setTimeout, clearTimeout } as unknown as Window & typeof globalThis;
actGlobal.IS_REACT_ACT_ENVIRONMENT = true;
t.after(() => {
globalThis.window = previousWindow;
actGlobal.IS_REACT_ACT_ENVIRONMENT = previousActEnvironment;
});
const messages: ChatMessage[] = [
{ id: 'u1', role: 'user', content: 'Check nginx status', timestamp: 1 },
{ id: 'a1', role: 'assistant', content: 'Nginx is running.', timestamp: 2 },
];
let renderer: ReactTestRenderer;
await act(async () => {
renderer = create(
<I18nProvider locale="en">
<TooltipProvider>
<ChatMessageList messages={messages} />
</TooltipProvider>
</I18nProvider>,
);
});
const divs = renderer!.root.findAllByType('div');
const userRow = divs.find(
node => node.props['data-role'] === 'user' && String(node.props.className).includes('ai-chat-message '),
);
const assistantRow = divs.find(
node => node.props['data-role'] === 'assistant' && String(node.props.className).includes('ai-chat-message '),
);
const userBubble = divs.find(
node => node.props['data-role'] === 'user' && String(node.props.className).includes('ai-chat-message-content'),
);
const assistantContent = divs.find(
node => node.props['data-role'] === 'assistant' && String(node.props.className).includes('ai-chat-message-content'),
);
assert.ok(userRow, 'expected user message row');
assert.ok(assistantRow, 'expected assistant message row');
assert.ok(userBubble, 'expected user message bubble');
assert.ok(assistantContent, 'expected assistant message content');
const userRowClasses = String(userRow.props.className).split(/\s+/);
const assistantRowClasses = String(assistantRow.props.className).split(/\s+/);
assert.ok(userRowClasses.includes('is-user'));
assert.ok(!userRowClasses.includes('is-assistant'));
assert.ok(assistantRowClasses.includes('is-assistant'));
assert.ok(!assistantRowClasses.includes('is-user'));
const userBubbleClasses = String(userBubble.props.className).split(/\s+/);
assert.ok(userBubbleClasses.includes('group-[.is-user]:bg-primary/12'));
assert.ok(userBubbleClasses.includes('[.dark_&]:group-[.is-user]:bg-primary/18'));
assert.ok(userBubbleClasses.includes('group-[.is-user]:border-primary/25'));
assert.ok(userBubbleClasses.includes('[.dark_&]:group-[.is-user]:border-primary/30'));
assert.ok(userBubbleClasses.includes('group-[.is-user]:text-foreground'));
assert.ok(!userBubbleClasses.includes('group-[.is-user]:bg-muted/50'));
assert.ok(!userBubbleClasses.includes('group-[.is-user]:border-border/50'));
const assistantClasses = String(assistantContent.props.className).split(/\s+/);
assert.ok(assistantClasses.includes('group-[.is-assistant]:w-full'));
assert.ok(assistantClasses.includes('group-[.is-assistant]:text-foreground/90'));
assert.ok(!assistantClasses.some(cls => cls.startsWith('group-[.is-assistant]:bg-primary')));
assert.ok(!assistantClasses.some(cls => cls.startsWith('group-[.is-assistant]:border-primary')));
await act(async () => { renderer!.unmount(); });
});
+10 -10
View File
@@ -705,29 +705,29 @@ const ChatMessageList: React.FC<ChatMessageListProps> = ({
!att.vaultNoteId && (att.contentUnavailable || !att.base64Data) ? (
<div
key={att.filename ? `${att.filename}-${i}` : `att-${message.id}-${i}`}
className="inline-flex items-center gap-1.5 min-h-7 px-2 py-1 rounded-md bg-muted/20 border border-border/20 text-[11px] text-foreground/70"
className="inline-flex items-center gap-1.5 min-h-7 px-2 py-1 rounded-md bg-background/60 border border-primary/20 text-[11px] text-foreground/80"
title={t('ai.chat.attachmentContentUnavailable')}
>
{att.terminalSelection
? <SquareTerminal size={12} className="text-muted-foreground/60 shrink-0" />
: <FileText size={12} className="text-muted-foreground/60 shrink-0" />}
? <SquareTerminal size={12} className="text-foreground/60 shrink-0" />
: <FileText size={12} className="text-foreground/60 shrink-0" />}
<span className="truncate max-w-[150px]">{att.filename || (att.terminalSelection ? 'terminal selection' : 'file')}</span>
<span className="text-muted-foreground">{t('ai.chat.attachmentContentUnavailable')}</span>
</div>
) : att.terminalSelection ? (
<div
key={att.filename ? `${att.filename}-${i}` : `att-${message.id}-${i}`}
className="inline-flex items-center gap-1.5 h-7 px-2 rounded-md bg-muted/20 border border-border/20 text-[11px] text-foreground/70"
className="inline-flex items-center gap-1.5 h-7 px-2 rounded-md bg-background/60 border border-primary/20 text-[11px] text-foreground/80"
>
<SquareTerminal size={12} className="text-muted-foreground/60 shrink-0" />
<SquareTerminal size={12} className="text-foreground/60 shrink-0" />
<span className="truncate max-w-[150px]">{att.filename || 'terminal selection'}</span>
</div>
) : att.vaultNoteId ? (
<div
key={att.filename ? `${att.filename}-${i}` : `att-${message.id}-${i}`}
className="inline-flex items-center gap-1.5 h-7 px-2 rounded-md bg-muted/20 border border-border/20 text-[11px] text-foreground/70"
className="inline-flex items-center gap-1.5 h-7 px-2 rounded-md bg-background/60 border border-primary/20 text-[11px] text-foreground/80"
>
<BookOpen size={12} className="text-muted-foreground/60 shrink-0" />
<BookOpen size={12} className="text-foreground/60 shrink-0" />
<span className="truncate max-w-[150px]">{att.vaultNoteTitle || att.filename || 'note'}</span>
</div>
) : att.mediaType.startsWith('image/') ? (
@@ -735,15 +735,15 @@ const ChatMessageList: React.FC<ChatMessageListProps> = ({
key={att.filename ? `${att.filename}-${i}` : `att-${message.id}-${i}`}
src={`data:${att.mediaType};base64,${att.base64Data}`}
alt={att.filename || 'image'}
className="max-h-[120px] max-w-[200px] rounded-md object-contain border border-border/20 cursor-pointer hover:opacity-80 transition-opacity"
className="max-h-[120px] max-w-[200px] rounded-md object-contain border border-primary/20 cursor-pointer hover:opacity-80 transition-opacity"
onClick={() => openPreview(`data:${att.mediaType};base64,${att.base64Data}`, att.filename || 'image')}
/>
) : (
<div
key={att.filename ? `${att.filename}-${i}` : `att-${message.id}-${i}`}
className="inline-flex items-center gap-1.5 h-7 px-2 rounded-md bg-muted/20 border border-border/20 text-[11px] text-foreground/70"
className="inline-flex items-center gap-1.5 h-7 px-2 rounded-md bg-background/60 border border-primary/20 text-[11px] text-foreground/80"
>
<FileText size={12} className="text-muted-foreground/60 shrink-0" />
<FileText size={12} className="text-foreground/60 shrink-0" />
<span className="truncate max-w-[120px]">{att.filename || 'file'}</span>
</div>
)