UNPKG

1.96 kBJavaScriptView Raw
1import { Platform } from 'react-native';
2import createMultiStyleIconSet from './createMultiStyleIconSet';
3export const FA5Style = {
4 regular: 'regular',
5 light: 'light',
6 solid: 'solid',
7 brand: 'brand',
8};
9export function createFA5iconSet(glyphMap, metadata = {}, fonts, pro = false) {
10 const metadataKeys = Object.keys(metadata);
11 const fontFamily = `FontAwesome5${pro ? 'Pro' : 'Free'}`;
12 function fallbackFamily(glyph) {
13 for (let i = 0; i < metadataKeys.length; i += 1) {
14 const family = metadataKeys[i];
15 if (metadata[family].indexOf(glyph) !== -1) {
16 return family === 'brands' ? 'brand' : family;
17 }
18 }
19 return 'regular';
20 }
21 function glyphValidator(glyph, style) {
22 const family = style === 'brand' ? 'brands' : style;
23 if (metadataKeys.indexOf(family) === -1)
24 return false;
25 return metadata[family].indexOf(glyph) !== -1;
26 }
27 function createFontAwesomeStyle(styleName, fontWeight, family = fontFamily) {
28 let fontFile = fonts[styleName];
29 return {
30 fontFamily: `${family}-${styleName}`,
31 fontFile,
32 fontStyle: Platform.select({
33 ios: {
34 fontWeight,
35 },
36 default: {},
37 }),
38 glyphMap,
39 };
40 }
41 const brandIcons = createFontAwesomeStyle('Brand', '400');
42 const lightIcons = createFontAwesomeStyle('Light', '100');
43 const regularIcons = createFontAwesomeStyle('Regular', '400');
44 const solidIcons = createFontAwesomeStyle('Solid', '700');
45 const Icon = createMultiStyleIconSet({
46 brand: brandIcons,
47 light: lightIcons,
48 regular: regularIcons,
49 solid: solidIcons,
50 }, {
51 defaultStyle: 'regular',
52 fallbackFamily,
53 glyphValidator,
54 });
55 return Icon;
56}
57//# sourceMappingURL=createIconSetFromFontAwesome5.js.map
\No newline at end of file