-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfont.js
54 lines (47 loc) · 947 Bytes
/
font.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
import { load } from 'webfontloader'
import { Component, PropTypes } from 'react'
export default class Font extends Component {
componentDidMount() {
this.load()
}
componentDidUpdate() {
this.load()
}
load() {
const { props } = this
let source = props.source
let weight = ''
let urls
if (props.family === 'FontAwesome') {
source = 'custom'
urls = [
'https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css'
]
} else {
weight = `:${props.weight}`
}
load({
[source]: {
families: [
`${props.family}${weight}`
],
urls
}
})
}
render() {
return null
}
}
Font.defaultProps = {
source: 'google',
weight: '300'
}
Font.propTypes = {
family: PropTypes.string.isRequired,
source: PropTypes.oneOf([
'custom',
'google'
]).isRequired,
weight: PropTypes.string.isRequired
}