forked from nuotsu/sanitypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Social.tsx
69 lines (62 loc) · 1.49 KB
/
Social.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { getSite } from '@/lib/sanity'
import CTA from './CTA'
import { cn } from '@/lib/utils'
import {
FaFacebookF,
FaGithub,
FaInstagram,
FaLinkedinIn,
FaTiktok,
FaXTwitter,
FaYoutube,
} from 'react-icons/fa6'
import { IoIosLink } from 'react-icons/io'
export default async function Social({
className,
}: React.HTMLProps<HTMLDivElement>) {
const { social } = await getSite()
if (!social?.items?.length) return null
return (
<nav className={cn('group flex flex-wrap items-center', className)}>
{social.items.map((item, key) => {
switch (item._type) {
case 'link':
return (
<CTA
className="px-2 hover:!opacity-100 group-has-[a:hover]:opacity-50"
link={item}
key={key}
>
<Icon url={item.external} aria-label={item.label} />
</CTA>
)
default:
return null
}
})}
</nav>
)
}
function Icon({
url,
...props
}: { url?: string } & React.HTMLProps<SVGElement>) {
if (!url) return null
return url?.includes('facebook.com') ? (
<FaFacebookF {...props} />
) : url?.includes('github.com') ? (
<FaGithub {...props} />
) : url?.includes('instagram.com') ? (
<FaInstagram {...props} />
) : url?.includes('linkedin.com') ? (
<FaLinkedinIn {...props} />
) : url?.includes('tiktok.com') ? (
<FaTiktok {...props} />
) : url?.includes('twitter.com') || url?.includes('x.com') ? (
<FaXTwitter {...props} />
) : url?.includes('youtube.com') ? (
<FaYoutube {...props} />
) : (
<IoIosLink {...props} />
)
}