Spaces:
Running
Running
| <script setup lang="ts"> | |
| import { ref } from 'vue' | |
| const input = ref<string>('') | |
| const props = defineProps<{ | |
| loading: boolean | |
| error: string | null | |
| }>() | |
| const emit = defineEmits<{ | |
| (event: 'send', payload: string): void | |
| }>() | |
| function handleSubmit() { | |
| const trimmed = input.value.trim() | |
| if (!trimmed || props.loading) return | |
| emit('send', trimmed) | |
| input.value = '' | |
| } | |
| </script> | |
| <template> | |
| <form @submit.prevent="handleSubmit" class="chat-input"> | |
| <input v-model="input" type="text" placeholder="Type your message..." :disabled="loading" /> | |
| <button type="submit" :disabled="loading">Send</button> | |
| </form> | |
| <div v-if="error" class="error">{{ error }}</div> | |
| </template> | |
| <style scoped> | |
| .chat-input { | |
| display: flex; | |
| gap: 0.5rem; | |
| margin-bottom: 1rem; | |
| } | |
| input { | |
| flex: 1; | |
| padding: 0.75rem; | |
| font-size: 1rem; | |
| border: 1px solid #ccc; | |
| border-radius: 6px; | |
| } | |
| button { | |
| padding: 0.75rem 1rem; | |
| font-size: 1rem; | |
| background-color: #4caf50; | |
| color: white; | |
| border: none; | |
| border-radius: 6px; | |
| cursor: pointer; | |
| } | |
| button:disabled { | |
| background-color: #ccc; | |
| cursor: not-allowed; | |
| } | |
| button:hover:enabled { | |
| background-color: #45a049; | |
| } | |
| .error { | |
| color: red; | |
| font-size: 0.875rem; | |
| } | |
| </style> | |