Skip to content

Commit 7c4eefa

Browse files
committed
feat: Add copy-to-clipboard button to all code blocks
1 parent 1fb9d85 commit 7c4eefa

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

demo/src/components/common/CodeBlock.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Highlight, themes } from 'prism-react-renderer';
2+
import { CopyButton } from './CopyButton';
23

34
interface CodeBlockProps {
45
code: string;
@@ -14,7 +15,10 @@ export function CodeBlock({
1415
fileName,
1516
}: CodeBlockProps) {
1617
return (
17-
<div className="code-block rounded-lg overflow-hidden bg-gray-900">
18+
<div className="code-block rounded-lg overflow-hidden bg-gray-900 relative group">
19+
<div className="absolute top-2 right-2 z-10 opacity-0 group-hover:opacity-100 transition-opacity">
20+
<CopyButton text={code.trim()} />
21+
</div>
1822
{fileName && (
1923
<div className="px-4 py-2 bg-gray-800 text-gray-300 text-sm font-mono border-b border-gray-700">
2024
{fileName}

demo/src/components/playground/ComponentPlayground.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { SelectControl } from './controls/SelectControl';
77
import { BooleanControl } from './controls/BooleanControl';
88
import { TextControl } from './controls/TextControl';
99
import { CodeBlock } from '../common/CodeBlock';
10-
import { CopyButton } from '../common/CopyButton';
1110
import { ThemeSwitch } from '../common/ThemeSwitch';
1211
import { useTheme, THEME_COLORS } from '../../contexts/ThemeContext';
1312
import { generateComponentCode, generateImportStatement } from '../../utils/codeGenerator';
@@ -147,10 +146,7 @@ function App() {
147146

148147
{/* Code */}
149148
<div className="space-y-2">
150-
<div className="flex items-center justify-between">
151-
<h3 className="text-lg font-semibold">Code</h3>
152-
<CopyButton text={generatedCode} />
153-
</div>
149+
<h3 className="text-lg font-semibold mb-2">Code</h3>
154150
<CodeBlock code={generatedCode} language="tsx" />
155151
</div>
156152

0 commit comments

Comments
 (0)