From 41dacc0d80fa84aed1b714a0d13c1c5463d4277a Mon Sep 17 00:00:00 2001 From: Drew Winget Date: Thu, 21 Jul 2022 17:39:05 -0500 Subject: [PATCH] fixes #175 - copy to clipboard --- components/text.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/components/text.js b/components/text.js index 80495d12..c57b4992 100644 --- a/components/text.js +++ b/components/text.js @@ -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 (
{React.createElement(h, { id, ...props }, children)} - {!noFragments && topLevel && } + {!noFragments && topLevel && copyToClipboard(id)} + width={18} + height={18} + className='fill-grey' + /> + }
) }