Files
sage-home/components/social-icons/index.tsx
砂糖 70f337bb92 init
2026-01-24 16:54:44 +08:00

63 lines
1.2 KiB
TypeScript

import {
Facebook,
Github,
Instagram,
JueJin,
Linkedin,
Mail,
Mastodon,
Threads,
Twitter,
TwitterX,
WeChat,
Youtube
} from './icons'
const components = {
mail: Mail,
github: Github,
facebook: Facebook,
youtube: Youtube,
linkedin: Linkedin,
twitter: Twitter,
twitterX: TwitterX,
weChat: WeChat,
jueJin: JueJin,
mastodon: Mastodon,
threads: Threads,
instagram: Instagram
}
type SocialIconProps = {
kind: keyof typeof components
href: string | undefined
size?: number
}
const SocialIcon = ({ kind, href, size = 8 }: SocialIconProps) => {
if (
!href ||
(kind === 'mail' &&
!/^mailto:\w+([.-]?\w+)@\w+([.-]?\w+)(.\w{2,3})+$/.test(href))
)
return null
const SocialSvg = components[kind]
return (
<a
className="text-sm text-gray-500 transition hover:text-gray-600"
target="_blank"
rel="noopener noreferrer"
href={href}
>
<span className="sr-only">{kind}</span>
<SocialSvg
className={`fill-current text-gray-400 hover:text-primary-500 dark:text-gray-200 dark:hover:text-primary-400 h-${size} w-${size}`}
/>
</a>
)
}
export default SocialIcon