āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā š shadcn/directory/ibelick/prompt-kit/chat-container/page ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
import ComponentCodePreview from "@/components/app/component-code-preview" import { generateMetadata } from "../utils/metadata" import { ChatBasic } from "./chat-basic" import { ChatWithCustomScroll } from "./chat-with-custom-scroll"
export const metadata = generateMetadata( "Chat Container", "A component for creating chat interfaces with intelligent auto-scrolling behavior, designed to provide a smooth experience in conversation interfaces." )
A component for creating chat interfaces with intelligent auto-scrolling behavior, designed to provide a smooth experience in conversation interfaces.
<ComponentCodePreview component={<ChatWithCustomScroll />} filePath="app/docs/chat-container/chat-with-custom-scroll.tsx" classNameComponentContainer="p-0" />
A chat container that demonstrates text streaming with automatic scrolling. Click the "Show Streaming" button to see a simulated streaming response with the smart auto-scroll behavior in action.
<ComponentCodePreview component={<ChatBasic />} filePath="app/docs/chat-container/chat-basic.tsx" classNameComponentContainer="p-0" />
<CodeBlock
code={npx shadcn add "https://prompt-kit.com/c/chat-container.json"}
language="bash"
/>
<Step>Copy and paste the following code into your project.</Step>
<CodeBlock filePath="components/prompt-kit/chat-container.tsx" language="tsx" /><Step>Update the import paths to match your project setup.</Step>
</Steps> </TabsContent> </Tabs>The ChatContainer is built using three separate components that work together:
The main container that provides auto-scrolling functionality using the use-stick-to-bottom library.
| Prop | Type | Default | Description | | :-------- | :------------------------------------- | :------ | :---------------------------------------------- | | children | React.ReactNode | | Child components to render inside the container | | className | string | | Additional CSS classes | | ...props | React.HTMLAttributes<HTMLDivElement> | | All other div props |
The content wrapper that should contain your messages.
| Prop | Type | Default | Description | | :-------- | :------------------------------------- | :------ | :------------------------------------------------------ | | children | React.ReactNode | | Child components to render inside the content container | | className | string | | Additional CSS classes | | ...props | React.HTMLAttributes<HTMLDivElement> | | All other div props |
An optional scroll anchor element that can be used for scroll targeting.
| Prop | Type | Default | Description | | :-------- | :------------------------------------- | :------ | :----------------------------------------- | | className | string | | Additional CSS classes | | ref | React.RefObject<HTMLDivElement> | | Optional ref for the scroll anchor element | | ...props | React.HTMLAttributes<HTMLDivElement> | | All other div props |
The component uses the use-stick-to-bottom library to provide sophisticated auto-scrolling:
Key behaviors:
The ChatContainer pairs perfectly with the ScrollButton component. The ScrollButton automatically appears when the user scrolls up and disappears when at the bottom:
<CodeBlock code={`import { ChatContainerRoot, ChatContainerContent, ChatContainerScrollAnchor } from "@/components/prompt-kit/chat-container" import { ScrollButton } from "@/components/prompt-kit/scroll-button"
function ChatInterface() { return (
<div className="relative h-[500px]"> <ChatContainerRoot className="h-full"> <ChatContainerContent className="space-y-4"> {/* Your chat messages here */} <div>Message 1</div> <div>Message 2</div> <div>Message 3</div> </ChatContainerContent> <ChatContainerScrollAnchor /> <div className="absolute right-4 bottom-4"> <ScrollButton className="shadow-sm" /> </div> </ChatContainerRoot> </div> ) } `} language="tsx" />ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā