UNPKG

antd

Version:

An enterprise-class UI design language and React components implementation

143 lines (114 loc) 5.99 kB
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } 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; } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } 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; }; /* eslint-disable camelcase */ import * as React from 'react'; import classNames from 'classnames'; import * as allIcons from '@ant-design/icons/lib/dist'; import ReactIcon from '@ant-design/icons-react'; import createFromIconfontCN from './IconFont'; import { svgBaseProps, withThemeSuffix, removeTypeTheme, getThemeFromTypeName, alias } from './utils'; import warning from '../_util/warning'; import LocaleReceiver from '../locale-provider/LocaleReceiver'; import { getTwoToneColor, setTwoToneColor } from './twoTonePrimaryColor'; // Initial setting ReactIcon.add.apply(ReactIcon, _toConsumableArray(Object.keys(allIcons).map(function (key) { return allIcons[key]; }))); setTwoToneColor('#1890ff'); var defaultTheme = 'outlined'; var dangerousTheme; function unstable_ChangeThemeOfIconsDangerously(theme) { warning(false, 'Icon', "You are using the unstable method 'Icon.unstable_ChangeThemeOfAllIconsDangerously', " + "make sure that all the icons with theme '".concat(theme, "' display correctly.")); dangerousTheme = theme; } function unstable_ChangeDefaultThemeOfIcons(theme) { warning(false, 'Icon', "You are using the unstable method 'Icon.unstable_ChangeDefaultThemeOfIcons', " + "make sure that all the icons with theme '".concat(theme, "' display correctly.")); defaultTheme = theme; } var Icon = function Icon(props) { var _classNames; var className = props.className, type = props.type, Component = props.component, viewBox = props.viewBox, spin = props.spin, rotate = props.rotate, tabIndex = props.tabIndex, onClick = props.onClick, children = props.children, theme = props.theme, twoToneColor = props.twoToneColor, restProps = __rest(props, ["className", "type", "component", "viewBox", "spin", "rotate", "tabIndex", "onClick", "children", "theme", "twoToneColor"]); warning(Boolean(type || Component || children), 'Icon', 'Should have `type` prop or `component` prop or `children`.'); var classString = classNames((_classNames = {}, _defineProperty(_classNames, "anticon", true), _defineProperty(_classNames, "anticon-".concat(type), Boolean(type)), _classNames), className); var svgClassString = classNames(_defineProperty({}, "anticon-spin", !!spin || type === 'loading')); var innerNode; var svgStyle = rotate ? { msTransform: "rotate(".concat(rotate, "deg)"), transform: "rotate(".concat(rotate, "deg)") } : undefined; var innerSvgProps = _extends(_extends({}, svgBaseProps), { className: svgClassString, style: svgStyle, viewBox: viewBox }); if (!viewBox) { delete innerSvgProps.viewBox; } // component > children > type if (Component) { innerNode = React.createElement(Component, innerSvgProps, children); } if (children) { warning(Boolean(viewBox) || React.Children.count(children) === 1 && React.isValidElement(children) && React.Children.only(children).type === 'use', 'Icon', 'Make sure that you provide correct `viewBox`' + ' prop (default `0 0 1024 1024`) to the icon.'); innerNode = React.createElement("svg", _extends({}, innerSvgProps, { viewBox: viewBox }), children); } if (typeof type === 'string') { var computedType = type; if (theme) { var themeInName = getThemeFromTypeName(type); warning(!themeInName || theme === themeInName, 'Icon', "The icon name '".concat(type, "' already specify a theme '").concat(themeInName, "',") + " the 'theme' prop '".concat(theme, "' will be ignored.")); } computedType = withThemeSuffix(removeTypeTheme(alias(computedType)), dangerousTheme || theme || defaultTheme); innerNode = React.createElement(ReactIcon, { className: svgClassString, type: computedType, primaryColor: twoToneColor, style: svgStyle }); } var iconTabIndex = tabIndex; if (iconTabIndex === undefined && onClick) { iconTabIndex = -1; } return React.createElement(LocaleReceiver, { componentName: "Icon" }, function (locale) { return React.createElement("i", _extends({ "aria-label": type && "".concat(locale.icon, ": ").concat(type) }, restProps, { tabIndex: iconTabIndex, onClick: onClick, className: classString }), innerNode); }); }; Icon.createFromIconfontCN = createFromIconfontCN; Icon.getTwoToneColor = getTwoToneColor; Icon.setTwoToneColor = setTwoToneColor; export default Icon; //# sourceMappingURL=index.js.map