AI chat components for React.
49 components for chat, code, voice and workflow interfaces, built on shadcn/ui and Tailwind CSS. Install from npm and import what you use.
"use client";import { Attachment, AttachmentPreview, AttachmentRemove, Attachments,} from "zjkm-ui-ai-elements/attachments";import { ModelSelector, ModelSelectorContent, ModelSelectorEmpty, ModelSelectorGroup, ModelSelectorInput, ModelSelectorItem, ModelSelectorList, ModelSelectorLogo, ModelSelectorLogoGroup, ModelSelectorName, ModelSelectorTrigger,} from "zjkm-ui-ai-elements/model-selector";import type { PromptInputMessage } from "zjkm-ui-ai-elements/prompt-input";import { PromptInput, PromptInputActionAddAttachments, PromptInputActionAddScreenshot, PromptInputActionMenu, PromptInputActionMenuContent, PromptInputActionMenuTrigger, PromptInputBody, PromptInputButton, PromptInputFooter, PromptInputProvider, PromptInputSubmit, PromptInputTextarea, PromptInputTools, usePromptInputAttachments,} from "zjkm-ui-ai-elements/prompt-input";import { CheckIcon, GlobeIcon } from "lucide-react";import { memo, useCallback, useState } from "react";const models = [ { chef: "OpenAI", chefSlug: "openai", id: "gpt-4o", name: "GPT-4o", providers: ["openai", "azure"], }, { chef: "OpenAI", chefSlug: "openai", id: "gpt-4o-mini", name: "GPT-4o Mini", providers: ["openai", "azure"], }, { chef: "Anthropic", chefSlug: "anthropic", id: "claude-opus-4-20250514", name: "Claude 4 Opus", providers: ["anthropic", "azure", "google", "amazon-bedrock"], }, { chef: "Anthropic", chefSlug: "anthropic", id: "claude-sonnet-4-20250514", name: "Claude 4 Sonnet", providers: ["anthropic", "azure", "google", "amazon-bedrock"], }, { chef: "Google", chefSlug: "google", id: "gemini-2.0-flash-exp", name: "Gemini 2.0 Flash", providers: ["google"], },];const SUBMITTING_TIMEOUT = 200;const STREAMING_TIMEOUT = 2000;interface AttachmentItemProps { attachment: { id: string; type: "file"; filename?: string; mediaType: string; url: string; }; onRemove: (id: string) => void;}const AttachmentItem = memo(({ attachment, onRemove }: AttachmentItemProps) => { const handleRemove = useCallback( () => onRemove(attachment.id), [onRemove, attachment.id] ); return ( <Attachment data={attachment} key={attachment.id} onRemove={handleRemove}> <AttachmentPreview /> <AttachmentRemove /> </Attachment> );});AttachmentItem.displayName = "AttachmentItem";interface ModelItemProps { m: (typeof models)[0]; selectedModel: string; onSelect: (id: string) => void;}const ModelItem = memo(({ m, selectedModel, onSelect }: ModelItemProps) => { const handleSelect = useCallback(() => onSelect(m.id), [onSelect, m.id]); return ( <ModelSelectorItem key={m.id} onSelect={handleSelect} value={m.id}> <ModelSelectorLogo provider={m.chefSlug} /> <ModelSelectorName>{m.name}</ModelSelectorName> <ModelSelectorLogoGroup> {m.providers.map((provider) => ( <ModelSelectorLogo key={provider} provider={provider} /> ))} </ModelSelectorLogoGroup> {selectedModel === m.id ? ( <CheckIcon className="ml-auto size-4" /> ) : ( <div className="ml-auto size-4" /> )} </ModelSelectorItem> );});ModelItem.displayName = "ModelItem";const PromptInputAttachmentsDisplay = () => { const attachments = usePromptInputAttachments(); const handleRemove = useCallback( (id: string) => attachments.remove(id), [attachments] ); if (attachments.files.length === 0) { return null; } return ( <Attachments variant="inline"> {attachments.files.map((attachment) => ( <AttachmentItem attachment={attachment} key={attachment.id} onRemove={handleRemove} /> ))} </Attachments> );};const Example = () => { const [model, setModel] = useState<string>(models[0].id); const [modelSelectorOpen, setModelSelectorOpen] = useState(false); const [status, setStatus] = useState< "submitted" | "streaming" | "ready" | "error" >("ready"); const selectedModelData = models.find((m) => m.id === model); const handleModelSelect = useCallback((id: string) => { setModel(id); setModelSelectorOpen(false); }, []); const handleSubmit = useCallback((message: PromptInputMessage) => { const hasText = Boolean(message.text); const hasAttachments = Boolean(message.files?.length); if (!(hasText || hasAttachments)) { return; } setStatus("submitted"); // eslint-disable-next-line no-console console.log("Submitting message:", message); setTimeout(() => { setStatus("streaming"); }, SUBMITTING_TIMEOUT); setTimeout(() => { setStatus("ready"); }, STREAMING_TIMEOUT); }, []); return ( <div className="size-full"> <PromptInputProvider> <PromptInput globalDrop multiple onSubmit={handleSubmit}> <PromptInputAttachmentsDisplay /> <PromptInputBody> <PromptInputTextarea /> </PromptInputBody> <PromptInputFooter> <PromptInputTools> <PromptInputActionMenu> <PromptInputActionMenuTrigger /> <PromptInputActionMenuContent> <PromptInputActionAddAttachments /> <PromptInputActionAddScreenshot /> </PromptInputActionMenuContent> </PromptInputActionMenu> <PromptInputButton> <GlobeIcon size={16} /> <span>Search</span> </PromptInputButton> <ModelSelector onOpenChange={setModelSelectorOpen} open={modelSelectorOpen} > <ModelSelectorTrigger asChild> <PromptInputButton> {selectedModelData?.chefSlug && ( <ModelSelectorLogo provider={selectedModelData.chefSlug} /> )} {selectedModelData?.name && ( <ModelSelectorName> {selectedModelData.name} </ModelSelectorName> )} </PromptInputButton> </ModelSelectorTrigger> <ModelSelectorContent> <ModelSelectorInput placeholder="Search models..." /> <ModelSelectorList> <ModelSelectorEmpty>No models found.</ModelSelectorEmpty> {["OpenAI", "Anthropic", "Google"].map((chef) => ( <ModelSelectorGroup heading={chef} key={chef}> {models .filter((m) => m.chef === chef) .map((m) => ( <ModelItem key={m.id} m={m} onSelect={handleModelSelect} selectedModel={model} /> ))} </ModelSelectorGroup> ))} </ModelSelectorList> </ModelSelectorContent> </ModelSelector> </PromptInputTools> <PromptInputSubmit status={status} /> </PromptInputFooter> </PromptInput> </PromptInputProvider> </div> );};export default Example;Live267 lines
Loading preview…
$ npm i zjkm-ui-ai-elementsThen import from zjkm-ui-ai-elements/prompt-input. Prompt Input docs
All 49 components
Each one has a live preview, its install and import lines, and a props table.
Chatbot
Attachments
A flexible, composable attachment component for displaying files, images, videos, audio, and source documents.
Chain of Thought
A collapsible component that visualizes AI reasoning steps with support for search results, images, and step-by-step progress indicators.
Checkpoint
A simple component for marking conversation history points and restoring the chat to a previous state.
Confirmation
An alert-based component for managing tool execution approval workflows with request, accept, and reject states.
Context
A compound component system for displaying AI model context window usage, token consumption, and cost estimation.
Conversation
Wraps messages and automatically scrolls to the bottom. Also includes a scroll button that appears when not at the bottom.
Inline Citation
A hoverable citation component that displays source information and quotes inline with text, perfect for AI-generated content with references.
Message
A comprehensive suite of components for displaying chat messages, including message rendering, branching, actions, and markdown responses.
Model Selector
A searchable command palette for selecting AI models in your chat interface.
Plan
A collapsible plan component for displaying AI-generated execution plans with streaming support and shimmer animations.
Prompt Input
Allows a user to send a message with file attachments to a large language model. It includes a textarea, file upload capabilities, a submit button, and a dropdown for selecting the model.
Question
A composable prompt for collecting choices, freeform text, or both from a user.
Queue
A comprehensive queue component system for displaying message lists, todos, and collapsible task sections in AI applications.
Reasoning
A collapsible component that displays AI reasoning content, automatically opening during streaming and closing when finished.
Shimmer
An animated text shimmer component for creating eye-catching loading states and progressive reveal effects.
Sources
A component that allows a user to view the sources or citations used to generate a response.
Suggestion
A suggestion component that displays a horizontal row of clickable suggestions for user interaction.
Task
A collapsible task list component for displaying AI workflow progress, with status indicators and optional descriptions.
Tool
A collapsible component for displaying tool invocation details in AI chatbot interfaces.
Code
Agent
A composable component for displaying AI agent configuration with model, instructions, tools, and output schema.
Artifact
A container component for displaying generated content like code, documents, or other outputs with built-in actions.
Code Block
Provides syntax highlighting, line numbers, and copy to clipboard functionality for code blocks.
Commit
Display commit information with hash, message, author, and file changes.
Environment Variables
Display environment variables with masking and copy functionality.
File Tree
Display hierarchical file and folder structure with expand/collapse functionality.
JSX Preview
A component that dynamically renders JSX strings with streaming support for AI-generated UI.
Package Info
Display dependency information and version changes.
Sandbox
A collapsible container for displaying AI-generated code and output in chat interfaces.
Schema Display
Display REST API endpoint documentation with parameters, request/response bodies.
Snippet
Lightweight inline code display for terminal commands and short code references.
Stack Trace
Displays formatted JavaScript/Node.js error stack traces with syntax highlighting and collapsible frames.
Terminal
Display streaming console output with full ANSI color support.
Test Results
Display test suite results with pass/fail/skip status and error details.
Web Preview
A composable component for previewing the result of a generated UI, with support for live examples and code display.
Voice
Audio Player
A composable audio player component built on media-chrome, with shadcn styling and flexible controls.
Mic Selector
A composable dropdown component for selecting audio input devices with permission handling and device change detection.
Persona
An animated AI visual component powered by Rive that responds to different states like listening, thinking, and speaking.
Speech Input
A button component that captures voice input and converts it to text, with cross-browser support.
Transcription
A composable component for displaying interactive, synchronized transcripts from AI SDK transcribe() results with click-to-seek functionality.
Voice Selector
A composable dialog component for selecting AI voices with metadata display and search functionality.
Workflow
Canvas
A React Flow-based canvas component for building interactive node-based interfaces.
Connection
A custom connection line component for React Flow-based canvases with animated bezier curve styling.
Controls
A styled controls component for React Flow-based canvases with zoom and fit view functionality.
Edge
Customizable edge components for React Flow canvases with animated and temporary states.
Node
A composable node component for React Flow-based canvases with Card-based styling.
Panel
A styled panel component for React Flow-based canvases to position custom UI elements.
Toolbar
A styled toolbar component for React Flow nodes with flexible positioning and custom actions.