Site widget
A website with a support assistant in the corner: launcher, nudge, a panel that grows out of the launcher into a chat with sources, and a handoff to a person. A full screen sheet on phone viewports.
On this page
Installation
Usage
import {
SiteWidgetFrame,
WidgetMessage,
WidgetSources,
} from "@/components/ui/chatcn/site-widget"
<SiteWidgetFrame
assistant={{ name: "Wren", initials: "W" }}
nudge="Questions about plans? Ask me."
chips={["Change plan", "Talk to a person"]}
composer="live"
onSend={(text) => chat.send(text)}
>
<WidgetMessage from="user">Can I change plans mid month?</WidgetMessage>
<WidgetMessage from="assistant" pending={chat.status === "submitted"}>
{answer}
<WidgetSources sources={[{ title: "Billing FAQ", href: "/help/billing" }]} />
</WidgetMessage>
</SiteWidgetFrame>The site lays out at a true 1280 by 800 viewport and scales to fit. Pass your own page as site; the default is a quiet drawn page so the widget stays the subject. Under a 640 px viewport (not page) width the panel becomes a full screen sheet with a top bar, as it would on a phone.
The panel is a dialog named by the assistant. Opening it from the launcher or the nudge moves focus in; Escape or the close button closes it and gives focus back to the launcher. A scripted open never takes focus from the page. On the sheet, Tab stays inside.
A pending reply shows nothing for 300 ms, then Thinking, held at least 400 ms, in the place the answer lands. composer is static by default (drawn, not focusable), live to send with Enter (never during IME composition), or none.
Examples
States
Closed, the nudge, open with sources and chips, a handoff to a person, the phone sheet inside PlainScreen, and a dark site on a light page.
Props
| Prop | Type | Notes |
|---|---|---|
assistant | { name, initials } | Names the panel and its avatar |
site | ReactNode | The host page. Default SitePlaceholder |
chrome, address | browser | none, string | The browser bar and its address |
open, defaultOpen, onOpenChange | boolean | Controlled or not |
nudge, nudgeAfter | string, number | Shown after 800 ms, gone once opened or dismissed |
chips, onChip | string[] | One row that scrolls sideways |
composer, onSend | static | live | none | Default static |
placeholder | string | Default “Ask a question…” |
welcome, intro, stamp | boolean, string, string | false | The greeting, one line under it, and the Today stamp |
viewport, width, bezel, radius | Frame props | Default 1280 by 800, hairline, 12 |
Parts: WidgetMessage (from is user, assistant or person, with author and pending), WidgetSources, WidgetChips and WidgetHandoff (a centred rule with the teammate's initials).