Skip to content

Commit b29a190

Browse files
committed
Add subsets and minor improvements
Added an option to also fetch subsets, and an changed weight type to string from number. Fixes #3
1 parent 6b4b085 commit b29a190

File tree

6 files changed

+6654
-6
lines changed

6 files changed

+6654
-6
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ const App = () => (
2626
{
2727
font: 'Roboto',
2828
weights: [400],
29+
subsets: ['cyrillic-ext', 'greek'],
2930
},
3031
{
3132
font: 'Roboto Mono',
3233
weights: [400, 700],
34+
subsets: ['cyrillic-ext', 'greek'],
3335
},
3436
]} />
3537

@@ -48,6 +50,7 @@ The Component takes one prop: `fonts`. It should be an array of objects describi
4850
{
4951
font: 'Roboto Mono', // The name of the font on Google Fonts.
5052
weights: [400, 700], // An array of weights you want to load.
53+
['cyrillic-ext', 'greek'], // An array of subsets you want to load.
5154
},
5255
// ...
5356
// You can include as many of these objects as you want.

build/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import * as React from 'react';
22

33
export interface Font {
44
font: string;
5-
weights?: number[];
5+
weights?: string[];
6+
subsets?: string[];
67
}
78

89
export interface GoogleFontLoaderProps {

build/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ var GoogleFontLoader = function (_React$PureComponent) {
4343
var families = fonts.reduce(function (acc, font) {
4444
var family = font.font.replace(/ +/g, '+');
4545
var weights = (font.weights || []).join(',');
46+
var subsets = (font.subsets || []).join(',');
4647

47-
acc.push(family + (weights && ':' + weights));
48+
acc.push(family + (weights && ':' + weights) + (subsets && '&subset=' + subsets));
4849

4950
return acc;
5051
}, []).join('|');
@@ -93,7 +94,8 @@ var GoogleFontLoader = function (_React$PureComponent) {
9394
GoogleFontLoader.propTypes = {
9495
fonts: _propTypes2.default.arrayOf(_propTypes2.default.shape({
9596
font: _propTypes2.default.string.isRequired,
96-
weights: _propTypes2.default.arrayOf(_propTypes2.default.number)
97+
weights: _propTypes2.default.arrayOf(_propTypes2.default.string),
98+
subsets: _propTypes2.default.arrayOf(_propTypes2.default.string)
9799
})).isRequired
98100
};
99101

0 commit comments

Comments
 (0)