Citation

Numbered source chips for AI answers. Hover one to see where a claim came from, or open the sources list to see them all.

Preview

Setup

Install with the shadcn CLI

$npx shadcn@latest add https://kinetikui.singhgourav.site/r/citation.json

One command adds every file, the npm packages and any Kinetik components it builds on. Needs a components.json; the CLI offers to create one if your project has none.

Or install manually

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge framer-motion lucide-react @radix-ui/react-slot class-variance-authority
  2. 2

    Copy lib/utils.ts from the Code tab. Skip if you already have cn().

  3. 3

    Copy styles/tokens.css from the Code tab and import it in your global CSS after Tailwind: @import "./styles/tokens.css";

  4. 4

    This component uses Button. Copy components/ui/button/ from the Code tab too, at the same path so the import resolves. Skip any you already have.

  5. 5

    Create a components/ui/citation/ folder and copy every file from the Code tab into it. Each file does one job, so you can read or change a piece without the rest.

  6. 6

    Import and render:

    Example
    import { Citation } from "@/components/ui/citation"
    
    <p>The sky is blue <Citation index={1} source={{ title: "Rayleigh scattering", url: "https://example.com" }} /></p>

Usage

Put a Citation right after the sentence it backs up. Pass the source directly:

Example
import { Citation } from "@/components/ui/citation"

<p>
  Water absorbs red light
  <Citation index={1} source={{ title: "Why the ocean is blue", url: "https://…", snippet: "…" }} />
</p>

When a reply has several sources, wrap it in CitationProvider once. Each chip then finds its own source by number, so index={2} shows sources[1]:

Example
import { Citation, CitationProvider, CitationSources } from "@/components/ui/citation"

<CitationProvider sources={sources}>
  <CitationSources sources={sources} />
  <p>
    Water absorbs red light <Citation index={1} />. Scattering adds to it <Citation index={2} />.
  </p>
</CitationProvider>

CitationSources is the “3 sources” pill with stacked site icons. Click it to see every source as a card.

Each site icon uses favicon when you pass it. Without one, it shows the first letter of the domain in a color picked from the domain name.

Props

Citation

PropTypeDefaultWhat it does
indexnumber—The number in the chip, starting at 1.
sourceCitationSourcefrom providerThe source to show. Optional inside CitationProvider.
flickerbooleantrueA flickering grid in the card's top-right corner.
flickerColorstringaccentColour of the flickering squares. Any CSS colour or var().

CitationSources

PropTypeDefaultWhat it does
sourcesCitationSource[]—Every source in the reply.
defaultOpenbooleanfalseStart with the cards showing.
maxnumber4How many icons to stack in the pill.

CitationSource

FieldTypeWhat it is
titlestringPage title.
urlstringLink to the page. The domain is read from it.
snippetstring?A short quote shown in the hover card.
faviconstring?Site icon URL.
siteNamestring?Shown instead of the domain.

Accessibility

  • Each chip is a link labelled “Source 1: title”, and it opens in a new tab
  • The card opens on keyboard focus as well as hover, and Escape closes it
  • The sources pill is a button that says whether the list is open (aria-expanded)