Mehi

Source Citation Rail

AI chats 7

About

A citation panel that keeps inline [n] reference markers in an AI answer synced with a side list of sources, with active highlighting, expandable excerpts, copy-link, and keyboard navigation.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Source Citation Rail to your project and fits it to your theme.

Code

How Source Citation Rail is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import * as React from "react";
import {
  SourceCitationRail,
  CitationMarker,
  type CitationSource,
} from "@/components/ui/source-citation-rail";

const sources: CitationSource[] = [
  {
    id: "s1",
    index: 1,
    title: "Streaming responses guide",
    domain: "docs.example.dev",
    url: "https://example.dev/streaming",
    type: "docs",
    excerpt:
      "Flush tokens to the client as soon as they are produced instead of buffering the whole response, and apply backpressure when the read buffer fills.",
    verified: true,
  },
  {
    id: "s2",
    index: 2,
    title: "Trust in cited AI answers",
    domain: "research.example.org",
    url: "https://example.org/citations-study",
    type: "paper",
    excerpt:
      "In a field study, readers trusted answers more when inline markers were clearly tied to a source list they could open and inspect.",
    author: "J. Alvarez",
    publishedAt: "2024-03-12",
  },
];

export default function SourceCitationRailDemo() {
  const [activeId, setActiveId] = React.useState<string | null>(null);

  return (
    <div className="w-full max-w-3xl">
      <SourceCitationRail
        sources={sources}
        activeSourceId={activeId}
        onActiveSourceChange={setActiveId}
        layout="rail"
      >
        <article className="text-sm leading-relaxed">
          <h2 className="mb-2 text-base font-semibold">
            How should a product stream AI answers with low latency?
          </h2>
          <p>
            Flush tokens to the client as soon as they are produced instead of
            buffering the whole response
            <CitationMarker source="s1" />. Readers trusted answers more when
            inline markers were clearly tied to a source list they could open
            and inspect <CitationMarker source="s2" />.
          </p>
        </article>
      </SourceCitationRail>
    </div>
  );
}

Dependencies

More by Mehi

View all
  • Border Beam Panel

    Border Beam Panel

    926
  • Compare Reveal

    Compare Reveal

    302
  • Decrypt Text

    Decrypt Text

    237
  • Holo Card

    Holo Card

    216
  • Magnetic Dock

    Magnetic Dock

    156
  • Luminous Topography

    Luminous Topography

    105
  • Lens Card

    Lens Card

    83
  • Copperplate Hatch

    Copperplate Hatch

    59

More in AI chats

View all
  • AI Actions

    AI Actions

    318
  • Color Picker

    Color Picker

    77
  • Agent Chat

    Agent Chat

    17
  • Approval Card

    Approval Card

    13
  • System Message

    System Message

    53
  • Prompt with Model Picker

    Prompt with Model Picker

    2
  • Message

    Message

    48
  • AI Task List

    AI Task List

    159

Explore more

Part of Motiq — browse the full library on 21st.dev.