Skip to content
ResearchSource documentMenu

Source document

A document source with its cited page. Opens the document with the passage highlighted and scrolled into view.

Chips with the cited page open the document with the passage highlighted.

Installation

$ pnpm dlx shadcn@latest add https://chatcn.dev/r/source-document.json

Usage

tsx
import { SourceDocument } from "@/components/ui/chatcn/source-document"

<SourceDocument
  document={{ title: "Help center readability study", filename, pages }}
  page={4}
  quote="9 percent more often than readers in layout A"
/>

documentFromPart(part) maps an AI SDK source-document part to the document prop. Add pages with the extracted text when you have it, or pass viewerLoading while you fetch it.

Examples

In a side panel

With viewer="none" the chip only calls onOpen, so a DocumentViewer elsewhere can follow the citation. hideTitle keeps the chips short and active marks the one in view.

Citations in an answer drive a document panel: page, highlight and scroll follow the click.

Props

PropTypeNotes
documentDocumentSourcetitle, filename?, pageCount?, pages?, url?
pagenumberCited page, shown as p. 4
quotestringHighlighted in the viewer, quoted on the card
indexnumberCitation number instead of the file icon
variant"chip" | "card"Inline in prose, or a row for source lists
viewer"dialog" | "none"Built-in dialog or your own panel
onOpen() => voidCalled on every open
hideTitle, activebooleanCompact chip and the selected state for panels
viewerLoading, viewerError, onViewerRetryPassed to the viewer
open, defaultOpen, onOpenChangeDialog state, controlled or not

Keyboard

KeyAction
Enter, SpaceOpen the document
EscClose the dialog and return focus to the chip

Accessibility

  • The chip is a button named Open, the title and the page, with aria-haspopup="dialog". In panel mode it is a toggle with aria-pressed.
  • The dialog is labelled by the document title and traps focus while open.

Motion

  • Press feedback scales the chip to 0.97 over 100 ms.
  • The dialog grows from 0.96 over 220 ms with the scrim, and opens instantly from the keyboard. The highlight is already centered when it appears.