Skip to content

Commit

Permalink
feat: 공유 컴포넌트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
doputer committed Feb 9, 2024
1 parent 973f3df commit a978626
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
37 changes: 37 additions & 0 deletions src/components/share.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ShareIcon } from '@heroicons/react/24/solid';

interface ShareProps {
title: string;
description: string;
}

function Share({ title, description }: ShareProps) {
const handleShareClick = () => {
const shareData = {
title: title,
text: description,
url: decodeURI(window.location.href),
};

if (navigator.canShare && navigator.canShare(shareData)) {
window.navigator.share();
} else {
navigator.clipboard.writeText(decodeURI(window.location.href));
}
};

return (
<div className="flex justify-center rounded-lg bg-background-light py-8 dark:bg-background-dark">
<button
className="flex gap-2 hover:text-link-light dark:hover:text-link-dark"
onClick={handleShareClick}
aria-label="share_button"
>
공유하기
<ShareIcon className="h-6 w-6" />
</button>
</div>
);
}

export default Share;
6 changes: 5 additions & 1 deletion src/templates/post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { graphql, type HeadProps, type PageProps } from 'gatsby';

import Comment from '@/components/comment';
import SEO from '@/components/seo';
import Share from '@/components/share';
import TOC from '@/components/toc';
import typography from '@/components/typography';

function PostTemplate({ data: { mdx }, children }: PageProps<Queries.PostQuery>) {
const { title, date } = mdx.frontmatter;
const { title, description, date } = mdx.frontmatter;

return (
<>
Expand All @@ -21,6 +22,9 @@ function PostTemplate({ data: { mdx }, children }: PageProps<Queries.PostQuery>)
{children}
</MDXProvider>
</article>
<div className="my-16">
<Share title={title} description={description} />
</div>
<div className="my-16">
<Comment />
</div>
Expand Down

0 comments on commit a978626

Please sign in to comment.