Chat App
Chat App: A complete agent conversation workspace composing navigation, messages, streaming, planning, approvals, tools, code, diffs, generated media, sources, and prompt input. Free MIT React & Next.js source with Motion and Tailwind CSS, live preview, CLI install and docs.
Install Chat App
npx motion-ui-skill add chat-appComponents install as source into your project. The interactive page also includes preview, code, documentation and install tabs.
Dependencies
clsxlucide-reactmotionreactreact-domshikitailwind-merge
Source files
components/agents/chat-app.tsxcomponents/agents/agent-activity/index.tsxcomponents/agents/ai-sidebar.tsxcomponents/agents/approval-card/index.tsxcomponents/agents/code-block.tsxcomponents/agents/file-diff.tsxcomponents/agents/image-generation.tsxcomponents/agents/loading-states/thinking-shimmer.tsxcomponents/agents/message-bubble.tsxcomponents/agents/message-scroller.tsxcomponents/agents/message.tsxcomponents/agents/prompt-input.tsxcomponents/agents/streaming-response.tsxcomponents/agents/todo-list.tsxcomponents/agents/tool-approval.tsxcomponents/agents/tool-result.tsxcomponents/agents/agent-activity/activity-row.tsxcomponents/agents/agent-activity/types.tscomponents/agents/agent-code.tsxcomponents/agents/agent-disclosure.tsxcomponents/agents/approval-card/types.tscomponents/agents/citations.tsxcomponents/agents/loading-states/agent-progress.tsxcomponents/agents/loading-states/index.tscomponents/agents/loading-states/reasoning-text.tsxcomponents/agents/message-context.tsxcomponents/motion/action-swap-roll.tsxcomponents/motion/action-swap.tsxcomponents/motion/animated-sidebar.tsxcomponents/motion/button/base.tsxcomponents/motion/button/index.tsxcomponents/motion/button/magnetic.tsxcomponents/motion/button/metallic.tsxcomponents/motion/button/stateful.tsxcomponents/motion/checkbox.tsxcomponents/motion/input.tsxcomponents/motion/loader.tsxcomponents/motion/magnetic.tsxcomponents/motion/popover-morph.tsxcomponents/motion/popover-position.tscomponents/motion/preview-rail.tsxcomponents/motion/radio.tsxcomponents/motion/select.tsxcomponents/motion/shared-layout-bg.tsxcomponents/motion/text-scramble.tsxcomponents/motion/text-shimmer.tsxcomponents/previews/agents/chat-app-usage.tsxlib/ease.tslib/favicon.tslib/hooks/use-dismiss.tslib/hooks/use-favicon.tslib/hooks/use-hover-capable.tslib/hooks/use-hover-gesture.tslib/hooks/use-tap-gesture.tslib/hooks/use-touch-capable.tslib/portal.tsxlib/text-shimmer.tslib/touch.tslib/utils.ts
Chat App
A complete agent conversation workspace composing navigation, messages, streaming, planning, approvals, tools, code, diffs, generated media, sources, and prompt input.
Install
npx motion-ui-skill add chat-app
Dependencies
clsxlucide-reactmotionreactreact-domshikitailwind-merge
Usage
"use client";
import { Maximize2, Minimize2 } from "lucide-react";
import { useCallback, useEffect, useRef, useState } from "react";
import { ChatAppExample } from "@/components/previews/agents/chat-app-usage";
import { ActionSwapIcon } from "@/components/motion/action-swap";
import { cn } from "@/lib/utils";
export function ChatAppPreview() {
const [expanded, setExpanded] = useState(false);
const containerRef = useRef<HTMLDivElement>(null);
const toggleRef = useRef<HTMLButtonElement>(null);
useEffect(() => {
if (!expanded) return;
const container = containerRef.current;
if (!container) return;
const previousOverflow = document.body.style.overflow;
document.body.style.overflow = "hidden";
const isolated: Array<{
element: HTMLElement;
inert: boolean;
ariaHidden: string | null;
}> = [];
let branch: HTMLElement = container;
while (branch.parentElement) {
const parent = branch.parentElement;
for (const sibling of Array.from(parent.children)) {
if (sibling === branch || !(sibling instanceof HTMLElement)) continue;
isolated.push({
element: sibling,
inert: sibling.inert,
ariaHidden: sibling.getAttribute("aria-hidden"),
});
sibling.inert = true;
sibling.setAttribute("aria-hidden", "true");
}
if (parent === document.body) break;
branch = parent;
}
const focusableSelector = [
"a[href]",
"button:not([disabled])",
"input:not([disabled])",
"select:not([disabled])",
"textarea:not([disabled])",
"[tabindex]:not([tabindex='-1'])",
].join(",");
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === "Escape") {
event.preventDefault();
setExpanded(false);
return;
}
if (event.key !== "Tab") return;
const focusable = Array.from(
container.querySelectorAll<HTMLElement>(focusableSelector),
).filter((element) => !element.inert && element.offsetParent !== null);
const first = focusable[0];
const last = focusable.at(-1);
if (!first || !last) {
event.preventDefault();
container.focus();
} else if (event.shiftKey && document.activeElement === first) {
event.preventDefault();
last.focus();
} else if (!event.shiftKey && document.activeElement === last) {
event.preventDefault();
first.focus();
}
};
window.addEventListener("keydown", handleKeyDown);
requestAnimationFrame(() =>
toggleRef.current?.focus({ preventScroll: true }),
);
return () => {
document.body.style.overflow = previousOverflow;
window.removeEventListener("keydown", handleKeyDown);
for (const { element, inert, ariaHidden } of isolated) {
element.inert = inert;
if (ariaHidden === null) element.removeAttribute("aria-hidden");
else element.setAttribute("aria-hidden", ariaHidden);
}
requestAnimationFrame(() =>
toggleRef.current?.focus({ preventScroll: true }),
);
};
}, [expanded]);
const toggleExpanded = useCallback(() => {
setExpanded((current) => !current);
}, []);
return (
<div
ref={containerRef}
role="dialog"
aria-modal={expanded || undefined}
aria-label="Chat app preview"
tabIndex={expanded ? -1 : undefined}
className={cn(
"relative w-full bg-background px-0 py-2 sm:p-3",
expanded &&
"fixed inset-0 z-[100] h-dvh overscroll-contain p-3 sm:p-4",
)}
>
<button
ref={toggleRef}
type="button"
onClick={toggleExpanded}
aria-label={expanded ? "Exit expanded preview" : "Expand preview"}
title={expanded ? "Exit expanded preview" : "Expand preview"}
className="absolute top-5 right-24 z-50 grid size-10 place-items-center rounded-full border border-border/80 bg-background/90 text-muted-foreground backdrop-blur-sm transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
>
<ActionSwapIcon
value={expanded ? "minimize" : "maximize"}
animation="blur"
>
{expanded ? (
<Minimize2 className="size-4" />
) : (
<Maximize2 className="size-4" />
)}
</ActionSwapIcon>
</button>
<ChatAppExample className={expanded ? "h-full" : undefined} />
</div>
);
}
API Reference
ChatApp
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
sidebarWidth |
string |
17rem |
No | Docked sidebar width as a CSS length. Default 17rem. |
collapseSidebarBelow |
number |
600 |
No | Shell width in px under which the sidebar folds off-canvas. Ignored while open is controlled — the consumer owns the state then. |
open |
boolean |
— | No | — |
defaultOpen |
boolean |
— | No | — |
onOpenChange |
((open: boolean) => void) |
— | No | — |
openMobile |
boolean |
— | No | — |
defaultOpenMobile |
boolean |
— | No | — |
onOpenMobileChange |
((open: boolean) => void) |
— | No | — |
style |
SidebarProviderStyle |
— | No | — |
className |
string |
— | No | — |