|
| 1 | +import { ExternalLink } from "~/components/ui/Link"; |
| 2 | +import { |
| 3 | + SiFarcaster as Farcaster, |
| 4 | + SiTelegram as Telegram, |
| 5 | +} from "react-icons/si"; |
| 6 | +import { FaXTwitter as Twitter } from "react-icons/fa6"; |
| 7 | +import { LuGithub as Github, LuGlobe as Globe } from "react-icons/lu"; |
| 8 | +import { MdOutlineMail as Mail } from "react-icons/md"; |
| 9 | +import { type IconType } from "react-icons/lib"; |
| 10 | + |
| 11 | +const InfoItem = ({ |
| 12 | + type, |
| 13 | + value, |
| 14 | +}: { |
| 15 | + type: "github" | "twitter" | "farcaster" | "telegram" | "email" | "country"; |
| 16 | + value: string; |
| 17 | +}) => { |
| 18 | + const Icon: IconType | undefined = { |
| 19 | + github: Github, |
| 20 | + twitter: Twitter, |
| 21 | + farcaster: Farcaster, |
| 22 | + telegram: Telegram, |
| 23 | + email: Mail, |
| 24 | + country: Globe, |
| 25 | + }[type]; |
| 26 | + |
| 27 | + const sanitizedValue = value.startsWith("@") ? value.slice(1) : value; |
| 28 | + |
| 29 | + const url = |
| 30 | + sanitizedValue.startsWith("http://") || |
| 31 | + sanitizedValue.startsWith("https://") |
| 32 | + ? sanitizedValue |
| 33 | + : { |
| 34 | + github: `https://github.com/${sanitizedValue}`, |
| 35 | + twitter: `https://x.com/${sanitizedValue}`, |
| 36 | + farcaster: `https://warpcast.com/${sanitizedValue}`, |
| 37 | + telegram: `https://t.me/${sanitizedValue}`, |
| 38 | + email: `mailto:${sanitizedValue}`, |
| 39 | + country: `https://www.google.com/maps/search/${sanitizedValue}`, |
| 40 | + }[type]; |
| 41 | + |
| 42 | + if (type === "country") { |
| 43 | + return ( |
| 44 | + <div className="flex gap-2"> |
| 45 | + <Icon className="mt-1 h-4 w-4" /> |
| 46 | + {value} |
| 47 | + </div> |
| 48 | + ); |
| 49 | + } |
| 50 | + |
| 51 | + return ( |
| 52 | + <ExternalLink href={url} className="flex gap-2 hover:underline"> |
| 53 | + <Icon className="mt-1 h-4 w-4" /> |
| 54 | + {value} |
| 55 | + </ExternalLink> |
| 56 | + ); |
| 57 | +}; |
| 58 | + |
| 59 | +export interface InfoBoxProps { |
| 60 | + label: string; |
| 61 | + elements?: { |
| 62 | + type: "github" | "twitter" | "farcaster" | "telegram" | "email" | "country"; |
| 63 | + value?: string; |
| 64 | + }[]; |
| 65 | +} |
| 66 | + |
| 67 | +export const InfoBox = ({ label, elements }: InfoBoxProps) => { |
| 68 | + const filteredElements = elements?.filter(({ value }) => value); |
| 69 | + return ( |
| 70 | + <div className="rounded-xl border p-3 dark:border-gray-700"> |
| 71 | + <div className="mb-2 font-bold tracking-wider text-gray-600 dark:text-gray-500"> |
| 72 | + {label} |
| 73 | + </div> |
| 74 | + <div className="space-y-2"> |
| 75 | + {filteredElements?.map(({ type, value }, i) => ( |
| 76 | + <InfoItem key={i} type={type} value={value!} /> |
| 77 | + ))} |
| 78 | + </div> |
| 79 | + </div> |
| 80 | + ); |
| 81 | +}; |
0 commit comments