diff --git a/components/CopyToClipboard/CopyToClipboard.tsx b/components/CopyToClipboard/CopyToClipboard.tsx index dac287271..e28002ea7 100644 --- a/components/CopyToClipboard/CopyToClipboard.tsx +++ b/components/CopyToClipboard/CopyToClipboard.tsx @@ -1,5 +1,5 @@ import useCopyToClipboard from 'hooks/useCopyToClipboard' -import React from 'react' +import React, { useState } from 'react' import { FaRegCopy } from 'react-icons/fa' type CopyToClipboardProps = { @@ -8,6 +8,7 @@ type CopyToClipboardProps = { export const CopyToClipboard = ({ url }: CopyToClipboardProps): JSX.Element => { const [copyToClipboard, { success }] = useCopyToClipboard() + const [isHovering, setIsHovering] = useState(false) function handleCopy(e: React.MouseEvent) { e.stopPropagation() @@ -15,16 +16,33 @@ export const CopyToClipboard = ({ url }: CopyToClipboardProps): JSX.Element => { } return ( -
- handleCopy(e)} - /> -

- {success ? 'Copied!' : 'Copy'} -

+
setIsHovering(true)} + onMouseLeave={() => setIsHovering(false)} + > +
+ handleCopy(e)} + /> + {isHovering && ( +

+ {success ? 'Copied!' : 'Copy'} +

+ )} +
) } diff --git a/components/Share/Share.tsx b/components/Share/Share.tsx index 37d491473..349a532f6 100644 --- a/components/Share/Share.tsx +++ b/components/Share/Share.tsx @@ -1,43 +1,65 @@ -import React from 'react'; -import { FaShareAlt } from 'react-icons/fa'; +import React, { useState } from 'react' +import { FaShareAlt } from 'react-icons/fa' type ShareProps = { - url: string; - title: string; -}; + url: string + title: string +} export const Share: React.FC = ({ url, title }) => { + const [showShareOptions, setShowShareOptions] = useState(false) + async function handleShare() { if (navigator.share) { try { await navigator.share({ title: title, url: url, - }); - console.log('Share was successful.'); + }) + console.log('Share was successful.') } catch (error) { - console.error('Error sharing:', error); + console.error('Error sharing:', error) } } else { - console.log('Web Share API not supported on this browser.'); - // Fallback behavior when Web Share API is not supported (e.g., open a new tab with the URL) - window.open(url, '_blank'); + console.log('Web Share API not supported on this browser.') + // Fallback behavior when Web Share API is not supported (e.g., open a new tab with the URL) + window.open(url, '_blank') } } return ( -
+
setShowShareOptions(true)} + onMouseLeave={() => setShowShareOptions(false)} + > -

- Share -

+ {showShareOptions && ( +

+ Share +

+ )}
- ); -}; + ) +} -export default Share; +export default Share