Skip to content

Commit b2e553b

Browse files
committed
Move 'subsets' to standalone prop rather than per font, Google Fonts doesn't support per font subsets
1 parent c7da775 commit b2e553b

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import * as React from 'react';
33
export interface Font {
44
font: string;
55
weights?: (string|number)[];
6-
subsets?: string[];
76
}
87

98
export interface GoogleFontLoaderProps {
109
fonts: Font[];
10+
subsets?: string[];
1111
}
1212

1313
declare class GoogleFontLoader extends React.PureComponent<GoogleFontLoaderProps> {};

src/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ class GoogleFontLoader extends React.PureComponent {
55
link = null;
66

77
createLink = () => {
8-
const { fonts } = this.props;
8+
const { fonts, subsets } = this.props;
99

1010
const families = fonts.reduce((acc, font) => {
1111
const family = font.font.replace(/ +/g, '+');
1212
const weights = (font.weights || []).join(',');
13-
const subsets = (font.subsets || []).join(',');
1413

15-
acc.push(family + (weights && `:${weights}`) + (subsets && `&subset=${subsets}`));
14+
acc.push(family + (weights && `:${weights}`));
1615

1716
return acc;
1817
}, []).join('|');
@@ -21,6 +20,10 @@ class GoogleFontLoader extends React.PureComponent {
2120
link.rel = 'stylesheet';
2221
link.href = `https://fonts.googleapis.com/css?family=${families}`;
2322

23+
if (subsets && Array.isArray(subsets) && subsets.length > 0) {
24+
link.href += `&subset=${subsets.join(',')}`;
25+
}
26+
2427
return link;
2528
}
2629

@@ -57,9 +60,9 @@ GoogleFontLoader.propTypes = {
5760
PropTypes.shape({
5861
font: PropTypes.string.isRequired,
5962
weights: PropTypes.arrayOf(PropTypes.oneOf([PropTypes.string, PropTypes.number])),
60-
subsets: PropTypes.arrayOf(PropTypes.string),
6163
}),
6264
).isRequired,
65+
subsets: PropTypes.arrayOf(PropTypes.string),
6366
};
6467

6568
export default GoogleFontLoader;

0 commit comments

Comments
 (0)