mirror of
https://github.com/r-freeman/portfolio.git
synced 2025-06-28 00:00:21 +00:00
Some checks failed
Build And Publish / BuildAndPublish (push) Failing after 2m16s
22 lines
667 B
TypeScript
22 lines
667 B
TypeScript
'use client'
|
|
|
|
import React, {ReactNode, useRef} from 'react'
|
|
import {CopyIcon} from '@/components/icons/CopyIcon'
|
|
|
|
export function Code({children}: { children: ReactNode }) {
|
|
const preRef = useRef<HTMLPreElement>(null)
|
|
|
|
const handleCopy = async (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
e.preventDefault()
|
|
await navigator.clipboard.writeText(preRef.current?.innerText ?? '')
|
|
}
|
|
|
|
return (
|
|
<pre className="relative" ref={preRef}>
|
|
<button className="absolute right-0 top-0 m-5" onClick={handleCopy}>
|
|
<CopyIcon className="w-5 h-5"/>
|
|
</button>
|
|
{children}
|
|
</pre>
|
|
)
|
|
} |