1- import { Card } from "react-bootstrap" ;
1+ import { Button , Card } from "react-bootstrap" ;
22import SyntaxHighlighter from "react-syntax-highlighter" ;
3+ import { CopyToClipboard } from "react-copy-to-clipboard" ;
4+ import { useState } from "react" ;
35
46export default function CodeBlock ( {
57 code,
@@ -16,27 +18,42 @@ export default function CodeBlock({
1618 wrapLines ?: boolean ;
1719 wrapLongLines ?: boolean ;
1820} ) {
21+ const [ copied , setCopied ] = useState ( false ) ;
22+
23+ // Reset the copied state after 2 seconds.
24+ if ( copied ) {
25+ setTimeout ( ( ) => {
26+ setCopied ( false ) ;
27+ } , 2000 ) ;
28+ }
29+
1930 return (
20- < Card bg = { "secondary" } text = "white" className = "mt-2" >
21- < Card . Body >
22- < Card . Text > { title } </ Card . Text >
23- < SyntaxHighlighter
24- language = { language }
25- style = { style }
26- wrapLines = { wrapLines }
27- wrapLongLines = { wrapLongLines }
28- showLineNumbers = { true }
29- showInlineLineNumbers = { false }
30- header = { "Code" }
31- customStyle = { {
32- border : "1px solid #c3c3c3" ,
33- borderRadius : "5px" ,
34- marginBottom : 0 ,
35- } }
36- >
37- { code }
38- </ SyntaxHighlighter >
39- </ Card . Body >
40- </ Card >
31+ < div className = "bg-primary mt-2 rounded" >
32+ < div className = "d-flex flex-row justify-content-between align-items-center p-2" >
33+ < h6 className = "mb-0 ml-2 text-white" > { title } </ h6 >
34+ < CopyToClipboard text = { code } >
35+ < a className = "btn btn-primary" onClick = { ( ) => setCopied ( true ) } >
36+ < small > { copied ? "Gekopieerd" : "Kopieer" } </ small >
37+ </ a >
38+ </ CopyToClipboard >
39+ </ div >
40+
41+ < SyntaxHighlighter
42+ language = { language }
43+ style = { style }
44+ wrapLines = { wrapLines }
45+ wrapLongLines = { wrapLongLines }
46+ showLineNumbers = { true }
47+ showInlineLineNumbers = { false }
48+ header = { "Code" }
49+ customStyle = { {
50+ border : "1px solid #c3c3c3" ,
51+ borderRadius : "5px" ,
52+ marginBottom : 0 ,
53+ } }
54+ >
55+ { code }
56+ </ SyntaxHighlighter >
57+ </ div >
4158 ) ;
4259}
0 commit comments