-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(copy): move the 'click to copy' to a separate component
- Loading branch information
Showing
3 changed files
with
52 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import ClipboardJS from 'clipboard'; | ||
|
||
interface Props { | ||
link: string; | ||
} | ||
|
||
const Copy: React.FC<Props> = ({ link }) => { | ||
const [tooltip, setTooltip] = useState(false); | ||
useEffect(() => { | ||
const clipboard = new ClipboardJS('.btn-link.text-gray-light'); | ||
clipboard.on('success', () => setTooltip(true)); | ||
}); | ||
|
||
return ( | ||
<span | ||
className={`btn-link text-gray-light ml-1 ${tooltip && | ||
'tooltipped tooltipped-s'}`} | ||
data-clipboard-text={link} | ||
aria-label="Copied" | ||
onBlur={() => setTooltip(false)} | ||
onMouseLeave={() => setTooltip(false)} | ||
> | ||
{link} | ||
</span> | ||
); | ||
}; | ||
|
||
export default Copy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import Copy from './Copy'; | ||
export default Copy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters