33 * Usage: <Fontello name="icon-name" size={20} color="#4F8EF7" />
44 */
55
6- import { createIconSet } from '@react-native-vector-icons/common' ;
6+ import { type CreateIconSetOptions , createIconSet , type IconComponent } from '@react-native-vector-icons/common' ;
77
88type FontelloConfig = {
99 name : string ;
@@ -20,13 +20,41 @@ type FontelloConfig = {
2020 } > ;
2121} ;
2222
23- export default function createIconSetFromFontello ( config : FontelloConfig , fontFamilyArg ?: string , fontFile ?: string ) {
23+ type FontelloComponent = IconComponent < Record < string , number > > ;
24+
25+ // entries are optional because they can be derived from the config
26+ type Options = Partial < CreateIconSetOptions > ;
27+
28+ export default function createIconSetFromFontello (
29+ config : FontelloConfig ,
30+ postScriptName ?: string ,
31+ fontFileName ?: string ,
32+ ) : FontelloComponent ;
33+ export default function createIconSetFromFontello ( config : FontelloConfig , options : Options ) : FontelloComponent ;
34+ export default function createIconSetFromFontello (
35+ config : FontelloConfig ,
36+ postScriptNameOrOptions ?: string | Options ,
37+ fontFileNameParam ?: string ,
38+ ) : FontelloComponent {
39+ const { postScriptName, fontFileName, fontSource, fontStyle } =
40+ typeof postScriptNameOrOptions === 'object'
41+ ? postScriptNameOrOptions
42+ : {
43+ postScriptName : postScriptNameOrOptions ,
44+ fontFileName : fontFileNameParam ,
45+ } ;
46+
2447 const glyphMap : Record < string , number > = { } ;
2548 config . glyphs . forEach ( ( glyph ) => {
2649 glyphMap [ glyph . css ] = glyph . code ;
2750 } ) ;
2851
29- const fontFamily = fontFamilyArg || config . name || 'fontello' ;
52+ const fontFamily = postScriptName || config . name || 'fontello' ;
3053
31- return createIconSet ( glyphMap , fontFamily , fontFile || `${ fontFamily } .ttf` ) ;
54+ return createIconSet ( glyphMap , {
55+ postScriptName : fontFamily ,
56+ fontFileName : fontFileName || `${ fontFamily } .ttf` ,
57+ fontSource,
58+ fontStyle,
59+ } ) ;
3260}
0 commit comments