-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from youngeek-0410/yuto/stylingShareButton
Yuto/styling share button
- Loading branch information
Showing
3 changed files
with
57 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
NEXT_PUBLIC_SPOTIFY_API_CLIENT_ID= | ||
NEXT_PUBLIC_SPOTIFY_API_CLIENT_SECRET= | ||
NEXT_PUBLIC_BACKEND_API_KEY= | ||
HOSTNAME= |
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 |
---|---|---|
@@ -1,36 +1,63 @@ | ||
import { useRouter } from "next/router"; | ||
import React from "react"; | ||
import React, { useEffect, useState } from "react"; | ||
import { FiShare, FiClipboard } from "react-icons/fi"; | ||
|
||
import { styled } from "../stitches.config"; | ||
|
||
export const LinkShare: React.FC = () => { | ||
export const LinkShare: React.FC<{ url: string }> = (props) => { | ||
const router = useRouter(); | ||
const hostName = "https://app.cloveeee.com"; | ||
const url = `${hostName}${router.asPath}`; | ||
const [canShare, setCanShare] = useState(false); | ||
const copyLink = () => { | ||
navigator.clipboard.writeText(url); | ||
navigator.clipboard.writeText(props.url); | ||
}; | ||
const shareLink = () => { | ||
const data: ShareData = { | ||
url: url, | ||
url: props.url, | ||
}; | ||
navigator.share(data); | ||
}; | ||
|
||
useEffect(() => { | ||
// NOTE: mac chrome で share がかけないらしいがぱっと対応コードが書けなかったのであと回し | ||
// setCanShare(Object.hasOwn(navigator, "share")); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<span>{url}</span> | ||
<ShareButton onClick={shareLink}> | ||
<FiShare /> | ||
</ShareButton> | ||
<CopyClipboard onClick={copyLink}> | ||
<FiClipboard /> | ||
</CopyClipboard> | ||
</> | ||
<Base> | ||
<PostMessageUrl>{props.url}</PostMessageUrl> | ||
{canShare ? ( | ||
<Icon onClick={shareLink}> | ||
<FiShare /> | ||
</Icon> | ||
) : ( | ||
<Icon onClick={copyLink}> | ||
<FiClipboard /> | ||
</Icon> | ||
)} | ||
|
||
{/* 実際にサイトに飛べるアイコンリンク */} | ||
</Base> | ||
); | ||
}; | ||
|
||
const CopyClipboard = styled("button", {}); | ||
const Base = styled("div", { | ||
display: "flex", | ||
}); | ||
|
||
const PostMessageUrl = styled("p", { | ||
overflowWrap: "anywhere", | ||
marginRight: "8px", | ||
}); | ||
|
||
const ShareButton = styled("button", {}); | ||
const Icon = styled("button", { | ||
border: "none", | ||
margin: "8px 16px 0 0", | ||
padding: "0", | ||
fontSize: "24px", | ||
background: "inherit", | ||
cursor: "pointer", | ||
transition: "opacity 0.15s 0.05s", | ||
"&:active": { | ||
opacity: 0.5, | ||
}, | ||
}); |
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
d84afa8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
hacku-kosen-2022-frontend – ./
hacku-kosen-2022-frontend.vercel.app
hacku-kosen-2022-frontend-youngeek.vercel.app
app.cloveeee.com
hacku-kosen-2022-frontend-git-master-youngeek.vercel.app