ShareWidget.js
2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { CopyTwoTone } from "@ant-design/icons";
import { useRouter } from "next/router";
import React, { useEffect, useState } from "react";
import { CopyToClipboard } from "react-copy-to-clipboard";
import {
FacebookIcon,
FacebookShareButton,
FacebookShareCount,
LinkedinIcon,
LinkedinShareButton,
TwitterShareButton,
WhatsappIcon,
WhatsappShareButton,
XIcon
} from "react-share";
const ShareWidget = () => {
const [shareUrl, setshareUrl] = useState();
const [title, settitle] = useState("");
const [copy, setcopy] = useState({ copied: false });
const router = useRouter();
useEffect(() => {
console.log(`${process.env.NEXT_PUBLIC_FRONTEND_URL}${router.asPath}`);
setshareUrl(`${process.env.NEXT_PUBLIC_FRONTEND_URL}${router.asPath}`);
}, []);
return (
<div className=" d-flex align-items-center justify-content-between">
<div className="share-social-container">
<div className="share-social-some-network">
<FacebookShareButton url={shareUrl} className="share-social-some-network-share-button">
<FacebookIcon size={32} round />
</FacebookShareButton>
</div>
<div className="share-social-some-network">
<WhatsappShareButton url={shareUrl} title={title} separator=":: " className="share-social-some-network-share-button">
<WhatsappIcon size={32} round />
</WhatsappShareButton>
</div>
<div className="share-social-some-network">
<LinkedinShareButton url={shareUrl} className="share-social-some-network-share-button">
<LinkedinIcon size={32} round />
</LinkedinShareButton>
</div>
<div className="share-social-some-network">
<TwitterShareButton url={shareUrl} title={title} className="share-social-some-network-share-button">
<XIcon size={32} round />
</TwitterShareButton>
</div>
</div>
<div>
<CopyToClipboard text={shareUrl} onCopy={() => setcopy({ copied: true })}>
<span>
{!copy.copied && (
<div style={{ cursor: "pointer" }}>
<CopyTwoTone /> Copy to clipboard
</div>
)}
{copy.copied ? <span>Copied to clipboard!</span> : null}
</span>
</CopyToClipboard>
</div>
</div>
);
};
export default ShareWidget;