Open History to see the last commit
1<script lang="ts">
2 import { Send, Square } from 'lucide-svelte'
3
4 interface Props {
5 value: string
6 isLoading: boolean
7 onSend: (message: string) => void
8 onStop: () => void
9 }
10
11 let { value = $bindable(''), isLoading, onSend, onStop }: Props = $props()
12
13 let textarea: HTMLTextAreaElement | undefined = $state()
14
15 function handleInput(e: Event) {
16 const target = e.target as HTMLTextAreaElement
17 target.style.height = 'auto'
18 target.style.height = Math.min(target.scrollHeight, 200) + 'px'
19 }
20
21 function handleKeyDown(e: KeyboardEvent) {
22 if (e.key === 'Enter' && !e.shiftKey && value.trim()) {
23 e.preventDefault()
24 onSend(value)
25 value = ''
26 if (textarea) {
27 textarea.style.height = 'auto'
28 }
29 }
30 }
31
32 function handleSubmit() {
33 if (value.trim()) {
34 onSend(value)
35 value = ''
36 if (textarea) {
37 textarea.style.height = 'auto'
38 }
39 }
40 }
41</script>
42
43<div class="border-t border-orange-500/10 bg-gray-900/80 backdrop-blur-sm">
44 <div class="w-full px-4 py-3">
45 <div class="space-y-3">
46 {#if isLoading}
47 <div class="flex items-center justify-center">
48 <button
49 onclick={onStop}
50 class="px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-lg text-sm font-medium transition-colors flex items-center gap-2"
51 >
52 <Square class="w-4 h-4 fill-current" />
53 Stop
54 </button>
55 </div>
56 {/if}
57 <div class="relative">
58 <textarea
59 bind:this={textarea}
60 bind:value
61 oninput={handleInput}
62 onkeydown={handleKeyDown}
63 placeholder="Type something clever (or don't, we won't judge)..."
64 class="w-full rounded-lg border border-orange-500/20 bg-gray-800/50 pl-4 pr-12 py-3 text-sm text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-orange-500/50 focus:border-transparent resize-none overflow-hidden shadow-lg"
65 rows="1"
66 style="min-height: 44px; max-height: 200px"
67 disabled={isLoading}></textarea>
68 <button
69 onclick={handleSubmit}
70 disabled={!value.trim() || isLoading}
71 class="absolute right-2 top-1/2 -translate-y-1/2 p-2 text-orange-500 hover:text-orange-400 disabled:text-gray-500 transition-colors focus:outline-none"
72 >
73 <Send class="w-4 h-4" />
74 </button>
75 </div>
76 </div>
77 </div>
78</div>