-
-
Notifications
You must be signed in to change notification settings - Fork 557
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: fix share button hover text (#1406)
- Loading branch information
1 parent
4d5475a
commit be033fc
Showing
2 changed files
with
69 additions
and
29 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
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 |
---|---|---|
@@ -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 |
be033fc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
linkshub – ./
linkshub.vercel.app
linkshub-git-main-rupali-codes.vercel.app
linkshub-rupali-codes.vercel.app
linkshub.dev
www.linkshub.dev