Vilqor

AI Answer with Citations

AI chats

About

An answer where every claim carries a numbered source. Hover, focus or tap a number to see where the line came from; the sources are listed underneath. Built on Radix Tooltip. Part of Midnight, the full template on 21st; also in the free Midnight Lite (MIT).

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

Code

How AI Answer with Citations is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

import { useSyncExternalStore, type CSSProperties } from "react"

import { CitedAnswer } from "@/components/ui/cited-answer"

const geist = "@import url('https://fonts.googleapis.com/css2?family=Geist:wght@400..600&family=Geist+Mono:wght@400..500&display=swap');"

// Midnight by day: warm paper, a white card, night-blue ink, deep gold for the label and the open citation
const settings = {
  background: "#f7f5f0",
  card: "#ffffff",
  text: "#141a2e",
  muted: "#4a5166",
  accent: "#a8803a",
  accentText: "#ffffff",
  label: "#8a6a2e",
}

// Midnight by night, the template's own palette
const night: Partial<typeof settings> = {
  background: "#0b1020",
  card: "#111731",
  text: "#ece9e1",
  muted: "#a9afc4",
  accent: "#d9b77e",
  accentText: "#0b1020",
  label: "#e3c592",
}

// 21st marks its dark theme with .dark on <html>; the demo answers with Midnight by night
function useDark() {
  return useSyncExternalStore(
    (on) => {
      const watch = new MutationObserver(on)
      watch.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] })
      return () => watch.disconnect()
    },
    () => document.documentElement.classList.contains("dark"),
    () => false,
  )
}

// the palette as theme tokens; the component itself only reads the tokens
function tokens(s: typeof settings) {
  const t: Record<string, string> = {
    background: s.background,
    foreground: s.text,
    card: s.card,
    primary: s.accent,
    "primary-foreground": s.accentText,
    "muted-foreground": s.muted,
    ring: s.accent,
  }
  return Object.fromEntries(Object.entries(t).flatMap(([k, v]) => [[`--${k}`, v], [`--color-${k}`, v]])) as CSSProperties
}

// the template's card: white and lifted by day, a deep tile with a lit top edge by night
function card(s: typeof settings, dark: boolean): CSSProperties {
  return dark
    ? {
        background: `linear-gradient(180deg, color-mix(in oklab, ${s.card} 80%, ${s.background}), color-mix(in oklab, ${s.card} 62%, ${s.background}))`,
        boxShadow: "inset 0 1px 0 0 rgb(255 255 255 / 0.09), inset 0 0 0 1px rgb(255 255 255 / 0.045), 0 14px 28px -18px rgb(0 0 0 / 0.55)",
      }
    : { background: s.card, boxShadow: "inset 0 0 0 1px rgb(20 26 46 / 0.07), 0 1px 2px rgb(20 26 46 / 0.05), 0 16px 32px -20px rgb(20 26 46 / 0.22)" }
}

export default function Demo(props: Partial<typeof settings>) {
  const dark = useDark()
  const s = { ...settings, ...props, ...(dark ? night : {}) }
  return (
    <div
      className="flex min-h-svh w-full items-center justify-center px-5 py-12"
      style={{ ...tokens(s), fontFamily: "Geist, ui-sans-serif, system-ui, sans-serif", background: s.background, color: s.text } as CSSProperties}
    >
      <style>{geist}</style>
      <div className="w-full max-w-[520px] rounded-[28px] p-8 md:p-10" style={card(s, dark)}>
        <p className="text-[14px] font-medium" style={{ color: s.label }}>
          Sources
        </p>
        <h3 className="mt-3 text-[26px] leading-[32px] font-semibold tracking-[-0.025em] text-balance">
          <span>Every line has a source.</span> <span style={{ color: s.muted }}>Click a number to see where it came from.</span>
        </h3>
        <CitedAnswer
          className="mt-10"
          parts={[
            { text: "Billing errors are up 3× since Tuesday", cite: 1 },
            { text: ", all from the v3 invoice template", cite: 2 },
            { text: ". Refunds now take two days longer", cite: 3 },
            { text: "." },
          ]}
          sources={[
            { n: 1, title: "38 tickets tagged billing, Tue to Thu", where: "Support inbox" },
            { n: 2, title: "Invoice template v3 · release notes", where: "Help center" },
            { n: 3, title: "Refund queue · median 4.1 days", where: "Finance sheet" },
          ]}
        />
      </div>
    </div>
  )
}

Dependencies

More by Vilqor

View all
  • 3D Glass Cube Hero

    3D Glass Cube Hero

    213
  • Footer with Big Wordmark

    Footer with Big Wordmark

    169
  • Guilloche Background Pattern

    Guilloche Background Pattern

    8
  • Card Carousel to Grid

    Card Carousel to Grid

  • AI Email Reply with Tones

    AI Email Reply with Tones

  • AI Memory Timeline

    AI Memory Timeline

  • Use Cases Tabs Section

    Use Cases Tabs Section

  • Pricing Section with Toggle

    Pricing Section with Toggle

More in AI chats

View all
  • Agent Chat

    Agent Chat

    21
  • AI Actions

    AI Actions

    372
  • AI Suggestions

    AI Suggestions

    27
  • Interactive LLM Token & Context Window Visualizer

    Interactive LLM Token & Context Window Visualizer

    30
  • AI SaaS Workflow Hero

    AI SaaS Workflow Hero

    36
  • Aquarium Prompt

    Aquarium Prompt

    219
  • Message Parts

    Message Parts

    10
  • AI Chat Composer

    AI Chat Composer

    21