1
+ "use strict" ;
2
+
3
+ Object . defineProperty ( exports , "__esModule" , {
4
+ value : true
5
+ } ) ;
6
+ exports . default = FontAwesomeIcon ;
7
+
8
+ var _react = _interopRequireDefault ( require ( "react" ) ) ;
9
+
10
+ var _converter = _interopRequireDefault ( require ( "../converter" ) ) ;
11
+
12
+ var _propTypes = _interopRequireDefault ( require ( "prop-types" ) ) ;
13
+
14
+ var _reactNative = require ( "react-native" ) ;
15
+
16
+ var _fontawesomeSvgCore = require ( "@fortawesome/fontawesome-svg-core" ) ;
17
+
18
+ var _logger = _interopRequireDefault ( require ( "../logger" ) ) ;
19
+
20
+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
21
+
22
+ function _objectSpread ( target ) { for ( var i = 1 ; i < arguments . length ; i ++ ) { var source = arguments [ i ] != null ? arguments [ i ] : { } ; var ownKeys = Object . keys ( source ) ; if ( typeof Object . getOwnPropertySymbols === 'function' ) { ownKeys = ownKeys . concat ( Object . getOwnPropertySymbols ( source ) . filter ( function ( sym ) { return Object . getOwnPropertyDescriptor ( source , sym ) . enumerable ; } ) ) ; } ownKeys . forEach ( function ( key ) { _defineProperty ( target , key , source [ key ] ) ; } ) ; } return target ; }
23
+
24
+ function _typeof ( obj ) { if ( typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ) { _typeof = function _typeof ( obj ) { return typeof obj ; } ; } else { _typeof = function _typeof ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ; } return _typeof ( obj ) ; }
25
+
26
+ function _defineProperty ( obj , key , value ) { if ( key in obj ) { Object . defineProperty ( obj , key , { value : value , enumerable : true , configurable : true , writable : true } ) ; } else { obj [ key ] = value ; } return obj ; }
27
+
28
+ var _Dimensions$get = _reactNative . Dimensions . get ( 'window' ) ,
29
+ windowWidth = _Dimensions$get . width ,
30
+ windowHeight = _Dimensions$get . height ;
31
+
32
+ function objectWithKey ( key , value ) {
33
+ return Array . isArray ( value ) && value . length > 0 || ! Array . isArray ( value ) && value ? _defineProperty ( { } , key , value ) : { } ;
34
+ }
35
+
36
+ function normalizeIconArgs ( icon ) {
37
+ if ( icon === null ) {
38
+ return null ;
39
+ }
40
+
41
+ if ( _typeof ( icon ) === 'object' && icon . prefix && icon . iconName ) {
42
+ return icon ;
43
+ }
44
+
45
+ if ( Array . isArray ( icon ) && icon . length === 2 ) {
46
+ return {
47
+ prefix : icon [ 0 ] ,
48
+ iconName : icon [ 1 ]
49
+ } ;
50
+ }
51
+
52
+ if ( typeof icon === 'string' ) {
53
+ return {
54
+ prefix : 'fas' ,
55
+ iconName : icon
56
+ } ;
57
+ }
58
+ }
59
+
60
+ function FontAwesomeIcon ( props ) {
61
+ var iconArgs = props . icon ,
62
+ maskArgs = props . mask ,
63
+ _props$height = props . height ,
64
+ height = _props$height === void 0 ? windowHeight * 0.1 : _props$height ,
65
+ _props$width = props . width ,
66
+ width = _props$width === void 0 ? windowWidth * 0.1 : _props$width ;
67
+ var iconLookup = normalizeIconArgs ( iconArgs ) ;
68
+ var transform = objectWithKey ( 'transform' , typeof props . transform === 'string' ? _fontawesomeSvgCore . parse . transform ( props . transform ) : props . transform ) ;
69
+ var mask = objectWithKey ( 'mask' , normalizeIconArgs ( maskArgs ) ) ;
70
+ var renderedIcon = ( 0 , _fontawesomeSvgCore . icon ) ( iconLookup , _objectSpread ( { } , transform , mask ) ) ;
71
+
72
+ if ( ! renderedIcon ) {
73
+ ( 0 , _logger . default ) ( "ERROR: icon not found for icon = " , iconArgs ) ;
74
+ return null ;
75
+ }
76
+
77
+ var abstract = renderedIcon . abstract ;
78
+ var extraProps = {
79
+ height : height ,
80
+ width : width
81
+ } ;
82
+ Object . keys ( props ) . forEach ( function ( key ) {
83
+ if ( ! FontAwesomeIcon . defaultProps . hasOwnProperty ( key ) ) {
84
+ extraProps [ key ] = props [ key ] ;
85
+ }
86
+ } ) ;
87
+ return convertCurry ( abstract [ 0 ] , extraProps ) ;
88
+ }
89
+
90
+ FontAwesomeIcon . displayName = 'FontAwesomeIcon' ;
91
+ FontAwesomeIcon . propTypes = {
92
+ mask : _propTypes . default . oneOfType ( [ _propTypes . default . object , _propTypes . default . array , _propTypes . default . string ] ) ,
93
+ icon : _propTypes . default . oneOfType ( [ _propTypes . default . object , _propTypes . default . array , _propTypes . default . string ] ) ,
94
+ listItem : _propTypes . default . bool ,
95
+ pull : _propTypes . default . oneOf ( [ 'right' , 'left' ] ) ,
96
+ pulse : _propTypes . default . bool ,
97
+ rotation : _propTypes . default . oneOf ( [ 90 , 180 , 270 ] ) ,
98
+ spin : _propTypes . default . bool ,
99
+ transform : _propTypes . default . oneOfType ( [ _propTypes . default . string , _propTypes . default . object ] )
100
+ } ;
101
+ FontAwesomeIcon . defaultProps = {
102
+ mask : null ,
103
+ inverse : false ,
104
+ icon : null ,
105
+ listItem : false ,
106
+ pull : null ,
107
+ pulse : false ,
108
+ rotation : null ,
109
+ spin : false ,
110
+ transform : null
111
+ } ;
112
+
113
+ var convertCurry = _converter . default . bind ( null , _react . default . createElement ) ;
0 commit comments