ai citations.md

AI Inline Citations

An answer with source chips beside each claim. One preview glides between chips and lights up the sentence it backs.

Source: https://kokonutui.com/docs/ai/ai-citations

Installation

npx shadcn@latest add @kokonutui/ai-citations

Props

Prop Type Default Description
parts? AnswerPart[] demo The answer, split where citations go. Demo content when omitted.
sources? CitationSource[] demo
className? string Extra classes for the root element.

AnswerPart

Field Type Description
text string
cite? string[] Ids of the sources that back this text. A chip follows it.

CitationSource

Field Type Description
id string
title string
url string
site? string Short site name for the chip, such as MDN. Defaults to the host.
snippet? string The passage that backs the claim, shown in the preview.

Source

"use client";

/**
 * @author: @kokonutui
 * @description: AI Inline Citations
 * @version: 1.0.0
 * @date: 2026-10-15
 * @license: MIT
 * @website: https://kokonutui.com
 * @github: https://github.com/kokonut-labs/kokonutui
 */

import { ArrowUpRight, ChevronDown } from "lucide-react";
import { AnimatePresence, MotionConfig, motion } from "motion/react";
import {
  useCallback,
  useEffect,
  useId,
  useLayoutEffect,
  useRef,
  useState,
} from "react";
import { cn } from "@/lib/utils";

export interface CitationSource {
  id: string;
  title: string;
  url: string;
  /** Short site name for the chip, such as `MDN`. Defaults to the host. */
  site?: string;
  /** The passage that backs the claim, shown in the preview. */
  snippet?: string;
}

export interface AnswerPart {
  text: string;
  /** Ids of the sources that back this text. A chip follows it. */
  cite?: string[];
}

interface AICitationsProps {
  /** The answer, split where citations go. Demo content when omitted. */
  parts?: AnswerPart[];
  sources?: CitationSource[];
  className?: string;
}

const DEMO_SOURCES: CitationSource[] = [
  {
    id: "emil",
    title: "Great animations",
    url: "https://emilkowal.ski/ui/great-animations",
    site: "emilkowal.ski",
    snippet:
      "UI motion should be fast, mostly under 300ms, with an ease-out curve so movement starts right away. Popovers scale from their trigger.",
  },
  {
    id: "webdev",
    title: "Animations and performance",
    url: "https://web.dev/articles/animations-and-performance",
    site: "web.dev",
    snippet:
      "Stick to transform and opacity where you can. Changing them skips layout and paint, so the compositor can run the animation.",
  },
  {
    id: "mdn-perf",
    title: "CSS and JavaScript animation performance",
    url: "https://developer.mozilla.org/en-US/docs/Web/Performance/Guides/CSS_JavaScript_animation_performance",
    site: "MDN",
    snippet:
      "Properties that trigger layout are expensive to animate. Transforms and opacity can be handed to the GPU.",
  },
  {
    id: "mdn-reduce",
    title: "prefers-reduced-motion",
    url: "https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion",
    site: "MDN",
    snippet:
      "Detects whether the user asked the system to minimize non-essential motion.",
  },
];

const DEMO_PARTS: AnswerPart[] = [
  { text: "Keep the dropdown quick. " },
  {
    text: "Most UI motion should finish in under 300ms, and an ease-out curve feels faster than ease-in at the same duration.",
    cite: ["emil"],
  },
  { text: " " },
  {
    text: "Animate only transform and opacity, which the browser can run without layout or paint.",
    cite: ["webdev", "mdn-perf"],
  },
  { text: " " },
  {
    text: "When someone asks for reduced motion, swap the movement for a plain fade.",
    cite: ["mdn-reduce"],
  },
  { text: " Finally, " },
  {
    text: "scale the menu from its trigger rather than its center",
    cite: ["emil"],
  },
  { text: ", so it feels attached to the button that opened it." },
];

export default function AICitations({
  parts = DEMO_PARTS,
  sources = DEMO_SOURCES,
  className,
}: AICitationsProps) {
  // Function body omitted for brevity...
}