"use client"; import { Check, Copy } from "lucide-react"; import { ReactNode, useState } from "react"; import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/shadcn/tooltip"; import { cn } from "@/lib/utils"; interface CodeSnippetProps { value: string; className?: string; /** Hide the code text and show only the copy button */ hideCode?: boolean; /** Hide the copy button */ hideCopyButton?: boolean; /** Icon to display before the text */ icon?: ReactNode; /** Function to format the displayed text (value is still copied as-is) */ formatter?: (value: string) => string; /** Enable multiline display (disables truncation, enables word wrap) */ multiline?: boolean; /** Remove background and border */ transparent?: boolean; /** Custom aria-label for the copy button */ ariaLabel?: string; } export const CodeSnippet = ({ value, className, hideCode = false, hideCopyButton = false, icon, formatter, transparent = false, multiline = false, ariaLabel = "Copy to clipboard", }: CodeSnippetProps) => { const [copied, setCopied] = useState(false); const handleCopy = async () => { await navigator.clipboard.writeText(value); setCopied(true); setTimeout(() => setCopied(false), 2000); }; const displayValue = formatter ? formatter(value) : value; // When hideCode is true, render only the copy button without container styling if (hideCode) { return ( ); } return (