|
| 1 | +import React from "react"; |
| 2 | +import { FooterPartsPrimitiveProps } from "./types"; |
| 3 | +import { TwitterXIcon, GithubIcon, DiscordIcon, NostrIcon } from "../../icons"; |
| 4 | + |
| 5 | +type SupportedSocialMedia = "twitter" | "github" | "discord" | "nostr"; |
| 6 | + |
| 7 | +type ManadatorySocialMediaProps<T> = { |
| 8 | + entityLink: string; |
| 9 | + iconProps?: React.SVGProps<SVGSVGElement>; |
| 10 | +} & T; |
| 11 | + |
| 12 | + |
| 13 | +type SocialMediaProps = |
| 14 | + | ManadatorySocialMediaProps<{ |
| 15 | + entity: SupportedSocialMedia; |
| 16 | + icon?: React.ReactElement; |
| 17 | + }> |
| 18 | + | ManadatorySocialMediaProps<{ |
| 19 | + entity: Exclude<string, SupportedSocialMedia>; |
| 20 | + icon: React.ReactElement; |
| 21 | + }>; |
| 22 | + |
| 23 | +interface FooterSocialsProps extends FooterPartsPrimitiveProps<HTMLDivElement> { |
| 24 | + platforms: SocialMediaProps[]; |
| 25 | +} |
| 26 | + |
| 27 | +const Platform = ({ platform }: { platform: SocialMediaProps }) => { |
| 28 | + const { entity, entityLink, icon, iconProps } = platform; |
| 29 | + const { className, ...rest } = iconProps ?? {}; |
| 30 | + const getIcon = (entity: SocialMediaProps["entity"]) => { |
| 31 | + if (icon) { |
| 32 | + return React.cloneElement(icon, { ...rest, className }); |
| 33 | + } |
| 34 | + if (entity === "twitter") { |
| 35 | + return <TwitterXIcon className={`w-full ${className}`} {...rest} />; |
| 36 | + } |
| 37 | + if (entity === "github") { |
| 38 | + return <GithubIcon className={`w-full ${className}`} {...rest} />; |
| 39 | + } |
| 40 | + if (entity === "discord") { |
| 41 | + return <DiscordIcon className={`w-full ${className}`} {...rest} />; |
| 42 | + } |
| 43 | + if (entity === "nostr") { |
| 44 | + return <NostrIcon className={`w-full ${className}`} {...rest} />; |
| 45 | + } |
| 46 | + }; |
| 47 | + const iconElement = getIcon(entity); |
| 48 | + |
| 49 | + return ( |
| 50 | + <div className="flex items-center justify-center w-full max-w-[40px] min-w-[24px]"> |
| 51 | + <a |
| 52 | + href={entityLink} |
| 53 | + target="_blank" |
| 54 | + rel="noreferrer" |
| 55 | + className="underline font-medium" |
| 56 | + > |
| 57 | + {iconElement} |
| 58 | + </a> |
| 59 | + </div> |
| 60 | + ); |
| 61 | +}; |
| 62 | + |
| 63 | +/** |
| 64 | + * FooterSocials Component |
| 65 | + * @description Renders social media icons with links in the footer. |
| 66 | + * @param {FooterSocialsProps} props - The component props |
| 67 | + * @param {SocialMediaProps[]} props.platforms - Array of social media platform configurations |
| 68 | + * @remarks |
| 69 | + * Provides corresponding icons for twitter, github, discord, and nostr entities. |
| 70 | + * If a custom string is passed as entity, the icon prop is required. |
| 71 | + */ |
| 72 | + |
| 73 | +export const FooterSocials = ( |
| 74 | + props: React.PropsWithChildren<FooterSocialsProps> |
| 75 | +) => { |
| 76 | + const { className: classname, children, platforms, ...rest } = props; |
| 77 | + if (children) { |
| 78 | + <div {...rest} className={classname}> |
| 79 | + {props.children} |
| 80 | + </div>; |
| 81 | + } |
| 82 | + return ( |
| 83 | + <div |
| 84 | + {...rest} |
| 85 | + className={`text-black mb-[6px] md:mb-0 dark:text-white flex w-fit max-w-full gap-[24px] ${classname}`} |
| 86 | + > |
| 87 | + {platforms.map((platform, index) => ( |
| 88 | + <Platform key={platform.entity} platform={platform} /> |
| 89 | + ))} |
| 90 | + </div> |
| 91 | + ); |
| 92 | +}; |
| 93 | + |
| 94 | +FooterSocials.displayName = "FooterSocials"; |
0 commit comments