mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-14 09:19:03 +05:30
39 lines
963 B
JavaScript
39 lines
963 B
JavaScript
import webFont from 'webfontloader';
|
|
import logger from 'services/logger';
|
|
|
|
export default {
|
|
/**
|
|
* @param {array} families
|
|
* @param {object} options
|
|
* @param {bool} [options.external=false] - whether the font should be loaded from external source (e.g. google)
|
|
*
|
|
* @return {Promise}
|
|
*/
|
|
load(families = [], options = {}) {
|
|
let config = {
|
|
custom: {families}
|
|
};
|
|
|
|
if (options.external) {
|
|
config = {
|
|
google: {families}
|
|
};
|
|
}
|
|
|
|
return new Promise((resolve) =>
|
|
webFont.load({
|
|
classes: false,
|
|
active: resolve,
|
|
inactive() {
|
|
logger.warn('Failed loading the font', {
|
|
families
|
|
});
|
|
resolve();
|
|
},
|
|
timeout: 2000,
|
|
...config
|
|
})
|
|
);
|
|
}
|
|
};
|