UNPKG

7.55 kBJavaScriptView Raw
1// Seems this is used for iconFont
2"use strict";
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6Object.defineProperty(exports, "default", {
7 enumerable: true,
8 get: function() {
9 return _default;
10 }
11});
12var _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
13var _classnames = /*#__PURE__*/ _interop_require_default(require("classnames"));
14var _ref = require("rc-util/lib/ref");
15var _Context = /*#__PURE__*/ _interop_require_default(require("./Context"));
16var _utils = require("../utils");
17function _define_property(obj, key, value) {
18 if (key in obj) {
19 Object.defineProperty(obj, key, {
20 value: value,
21 enumerable: true,
22 configurable: true,
23 writable: true
24 });
25 } else {
26 obj[key] = value;
27 }
28 return obj;
29}
30function _interop_require_default(obj) {
31 return obj && obj.__esModule ? obj : {
32 default: obj
33 };
34}
35function _getRequireWildcardCache(nodeInterop) {
36 if (typeof WeakMap !== "function") return null;
37 var cacheBabelInterop = new WeakMap();
38 var cacheNodeInterop = new WeakMap();
39 return (_getRequireWildcardCache = function(nodeInterop) {
40 return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
41 })(nodeInterop);
42}
43function _interop_require_wildcard(obj, nodeInterop) {
44 if (!nodeInterop && obj && obj.__esModule) {
45 return obj;
46 }
47 if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
48 return {
49 default: obj
50 };
51 }
52 var cache = _getRequireWildcardCache(nodeInterop);
53 if (cache && cache.has(obj)) {
54 return cache.get(obj);
55 }
56 var newObj = {};
57 var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
58 for(var key in obj){
59 if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
60 var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
61 if (desc && (desc.get || desc.set)) {
62 Object.defineProperty(newObj, key, desc);
63 } else {
64 newObj[key] = obj[key];
65 }
66 }
67 }
68 newObj.default = obj;
69 if (cache) {
70 cache.set(obj, newObj);
71 }
72 return newObj;
73}
74function _object_spread(target) {
75 for(var i = 1; i < arguments.length; i++){
76 var source = arguments[i] != null ? arguments[i] : {};
77 var ownKeys = Object.keys(source);
78 if (typeof Object.getOwnPropertySymbols === "function") {
79 ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
80 return Object.getOwnPropertyDescriptor(source, sym).enumerable;
81 }));
82 }
83 ownKeys.forEach(function(key) {
84 _define_property(target, key, source[key]);
85 });
86 }
87 return target;
88}
89function ownKeys(object, enumerableOnly) {
90 var keys = Object.keys(object);
91 if (Object.getOwnPropertySymbols) {
92 var symbols = Object.getOwnPropertySymbols(object);
93 if (enumerableOnly) {
94 symbols = symbols.filter(function(sym) {
95 return Object.getOwnPropertyDescriptor(object, sym).enumerable;
96 });
97 }
98 keys.push.apply(keys, symbols);
99 }
100 return keys;
101}
102function _object_spread_props(target, source) {
103 source = source != null ? source : {};
104 if (Object.getOwnPropertyDescriptors) {
105 Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
106 } else {
107 ownKeys(Object(source)).forEach(function(key) {
108 Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
109 });
110 }
111 return target;
112}
113function _object_without_properties(source, excluded) {
114 if (source == null) return {};
115 var target = _object_without_properties_loose(source, excluded);
116 var key, i;
117 if (Object.getOwnPropertySymbols) {
118 var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
119 for(i = 0; i < sourceSymbolKeys.length; i++){
120 key = sourceSymbolKeys[i];
121 if (excluded.indexOf(key) >= 0) continue;
122 if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
123 target[key] = source[key];
124 }
125 }
126 return target;
127}
128function _object_without_properties_loose(source, excluded) {
129 if (source == null) return {};
130 var target = {};
131 var sourceKeys = Object.keys(source);
132 var key, i;
133 for(i = 0; i < sourceKeys.length; i++){
134 key = sourceKeys[i];
135 if (excluded.indexOf(key) >= 0) continue;
136 target[key] = source[key];
137 }
138 return target;
139}
140var Icon = /*#__PURE__*/ _react.forwardRef(function(props, ref) {
141 var // affect outter <i>...</i>
142 className = props.className, // affect inner <svg>...</svg>
143 Component = props.component, viewBox = props.viewBox, spin = props.spin, rotate = props.rotate, tabIndex = props.tabIndex, onClick = props.onClick, // children
144 children = props.children, restProps = _object_without_properties(props, [
145 "className",
146 "component",
147 "viewBox",
148 "spin",
149 "rotate",
150 "tabIndex",
151 "onClick",
152 "children"
153 ]);
154 var iconRef = _react.useRef();
155 var mergedRef = (0, _ref.useComposeRef)(iconRef, ref);
156 (0, _utils.warning)(Boolean(Component || children), "Should have `component` prop or `children`.");
157 (0, _utils.useInsertStyles)(iconRef);
158 var _React_useContext = _react.useContext(_Context.default), _React_useContext_prefixCls = _React_useContext.prefixCls, prefixCls = _React_useContext_prefixCls === void 0 ? "anticon" : _React_useContext_prefixCls, rootClassName = _React_useContext.rootClassName;
159 var classString = (0, _classnames.default)(rootClassName, prefixCls, className);
160 var svgClassString = (0, _classnames.default)(_define_property({}, "".concat(prefixCls, "-spin"), !!spin));
161 var svgStyle = rotate ? {
162 msTransform: "rotate(".concat(rotate, "deg)"),
163 transform: "rotate(".concat(rotate, "deg)")
164 } : undefined;
165 var innerSvgProps = _object_spread_props(_object_spread({}, _utils.svgBaseProps), {
166 className: svgClassString,
167 style: svgStyle,
168 viewBox: viewBox
169 });
170 if (!viewBox) {
171 delete innerSvgProps.viewBox;
172 }
173 // component > children
174 var renderInnerNode = function() {
175 if (Component) {
176 return /*#__PURE__*/ _react.createElement(Component, innerSvgProps, children);
177 }
178 if (children) {
179 (0, _utils.warning)(Boolean(viewBox) || _react.Children.count(children) === 1 && /*#__PURE__*/ _react.isValidElement(children) && _react.Children.only(children).type === "use", "Make sure that you provide correct `viewBox`" + " prop (default `0 0 1024 1024`) to the icon.");
180 return /*#__PURE__*/ _react.createElement("svg", _object_spread_props(_object_spread({}, innerSvgProps), {
181 viewBox: viewBox
182 }), children);
183 }
184 return null;
185 };
186 var iconTabIndex = tabIndex;
187 if (iconTabIndex === undefined && onClick) {
188 iconTabIndex = -1;
189 }
190 return /*#__PURE__*/ _react.createElement("span", _object_spread_props(_object_spread({
191 role: "img"
192 }, restProps), {
193 ref: mergedRef,
194 tabIndex: iconTabIndex,
195 onClick: onClick,
196 className: classString
197 }), renderInnerNode());
198});
199Icon.displayName = "AntdIcon";
200var _default = Icon;