-
-
Notifications
You must be signed in to change notification settings - Fork 769
/
Copy pathblog-article-sharebar.tsx
86 lines (74 loc) · 1.82 KB
/
blog-article-sharebar.tsx
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { graphql } from "gatsby";
import React, { FC } from "react";
import { LinkedinShareButton, TwitterShareButton } from "react-share";
import styled from "styled-components";
import { Icon } from "@/components/sprites";
import { BlogArticleSharebarFragment } from "@/graphql-types";
// Icons
import LinkedInIconSvg from "@/images/icons/linkedin-square.svg";
import XIconSvg from "@/images/icons/x-square.svg";
export interface BlogArticleSharebarProps {
readonly data: BlogArticleSharebarFragment;
readonly tags: string[];
}
export const BlogArticleSharebar: FC<BlogArticleSharebarProps> = ({
data: { mdx, site },
tags,
}) => {
const { frontmatter } = mdx!;
const articelUrl = site!.siteMetadata!.siteUrl! + frontmatter!.path!;
const title = frontmatter!.title!;
return (
<ShareButtons>
<TwitterShareButton
url={articelUrl}
title={title}
via={site!.siteMetadata!.author!}
hashtags={tags}
>
<XIcon />
</TwitterShareButton>
<LinkedinShareButton url={articelUrl} title={title}>
<LinkedinIcon />
</LinkedinShareButton>
</ShareButtons>
);
};
export const BlogArticleSharebarGraphQLFragment = graphql`
fragment BlogArticleSharebar on Query {
mdx(frontmatter: { path: { eq: $path } }) {
frontmatter {
path
tags
title
}
}
site {
siteMetadata {
author
siteUrl
}
}
}
`;
const ShareButtons = styled.div`
display: flex;
flex-direction: row;
align-items: center;
gap: 16px;
> button {
flex: 0 0 auto;
> svg {
width: 24px;
}
}
@media only screen and (min-width: 992px) {
display: flex;
}
`;
const XIcon = styled(Icon).attrs(XIconSvg)`
fill: #ffffff;
`;
const LinkedinIcon = styled(Icon).attrs(LinkedInIconSvg)`
fill: #ffffff;
`;