Skip to content

Commit 05f976a

Browse files
committed
feat: Chat Form improvements
1 parent 23510ae commit 05f976a

File tree

7 files changed

+50
-45
lines changed

7 files changed

+50
-45
lines changed

tools/server/webui/src/lib/components/app/chat/ChatForm/ChatForm.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import { ChatAttachmentsList } from '$lib/components/app';
3-
import { ChatFormActionButtons, ChatFormFileInput, ChatFormHelperText, ChatFormTextarea } from '$lib/components/app';
3+
import { ChatFormActionButtons, ChatFormFileInputInvisible, ChatFormHelperText, ChatFormTextarea } from '$lib/components/app';
44
import { inputClasses } from '$lib/constants/input-classes';
55
import { onMount } from 'svelte';
66
import { config } from '$lib/stores/settings.svelte';
@@ -34,7 +34,7 @@
3434
const pasteLongTextToFileLength = $derived(Number(currentConfig.pasteLongTextToFileLen) || 2500);
3535
3636
let message = $state('');
37-
let fileInputRef: ChatFormFileInput | undefined;
37+
let fileInputRef: ChatFormFileInputInvisible | undefined;
3838
let previousIsLoading = $state(isLoading);
3939
let textareaRef: ChatFormTextarea | undefined;
4040
@@ -137,7 +137,7 @@
137137
}
138138
</script>
139139

140-
<ChatFormFileInput bind:this={fileInputRef} onFileSelect={handleFileSelect} />
140+
<ChatFormFileInputInvisible bind:this={fileInputRef} onFileSelect={handleFileSelect} />
141141

142142
<form
143143
onsubmit={handleSubmit}
@@ -153,7 +153,7 @@
153153
bind:this={textareaRef}
154154
bind:value={message}
155155
onKeydown={handleKeydown}
156-
{disabled}
156+
disabled={isLoading}
157157
/>
158158

159159
<ChatFormActionButtons

tools/server/webui/src/lib/components/app/chat/ChatForm/ChatFormActionButtons.svelte

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,41 @@
2626
<div class="flex items-center justify-between gap-1 {className}">
2727
<Button
2828
type="button"
29-
variant="ghost"
30-
class="text-muted-foreground hover:text-foreground h-8 w-8 rounded-full p-0"
29+
class="text-muted-foreground bg-transparent hover:bg-foreground/10 hover:text-foreground h-8 w-8 rounded-full p-0"
3130
disabled={disabled || isLoading}
3231
onclick={onFileUpload}
3332
>
33+
<span class="sr-only">Attach files</span>
3434
<Paperclip class="h-4 w-4" />
3535
</Button>
3636

37-
<div>
37+
<div class="flex gap-2">
3838
{#if isLoading}
3939
<Button
4040
type="button"
41-
variant="ghost"
4241
onclick={onStop}
43-
class="text-muted-foreground hover:text-destructive h-8 w-8 rounded-full p-0"
42+
class="p-0 h-8 w-8 bg-transparent hover:bg-destructive/20"
4443
>
45-
<Square class="h-8 w-8" />
44+
<span class="sr-only">Stop</span>
45+
<Square class="h-8 w-8 fill-destructive stroke-destructive" />
4646
</Button>
4747
{:else}
4848
<Button
4949
type="button"
50-
variant="ghost"
51-
class="text-muted-foreground hover:text-foreground h-8 w-8 rounded-full p-0"
50+
class="text-muted-foreground bg-transparent hover:bg-foreground/10 hover:text-foreground h-8 w-8 rounded-full p-0"
5251
disabled={disabled || isLoading}
5352
onclick={onMicClick}
5453
>
54+
<span class="sr-only">Start recording</span>
5555
<Mic class="h-8 w-8" />
5656
</Button>
57+
5758
<Button
5859
type="submit"
5960
disabled={!canSend || disabled || isLoading}
6061
class="h-8 w-8 rounded-full p-0"
6162
>
63+
<span class="sr-only">Send</span>
6264
<ArrowUp class="h-12 w-12" />
6365
</Button>
6466
{/if}

tools/server/webui/src/lib/components/app/chat/ChatForm/ChatFormTextarea.svelte

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
import { onMount } from 'svelte';
44
55
interface Props {
6-
value?: string;
6+
class?: string;
77
disabled?: boolean;
8-
placeholder?: string;
98
onKeydown?: (event: KeyboardEvent) => void;
109
onPaste?: (event: ClipboardEvent) => void;
11-
class?: string;
10+
placeholder?: string;
11+
value?: string;
1212
}
1313
1414
let {
15-
value = $bindable(''),
15+
class: className = '',
1616
disabled = false,
17-
placeholder = 'Ask anything...',
1817
onKeydown,
1918
onPaste,
20-
class: className = ''
19+
placeholder = 'Ask anything...',
20+
value = $bindable(''),
2121
}: Props = $props();
2222
2323
let textareaElement: HTMLTextAreaElement | undefined;
@@ -48,11 +48,12 @@
4848
<textarea
4949
bind:this={textareaElement}
5050
bind:value
51+
class="placeholder:text-muted-foreground text-md max-h-32 min-h-[24px] w-full resize-none border-0 bg-transparent p-0 leading-6 outline-none focus-visible:ring-0 focus-visible:ring-offset-0"
5152
onkeydown={onKeydown}
5253
oninput={(event) => autoResizeTextarea(event.currentTarget)}
5354
onpaste={onPaste}
5455
{placeholder}
55-
class="placeholder:text-muted-foreground text-md max-h-32 min-h-[24px] w-full resize-none border-0 bg-transparent p-0 leading-6 outline-none focus-visible:ring-0 focus-visible:ring-offset-0"
5656
{disabled}
57+
class:cursor-not-allowed={disabled}
5758
></textarea>
5859
</div>

tools/server/webui/src/lib/components/app/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export { default as ChatForm } from './chat/ChatForm/ChatForm.svelte';
77
export { default as ChatFormTextarea } from './chat/ChatForm/ChatFormTextarea.svelte';
88
export { default as ChatFormActionButtons } from './chat/ChatForm/ChatFormActionButtons.svelte';
99
export { default as ChatFormHelperText } from './chat/ChatForm/ChatFormHelperText.svelte';
10-
export { default as ChatFormFileInput } from './chat/ChatForm/ChatFormFileInput.svelte';
10+
export { default as ChatFormFileInputInvisible } from './chat/ChatForm/ChatFormFileInputInvisible.svelte';
1111

1212
export { default as ChatMessage } from './chat/ChatMessages/ChatMessage.svelte';
1313
export { default as ChatMessages } from './chat/ChatMessages/ChatMessages.svelte';

tools/server/webui/src/stories/ChatForm.stories.svelte

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script module>
22
import { defineMeta } from '@storybook/addon-svelte-csf';
33
import ChatForm from '$lib/components/app/chat/ChatForm/ChatForm.svelte';
4+
import { expect } from 'storybook/internal/test';
45
56
const { Story } = defineMeta({
67
title: 'Components/ChatForm',
@@ -11,4 +12,29 @@
1112
});
1213
</script>
1314

14-
<Story name="Default" args={{ class: 'max-w-[56rem] w-[calc(100vw-2rem)]' }} />
15+
<Story
16+
name="Default"
17+
args={{ class: 'max-w-[56rem] w-[calc(100vw-2rem)]' }}
18+
play={async ({ canvas, userEvent }) => {
19+
const textarea = await canvas.findByRole('textbox');
20+
const submitButton = await canvas.findByRole('button', { name: 'Send' });
21+
22+
// Expect the input to be focused after the component is mounted
23+
await expect(textarea).toHaveFocus();
24+
25+
// Expect the submit button to be disabled
26+
await expect(submitButton).toBeDisabled();
27+
28+
const text = 'What is the meaning of life?';
29+
30+
await userEvent.clear(textarea);
31+
await userEvent.type(textarea, text);
32+
33+
await expect(textarea).toHaveValue(text);
34+
}}
35+
/>
36+
37+
<Story
38+
name="Loading"
39+
args={{ class: 'max-w-[56rem] w-[calc(100vw-2rem)]', isLoading: true }}
40+
/>

tools/server/webui/src/stories/ChatSettingsSection.stories.svelte

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)