2023-08-16 23:55:57 +08:00
|
|
|
import {
|
|
|
|
Mail,
|
|
|
|
Github,
|
|
|
|
Facebook,
|
|
|
|
Youtube,
|
|
|
|
Linkedin,
|
|
|
|
Twitter,
|
|
|
|
Mastodon,
|
|
|
|
} from './icons';
|
2022-07-17 21:40:41 +08:00
|
|
|
|
|
|
|
const components = {
|
|
|
|
mail: Mail,
|
|
|
|
github: Github,
|
|
|
|
facebook: Facebook,
|
|
|
|
youtube: Youtube,
|
|
|
|
linkedin: Linkedin,
|
|
|
|
twitter: Twitter,
|
2023-08-16 23:29:22 +08:00
|
|
|
mastodon: Mastodon,
|
2023-08-16 23:55:57 +08:00
|
|
|
};
|
2022-07-17 21:40:41 +08:00
|
|
|
|
2023-08-16 23:29:22 +08:00
|
|
|
type SocialIconProps = {
|
2023-08-16 23:55:57 +08:00
|
|
|
kind: keyof typeof components;
|
|
|
|
href: string | undefined;
|
|
|
|
size?: number;
|
|
|
|
};
|
2022-07-17 21:40:41 +08:00
|
|
|
|
2023-08-16 23:29:22 +08:00
|
|
|
const SocialIcon = ({ kind, href, size = 8 }: SocialIconProps) => {
|
2023-08-16 23:55:57 +08:00
|
|
|
if (
|
|
|
|
!href ||
|
|
|
|
(kind === 'mail' &&
|
|
|
|
!/^mailto:\w+([.-]?\w+)@\w+([.-]?\w+)(.\w{2,3})+$/.test(href))
|
|
|
|
)
|
|
|
|
return null;
|
2023-08-16 23:29:22 +08:00
|
|
|
|
2023-08-16 23:55:57 +08:00
|
|
|
const SocialSvg = components[kind];
|
2022-07-17 21:40:41 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<a
|
|
|
|
className="text-sm text-gray-500 transition hover:text-gray-600"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
2023-08-16 23:55:57 +08:00
|
|
|
href={href}>
|
2022-07-17 21:40:41 +08:00
|
|
|
<span className="sr-only">{kind}</span>
|
|
|
|
<SocialSvg
|
2023-08-16 23:29:22 +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}`}
|
2022-07-17 21:40:41 +08:00
|
|
|
/>
|
|
|
|
</a>
|
2023-08-16 23:55:57 +08:00
|
|
|
);
|
|
|
|
};
|
2022-07-17 21:40:41 +08:00
|
|
|
|
2023-08-16 23:55:57 +08:00
|
|
|
export default SocialIcon;
|