feat: implement social share buttons
This commit is contained in:
@@ -1,59 +1,70 @@
|
||||
import type { FC } from 'react'
|
||||
import { Link } from 'react-router'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
import { LinkIcon } from '@heroicons/react/20/solid'
|
||||
import { useState } from 'react'
|
||||
import {
|
||||
FacebookShareButton,
|
||||
LinkedinShareButton,
|
||||
TwitterShareButton,
|
||||
InstapaperShareButton,
|
||||
} from 'react-share'
|
||||
|
||||
import { FacebookIcon } from '~/components/icons/facebook'
|
||||
import { InstagramIcon } from '~/components/icons/instagram'
|
||||
import { LinkIcon } from '~/components/icons/link-icon'
|
||||
import { LinkedinIcon } from '~/components/icons/linkedin'
|
||||
import { XIcon } from '~/components/icons/x'
|
||||
|
||||
type SocialMediaProperties = {
|
||||
className?: string
|
||||
slug?: string
|
||||
type SocialShareButtonsProperties = {
|
||||
url: string
|
||||
title: string
|
||||
}
|
||||
|
||||
const dataSocialMedia = [
|
||||
{
|
||||
type: 'link',
|
||||
url: 'post-id/',
|
||||
icon: LinkIcon,
|
||||
},
|
||||
{
|
||||
type: 'facebook',
|
||||
url: 'https://facebook.com/',
|
||||
icon: FacebookIcon,
|
||||
},
|
||||
{
|
||||
type: 'linkedin',
|
||||
url: 'https://linkedin.com/',
|
||||
icon: LinkedinIcon,
|
||||
},
|
||||
{
|
||||
type: 'x',
|
||||
url: 'https://x.com/',
|
||||
icon: XIcon,
|
||||
},
|
||||
{
|
||||
type: 'instagram',
|
||||
url: 'https://instagram.com/',
|
||||
icon: InstagramIcon,
|
||||
},
|
||||
]
|
||||
export const SocialShareButtons = ({
|
||||
url,
|
||||
title,
|
||||
}: SocialShareButtonsProperties) => {
|
||||
const [showPopup, setShowPopup] = useState(false)
|
||||
|
||||
export const IconsSocial: FC<SocialMediaProperties> = ({ className }) => {
|
||||
const handleCopyLink = () => {
|
||||
navigator.clipboard.writeText(url)
|
||||
setShowPopup(true)
|
||||
setTimeout(() => setShowPopup(false), 2000)
|
||||
}
|
||||
return (
|
||||
<div className={twMerge('flex gap-2', className)}>
|
||||
{dataSocialMedia.map(({ url, icon: Icon }, index) => (
|
||||
<Link
|
||||
key={index}
|
||||
to={url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Icon className="h-8 w-8 rounded-full bg-gray-400 p-2 sm:h-10 sm:w-10" />
|
||||
</Link>
|
||||
))}
|
||||
<div className="flex items-center space-x-2">
|
||||
{showPopup && (
|
||||
<div className="absolute top-0 rounded-lg border-2 border-gray-400 bg-white p-2 shadow-lg">
|
||||
Link berhasil disalin!
|
||||
</div>
|
||||
)}
|
||||
<button onClick={handleCopyLink}>
|
||||
<LinkIcon className="h-8 w-8 rounded-full bg-gray-400 p-2 sm:h-10 sm:w-10" />
|
||||
</button>
|
||||
<FacebookShareButton
|
||||
url={url}
|
||||
title={title}
|
||||
>
|
||||
<FacebookIcon className="h-8 w-8 rounded-full bg-gray-400 p-2 sm:h-10 sm:w-10" />
|
||||
</FacebookShareButton>
|
||||
|
||||
<LinkedinShareButton
|
||||
url={url}
|
||||
title={title}
|
||||
>
|
||||
<LinkedinIcon className="h-8 w-8 rounded-full bg-gray-400 p-2 sm:h-10 sm:w-10" />
|
||||
</LinkedinShareButton>
|
||||
|
||||
<TwitterShareButton
|
||||
url={url}
|
||||
title={title}
|
||||
>
|
||||
<XIcon className="h-8 w-8 rounded-full bg-gray-400 p-2 sm:h-10 sm:w-10" />
|
||||
</TwitterShareButton>
|
||||
|
||||
<InstapaperShareButton
|
||||
url={url}
|
||||
title={title}
|
||||
>
|
||||
<InstagramIcon className="h-8 w-8 rounded-full bg-gray-400 p-2 sm:h-10 sm:w-10" />
|
||||
</InstapaperShareButton>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user