InlineCitation
neon-ui/inline-citationFreeComponent
Inline source pill that previews stacked citations on hover and links to the source on click.
Install it
npx shadcn@latest add https://ui.neon.com/r/inline-citation.jsonSource
1"use client";23import { PreviewCard } from "@base-ui/react/preview-card";4import type { ComponentProps } from "react";5import { useState } from "react";67import { cn } from "@/lib/utils";89/** Strip a URL down to its readable hostname. */10const hostnameOf = (url: string): string => {11 try {12 return new URL(url).hostname.replace(/^www\./u, "");13 } catch {14 return url;15 }16};1718const faviconOf = (url: string): string | null => {19 try {20 const host = new URL(url).hostname;21 return `https://www.google.com/s2/favicons?domain=${host}&sz=64`;22 } catch {23 return null;24 }25};2627/**28 * The source site's favicon, resolved through Google's favicon29 * service. Decorative — vanishes silently if it fails to load, so30 * the pill never shows a broken-image glyph.31 */32const SourceFavicon = ({33 className,34 url,35}: {36 url: string;37 className?: string;38}) => {39 const [failed, setFailed] = useState(false);40 const src = faviconOf(url);4142 if (!src || failed) {43 return null;44 }4546 return (47 // oxlint-disable-next-line react/no-unknown-property -- plain img: registry components stay framework-agnostic48 <img49 alt=""50 aria-hidden="true"51 className={cn("size-3 shrink-0 select-none rounded-[2px]", className)}52 data-slot="inline-citation-favicon"53 loading="lazy"54 onError={() => setFailed(true)}55 src={src}56 />57 );58};5960export type InlineCitationProps = ComponentProps<"span">;6162/* ─────────────────────────────────────────────────────63 * A sourced claim inline with prose: the text reads64 * normally, a small mono pill names where it came from,65 * and hovering (or focusing) the pill previews the66 * source without leaving the paragraph. Sources stack67 * in one readable list — no carousel to page through.68 * Inspired by Inline Citation from Vercel's AI SDK69 * Elements (elements.ai-sdk.dev), rebuilt on Base UI.70 * ─────────────────────────────────────────────────── */71export const InlineCitation = ({72 className,73 ...props74}: InlineCitationProps) => (75 <span76 className={cn("group/citation inline items-baseline", className)}77 data-slot="inline-citation"78 {...props}79 />80);8182export type InlineCitationTextProps = ComponentProps<"span">;8384/** The cited span itself; tints gently while its pill is hovered. */85// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from neon-ui
All 77 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ActivityFeedactivity-feed | neon-ui | Components | Free | 2 deps | |
| AgentChatagent-chat | neon-ui | Components | Free | 6 deps | |
| AnimatedWashanimated-wash | neon-ui | Components | Free | no deps · 2 files | |
| ApiKeyListapi-key-list | neon-ui | Components | Free | 2 deps | |
| AppCardapp-card | neon-ui | Components | Free | 2 deps | |
| AppCreatorapp-creator | neon-ui | Components | Free | 2 deps | |
| AuthFormauth-form | neon-ui | Components | Free | no deps | |
| AutoscaleChartautoscale-chart | neon-ui | Components | Free | 1 dep |
