@fortawesome/react-native-fontawesome 0.3.2 → 1.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/lib/module/FontAwesomeIcon.js +204 -0
- package/lib/module/FontAwesomeIcon.js.map +1 -0
- package/lib/module/converter.js +49 -0
- package/lib/module/converter.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/logger.js +9 -0
- package/lib/module/logger.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/FontAwesomeIcon.d.ts +41 -0
- package/lib/typescript/src/FontAwesomeIcon.d.ts.map +1 -0
- package/lib/typescript/src/converter.d.ts +10 -0
- package/lib/typescript/src/converter.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/logger.d.ts +2 -0
- package/lib/typescript/src/logger.d.ts.map +1 -0
- package/package.json +169 -58
- package/src/FontAwesomeIcon.tsx +331 -0
- package/src/converter.ts +71 -0
- package/src/index.tsx +7 -0
- package/src/logger.ts +7 -0
- package/dist/components/FontAwesomeIcon.js +0 -189
- package/dist/converter.js +0 -81
- package/dist/logger.js +0 -15
- package/index.d.ts +0 -29
- package/index.js +0 -1
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.DEFAULT_SIZE = exports.DEFAULT_SECONDARY_OPACITY = exports.DEFAULT_COLOR = void 0;
|
|
7
|
-
exports["default"] = FontAwesomeIcon;
|
|
8
|
-
|
|
9
|
-
var _react = _interopRequireDefault(require("react"));
|
|
10
|
-
|
|
11
|
-
var _converter = _interopRequireDefault(require("../converter"));
|
|
12
|
-
|
|
13
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
14
|
-
|
|
15
|
-
var _reactNative = require("react-native");
|
|
16
|
-
|
|
17
|
-
var _fontawesomeSvgCore = require("@fortawesome/fontawesome-svg-core");
|
|
18
|
-
|
|
19
|
-
var _logger = _interopRequireDefault(require("../logger"));
|
|
20
|
-
|
|
21
|
-
var _excluded = ["color"];
|
|
22
|
-
|
|
23
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
24
|
-
|
|
25
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
26
|
-
|
|
27
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
28
|
-
|
|
29
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
30
|
-
|
|
31
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
32
|
-
|
|
33
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
34
|
-
|
|
35
|
-
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; }
|
|
36
|
-
|
|
37
|
-
var DEFAULT_SIZE = 16;
|
|
38
|
-
exports.DEFAULT_SIZE = DEFAULT_SIZE;
|
|
39
|
-
var DEFAULT_COLOR = '#000';
|
|
40
|
-
exports.DEFAULT_COLOR = DEFAULT_COLOR;
|
|
41
|
-
var DEFAULT_SECONDARY_OPACITY = 0.4;
|
|
42
|
-
exports.DEFAULT_SECONDARY_OPACITY = DEFAULT_SECONDARY_OPACITY;
|
|
43
|
-
|
|
44
|
-
function objectWithKey(key, value) {
|
|
45
|
-
return Array.isArray(value) && value.length > 0 || !Array.isArray(value) && value ? _defineProperty({}, key, value) : {};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function normalizeIconArgs(icon) {
|
|
49
|
-
if (icon && _typeof(icon) === 'object' && icon.prefix && icon.iconName && icon.icon) {
|
|
50
|
-
return icon;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (_fontawesomeSvgCore.parse.icon) {
|
|
54
|
-
return _fontawesomeSvgCore.parse.icon(icon);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (icon === null) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (Array.isArray(icon) && icon.length === 2) {
|
|
62
|
-
return {
|
|
63
|
-
prefix: icon[0],
|
|
64
|
-
iconName: icon[1]
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (typeof icon === 'string') {
|
|
69
|
-
return {
|
|
70
|
-
prefix: 'fas',
|
|
71
|
-
iconName: icon
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function FontAwesomeIcon(props) {
|
|
77
|
-
var _props = _objectSpread({
|
|
78
|
-
icon: null,
|
|
79
|
-
mask: null,
|
|
80
|
-
maskId: null,
|
|
81
|
-
transform: null,
|
|
82
|
-
style: {},
|
|
83
|
-
color: null,
|
|
84
|
-
secondaryColor: null,
|
|
85
|
-
secondaryOpacity: null,
|
|
86
|
-
size: DEFAULT_SIZE
|
|
87
|
-
}, props);
|
|
88
|
-
|
|
89
|
-
var iconArgs = _props.icon,
|
|
90
|
-
maskArgs = _props.mask,
|
|
91
|
-
maskId = _props.maskId,
|
|
92
|
-
height = _props.height,
|
|
93
|
-
width = _props.width,
|
|
94
|
-
size = _props.size;
|
|
95
|
-
|
|
96
|
-
var style = _reactNative.StyleSheet.flatten(_props.style);
|
|
97
|
-
|
|
98
|
-
var iconLookup = normalizeIconArgs(iconArgs);
|
|
99
|
-
var transform = objectWithKey('transform', typeof _props.transform === 'string' ? _fontawesomeSvgCore.parse.transform(_props.transform) : _props.transform);
|
|
100
|
-
var mask = objectWithKey('mask', normalizeIconArgs(maskArgs));
|
|
101
|
-
var renderedIcon = (0, _fontawesomeSvgCore.icon)(iconLookup, _objectSpread(_objectSpread(_objectSpread({}, transform), mask), {}, {
|
|
102
|
-
maskId: maskId
|
|
103
|
-
}));
|
|
104
|
-
|
|
105
|
-
if (!renderedIcon) {
|
|
106
|
-
(0, _logger["default"])('ERROR: icon not found for icon = ', iconArgs);
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
var _abstract = renderedIcon["abstract"]; // This is the color that will be passed to the "fill" prop of the Svg element
|
|
111
|
-
|
|
112
|
-
var color = _props.color || (style || {}).color || DEFAULT_COLOR; // This is the color that will be passed to the "fill" prop of the secondary Path element child (in Duotone Icons)
|
|
113
|
-
// `null` value will result in using the primary color, at 40% opacity
|
|
114
|
-
|
|
115
|
-
var secondaryColor = _props.secondaryColor || color; // Secondary layer opacity should default to 0.4, unless a specific opacity value or a specific secondary color was given
|
|
116
|
-
|
|
117
|
-
var secondaryOpacity = _props.secondaryOpacity || DEFAULT_SECONDARY_OPACITY; // To avoid confusion down the line, we'll remove properties from the StyleSheet, like color, that are being overridden
|
|
118
|
-
// or resolved in other ways, to avoid ambiguity as to which inputs cause which outputs in the underlying rendering process.
|
|
119
|
-
// In other words, we don't want color (for example) to be specified via two different inputs.
|
|
120
|
-
|
|
121
|
-
var _ref2 = style || {},
|
|
122
|
-
styleColor = _ref2.color,
|
|
123
|
-
modifiedStyle = _objectWithoutProperties(_ref2, _excluded);
|
|
124
|
-
|
|
125
|
-
var resolvedHeight, resolvedWidth;
|
|
126
|
-
|
|
127
|
-
if (height || width) {
|
|
128
|
-
throw new Error("Prop height and width for component ".concat(FontAwesomeIcon.displayName, " have been deprecated. ") + "Use the size prop instead like <".concat(FontAwesomeIcon.displayName, " size={").concat(width, "} />."));
|
|
129
|
-
} else {
|
|
130
|
-
resolvedHeight = resolvedWidth = size || DEFAULT_SIZE;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
var rootAttributes = _abstract[0].attributes;
|
|
134
|
-
rootAttributes.height = resolvedHeight;
|
|
135
|
-
rootAttributes.width = resolvedWidth;
|
|
136
|
-
rootAttributes.style = modifiedStyle;
|
|
137
|
-
replaceCurrentColor(_abstract[0], color, secondaryColor, secondaryOpacity);
|
|
138
|
-
return convertCurry(_abstract[0]);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
FontAwesomeIcon.displayName = 'FontAwesomeIcon';
|
|
142
|
-
FontAwesomeIcon.propTypes = {
|
|
143
|
-
height: _propTypes["default"].number,
|
|
144
|
-
width: _propTypes["default"].number,
|
|
145
|
-
size: _propTypes["default"].number,
|
|
146
|
-
color: _propTypes["default"].string,
|
|
147
|
-
secondaryColor: _propTypes["default"].string,
|
|
148
|
-
secondaryOpacity: _propTypes["default"].number,
|
|
149
|
-
style: _propTypes["default"].oneOfType([_propTypes["default"].shape({
|
|
150
|
-
style: _propTypes["default"].any
|
|
151
|
-
}), _propTypes["default"].array]),
|
|
152
|
-
icon: _propTypes["default"].oneOfType([_propTypes["default"].object, _propTypes["default"].array, _propTypes["default"].string]),
|
|
153
|
-
mask: _propTypes["default"].oneOfType([_propTypes["default"].object, _propTypes["default"].array, _propTypes["default"].string]),
|
|
154
|
-
maskId: _propTypes["default"].string,
|
|
155
|
-
transform: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].object])
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
var convertCurry = _converter["default"].bind(null, _react["default"].createElement);
|
|
159
|
-
|
|
160
|
-
function replaceCurrentColor(obj, primaryColor, secondaryColor, secondaryOpacity) {
|
|
161
|
-
obj.children.forEach(function (child, childIndex) {
|
|
162
|
-
replaceFill(child, primaryColor, secondaryColor, secondaryOpacity);
|
|
163
|
-
|
|
164
|
-
if (Object.prototype.hasOwnProperty.call(child, 'attributes')) {
|
|
165
|
-
replaceFill(child.attributes, primaryColor, secondaryColor, secondaryOpacity);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (Array.isArray(child.children) && child.children.length > 0) {
|
|
169
|
-
replaceCurrentColor(child, primaryColor, secondaryColor, secondaryOpacity);
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function replaceFill(obj, primaryColor, secondaryColor, secondaryOpacity) {
|
|
175
|
-
if (hasPropertySetToValue(obj, 'fill', 'currentColor')) {
|
|
176
|
-
if (hasPropertySetToValue(obj, 'class', 'fa-primary')) {
|
|
177
|
-
obj.fill = primaryColor;
|
|
178
|
-
} else if (hasPropertySetToValue(obj, 'class', 'fa-secondary')) {
|
|
179
|
-
obj.fill = secondaryColor;
|
|
180
|
-
obj.fillOpacity = secondaryOpacity;
|
|
181
|
-
} else {
|
|
182
|
-
obj.fill = primaryColor;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function hasPropertySetToValue(obj, property, value) {
|
|
188
|
-
return Object.prototype.hasOwnProperty.call(obj, property) && obj[property] === value;
|
|
189
|
-
}
|
package/dist/converter.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
|
|
8
|
-
var _humps = _interopRequireDefault(require("humps"));
|
|
9
|
-
|
|
10
|
-
var _reactNativeSvg = require("react-native-svg");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
-
|
|
14
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
-
|
|
16
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
-
|
|
18
|
-
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; }
|
|
19
|
-
|
|
20
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
21
|
-
|
|
22
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
23
|
-
|
|
24
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
25
|
-
|
|
26
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
27
|
-
|
|
28
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
29
|
-
|
|
30
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
31
|
-
|
|
32
|
-
var svgObjectMap = {
|
|
33
|
-
svg: _reactNativeSvg.Svg,
|
|
34
|
-
path: _reactNativeSvg.Path,
|
|
35
|
-
rect: _reactNativeSvg.Rect,
|
|
36
|
-
defs: _reactNativeSvg.Defs,
|
|
37
|
-
mask: _reactNativeSvg.Mask,
|
|
38
|
-
g: _reactNativeSvg.G,
|
|
39
|
-
clipPath: _reactNativeSvg.ClipPath
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
function convert(createElement, element) {
|
|
43
|
-
if (typeof element === 'string') {
|
|
44
|
-
return element;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
var children = (element.children || []).map(function (child, childIndex) {
|
|
48
|
-
return convert(createElement, child);
|
|
49
|
-
});
|
|
50
|
-
var mixins = Object.keys(element.attributes || {}).reduce(function (acc, key) {
|
|
51
|
-
var val = element.attributes[key];
|
|
52
|
-
|
|
53
|
-
switch (key) {
|
|
54
|
-
case 'class':
|
|
55
|
-
case 'role':
|
|
56
|
-
case 'xmlns':
|
|
57
|
-
delete element.attributes[key];
|
|
58
|
-
break;
|
|
59
|
-
|
|
60
|
-
case 'focusable':
|
|
61
|
-
acc.attrs[key] = val === 'true';
|
|
62
|
-
break;
|
|
63
|
-
|
|
64
|
-
default:
|
|
65
|
-
if (key.indexOf('aria-') === 0 || key.indexOf('data-') === 0 || key === 'fill' && val === 'currentColor') {
|
|
66
|
-
delete element.attributes[key];
|
|
67
|
-
} else {
|
|
68
|
-
acc.attrs[_humps["default"].camelize(key)] = val;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return acc;
|
|
74
|
-
}, {
|
|
75
|
-
attrs: {}
|
|
76
|
-
});
|
|
77
|
-
return createElement.apply(void 0, [svgObjectMap[element.tag], _objectSpread({}, mixins.attrs)].concat(_toConsumableArray(children)));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
var _default = convert;
|
|
81
|
-
exports["default"] = _default;
|
package/dist/logger.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = _default;
|
|
7
|
-
var PRODUCTION = false;
|
|
8
|
-
|
|
9
|
-
function _default() {
|
|
10
|
-
if (!PRODUCTION && console && typeof console.error === 'function') {
|
|
11
|
-
var _console;
|
|
12
|
-
|
|
13
|
-
(_console = console).error.apply(_console, arguments);
|
|
14
|
-
}
|
|
15
|
-
}
|
package/index.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { StyleProp, ViewStyle } from "react-native";
|
|
2
|
-
import { Transform, IconProp } from "@fortawesome/fontawesome-svg-core";
|
|
3
|
-
|
|
4
|
-
export type FontAwesomeIconStyle = StyleProp<ViewStyle> & {
|
|
5
|
-
color?: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export interface Props {
|
|
9
|
-
icon: IconProp;
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated
|
|
12
|
-
*/
|
|
13
|
-
height?: number;
|
|
14
|
-
/**
|
|
15
|
-
* @deprecated
|
|
16
|
-
*/
|
|
17
|
-
width?: number;
|
|
18
|
-
size?: number;
|
|
19
|
-
color?: string;
|
|
20
|
-
secondaryColor?: string;
|
|
21
|
-
secondaryOpacity?: number;
|
|
22
|
-
mask?: IconProp;
|
|
23
|
-
maskId?: string;
|
|
24
|
-
transform?: string | Transform;
|
|
25
|
-
style?: FontAwesomeIconStyle;
|
|
26
|
-
testID?: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function FontAwesomeIcon(props: Props): JSX.Element;
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as FontAwesomeIcon } from './dist/components/FontAwesomeIcon'
|