showcase/shell-docs/src/content/reference/v1/components/chat/CopilotPopup.mdx
{ /*
A chatbot popup component for the CopilotKit framework. The component allows for a high degree of customization through various props and custom CSS.
See CopilotSidebar for a sidebar version of this component.
This component is part of the @copilotkit/react-ui package.
npm install @copilotkit/react-core @copilotkit/react-ui
import { CopilotPopup } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
<CopilotPopup
labels={{
title: "Your Assistant",
initial: "Hi! 👋 How can I assist you today?",
}}
/>
To monitor user interactions, provide the observabilityHooks prop.
Note: This requires a publicApiKey in the <CopilotKit> provider.
<CopilotKit publicApiKey="YOUR_PUBLIC_API_KEY">
<CopilotPopup
observabilityHooks={{
onChatExpanded: () => {
console.log("Popup opened");
},
onChatMinimized: () => {
console.log("Popup closed");
},
}}
/>
</CopilotKit>
By default, CopilotKit components do not have any styles. You can import CopilotKit's stylesheet at the root of your project:
...
import "@copilotkit/react-ui/styles.css"; // [!code highlight]
export function YourRootComponent() {
return (
<CopilotKit>
...
</CopilotKit>
);
}
For more information about how to customize the styles, check out the Customize Look & Feel guide.
auto (default) - Suggestions are generated automatically:
- When the chat is first opened (empty state)
- After each message exchange completes
- Uses configuration from useCopilotChatSuggestions hooks
manual - Suggestions are controlled programmatically:
- Use setSuggestions() to set custom suggestions
- Use generateSuggestions() to trigger AI generation
- Access via useCopilotChat hook
SuggestionItem[] - Static suggestions array:
- Always shows the same suggestions
- No AI generation involved
</PropertyReference>
@example
<CopilotChat
attachments={{
enabled: true,
accept: "image,application/pdf",
maxSize: 10 1024 1024, // 10MB
onUpload: async (file) => {
const url = await uploadToS3(file);
return { url, mimeType: file.type };
},
}}
/>
Warning: This is a break-glass solution to allow for custom rendering of messages. You are most likely looking to swap out the AssistantMessage and UserMessage components instead which are also props. </PropertyReference>
<PropertyReference name="RenderSuggestionsList" type="React.ComponentType<RenderSuggestionsListProps>" > A custom suggestions list component to use instead of the default. </PropertyReference> <PropertyReference name="Input" type="React.ComponentType<InputProps>" > A custom Input component to use instead of the default. </PropertyReference> <PropertyReference name="className" type="string" > A class name to apply to the root element. </PropertyReference> <PropertyReference name="children" type="React.ReactNode" > Children to render. </PropertyReference> <PropertyReference name="hideStopButton" type="boolean" > </PropertyReference> <PropertyReference name="observabilityHooks" type="CopilotObservabilityHooks" > Event hooks for CopilotKit chat events. These hooks only work when publicApiKey is provided. </PropertyReference> <PropertyReference name="renderError" type="(error: { message: string; operation?: string; timestamp: number; onDismiss: () => void; onRetry?: () => void; }) => React.ReactNode" > Custom error renderer for chat-specific errors. When provided, errors will be displayed inline within the chat interface. </PropertyReference> <PropertyReference name="onError" type="CopilotErrorHandler" > Optional handler for comprehensive debugging and observability. </PropertyReference> <PropertyReference name="defaultOpen" type="boolean" default="false"> Whether the chat window should be open by default. </PropertyReference> <PropertyReference name="clickOutsideToClose" type="boolean" default="true"> If the chat window should close when the user clicks outside of it. </PropertyReference> <PropertyReference name="hitEscapeToClose" type="boolean" default="true"> If the chat window should close when the user hits the Escape key. </PropertyReference> <PropertyReference name="shortcut" type="string" default="'/'"> The shortcut key to open the chat window. Uses Command-[shortcut] on a Mac and Ctrl-[shortcut] on Windows. </PropertyReference> <PropertyReference name="onSetOpen" type="(open: boolean) => void" > A callback that gets called when the chat window opens or closes. </PropertyReference> <PropertyReference name="Window" type="React.ComponentType<WindowProps>" > A custom Window component to use instead of the default. </PropertyReference> <PropertyReference name="Button" type="React.ComponentType<ButtonProps>" > A custom Button component to use instead of the default. </PropertyReference> <PropertyReference name="Header" type="React.ComponentType<HeaderProps>" > A custom Header component to use instead of the default. </PropertyReference>