Skip to content

Commit c509281

Browse files
committed
feat: Improve user message padding for single vs multi line content
1 parent 3bc2826 commit c509281

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

tools/server/webui/src/lib/components/app/chat/ChatMessages/ChatMessageUser.svelte

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,32 @@
5252
onShowDeleteDialogChange,
5353
textareaElement = $bindable()
5454
}: Props = $props();
55+
56+
let innerWidth = $state(0);
57+
let isMultiline = $state(false);
58+
let messageElement: HTMLElement | undefined = $state();
59+
60+
$effect(() => {
61+
if (messageElement && message.content.trim() && innerWidth > 0) {
62+
if (message.content.includes('\n')) {
63+
isMultiline = true;
64+
return;
65+
}
66+
67+
const computedStyle = window.getComputedStyle(messageElement);
68+
const lineHeight = parseFloat(computedStyle.lineHeight);
69+
const actualHeight = messageElement.scrollHeight;
70+
71+
isMultiline = actualHeight > lineHeight * 1.2;
72+
}
73+
});
5574
</script>
5675

76+
<svelte:window bind:innerWidth />
77+
5778
<div
5879
aria-label="User message with actions"
59-
class="group flex flex-col items-end gap-2 {className}"
80+
class="group flex flex-col items-end gap-3 md:gap-2 {className}"
6081
role="group"
6182
>
6283
{#if isEditing}
@@ -92,10 +113,13 @@
92113
{/if}
93114

94115
{#if message.content.trim()}
95-
<Card class="max-w-[80%] rounded-2xl bg-primary px-2.5 py-1.5 text-primary-foreground">
96-
<div class="text-md whitespace-pre-wrap">
116+
<Card
117+
class="max-w-[80%] rounded-[1.125rem] bg-primary px-3.75 py-1.5 text-primary-foreground data-[multiline]:py-2.5"
118+
data-multiline={isMultiline ? '' : undefined}
119+
>
120+
<span bind:this={messageElement} class="text-md whitespace-pre-wrap">
97121
{message.content}
98-
</div>
122+
</span>
99123
</Card>
100124
{/if}
101125

0 commit comments

Comments
 (0)