qt-public-ui
Version:
新设计规范下业务组件库
46 lines • 1.74 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
var _excluded = ["type", "theme"];
import React, { isValidElement } from 'react';
import * as Icons from '@ant-design/icons';
import './style.less';
var string2Camal = function string2Camal(str) {
var firstLetter = str.slice(0, 1);
var restLetter = str.slice(1);
return firstLetter.toUpperCase() + restLetter.toLowerCase();
};
var slash2Camal = function slash2Camal(str) {
var words = str.split('-');
return words.map(string2Camal).join('');
};
var changeIconName = function changeIconName(type, theme) {
var _type = type.replace(/^ant-/, '');
return slash2Camal(_type) + string2Camal(theme);
};
var Icon = function Icon(props) {
var type = props.type,
_props$theme = props.theme,
theme = _props$theme === void 0 ? 'outlined' : _props$theme,
rest = _objectWithoutPropertiesLoose(props, _excluded);
if (!type) return null;
if (isValidElement(type)) return type;
var isAntd3Icon = Icons[changeIconName("ant-" + type, theme)];
var isAntIcon = /^ant-/.test(type);
if (isAntd3Icon || isAntIcon) {
var name = changeIconName(isAntd3Icon ? "ant-" + type : type, theme);
var IconComponent = Icons[name];
return /*#__PURE__*/React.createElement(IconComponent, rest);
}
return /*#__PURE__*/React.createElement("span", _extends({
className: "umui-icon anticon"
}, rest), /*#__PURE__*/React.createElement("svg", {
focusable: "false",
width: "1em",
height: "1em",
fill: "currentColor"
}, /*#__PURE__*/React.createElement("use", {
xlinkHref: "#" + type
})));
};
Icon.displayName = 'Icon';
export default Icon;