Citation list
Numbered sources and inline citation marks for AI answers.
$
pnpm dlx shadcn@latest add https://lodeui.com/r/citation-list.jsoncomponents/examples/citation-list-demo.tsx
"use client";
import { CitationList, CitationMark } from "@/components/ui/citation-list";
export default function CitationListDemo() {
return (
<div className="w-full max-w-xl space-y-4 text-sm leading-relaxed">
<p>
Retries after a timeout must reuse the same idempotency key<CitationMark id={1} />, otherwise the gateway treats each attempt as a new charge<CitationMark id={2} />.
</p>
<CitationList
sources={[
{ id: 1, title: "Idempotent requests", url: "https://docs.example.com/api/idempotency", snippet: "Reuse the key for every retry of the same operation." },
{ id: 2, title: "Handling timeouts safely", url: "https://engineering.example.com/timeouts", snippet: "A timeout doesn't mean the charge failed." },
]}
/>
</div>
);
}When to use
- Sources for AI answers or research summaries.
When not to use
- General link lists.
Installation
$
pnpm dlx shadcn@latest add https://lodeui.com/r/citation-list.json1Install the dependencies
npm install lucide-react2Copy the source into your project
components/ui/citation-list.tsx"use client"; import * as React from "react"; import { ExternalLink } from "lucide-react"; import { cn } from "@/lib/utils"; export interface Citation { id: number; title: string; url: string; snippet?: string; } /** Numbered sources for an AI answer. Pair with <CitationMark id={n} /> inline. */ export function CitationList({ sources, className }: { sources: Citation[]; className?: string }) { return ( <ol className={cn("grid gap-2 sm:grid-cols-2", className)}> {sources.map((s) => { let host = s.url; try { host = new URL(s.url).hostname.replace(/^www\./, ""); } catch {} return ( <li key={s.id} id={`source-${s.id}`}> <a href={s.url} target="_blank" rel="noreferrer" className="group flex h-full gap-3 rounded-lg border border-border p-3 text-sm transition-colors hover:bg-muted/50"> <span className="grid size-5 shrink-0 place-items-center rounded bg-muted font-mono text-[10px]">{s.id}</span> <span className="min-w-0"> <span className="flex items-center gap-1 font-medium"> <span className="truncate">{s.title}</span> <ExternalLink className="size-3 shrink-0 opacity-0 transition-opacity group-hover:opacity-60" /> </span> <span className="block truncate text-xs text-muted-foreground">{host}</span> {s.snippet && <span className="mt-1 line-clamp-2 block text-xs text-muted-foreground">{s.snippet}</span>} </span> </a> </li> ); })} </ol> ); } /** Inline superscript marker that jumps to its source. */ export function CitationMark({ id }: { id: number }) { return ( <a href={`#source-${id}`} aria-label={`Source ${id}`} className="mx-0.5 inline-grid size-4 -translate-y-1 place-items-center rounded bg-muted align-baseline font-mono text-[9px] text-muted-foreground no-underline hover:bg-accent hover:text-foreground"> {id} </a> ); }
Usage
Import it from @/components/ui/citation-list after installing.
example.tsx
import { CitationList, CitationMark } from "@/components/ui/citation-list";
export function Answer() {
return (
<>
<p>Revenue grew 18%<CitationMark id={1} /></p>
<CitationList sources={[{ id: 1, title: "Q3 report", url: "https://example.com/q3" }]} />
</>
);
}API reference
CitationList
Numbered source cards showing each site's hostname.
| Prop | Type | Default | Description |
|---|---|---|---|
| sources | { id; title; url; snippet? }[] | – | Sources. |
CitationMark
An inline number linking to its source.
| Prop | Type | Default | Description |
|---|---|---|---|
| id | number | – | Source id. |
Keyboard interactions
| Keys | Action |
|---|---|
| Tab | Move between marks and sources |
Accessibility
- Marks are labelled "Source N"; external links say they open sources.
Responsive behavior
- Two columns from 640px.
Performance
- Static.
Notes for AI
- Ids must match between marks and sources.
This page as Markdown, for assistants and coding agents:
/components/citation-list/markdownThe full library index for assistants is at /llms.txt.
Lode222 doc pagesllms.txt