-
Notifications
You must be signed in to change notification settings - Fork 3
Certificate social media / URL sharing #2524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1c15510
Share button and popover
jonkafton 46a25b5
OG metadata. Pass page URL for SSR
jonkafton ad00334
Center the popover to the buttons/page
jonkafton 97cfd2d
Element type
jonkafton 35ea3ac
Pass pageUrl
jonkafton 170a459
Update title and filnames
jonkafton ea3932c
Remove redundant aria-label. Add tests
jonkafton cc25a11
Merge branch 'main' into jk/certificate-share
jonkafton 6e781b9
Update frontends/main/src/app-pages/CertificatePage/CertificatePage.t…
jonkafton 71d741f
Remove unused
jonkafton 002f273
aria-labels and improve test selectors
jonkafton 1cb678a
Remove unused
jonkafton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
164 changes: 164 additions & 0 deletions
164
frontends/main/src/app-pages/CertificatePage/SharePopover.tsx
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,164 @@ | ||
import React, { useState } from "react" | ||
import { Popover, Typography, styled, theme } from "ol-components" | ||
import Link from "next/link" | ||
import { | ||
FACEBOOK_SHARE_BASE_URL, | ||
TWITTER_SHARE_BASE_URL, | ||
LINKEDIN_SHARE_BASE_URL, | ||
} from "@/common/urls" | ||
import { | ||
RiFacebookFill, | ||
RiTwitterXLine, | ||
RiLinkedinFill, | ||
RiLink, | ||
} from "@remixicon/react" | ||
import { Button, Input } from "@mitodl/smoot-design" | ||
|
||
const StyledPopover = styled(Popover)({ | ||
width: "648px", | ||
maxWidth: "calc(100vw - 48px)", | ||
".MuiPopper-arrow": { | ||
display: "none", | ||
}, | ||
}) | ||
|
||
const Contents = styled.div(({ theme }) => ({ | ||
padding: "8px", | ||
display: "flex", | ||
gap: "40px", | ||
[theme.breakpoints.down("sm")]: { | ||
flexDirection: "column", | ||
gap: "32px", | ||
}, | ||
})) | ||
|
||
const SocialContainer = styled.div({ | ||
display: "flex", | ||
flexDirection: "column", | ||
gap: "16px", | ||
}) | ||
|
||
const LinkContainer = styled.div({ | ||
display: "flex", | ||
flexDirection: "column", | ||
gap: "12px", | ||
flex: 1, | ||
}) | ||
|
||
const Heading = styled(Typography)(({ theme }) => ({ | ||
...theme.typography.body2, | ||
color: theme.custom.colors.darkGray2, | ||
fontWeight: theme.typography.fontWeightBold, | ||
})) | ||
|
||
const ButtonContainer = styled.div({ | ||
display: "flex", | ||
alignSelf: "stretch", | ||
gap: "16px", | ||
a: { | ||
height: "18px", | ||
}, | ||
}) | ||
|
||
const ShareLink = styled(Link)({ | ||
color: theme.custom.colors.silverGrayDark, | ||
"&:hover": { | ||
color: theme.custom.colors.lightRed, | ||
}, | ||
}) | ||
|
||
const LinkControls = styled.div(({ theme }) => ({ | ||
display: "flex", | ||
gap: "16px", | ||
input: { | ||
...theme.typography.body3, | ||
color: theme.custom.colors.darkGray2, | ||
padding: "0 3px", | ||
}, | ||
})) | ||
|
||
const RedLinkIcon = styled(RiLink)({ | ||
color: theme.custom.colors.red, | ||
}) | ||
|
||
const CopyLinkButton = styled(Button)({ | ||
minWidth: "104px", | ||
}) | ||
|
||
const SharePopover = ({ | ||
open, | ||
title, | ||
anchorEl, | ||
onClose, | ||
pageUrl, | ||
}: { | ||
open: boolean | ||
title: string | ||
anchorEl: HTMLDivElement | null | ||
onClose: () => void | ||
pageUrl: string | ||
}) => { | ||
const [copyText, setCopyText] = useState("Copy Link") | ||
|
||
return ( | ||
<StyledPopover open={open} onClose={onClose} anchorEl={anchorEl}> | ||
<Contents> | ||
<SocialContainer> | ||
<Heading variant="body2">Share on social</Heading> | ||
<ButtonContainer> | ||
<ShareLink | ||
href={`${FACEBOOK_SHARE_BASE_URL}?u=${encodeURIComponent(pageUrl)}`} | ||
aria-label="Share on Facebook" | ||
target="_blank" | ||
> | ||
<RiFacebookFill size={18} /> | ||
</ShareLink> | ||
<ShareLink | ||
href={`${TWITTER_SHARE_BASE_URL}?text=${encodeURIComponent(title)}&url=${encodeURIComponent(pageUrl)}`} | ||
aria-label="Share on Twitter" | ||
target="_blank" | ||
> | ||
<RiTwitterXLine size={18} /> | ||
</ShareLink> | ||
<ShareLink | ||
href={`${LINKEDIN_SHARE_BASE_URL}?url=${encodeURIComponent(pageUrl)}`} | ||
aria-label="Share on LinkedIn" | ||
target="_blank" | ||
> | ||
<RiLinkedinFill size={18} /> | ||
</ShareLink> | ||
</ButtonContainer> | ||
</SocialContainer> | ||
<LinkContainer> | ||
<Heading variant="body2">Share a link</Heading> | ||
<LinkControls> | ||
<Input | ||
fullWidth | ||
value={pageUrl} | ||
size="small" | ||
onClick={(event) => { | ||
const input = event.currentTarget.querySelector("input") | ||
if (!input) return | ||
input.select() | ||
}} | ||
/> | ||
<CopyLinkButton | ||
size="small" | ||
edge="circular" | ||
variant="bordered" | ||
startIcon={<RedLinkIcon />} | ||
onClick={() => { | ||
navigator.clipboard?.writeText(pageUrl) | ||
setCopyText("Copied!") | ||
}} | ||
> | ||
{copyText} | ||
</CopyLinkButton> | ||
</LinkControls> | ||
</LinkContainer> | ||
</Contents> | ||
</StyledPopover> | ||
) | ||
} | ||
|
||
export default SharePopover |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nice touch :)