"use client"; import { useRef, useState, type ComponentProps, type ReactElement } from "react"; import { Check, Copy } from "lucide-react"; //
with a copy button, used for every fenced code block in lessons
export function CodeBlock(props: ComponentProps<"pre">) {
const ref = useRef(null);
const [copied, setCopied] = useState(false);
// ```prompt fences hold a sentence to paste into an agent, so they wrap
const child = props.children as ReactElement<{ className?: string }> | undefined;
const isPrompt = child?.props?.className === "language-prompt";
const copy = async () => {
await navigator.clipboard.writeText(ref.current?.innerText ?? "");
setCopied(true);
setTimeout(() => setCopied(false), 1500);
};
return (
code]:whitespace-pre-wrap" : ""}`}
/>
);
}