medkit/src/kit/code-block.tsx

24 lines
954 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { CopyIcon } from "lucide-react"
import { cn } from "../lib/utils"
import { copyToClipboard } from "../lib/clipboard"
/** Фрагмент кода с кнопкой копирования. */
export function CodeBlock({ code, className }: { code: string; className?: string }) {
return (
<div className={cn("group relative", className)}>
<pre className="overflow-x-auto rounded-xl bg-muted/70 p-4 font-mono text-ui leading-relaxed text-foreground/90">
<code>{code}</code>
</pre>
<button
type="button"
aria-label="Скопировать код"
onClick={() => copyToClipboard(code, "Код скопирован")}
className="absolute top-2 right-2 grid size-7 place-items-center rounded-md bg-card text-muted-foreground opacity-0 shadow-xs transition group-hover:opacity-100 hover:text-foreground"
>
<CopyIcon className="size-3.5" />
</button>
</div>
)
}