This commit is contained in:
Ubuntu
2026-07-03 16:58:28 +08:00
commit 32b43f85bd
6240 changed files with 1987678 additions and 0 deletions
+81
View File
@@ -0,0 +1,81 @@
'use client'
import { useState } from 'react'
const CopyIcon = () => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<rect width="14" height="14" x="8" y="8" rx="2" ry="2" />
<path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" />
</svg>
)
const CheckIcon = () => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
>
<path d="M20 6 9 17l-5-5" />
</svg>
)
export const RichTextCodeBlock: React.FC<{
code: string
language?: string
title?: string
}> = ({ code, language, title }) => {
const [copied, setCopied] = useState(false)
const handleCopy = async () => {
await navigator.clipboard.writeText(code)
setCopied(true)
setTimeout(() => setCopied(false), 2000)
}
return (
<div className="my-6 rounded-lg overflow-hidden border-2 border-border bg-[#282A36]">
<div className="flex items-center justify-between px-4 py-2 bg-[#1e1f29] border-b-2 border-border">
<span className="text-sm text-gray-400 font-mono">
{title || language || 'code'}
</span>
<button
onClick={handleCopy}
className="flex items-center gap-1.5 text-xs text-gray-400 hover:text-white transition-colors"
>
{copied ? (
<>
<CheckIcon />
<span>Copied!</span>
</>
) : (
<>
<CopyIcon />
<span>Copy</span>
</>
)}
</button>
</div>
<pre className="p-4 overflow-x-auto">
<code className="text-sm text-accent font-mono whitespace-pre">
{code}
</code>
</pre>
</div>
)
}