53 lines
1.1 KiB
TypeScript
Raw Normal View History

import {
Mail,
Github,
Facebook,
Youtube,
Linkedin,
Twitter,
Mastodon,
Threads,
Instagram,
} 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,
threads: Threads,
instagram: Instagram,
2023-07-22 18:16:06 +08:00
}
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