fixes #175 - copy to clipboard

This commit is contained in:
Drew Winget 2022-07-21 17:39:05 -05:00
parent beef34abfa
commit 41dacc0d80
1 changed files with 14 additions and 1 deletions

View File

@ -12,6 +12,12 @@ import React, { useEffect, useState } from 'react'
import GithubSlugger from 'github-slugger'
import Link from '../svgs/link.svg'
function copyToClipboard (id) {
if (navigator && navigator.clipboard && navigator.clipboard.writeText)
return navigator.clipboard.writeText(str);
return Promise.reject('The Clipboard API is not available.');
}
function myRemarkPlugin () {
return (tree) => {
visit(tree, (node) => {
@ -39,11 +45,18 @@ function Heading ({ h, slugger, noFragments, topLevel, children, node, ...props
}
return acc + cur.replace(/[^\w\-\s]+/gi, '')
}, ''))
console.log(id)
return (
<div className={styles.heading}>
{React.createElement(h, { id, ...props }, children)}
{!noFragments && topLevel && <a className={styles.headingLink} href={`#${id}`}><Link width={18} height={18} className='fill-grey' /></a>}
{!noFragments && topLevel && <a className={styles.headingLink} href={`#${id}`}><Link
onClick={() => copyToClipboard(id)}
width={18}
height={18}
className='fill-grey'
/>
</a>}
</div>
)
}