58 lines
1.1 KiB
TypeScript
Raw Normal View History

import {
Mail,
Github,
Facebook,
Youtube,
Linkedin,
Twitter,
2024-05-01 11:09:29 +08:00
X,
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,
2024-05-01 11:09:29 +08:00
x: X,
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) => {
2024-06-23 17:45:11 +08:00
if (
!href ||
(kind === 'mail' && !/^mailto:[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(href))
)
2021-08-26 12:31:07 +08:00
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