72 lines
2.9 KiB
JavaScript
72 lines
2.9 KiB
JavaScript
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
||
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
||
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
||
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
||
|
var _excluded = ["className", "component", "viewBox", "spin", "rotate", "tabIndex", "onClick", "children"];
|
||
|
// Seems this is used for iconFont
|
||
|
import * as React from 'react';
|
||
|
import classNames from 'classnames';
|
||
|
import { useComposeRef } from "rc-util/es/ref";
|
||
|
import Context from "./Context";
|
||
|
import { svgBaseProps, warning, useInsertStyles } from "../utils";
|
||
|
var Icon = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
||
|
var className = props.className,
|
||
|
Component = props.component,
|
||
|
viewBox = props.viewBox,
|
||
|
spin = props.spin,
|
||
|
rotate = props.rotate,
|
||
|
tabIndex = props.tabIndex,
|
||
|
onClick = props.onClick,
|
||
|
children = props.children,
|
||
|
restProps = _objectWithoutProperties(props, _excluded);
|
||
|
var iconRef = React.useRef();
|
||
|
var mergedRef = useComposeRef(iconRef, ref);
|
||
|
warning(Boolean(Component || children), 'Should have `component` prop or `children`.');
|
||
|
useInsertStyles(iconRef);
|
||
|
var _React$useContext = React.useContext(Context),
|
||
|
_React$useContext$pre = _React$useContext.prefixCls,
|
||
|
prefixCls = _React$useContext$pre === void 0 ? 'anticon' : _React$useContext$pre,
|
||
|
rootClassName = _React$useContext.rootClassName;
|
||
|
var classString = classNames(rootClassName, prefixCls, className);
|
||
|
var svgClassString = classNames(_defineProperty({}, "".concat(prefixCls, "-spin"), !!spin));
|
||
|
var svgStyle = rotate ? {
|
||
|
msTransform: "rotate(".concat(rotate, "deg)"),
|
||
|
transform: "rotate(".concat(rotate, "deg)")
|
||
|
} : undefined;
|
||
|
var innerSvgProps = _objectSpread(_objectSpread({}, svgBaseProps), {}, {
|
||
|
className: svgClassString,
|
||
|
style: svgStyle,
|
||
|
viewBox: viewBox
|
||
|
});
|
||
|
if (!viewBox) {
|
||
|
delete innerSvgProps.viewBox;
|
||
|
}
|
||
|
|
||
|
// component > children
|
||
|
var renderInnerNode = function renderInnerNode() {
|
||
|
if (Component) {
|
||
|
return /*#__PURE__*/React.createElement(Component, innerSvgProps, children);
|
||
|
}
|
||
|
if (children) {
|
||
|
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.');
|
||
|
return /*#__PURE__*/React.createElement("svg", _extends({}, innerSvgProps, {
|
||
|
viewBox: viewBox
|
||
|
}), children);
|
||
|
}
|
||
|
return null;
|
||
|
};
|
||
|
var iconTabIndex = tabIndex;
|
||
|
if (iconTabIndex === undefined && onClick) {
|
||
|
iconTabIndex = -1;
|
||
|
}
|
||
|
return /*#__PURE__*/React.createElement("span", _extends({
|
||
|
role: "img"
|
||
|
}, restProps, {
|
||
|
ref: mergedRef,
|
||
|
tabIndex: iconTabIndex,
|
||
|
onClick: onClick,
|
||
|
className: classString
|
||
|
}), renderInnerNode());
|
||
|
});
|
||
|
Icon.displayName = 'AntdIcon';
|
||
|
export default Icon;
|