-
-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
312 additions
and
44 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 |
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,9 @@ | ||
[ | ||
{ | ||
"name": "An Introduction to Raspberry Pi microcontroller", | ||
"description": "The Raspberry Pi is a low-cost, credit-card-sized computer that plugs into a computer monitor or TV, and uses a standard keyboard and mouse. It also enables people of all ages to explore computing and learn programming languages like Scratch and Python.", | ||
"url": "https://www.raspberrypi.org/", | ||
"category": "internet of things", | ||
"subcategory": "raspberrypi" | ||
} | ||
] |
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
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
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
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
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
Oops, something went wrong.