Skip to content

    Citation

    Inline source reference pill for RAG and AI answers that opens a keyboard- and touch-accessible preview popover with the source domain, external title link and optional excerpt.

    Preview

    Every public role token points to a derived value.

    Props

    • index
    • title
    • href
    • domain
    • showDomain
    • snippet
    import { Citation } from "@/components/ui/citation"
    
    <p className="text-sm text-text-primary">
      Every public role token points to a derived value
      <Citation index="1" title="Design tokens reference" href="https://www.werewolf-ui.dev/docs/tokens" snippet="Two DTCG layers hold user choices and public role tokens." />
      .
    </p>

    Usage

    When to use

    • Attach inline numbered source references to RAG or AI answers with a keyboard- and touch-accessible preview.
    • Let readers verify the source domain, title and excerpt before opening an external link.

    When not to use

    • Standard navigation links in prose. Use Link.
    • Design token names or short machine values. Use Token.
    • Hover-only previews that do not need touch activation. Use HoverCard.

    Examples

    Inline citations

    Compact numbered pills inside an assistant answer that open a source preview popover on press.

    Every public role token points to a derived value.

    Compact controls extend their hit area on touch.

    import { Citation } from "@/components/ui/citation"
    
    <div className="flex max-w-md flex-col gap-xs text-sm text-text-primary">
      <p>
        Every public role token points to a derived value.
        <Citation index={1} title="Design tokens reference" href="https://www.werewolf-ui.dev/docs/tokens" snippet="Two DTCG layers hold user choices and public role tokens." />
      </p>
      <p>
        Compact controls extend their hit area on touch.
        <Citation index={2} title="Accessibility guide" href="https://www.werewolf-ui.dev/docs/accessibility" snippet="Compact controls extend their hit area to 44px on touch." />
      </p>
    </div>

    With domain in the pill

    showDomain displays the host beside the reference index inside the inline pill.

    import { Citation } from "@/components/ui/citation"
    
    <Citation index={1} showDomain title="Color system" href="https://www.werewolf-ui.dev/docs/foundations/colors" snippet="Neutral and accent pairs are checked for WCAG and APCA contrast." />

    Without an index

    When index is omitted, the pill falls back to displaying the source domain.

    import { Citation } from "@/components/ui/citation"
    
    <Citation title="CLI reference" href="https://www.werewolf-ui.dev/docs/cli" />

    Do and don't

    Do

    • Place compact `[1]` citations inline at the end of the claim they support.
    • Include a short `snippet` so readers can verify the source before leaving the page.
    • Always pass a descriptive `title` so screen readers and preview cards name the source clearly.

    Don't

    • Do not pack long paragraphs into `snippet`; keep excerpts to one or two sentences.
    • Do not use `Citation` for general navigation links; use Link.

    Props

    NameTypeValuesDefaultDescription
    indexnumber | string--Optional reference number or marker shown inside the inline pill, such as `1`.
    title requiredstring--Required source title shown as the external link in the preview popover and used in the trigger `aria-label`.
    href requiredstring--Required source URL opened by the external link and used to derive `domain` when omitted.
    domainstring--Optional short host label. Derived safely from `href` when omitted.
    snippetnode--Optional quoted excerpt shown inside the preview popover.
    showDomainboolean-falseShows the domain text beside the index inside the inline pill. When `false`, the pill shows `index`, or `domain` if `index` is omitted.
    openboolean--Controlled open state of the preview popover. Pair with `onOpenChange`.
    defaultOpenboolean-falseInitial open state when uncontrolled.
    onOpenChange(open: boolean) => void--Called with `true` or `false` when the preview popover opens or closes.

    Anatomy

    PartDescription
    rootThe inline pill button: `size-inline-sm` (20px) tall, `radius-full`, gray fill and monospace secondary text.
    hitAreaTransparent `::before` centered on the pill, never smaller than `size-target-min` (24px on mouse, 44px on touch).
    contentThe Popover panel holding the source domain, external title link and optional excerpt.
    domainHost label and external-link icon at the top of the preview card in tertiary text.
    linkUnderlined external link for the source title inside the preview card (`target="_blank"` and `rel="noopener noreferrer"`).
    snippetOptional quoted excerpt in small secondary text inside the preview card.

    Accessibility

    Role: button

    KeysAction
    Enter, SpaceOpens or closes the source preview popover.
    TabMoves focus to the external link inside the open popover.
    EscapeCloses the popover and returns focus to the citation pill.
    • The trigger defaults its `aria-label` to `${title} (${domain})` so compact `[1]` pills remain meaningful to screen readers.
    • The 20px pill extends its touch target to `size-target-min` (44px on touch) via a centered transparent `::before` pseudo-element.

    Install

    npx werewolf-ui add https://www.werewolf-ui.dev/r/citation.json

    Run npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.