-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathIcon.tsx
executable file
·84 lines (78 loc) · 2.46 KB
/
Icon.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import * as React from "react";
import { TextProps, GestureResponderEvent, TextStyle } from "react-native";
export enum IconType {
FontAwesome = "FontAwesome",
AntDesign = "AntDesign",
MaterialIcons = "MaterialIcons",
EvilIcons = "EvilIcons",
Entypo = "Entypo",
Foundation = "Foundation",
Ionicons = "Ionicons",
MaterialCommunityIcons = "MaterialCommunityIcons",
Zocial = "Zocial",
Octicons = "Octicons",
SimpleLineIcons = "SimpleLineIcons",
Fontisto = "Fontisto",
Feather = "Feather",
FontAwesome5 = "FontAwesome5",
}
export interface IconProps extends TextProps {
type: IconType;
name: string;
size?: number;
color?: string;
brand?: string;
solid?: string;
onPress?: (event: GestureResponderEvent) => void;
style?: TextStyle;
}
const iconComponents = {
[IconType.AntDesign]: require("react-native-vector-icons/AntDesign").default,
[IconType.Entypo]: require("react-native-vector-icons/Entypo").default,
[IconType.Ionicons]: require("react-native-vector-icons/Ionicons").default,
[IconType.SimpleLineIcons]:
require("react-native-vector-icons/SimpleLineIcons").default,
[IconType.EvilIcons]: require("react-native-vector-icons/EvilIcons").default,
[IconType.MaterialIcons]: require("react-native-vector-icons/MaterialIcons")
.default,
[IconType.FontAwesome]: require("react-native-vector-icons/FontAwesome")
.default,
[IconType.FontAwesome5]: require("react-native-vector-icons/FontAwesome5")
.default,
[IconType.Foundation]: require("react-native-vector-icons/Foundation")
.default,
[IconType.MaterialCommunityIcons]:
require("react-native-vector-icons/MaterialCommunityIcons").default,
[IconType.Zocial]: require("react-native-vector-icons/Zocial").default,
[IconType.Octicons]: require("react-native-vector-icons/Octicons").default,
[IconType.Fontisto]: require("react-native-vector-icons/Fontisto").default,
[IconType.Feather]: require("react-native-vector-icons/Feather").default,
};
const Icon = (props: IconProps): JSX.Element => {
const {
type,
name,
color = "#757575",
size = 20,
onPress = null,
style = {},
brand,
solid,
...textProps
} = props;
const IconComponent =
iconComponents[type] || iconComponents[IconType.MaterialIcons];
return (
<IconComponent
{...textProps}
name={name}
size={size}
style={style}
color={color}
onPress={onPress}
brand={brand}
solid={solid}
/>
);
};
export default Icon;