Skip to content

Commit

Permalink
chore: fix share button hover text (#1406)
Browse files Browse the repository at this point in the history
  • Loading branch information
k-deepak04 authored Jul 31, 2023
1 parent 4d5475a commit be033fc
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 29 deletions.
40 changes: 29 additions & 11 deletions components/CopyToClipboard/CopyToClipboard.tsx
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -8,23 +8,41 @@ type CopyToClipboardProps = {

export const CopyToClipboard = ({ url }: CopyToClipboardProps): JSX.Element => {
const [copyToClipboard, { success }] = useCopyToClipboard()
const [isHovering, setIsHovering] = useState(false)

function handleCopy(e: React.MouseEvent<SVGElement, MouseEvent>) {
e.stopPropagation()
copyToClipboard(url)
}

return (
<div className="dropdown dropdown-left dropdown-hover">
<FaRegCopy
size={'1.3rem'}
className="text-theme-primary cursor-pointer"
title="Copy link"
onClick={(e) => handleCopy(e)}
/>
<p className="dropdown-content bg-theme-secondary text-white text-sm rounded-lg px-3 py-1 cursor-default">
{success ? 'Copied!' : 'Copy'}
</p>
<div
className="dropdown dropdown-left dropdown-hover"
onMouseEnter={() => setIsHovering(true)}
onMouseLeave={() => setIsHovering(false)}
>
<div style={{ position: 'relative' }}>
<FaRegCopy
size={'1.3rem'}
className="text-theme-primary cursor-pointer"
title="Copy link"
onClick={(e) => handleCopy(e)}
/>
{isHovering && (
<p
className="bg-theme-secondary text-white text-sm rounded-lg px-3 py-1 cursor-default"
style={{
position: 'absolute',
top: '-2rem', // Adjust this value to position the text above the icon
left: '50%',
transform: 'translateX(-50%)',
zIndex: 1,
}}
>
{success ? 'Copied!' : 'Copy'}
</p>
)}
</div>
</div>
)
}
Expand Down
58 changes: 40 additions & 18 deletions components/Share/Share.tsx
Original file line number Diff line number Diff line change
@@ -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<ShareProps> = ({ 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 (
<div className="dropdown dropdown-left dropdown-hover">
<div
style={{
position: 'relative',
display: 'inline-block',
}}
onMouseEnter={() => setShowShareOptions(true)}
onMouseLeave={() => setShowShareOptions(false)}
>
<FaShareAlt
size={'1.2rem'}
className="text-theme-primary cursor-pointer"
title="Share link"
onClick={handleShare}
/>
<p className="dropdown-content bg-theme-secondary text-white text-sm rounded-lg px-3 py-1 cursor-default">
Share
</p>
{showShareOptions && (
<p
className="bg-theme-secondary text-white text-sm rounded-lg px-3 py-1"
style={{
position: 'absolute',
top: '100%',
left: '50%',
transform: 'translateX(-50%)',
zIndex: 1,
boxShadow: '0 2px 4px rgba(0, 0, 0, 0.1)',
cursor: 'default',
}}
>
Share
</p>
)}
</div>
);
};
)
}

export default Share;
export default Share

1 comment on commit be033fc

@vercel
Copy link

@vercel vercel bot commented on be033fc Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.