Usage
The ChatPrompt component renders a <form> element and extends the Textarea component so you can pass any property such as icon, placeholder, autofocus, etc.
The ChatPrompt handles the following events:
- The form is submitted when the user presses ↵ or when the user clicks on the submit button.
- The textarea is blurred when Esc is pressed and emits a
closeevent.
Variant
Use the variant prop to change the style of the prompt. Defaults to outline.
<template>
<B24ChatPrompt variant="tinted" />
</template>
Examples
As a starting point
You can also use it as a starting point for a chat interface.
pages/index.vue
<script setup lang="ts">
import { Chat } from '@ai-sdk/vue'
const input = ref('')
const chat = new Chat()
async function onSubmit() {
chat.sendMessage({ text: input.value })
// Navigate to chat page after first message
if (chat.messages.length === 1) {
await navigateTo('/chat')
}
}
</script>
<template>
<B24DashboardPanel>
<template #body>
<B24Container>
<h1>How can I help you today?</h1>
<B24ChatPrompt v-model="input" @submit="onSubmit">
<B24ChatPromptSubmit :status="chat.status" />
</B24ChatPrompt>
</B24Container>
</template>
</B24DashboardPanel>
</template>
Speech Recognition
Use composable useSpeechRecognition to provide speech recognition using the Web Speech API.
API
Props
Slots
Emits
Expose
When accessing the component via a template ref, you can use the following:
Theme
https://github.com/bitrix24/b24ui/tree/main/src/theme/chat-prompt.ts
export default {
slots: {
root: 'relative flex flex-col items-stretch gap-[2px] ps-[12px] pe-2 py-2 w-full rounded-lg',
header: 'flex items-center gap-2',
body: 'py-[4px] items-start',
footer: 'flex items-center justify-end gap-2',
base: 'pt-[1px] pb-[0px]'
},
variants: {
variant: {
outline: {
root: 'bg-(--ui-color-design-outline-bg) ring ring-(--ui-color-design-outline-stroke) ring-1 text-(--ui-color-design-outline-content)'
},
tinted: {
root: 'bg-(--ui-color-design-tinted-na-bg) ring ring-(--ui-color-design-tinted-na-stroke) ring-(length:--ui-design-tinted-na-stroke-weight) text-(--ui-color-design-tinted-na-content)'
},
filled: {
root: 'bg-(--ui-color-design-filled-na-bg) ring ring-(--ui-color-design-filled-na-stroke) ring-(length:--ui-design-filled-na-stroke-weight) text-(--ui-color-design-filled-na-content)'
},
plain: {
root: 'bg-(--ui-color-design-plain-bg) ring ring-(--ui-color-design-plain-stroke) ring-(length:--ui-design-plain-stroke-weight) text-(--ui-color-design-plain-content)'
}
}
},
defaultVariants: {
variant: 'outline'
}
}