mirror of
https://github.com/vercel/chat.git
synced 2026-09-14 18:32:29 +08:00
46fc5bbe9d
* docs: sync geistdocs template 1.2.0–1.2.3 + polish
- Ran @vercel/geistdocs@1.2.2 update --sync against origin/main
(already contains merged 1.2.3) for:
- components/geistdocs/*
- components/geistcn-fallbacks/**/* (new)
- components/ui/command-prompt.tsx, navigation-menu.tsx
- app/styles/geistdocs.css
- Manual overlays (paths skipped by sync due to chat customizations):
- app/[lang]/layout.tsx: drop scroll-smooth (1.2.2)
- app/[lang]/docs/[[...slug]]/page.tsx: MobileDocsBar + disable
default TOC popover (1.2.0)
- app/[lang]/docs/layout.tsx: wrap in bg-background-200 (1.2.3)
- components/ui/badge.tsx: secondary variant → bg-gray-300/text-gray-1000 (1.2.3)
- Home hero: replace Get Started + Installer with CommandPrompt
humans/agents switcher ("npm install chat" / "npx skills add vercel/chat")
- (home) layout: swap bg-sidebar dark:bg-background for bg-background-200
so /, /adapters, /resources share the navbar surface
- DesktopMenu: active-state detection with longest-prefix match
(so /docs/api highlights "API", not also "Docs")
- navbar-logo dropdown: drop Chat SDK self-entry
- New geist-fill icons (check-circle-fill, cross-circle-fill,
warning-fill) ported from @vercel/geistcn-assets; new
components/custom/status-icons.tsx registers Check/Cross/Warn MDX
components
- content/docs/adapters.mdx: replace ✅/❌/⚠️ emojis with the new
icons (emoji.mdx intentionally left alone)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs: use LogoChatSdk from geistcn-fallbacks as the app Logo
Replace the inline Chat SDK wordmark SVG in geistdocs.tsx with
<LogoChatSdk /> so the navbar and other Logo consumers share the
same source of truth.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs: default hero CommandPrompt to humans tab
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
135 lines
3.4 KiB
TypeScript
135 lines
3.4 KiB
TypeScript
"use client";
|
|
|
|
import { CheckIcon, CopyIcon } from "lucide-react";
|
|
import {
|
|
type CSSProperties,
|
|
type ReactNode,
|
|
useCallback,
|
|
useRef,
|
|
useState,
|
|
} from "react";
|
|
import { toast } from "sonner";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
interface CodeBlockProps {
|
|
children: ReactNode;
|
|
className?: string;
|
|
"data-line-highlighting"?: string;
|
|
"data-line-numbers"?: string;
|
|
icon?: ReactNode;
|
|
style?: CSSProperties;
|
|
tabIndex?: number;
|
|
title?: string;
|
|
}
|
|
|
|
export const CodeBlock = ({
|
|
children,
|
|
className,
|
|
icon,
|
|
style,
|
|
tabIndex,
|
|
title,
|
|
...rest
|
|
}: CodeBlockProps) => {
|
|
const ref = useRef<HTMLPreElement>(null);
|
|
const [isCopied, setIsCopied] = useState(false);
|
|
const { "data-line-numbers": lineNumbers } = rest;
|
|
|
|
const copyToClipboard = useCallback(async () => {
|
|
if (typeof window === "undefined" || !navigator?.clipboard?.writeText) {
|
|
toast.error("Clipboard API not available");
|
|
return;
|
|
}
|
|
|
|
const code = ref.current?.innerText;
|
|
|
|
if (!code) {
|
|
toast.error("No code to copy");
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await navigator.clipboard.writeText(code);
|
|
setIsCopied(true);
|
|
setTimeout(() => setIsCopied(false), 2000);
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
|
|
toast.error(message);
|
|
}
|
|
}, []);
|
|
|
|
const Icon = isCopied ? CheckIcon : CopyIcon;
|
|
|
|
const CodeBlockComponent = useCallback(
|
|
(props: { className?: string }) => (
|
|
<pre
|
|
className={cn(
|
|
"not-prose flex-1 overflow-x-auto rounded-sm border bg-background py-3 text-sm outline-none",
|
|
"[&>code]:grid [&>code]:min-w-max",
|
|
className,
|
|
props.className
|
|
)}
|
|
ref={ref}
|
|
style={style}
|
|
tabIndex={tabIndex}
|
|
>
|
|
{children}
|
|
</pre>
|
|
),
|
|
[children, style, tabIndex, className]
|
|
);
|
|
|
|
if (!title) {
|
|
return (
|
|
<div className="relative mb-6">
|
|
<CodeBlockComponent
|
|
className={cn(lineNumbers ? "line-numbers" : "", className)}
|
|
/>
|
|
<Button
|
|
className="absolute top-[5px] right-[5px] bg-background/80 backdrop-blur-sm"
|
|
onClick={copyToClipboard}
|
|
size="icon"
|
|
variant="ghost"
|
|
>
|
|
<Icon size={14} />
|
|
</Button>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Card className="not-prose mb-6 gap-0 overflow-hidden rounded-sm p-0 shadow-none">
|
|
<CardHeader className="flex items-center gap-2 border-b bg-sidebar py-1.5! pr-1.5 pl-4 text-muted-foreground">
|
|
<div
|
|
className="flex size-3.5 shrink-0"
|
|
// biome-ignore lint/security/noDangerouslySetInnerHtml: "Required for icon prop."
|
|
dangerouslySetInnerHTML={{ __html: icon as unknown as TrustedHTML }}
|
|
/>
|
|
<CardTitle className="flex-1 font-mono font-normal text-sm tracking-tight">
|
|
{title}
|
|
</CardTitle>
|
|
<Button
|
|
className={cn("shrink-0", className)}
|
|
onClick={copyToClipboard}
|
|
size="icon"
|
|
variant="ghost"
|
|
>
|
|
<Icon size={14} />
|
|
</Button>
|
|
</CardHeader>
|
|
<CardContent className="p-0">
|
|
<CodeBlockComponent
|
|
className={cn(
|
|
className,
|
|
"rounded-none border-none",
|
|
lineNumbers ? "line-numbers" : ""
|
|
)}
|
|
/>
|
|
</CardContent>
|
|
</Card>
|
|
);
|
|
};
|