aiellie

Search

Find a component, template or page

GitHub
Components

Inline Citation

A numbered mark in a reply's prose that names the page it cites on hover and opens it on a click.

Container queries style an element by its parent's size rather than the viewport's1, and every major browser has shipped them since 20232.

Open full screen
fig. 01 · open it full screen from the corner

Installation

npx shadcn@latest add "@aiellie/inline-citation"

shadcn needs the @aiellie registry in components.json first. npx aiellie add inline-citation adds it on its first run, then installs the same way.

Inline Citation is a small numbered mark in a reply's prose. Hovering or focusing it opens a card naming the page it cites, with the site's icon, its host and the title; clicking it opens the page. Its numbers count in the order the reply's Sources list them, so the mark and the chip point at the same page.

Getting started

  1. Mark a claim

    components/claim.tsx
    import { InlineCitation } from "@/components/aiellie/inline-citation"
    
    <p>
      Every major browser has shipped container queries since 2023
      <InlineCitation
        index={1}
        href="https://web.dev/blog/cq-stable"
        title="Container queries land in stable browsers"
      />
      .
    </p>
  2. Turn a reply's links into citations

    Models with web search often link the page a sentence came from. Give Response an a renderer that swaps a link to a listed source for its citation.

    <Response
      components={{
        a({ href, children }) {
          const index = sources.findIndex((source) => source.url === href)
          return index === -1 ? (
            <a href={href}>{children}</a>
          ) : (
            <InlineCitation index={index + 1} href={href} title={sources[index].title} />
          )
        },
      }}
    >
      {text}
    </Response>

Anatomy

<a data-slot="inline-citation" target="_blank">1</a> {/* HoverCard trigger */}
<div data-slot="inline-citation-preview" /> {/* HoverCard content, in a portal */}

The mark is set in the sans at 11px on muted, raised a little off the baseline rather than set as a superscript, so it doesn't open up the line's leading. It's named "Source 1: title" for a screen reader.

The card is the aiellie HoverCard, glass with a shadow, opening above. A site without a favicon shows a link glyph.

Examples

Not a web page

Only http and https addresses lead anywhere. Anything else keeps its number as plain text.

A citation whose address isn't a web page keeps its number but leads nowhere3.

API reference

InlineCitation

PropTypeDefaultDescription
hrefstringrequiredThe page cited.
indexnumberrequiredThe number it shows, counting from 1 in the order the sources are listed.
titlestringThe page's title, shown on its card.
descriptionstringA line or two under the title.

All other a props but children are forwarded.