-
Notifications
You must be signed in to change notification settings - Fork 276
/
Copy pathgetSocialPlatformDetails.tsx
63 lines (60 loc) · 1.58 KB
/
getSocialPlatformDetails.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
import { githubSvg } from '../../internal/svg/githubSvg';
import { twitterSvg } from '../../internal/svg/twitterSvg';
import { warpcastSvg } from '../../internal/svg/warpcastSvg';
import { websiteSvg } from '../../internal/svg/websiteSvg';
import { border, cn, pressable } from '../../styles/theme';
export type SocialPlatform = 'twitter' | 'github' | 'farcaster' | 'website';
export const PLATFORM_CONFIG: Record<
SocialPlatform,
{ href: (value: string) => string; icon: React.ReactNode }
> = {
twitter: {
href: (value) => `https://x.com/${value}`,
icon: twitterSvg,
},
github: {
href: (value) => `https://github.com/${value}`,
icon: githubSvg,
},
farcaster: {
href: (value) => {
const username = value.split('/').pop();
return `https://warpcast.com/${username}`;
},
icon: warpcastSvg,
},
website: {
href: (value) => value,
icon: websiteSvg,
},
};
export function GetSocialPlatformDetails({
platform,
value,
}: {
platform: SocialPlatform;
value: string;
}) {
const config = PLATFORM_CONFIG[platform];
return (
<a
href={config.href(value)}
target="_blank"
rel="noopener noreferrer"
className={cn(
pressable.default,
border.radius,
border.default,
'flex items-center justify-center p-2',
)}
data-testid={`ockSocials_${
platform.charAt(0).toUpperCase() + platform.slice(1)
}`}
>
<span className="sr-only">{platform}</span>
<div className={cn('flex h-4 w-4 items-center justify-center')}>
{config.icon}
</div>
</a>
);
}