Citations
beui/citationsFreeComponent
Inline citation markers paired with a collapsible, progressively rendered reference collection for grounded agent responses.
Install it
npx shadcn@latest add https://beui.dev/r/citations.jsonSource
1"use client";2// beui.dev/components/agents/citations34import { BookOpenText, ChevronDown, ExternalLink, Globe2 } from "lucide-react";5import { AnimatePresence, motion, useReducedMotion } from "motion/react";6import {7 type ReactNode,8 useCallback,9 useId,10 useState,11} from "react";12import { AgentDisclosure } from "@/components/agents/agent-disclosure";13import { EASE_OUT, SPRING_LAYOUT, SPRING_SWAP } from "@/lib/ease";14import { getFaviconUrl } from "@/lib/favicon";15import { cn } from "@/lib/utils";1617export interface CitationItem {18 id: string;19 title: ReactNode;20 domain?: ReactNode;21 url?: string;22}2324export interface CitationsProps {25 citations: CitationItem[];26 title?: ReactNode;27 open?: boolean;28 defaultOpen?: boolean;29 onOpenChange?: (open: boolean) => void;30 idPrefix?: string;31 className?: string;32}3334export interface CitationProps {35 citationId: string;36 index: number;37 /** Must match the related Citations idPrefix. */38 idPrefix: string;39 className?: string;40}4142export interface CitationListProps {43 citations: CitationItem[];44 idPrefix?: string;45 className?: string;46}4748export interface CitationStackProps {49 citations: CitationItem[];50 limit?: number;51 className?: string;52}5354function citationTargetId(prefix: string, citationId: string) {55 return `${prefix}-${citationId.replace(/[^a-zA-Z0-9_-]/g, "-")}`;56}5758export function Citation({59 citationId,60 index,61 idPrefix,62 className,63}: CitationProps) {64 return (65 <a66 href={`#${citationTargetId(idPrefix, citationId)}`}67 aria-label={`View citation ${index}`}68 className={cn(69 "mx-0.5 inline-flex min-w-4 -translate-y-0.5 items-center justify-center rounded-md bg-muted/60 px-1 py-0.5 text-[10px] font-semibold leading-none text-muted-foreground no-underline outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring",70 className,71 )}72 >73 {index}74 </a>75 );76}7778export function CitationFavicon({79 url,80 className,81}: {82 url?: string;83 className?: string;84}) {85 const favicon = url ? getFaviconUrl(url) : null;86 const [failedUrl, setFailedUrl] = useState<string | null>(null);8788 return (89 <span90 aria-hidden="true"91 className={cn(92 "grid size-5 shrink-0 place-items-center text-muted-foreground",93 className,94 )}95 >96 {favicon && failedUrl !== favicon ? (97// … truncated
What it pulls in
npm packages
Files it writes
More from beui
All 104 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Action Swap Bluraction-swap-blur | beui | Components | Free | 3 deps · 4 files | |
| Action Swap Cascadeaction-swap-cascade | beui | Components | Free | 3 deps · 4 files | |
| Action Swap Rollaction-swap-roll | beui | Components | Free | 3 deps · 4 files | |
| Agent Activityagent-activity | beui | Components | Free | 4 deps · 9 files | |
| Agent Loading States Agent Progressagent-progress | beui | Components | Free | 3 deps · 3 files | |
| AI Sidebarai-sidebar | beui | Components | Free | 4 deps · 5 files | |
| Animated Badgeanimated-badge | beui | Components | Free | 4 deps · 3 files | |
| Number Animation Animated Numberanimated-number | beui | Components | Free | 3 deps · 3 files |
