41 lines
995 B
TypeScript
Raw Normal View History

2023-07-22 18:16:06 +08:00
import { Mail, Github, Facebook, Youtube, Linkedin, Twitter, Mastodon } from './icons'
2021-01-09 17:50:45 +08:00
const components = {
mail: Mail,
github: Github,
facebook: Facebook,
youtube: Youtube,
linkedin: Linkedin,
twitter: Twitter,
2023-07-22 18:16:06 +08:00
mastodon: Mastodon,
}
type SocialIconProps = {
kind: keyof typeof components
href: string | undefined
size?: number
2021-01-09 17:50:45 +08:00
}
2023-07-22 18:16:06 +08:00
const SocialIcon = ({ kind, href, size = 8 }: SocialIconProps) => {
2021-08-26 12:31:07 +08:00
if (!href || (kind === 'mail' && !/^mailto:\w+([.-]?\w+)@\w+([.-]?\w+)(.\w{2,3})+$/.test(href)))
return null
2021-01-09 17:50:45 +08:00
const SocialSvg = components[kind]
return (
<a
2021-01-12 23:35:36 +08:00
className="text-sm text-gray-500 transition hover:text-gray-600"
2021-01-09 17:50:45 +08:00
target="_blank"
rel="noopener noreferrer"
href={href}
>
<span className="sr-only">{kind}</span>
<SocialSvg
2023-07-22 18:16:06 +08:00
className={`fill-current text-gray-700 hover:text-primary-500 dark:text-gray-200 dark:hover:text-primary-400 h-${size} w-${size}`}
2021-01-09 17:50:45 +08:00
/>
</a>
)
}
export default SocialIcon