-
Notifications
You must be signed in to change notification settings - Fork 1
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 #745 from CodeForAfrica/fix/roboshield_social_link
Fix @/roboshield social links
- Loading branch information
Showing
10 changed files
with
135 additions
and
88 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
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
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
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
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
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
22 changes: 22 additions & 0 deletions
22
apps/roboshield/src/components/SocialMediaLinkIcon/LinkIcon.tsx
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Link, RichTypography } from "@commons-ui/next"; | ||
import { Grid, SvgIcon } from "@mui/material"; | ||
import type { LinkProps, SvgIconProps } from "@mui/material"; | ||
import React from "react"; | ||
|
||
interface LinkIconProps extends LinkProps { | ||
IconProps: SvgIconProps; | ||
} | ||
|
||
const LinkIcon = React.forwardRef(function LinkIcon( | ||
{ IconProps, ...props }: LinkIconProps, | ||
ref: React.ForwardedRef<HTMLAnchorElement>, | ||
) { | ||
return ( | ||
<Link {...props} ref={ref}> | ||
<SvgIcon {...IconProps} /> | ||
</Link> | ||
); | ||
}); | ||
|
||
export type { LinkIconProps }; | ||
export default LinkIcon; |
64 changes: 64 additions & 0 deletions
64
apps/roboshield/src/components/SocialMediaLinkIcon/SocialMediaLinkIcon.tsx
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Link, RichTypography } from "@commons-ui/next"; | ||
import { Grid, SvgIcon } from "@mui/material"; | ||
import React from "react"; | ||
|
||
import FacebookIcon from "@/roboshield/assets/icons/Type=facebook, Size=24, Color=CurrentColor.svg"; | ||
import GitHubIcon from "@/roboshield/assets/icons/Type=github, Size=24, Color=CurrentColor.svg"; | ||
import InstagramIcon from "@/roboshield/assets/icons/Type=instagram, Size=24, Color=CurrentColor.svg"; | ||
import LinkedInIcon from "@/roboshield/assets/icons/Type=linkedin, Size=24, Color=CurrentColor.svg"; | ||
import SlackIcon from "@/roboshield/assets/icons/Type=slack, Size=24, Color=CurrentColor.svg"; | ||
import TwitterIcon from "@/roboshield/assets/icons/Type=twitter, Size=24, Color=CurrentColor.svg"; | ||
|
||
import LinkIcon from "./LinkIcon"; | ||
import type { LinkIconProps } from "./LinkIcon"; | ||
|
||
const platformToIconMap = new Map<string, any>(); | ||
platformToIconMap.set("Facebook", FacebookIcon); | ||
platformToIconMap.set("Twitter", TwitterIcon); | ||
platformToIconMap.set("Instagram", InstagramIcon); | ||
platformToIconMap.set("Linkedin", LinkedInIcon); | ||
platformToIconMap.set("Github", GitHubIcon); | ||
platformToIconMap.set("Slack", SlackIcon); | ||
|
||
type SocialMediaPlatform = | ||
| "Facebook" | ||
| "Github" | ||
| "Instagram" | ||
| "LinkedIn" | ||
| "Slack" | ||
| "Twitter"; | ||
|
||
interface SocialMediaLink { | ||
platform: SocialMediaPlatform; | ||
// TODO(koech): Confirm why we chose url instead of href in the CMS | ||
url: string; | ||
} | ||
|
||
interface SocialMediaLinkIconProps extends Omit<LinkIconProps, "href"> { | ||
platform: SocialMediaPlatform; | ||
url: string; | ||
} | ||
|
||
const SocialMediaLinkIcon = React.forwardRef(function SocialMediaLinkIcon( | ||
{ IconProps, url, platform, ...props }: SocialMediaLinkIconProps, | ||
ref: React.ForwardedRef<HTMLAnchorElement>, | ||
) { | ||
const Icon = platformToIconMap.get(platform); | ||
|
||
if (!Icon) { | ||
return null; | ||
} | ||
return ( | ||
<LinkIcon | ||
{...props} | ||
IconProps={{ | ||
component: Icon, | ||
...IconProps, | ||
}} | ||
href={url} | ||
/> | ||
); | ||
}); | ||
|
||
export type { SocialMediaLink, SocialMediaLinkIconProps, SocialMediaPlatform }; | ||
export default SocialMediaLinkIcon; |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { | ||
SocialMediaLink, | ||
SocialMediaLinkIconProps, | ||
SocialMediaPlatform, | ||
} from "./SocialMediaLinkIcon"; | ||
import SocialMediaLinkIcon from "./SocialMediaLinkIcon"; | ||
|
||
export type { SocialMediaLink, SocialMediaLinkIconProps, SocialMediaPlatform }; | ||
export default SocialMediaLinkIcon; |
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