-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: prevent skeleton from navigating to links * feat: add sharing feeature
- Loading branch information
1 parent
3fa56ea
commit 1915fc1
Showing
4 changed files
with
116 additions
and
15 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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import getShareApi from '@/utils/share'; | ||
import styled from '@emotion/styled'; | ||
import IconButton from '@mui/material/IconButton'; | ||
import { | ||
FaSquareFacebook, | ||
FaLine, | ||
FaLinkedin, | ||
FaSquareThreads, | ||
FaSquareXTwitter, | ||
FaShareFromSquare, | ||
} from 'react-icons/fa6'; | ||
|
||
const StyledShareButtonGroup = styled.div` | ||
display: flex; | ||
gap: 0.25rem; | ||
`; | ||
|
||
export default function ShareButtonGroup({ title, text, url, hashtag }) { | ||
const { | ||
hasNativeShare, | ||
nativeShare, | ||
facebookShare, | ||
lineShare, | ||
linkedinShare, | ||
threadsShare, | ||
xShare, | ||
} = getShareApi({ title, text, url, hashtag }); | ||
|
||
return ( | ||
<StyledShareButtonGroup> | ||
<IconButton size="small" onClick={facebookShare}> | ||
<FaSquareFacebook fill="#1877F2" /> | ||
</IconButton> | ||
<IconButton size="small" onClick={threadsShare}> | ||
<FaSquareThreads fill="#000" /> | ||
</IconButton> | ||
<IconButton size="small" onClick={lineShare}> | ||
<FaLine size={16} fill="#00B900" /> | ||
</IconButton> | ||
<IconButton size="small" onClick={linkedinShare}> | ||
<FaLinkedin fill="#0A66C2" /> | ||
</IconButton> | ||
<IconButton size="small" onClick={xShare}> | ||
<FaSquareXTwitter fill="#000" /> | ||
</IconButton> | ||
{hasNativeShare && ( | ||
<IconButton size="small" onClick={nativeShare}> | ||
<FaShareFromSquare size={16} /> | ||
</IconButton> | ||
)} | ||
</StyledShareButtonGroup> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export default function getShareApi({ | ||
title = '', | ||
text = '', | ||
url = '', | ||
hashtag = '', | ||
}) { | ||
const openInNewTab = (url) => () => window.open(url, '_blank'); | ||
|
||
const nativeShare = () => { | ||
if (!navigator?.share) return; | ||
navigator.share({ title, text, url }); | ||
}; | ||
|
||
const facebookShare = openInNewTab( | ||
`https://www.facebook.com/sharer/sharer.php?u=${url}&source_surface=external_reshare&display=popup&hashtag=${hashtag}`, | ||
); | ||
|
||
const lineShare = openInNewTab( | ||
`https://social-plugins.line.me/lineit/share?url=${url}`, | ||
); | ||
|
||
const linkedinShare = openInNewTab( | ||
`https://www.linkedin.com/sharing/share-offsite/?url=${url}&text=${text}`, | ||
); | ||
|
||
const threadsShare = openInNewTab( | ||
`https://threads.net/intent/post?text=${url}`, | ||
); | ||
|
||
const xShare = openInNewTab(`https://x.com/intent/tweet?text=${url}`); | ||
|
||
return { | ||
hasNativeShare: !!navigator?.share, | ||
facebookShare, | ||
lineShare, | ||
linkedinShare, | ||
nativeShare, | ||
threadsShare, | ||
xShare, | ||
}; | ||
} |