medkit/src/kit/code-block.tsx

24 lines
1005 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("relative", className)}>
<pre className="overflow-x-auto rounded-xl border bg-muted/60 p-3 pr-12 font-mono text-ui leading-relaxed text-foreground/90 sm:p-4 sm:pr-12">
<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 border bg-card text-muted-foreground shadow-xs transition hover:text-foreground focus:ring-[3px] focus:ring-ring/50 focus:outline-none"
>
<CopyIcon className="size-3.5" />
</button>
</div>
)
}