yantd
Version:
React component library
73 lines (72 loc) • 3.14 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import * as React from 'react';
import classNames from 'classnames';
import { svgBaseProps, warning } from './utils';
var Icon = React.forwardRef(function (props, ref) {
var
// affect outter <i>...</i>
className = props.className,
// affect inner <svg>...</svg>
Component = props.component, viewBox = props.viewBox, spin = props.spin, rotate = props.rotate, tabIndex = props.tabIndex, onClick = props.onClick,
// children
children = props.children, restProps = __rest(props, ["className", "component", "viewBox", "spin", "rotate", "tabIndex", "onClick", "children"]);
warning(Boolean(Component || children), 'Should have `component` prop or `children`.');
// useInsertStyles();
var classString = classNames('anticon', className);
var svgClassString = classNames({
'anticon-spin': !!spin,
});
var svgStyle = rotate
? {
msTransform: "rotate(" + rotate + "deg)",
transform: "rotate(" + rotate + "deg)",
}
: undefined;
var innerSvgProps = __assign(__assign({}, svgBaseProps), { className: svgClassString, style: svgStyle, viewBox: viewBox });
if (!viewBox) {
delete innerSvgProps.viewBox;
}
// component > children
var renderInnerNode = function () {
if (Component) {
return React.createElement(Component, __assign({}, innerSvgProps), children);
}
if (children) {
warning(Boolean(viewBox) ||
(React.Children.count(children) === 1 &&
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 (React.createElement("svg", __assign({}, innerSvgProps, { viewBox: viewBox }), children));
}
return null;
};
var iconTabIndex = tabIndex;
if (iconTabIndex === undefined && onClick) {
iconTabIndex = -1;
}
return (React.createElement("span", __assign({ role: "img" }, restProps, { ref: ref, tabIndex: iconTabIndex, onClick: onClick, className: classString }), renderInnerNode()));
});
Icon.displayName = 'AntdIcon';
export default Icon;