@@ -37,15 +37,16 @@ var GoogleFontLoader = function (_React$PureComponent) {
37
37
}
38
38
39
39
return _ret = ( _temp = ( _this = _possibleConstructorReturn ( this , ( _ref = GoogleFontLoader . __proto__ || Object . getPrototypeOf ( GoogleFontLoader ) ) . call . apply ( _ref , [ this ] . concat ( args ) ) ) , _this ) , _this . link = null , _this . createLink = function ( ) {
40
- var fonts = _this . props . fonts ;
40
+ var _this$props = _this . props ,
41
+ fonts = _this$props . fonts ,
42
+ subsets = _this$props . subsets ;
41
43
42
44
43
45
var families = fonts . reduce ( function ( acc , font ) {
44
46
var family = font . font . replace ( / + / g, '+' ) ;
45
47
var weights = ( font . weights || [ ] ) . join ( ',' ) ;
46
- var subsets = ( font . subsets || [ ] ) . join ( ',' ) ;
47
48
48
- acc . push ( family + ( weights && ':' + weights ) + ( subsets && '&subset=' + subsets ) ) ;
49
+ acc . push ( family + ( weights && ':' + weights ) ) ;
49
50
50
51
return acc ;
51
52
} , [ ] ) . join ( '|' ) ;
@@ -54,6 +55,10 @@ var GoogleFontLoader = function (_React$PureComponent) {
54
55
link . rel = 'stylesheet' ;
55
56
link . href = 'https://fonts.googleapis.com/css?family=' + families ;
56
57
58
+ if ( subsets && Array . isArray ( subsets ) && subsets . length > 0 ) {
59
+ link . href += '&subset=' + subsets . join ( ',' ) ;
60
+ }
61
+
57
62
return link ;
58
63
} , _this . appendLink = function ( ) {
59
64
return document . head . appendChild ( _this . link ) ;
@@ -94,9 +99,9 @@ var GoogleFontLoader = function (_React$PureComponent) {
94
99
GoogleFontLoader . propTypes = {
95
100
fonts : _propTypes2 . default . arrayOf ( _propTypes2 . default . shape ( {
96
101
font : _propTypes2 . default . string . isRequired ,
97
- weights : _propTypes2 . default . arrayOf ( _propTypes2 . default . oneOf ( [ _propTypes2 . default . string , _propTypes2 . default . number ] ) ) ,
98
- subsets : _propTypes2 . default . arrayOf ( _propTypes2 . default . string )
99
- } ) ) . isRequired
102
+ weights : _propTypes2 . default . arrayOf ( _propTypes2 . default . oneOfType ( [ _propTypes2 . default . string , _propTypes2 . default . number ] ) )
103
+ } ) ) . isRequired ,
104
+ subsets : _propTypes2 . default . arrayOf ( _propTypes2 . default . string )
100
105
} ;
101
106
102
107
exports . default = GoogleFontLoader ;
0 commit comments