Warn when uncached icons are used
Reviewed By: passy Differential Revision: D17602743 fbshipit-source-id: 8f7dc0cc8d181ad4f7784ed3aafe064d816832c9
This commit is contained in:
committed by
Facebook Github Bot
parent
9d4cc64bc9
commit
2bd8548252
@@ -14,37 +14,7 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const {remote} = require('electron');
|
||||
|
||||
// Takes a string like 'star', or 'star-outline', and converts it to
|
||||
// {trimmedName: 'star', variant: 'filled'} or {trimmedName: 'star', variant: 'outline'}
|
||||
function getIconPartsFromName(icon) {
|
||||
const isOutlineVersion = icon.endsWith('-outline');
|
||||
const trimmedName = isOutlineVersion ? icon.replace('-outline', '') : icon;
|
||||
const variant = isOutlineVersion ? 'outline' : 'filled';
|
||||
return {trimmedName: trimmedName, variant: variant};
|
||||
}
|
||||
|
||||
// $FlowFixMe not using flow in this file
|
||||
function buildLocalIconPath(name, size, density) {
|
||||
const icon = getIconPartsFromName(name);
|
||||
|
||||
return path.join(
|
||||
'icons',
|
||||
`${icon.trimmedName}-${icon.variant}-${size}@${density}x.png`,
|
||||
);
|
||||
}
|
||||
|
||||
// $FlowFixMe not using flow in this file
|
||||
function buildIconURL(name, size, density) {
|
||||
const icon = getIconPartsFromName(name);
|
||||
return `https://external.xx.fbcdn.net/assets/?name=${
|
||||
icon.trimmedName
|
||||
}&variant=${
|
||||
icon.variant
|
||||
}&size=${size}&set=facebook_icons&density=${density}x`;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ICONS: {
|
||||
const ICONS = {
|
||||
'arrow-right': [12],
|
||||
'caution-octagon': [16],
|
||||
'caution-triangle': [16],
|
||||
@@ -65,7 +35,47 @@ module.exports = {
|
||||
'chevron-down': [8],
|
||||
star: [16, 24],
|
||||
'star-outline': [16, 24],
|
||||
},
|
||||
};
|
||||
|
||||
// Takes a string like 'star', or 'star-outline', and converts it to
|
||||
// {trimmedName: 'star', variant: 'filled'} or {trimmedName: 'star', variant: 'outline'}
|
||||
function getIconPartsFromName(icon) {
|
||||
const isOutlineVersion = icon.endsWith('-outline');
|
||||
const trimmedName = isOutlineVersion ? icon.replace('-outline', '') : icon;
|
||||
const variant = isOutlineVersion ? 'outline' : 'filled';
|
||||
return {trimmedName: trimmedName, variant: variant};
|
||||
}
|
||||
|
||||
// $FlowFixMe not using flow in this file
|
||||
function buildLocalIconPath(name, size, density) {
|
||||
const icon = getIconPartsFromName(name);
|
||||
return path.join(
|
||||
'icons',
|
||||
`${icon.trimmedName}-${icon.variant}-${size}@${density}x.png`,
|
||||
);
|
||||
}
|
||||
|
||||
// $FlowFixMe not using flow in this file
|
||||
function buildIconURL(name, size, density) {
|
||||
const icon = getIconPartsFromName(name);
|
||||
const url = `https://external.xx.fbcdn.net/assets/?name=${
|
||||
icon.trimmedName
|
||||
}&variant=${
|
||||
icon.variant
|
||||
}&size=${size}&set=facebook_icons&density=${density}x`;
|
||||
if (
|
||||
typeof window !== 'undefined' &&
|
||||
(!ICONS[name] || !ICONS[name].includes(size))
|
||||
) {
|
||||
console.warn(
|
||||
`Using uncached icon: "${name}: [${size}]" Add it to icons.js to preload it.`,
|
||||
);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ICONS: ICONS,
|
||||
|
||||
buildLocalIconPath: buildLocalIconPath,
|
||||
buildIconURL: buildIconURL,
|
||||
|
||||
Reference in New Issue
Block a user