9
9
import { useTheme } from 'next-themes'
10
10
import { Children , ReactNode , useState } from 'react'
11
11
import { Light as SyntaxHighlighter , SyntaxHighlighterProps } from 'react-syntax-highlighter'
12
+ import { Copy } from 'lucide-react'
12
13
13
14
import curl from 'highlightjs-curl'
14
15
import bash from 'react-syntax-highlighter/dist/cjs/languages/hljs/bash'
@@ -23,6 +24,7 @@ import sql from 'react-syntax-highlighter/dist/cjs/languages/hljs/sql'
23
24
import ts from 'react-syntax-highlighter/dist/cjs/languages/hljs/typescript'
24
25
25
26
import { cn } from '~/lib/utils'
27
+ import { Button } from './ui/button'
26
28
27
29
export interface CodeBlockProps {
28
30
title ?: ReactNode
@@ -69,6 +71,7 @@ export const CodeBlock = ({
69
71
70
72
const handleCopy = ( ) => {
71
73
setCopied ( true )
74
+ navigator . clipboard . writeText ( value ?? '' )
72
75
setTimeout ( ( ) => {
73
76
setCopied ( false )
74
77
} , 1000 )
@@ -168,11 +171,24 @@ export const CodeBlock = ({
168
171
{ ! hideCopy && ( value || children ) && className ? (
169
172
< div
170
173
className = { [
171
- 'absolute right-2 top-2 ' ,
174
+ 'absolute right-1 top-1 ' ,
172
175
'opacity-0 group-hover:opacity-100 transition' ,
173
176
`${ isDarkTheme ? 'dark' : '' } ` ,
174
177
] . join ( ' ' ) }
175
- > </ div >
178
+ >
179
+ < Button
180
+ onClick = { handleCopy }
181
+ data-size = "tiny"
182
+ type = "button"
183
+ variant = "outline"
184
+ className = "relative"
185
+ >
186
+ < div className = "text-foreground-muted" >
187
+ < Copy size = { 14 } />
188
+ </ div > { ' ' }
189
+ < span className = "truncate" > Copy</ span >
190
+ </ Button >
191
+ </ div >
176
192
) : null }
177
193
</ div >
178
194
) : (
0 commit comments