tailwind-nextjs-blog/components/social-icons/index.tsx

44 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-10-17 23:37:01 +08:00
import Mail from './mail.svg';
import Github from './github.svg';
import Facebook from './facebook.svg';
import Youtube from './youtube.svg';
import Linkedin from './linkedin.svg';
import Twitter from './twitter.svg';
2022-07-17 21:40:41 +08:00
// Icons taken from: https://simpleicons.org/
const components = {
mail: Mail,
github: Github,
facebook: Facebook,
youtube: Youtube,
linkedin: Linkedin,
twitter: Twitter,
2022-10-17 23:37:01 +08:00
};
2022-07-17 21:40:41 +08:00
const SocialIcon = ({ kind, href, size = 8 }) => {
2022-10-17 23:37:01 +08:00
if (
!href ||
(kind === 'mail' &&
!/^mailto:\w+([.-]?\w+)@\w+([.-]?\w+)(.\w{2,3})+$/.test(href))
)
return null;
2022-07-17 21:40:41 +08:00
2022-10-17 23:37:01 +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"
2022-10-17 23:37:01 +08:00
href={href}>
2022-07-17 21:40:41 +08:00
<span className="sr-only">{kind}</span>
<SocialSvg
className={`fill-current text-gray-700 hover:text-blue-500 dark:text-gray-200 dark:hover:text-blue-400 h-${size} w-${size}`}
/>
</a>
2022-10-17 23:37:01 +08:00
);
};
2022-07-17 21:40:41 +08:00
2022-10-17 23:37:01 +08:00
export default SocialIcon;