Source
prompt-kit/sourceFreeComponent
Displays website sources used by AI-generated content, showing URL details, titles, and descriptions on hover.
Live preview
live · rendered by the registry
Rendered by prompt-kit on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://raw.githubusercontent.com/ibelick/prompt-kit/HEAD/public/c/source.jsonSource
1"use client"23import {4 HoverCard,5 HoverCardContent,6 HoverCardTrigger,7} from "@/components/ui/hover-card"8import { cn } from "@/lib/utils"9import { createContext, useContext } from "react"1011const SourceContext = createContext<{12 href: string13 domain: string14} | null>(null)1516function useSourceContext() {17 const ctx = useContext(SourceContext)18 if (!ctx) throw new Error("Source.* must be used inside <Source>")19 return ctx20}2122export type SourceProps = {23 href: string24 children: React.ReactNode25}2627export function Source({ href, children }: SourceProps) {28 let domain = ""29 try {30 domain = new URL(href).hostname31 } catch {32 domain = href.split("/").pop() || href33 }3435 return (36 <SourceContext.Provider value={{ href, domain }}>37 <HoverCard openDelay={150} closeDelay={0}>38 {children}39 </HoverCard>40 </SourceContext.Provider>41 )42}4344export type SourceTriggerProps = {45 label?: string | number46 showFavicon?: boolean47 className?: string48}4950export function SourceTrigger({51 label,52 showFavicon = false,53 className,54}: SourceTriggerProps) {55 const { href, domain } = useSourceContext()56 const labelToShow = label ?? domain.replace("www.", "")5758 return (59 <HoverCardTrigger asChild>60 <a61 href={href}62 target="_blank"63 rel="noopener noreferrer"64 className={cn(65 "bg-muted text-muted-foreground hover:bg-muted-foreground/30 hover:text-primary inline-flex h-5 max-w-32 items-center gap-1 overflow-hidden rounded-full py-0 text-xs no-underline transition-colors duration-150",66 showFavicon ? "pr-2 pl-1" : "px-1",67 className68 )}69 >70 {showFavicon && (71 <img72 src={`https://www.google.com/s2/favicons?sz=64&domain_url=${encodeURIComponent(73 href74 )}`}75 alt="favicon"76 width={14}77 height={14}78 className="size-3.5 rounded-full"79 />80 )}81 <span className="truncate tabular-nums text-center font-normal">{labelToShow}</span>82 </a>83 </HoverCardTrigger>84 )85}8687export type SourceContentProps = {88 title: string89 description: string90 className?: string91}9293export function SourceContent({94 title,95 description,96 className,97}: SourceContentProps) {98 const { href, domain } = useSourceContext()99100 return (101 <HoverCardContent className={cn("w-80 p-0 shadow-xs", className)}>102 <a103 href={href}104 target="_blank"105// … truncated
What it pulls in
Other registry items
Files it writes
More from prompt-kit
All 23 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Chain Of Thoughtchain-of-thought | prompt-kit | Components | Free | 1 dep | |
| Chat Containerchat-container | prompt-kit | Components | Free | 1 dep | |
| Code Blockcode-block | prompt-kit | Components | Free | 1 dep | |
| Feedback Barfeedback-bar | prompt-kit | Components | Free | 1 dep | |
| File Uploadfile-upload | prompt-kit | Components | Free | no deps | |
| Imageimage | prompt-kit | Components | Free | no deps | |
| Jsx Previewjsx-preview | prompt-kit | Components | Free | 1 dep | |
| Loaderloader | prompt-kit | Components | Free | no deps |
