-
Notifications
You must be signed in to change notification settings - Fork 140
/
social-icon.js
62 lines (54 loc) · 1.6 KB
/
social-icon.js
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
import PropTypes from 'prop-types'
import React from 'react'
import Background from './background.js'
import Icon from './icon.js'
import Mask from './mask.js'
import { keyFor, keyTo, DEFAULT_KEY } from './networks.js'
import { socialIcon, socialContainer, socialSvg } from './styles.js'
function getNetworkKey(props) {
return props.network || keyFor(props.url)
}
function SocialIcon(props) {
const {
url, network, bgColor, fgColor, className, label, children, defaultSVG, style,
...rest
} = props
if (typeof defaultSVG === 'object' && defaultSVG !== null) {
keyTo(DEFAULT_KEY, defaultSVG);
}
const networkKey = getNetworkKey({ url, network })
return (
<a
{...rest}
href={url}
className={'social-icon' + (className ? ' ' + className : '')}
style={{ ...socialIcon, ...style }}
aria-label={label || networkKey}
>
<div className="social-container" style={socialContainer}>
<svg className="social-svg" style={socialSvg} viewBox="0 0 64 64">
<Background />
<Icon networkKey={networkKey} fgColor={fgColor} />
<Mask networkKey={networkKey} bgColor={bgColor} />
</svg>
</div>
{children}
</a>
)
}
SocialIcon.propTypes = {
className: PropTypes.string,
bgColor: PropTypes.string,
fgColor: PropTypes.string,
label: PropTypes.string,
network: PropTypes.string,
url: PropTypes.string,
defaultSVG: PropTypes.exact({
icon: PropTypes.string,
mask: PropTypes.string,
color: PropTypes.string,
}),
style: PropTypes.PropTypes.object,
children: PropTypes.node,
}
export default SocialIcon