Usage
The ChatPromptSubmit component is used inside the ChatPrompt component to submit the prompt. It automatically handles the different status
values to control the chat.
It extends the Button component, so you can pass any property such as color
, variant
, size
, etc.
<template>
<UChatPrompt>
<UChatPromptSubmit />
</UChatPrompt>
</template>
footer
slot of the ChatPrompt
component.Ready
When its status is ready
, use the color
, variant
and icon
props to customize the Button. Defaults to:
color="primary"
variant="solid"
icon="i-lucide-arrow-up"
<template>
<UChatPromptSubmit color="primary" variant="solid" icon="i-lucide-arrow-up" />
</template>
Submitted
When its status is submitted
, use the submitted-color
, submitted-variant
and submitted-icon
props to customize the Button. Defaults to:
submittedColor="neutral"
submittedVariant="subtle"
submittedIcon="i-lucide-square"
stop
event is emitted when the user clicks on the Button.<template>
<UChatPromptSubmit
submitted-color="neutral"
submitted-variant="subtle"
submitted-icon="i-lucide-square"
status="submitted"
/>
</template>
Streaming
When its status is streaming
, use the streaming-color
, streaming-variant
and streaming-icon
props to customize the Button. Defaults to:
streamingColor="neutral"
streamingVariant="subtle"
streamingIcon="i-lucide-square"
stop
event is emitted when the user clicks on the Button.<template>
<UChatPromptSubmit
streaming-color="neutral"
streaming-variant="subtle"
streaming-icon="i-lucide-square"
status="streaming"
/>
</template>
Error
When its status is error
, use the error-color
, error-variant
and error-icon
props to customize the Button. Defaults to:
errorColor="error"
errorVariant="soft"
errorIcon="i-lucide-rotate-ccw"
reload
event is emitted when the user clicks on the Button.<template>
<UChatPromptSubmit
error-color="error"
error-variant="soft"
error-icon="i-lucide-rotate-ccw"
status="error"
/>
</template>
Examples
Within a page
Use the ChatPromptSubmit component with the useChat
composable to display a chat prompt within a page.
Pass the status
prop and listen to the stop
and reload
events to control the chat.
<script setup lang="ts">
import { useChat } from '@ai-sdk/vue'
const { messages, input, handleSubmit, reload, stop, status, error } = useChat()
</script>
<template>
<UDashboardPanel>
<template #body>
<UContainer>
<UChatMessages :messages="messages" :status="status">
<template #content="{ message }">
<MDC :value="message.content" :cache-key="message.id" unwrap="p" />
</template>
</UChatMessages>
</UContainer>
</template>
<template #footer>
<UContainer>
<UChatPrompt v-model="input" :error="error" @submit="handleSubmit">
<UChatPromptSubmit :status="status" @stop="stop" @reload="reload" />
</UChatPrompt>
</UContainer>
</template>
</UDashboardPanel>
</template>
API
Props
Prop | Default | Type |
---|
Slots
Slot | Type |
---|
Emits
Event | Type |
---|
Theme
export default defineAppConfig({
uiPro: {
chatPromptSubmit: {
slots: {
base: ''
}
}
}
})
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
uiPro: {
chatPromptSubmit: {
slots: {
base: ''
}
}
}
})
]
})
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import uiPro from '@nuxt/ui-pro/vite'
export default defineConfig({
plugins: [
vue(),
uiPro({
uiPro: {
chatPromptSubmit: {
slots: {
base: ''
}
}
}
})
]
})