2024-01-03 03:42:42 -05:00
|
|
|
import {
|
|
|
|
Mail,
|
|
|
|
Github,
|
|
|
|
Facebook,
|
|
|
|
Youtube,
|
|
|
|
Linkedin,
|
|
|
|
Twitter,
|
2024-05-01 11:09:29 +08:00
|
|
|
X,
|
2024-01-03 03:42:42 -05:00
|
|
|
Mastodon,
|
|
|
|
Threads,
|
|
|
|
Instagram,
|
2024-09-20 18:52:18 +09:00
|
|
|
Medium,
|
2025-01-25 10:57:16 -06:00
|
|
|
Resume,
|
2024-01-03 03:42:42 -05:00
|
|
|
} 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,
|
2024-01-03 03:42:42 -05:00
|
|
|
threads: Threads,
|
|
|
|
instagram: Instagram,
|
2024-09-20 18:52:18 +09:00
|
|
|
medium: Medium,
|
2025-01-25 10:57:16 -06:00
|
|
|
resume: Resume,
|
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-03-20 22:47:09 +08:00
|
|
|
|
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
|