1
- import { SocialIcon } from "react-social-icons" ;
1
+ import { SocialIcon , SocialIconProps } from "react-social-icons" ;
2
2
3
3
type SocialNetworkType =
4
4
| "linkedin"
@@ -12,15 +12,37 @@ interface SocialNetworkProps {
12
12
type : SocialNetworkType ;
13
13
}
14
14
15
- const baseHref : Record < SocialNetworkType , string > = {
16
- linkedin : "https://linkedin.com/in/" ,
17
- linkedinCompany : "https://linkdein.com/company/" ,
18
- email : "mailto:" ,
19
- github : "https://github.com/" ,
20
- website : "" ,
15
+ type SocialNetwork = {
16
+ baseHref : string ;
17
+ extraProps ?: SocialIconProps ;
18
+ transform ?( t : string , baseHref : string ) : string ;
19
+ } ;
20
+
21
+ const socialNetworks : Record < SocialNetworkType , SocialNetwork > = {
22
+ linkedin : { baseHref : "https://linkedin.com/in/" } ,
23
+ linkedinCompany : { baseHref : "https://linkdein.com/company/" } ,
24
+ email : { baseHref : "mailto:" } ,
25
+ github : { baseHref : "https://github.com/" } ,
26
+ website : {
27
+ baseHref : "" ,
28
+ transform : ( text ) => {
29
+ if ( ! text . startsWith ( "http" ) ) return `https://${ text } ` ;
30
+ return text ;
31
+ } ,
32
+ extraProps : { bgColor : "#323363" } ,
33
+ } ,
21
34
} ;
22
35
23
36
export function SocialNetwork ( { text, type } : SocialNetworkProps ) {
24
- const url = `${ baseHref [ type ] } ${ text } ` ;
25
- return < SocialIcon url = { url } style = { { height : 32 , width : 32 } } /> ;
37
+ const socialNetwork = socialNetworks [ type ] ;
38
+ const url = socialNetwork . transform
39
+ ? socialNetwork . transform ( text , socialNetwork . baseHref )
40
+ : `${ socialNetwork . baseHref } ${ text } ` ;
41
+ return (
42
+ < SocialIcon
43
+ url = { url }
44
+ style = { { height : 32 , width : 32 } }
45
+ { ...( socialNetwork . extraProps ?? { } ) }
46
+ />
47
+ ) ;
26
48
}
0 commit comments