Loading component…
Loading component…
An AI answer wired to its sources – point at a citation to light up its sentence and source, click to unfold the quoted passage with the matching words marked
To reuse this local React demo, copy all files from the Code tab into the same folder, then import CitedAnswer from ./cited-answer.
import { CitedAnswer, type CitedSegment, type CitedSource } from "@/components/ui/cited-answer";
const sources: CitedSource[] = [
{
id: "caching",
site: "Tokenwise",
title: "Prompt caching, explained",
url: "https://tokenwise.dev/blog/prompt-caching",
date: "Sep 18, 2026",
quote: "A cached prefix is read instead of recomputed …",
highlight: ["read instead of recomputed"],
},
];
const segments: CitedSegment[] = [
{ text: "Prompt caching reuses the processed start of your prompt.", cite: ["caching"] },
{ text: " Streaming makes the rest feel faster." },
];
export function Answer() {
return <CitedAnswer segments={segments} sources={sources} pagesRead={12} />;
}| Name | Type | Default | Description |
|---|---|---|---|
| segments | CitedSegment[] | { text, cite?, paragraph? } – the answer in order. cite lists source ids (one marker each); paragraph starts a new paragraph. Spaces at the edges of text stay outside the highlight | |
| sources | CitedSource[] | { id, title, site, url?, date?, quote?, highlight?, icon? } – numbered in this order, one chip each | |
| pagesRead | number | Pages read while searching – shown in the head as "3 sources · 12 pages read" | |
| defaultOpen | string | Id of the source whose preview is open at first | |
| onOpenSource | (source: CitedSource) => void | Called by Open source. With it the link doesn't navigate on its own; without it the url opens in a new tab | |
| onPreviewChange | (id: string \| null) => void | Called when a preview opens, switches or closes | |
| action | { label: string; onClick: () => void } | A button on the tray, e.g. Follow up | |
| className | string | Extra class on the root |
Fills its container up to 460px and works from 300px. Chips wrap onto a second row and long names shorten; below 360px the card gets tighter and the preview drops its number tag, below 280px Copy quote keeps only its icon
Touch screens: larger hit areas around the markers and taller chips and buttons
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"