AntdIcon.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. 'use client';
  2. import _extends from "@babel/runtime/helpers/esm/extends";
  3. import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
  4. import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
  5. import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
  6. var _excluded = ["className", "icon", "spin", "rotate", "tabIndex", "onClick", "twoToneColor"];
  7. import * as React from 'react';
  8. import classNames from 'classnames';
  9. import { blue } from '@ant-design/colors';
  10. import Context from "./Context";
  11. import ReactIcon from "./IconBase";
  12. import { getTwoToneColor, setTwoToneColor } from "./twoTonePrimaryColor";
  13. import { normalizeTwoToneColors } from "../utils";
  14. // Initial setting
  15. // should move it to antd main repo?
  16. setTwoToneColor(blue.primary);
  17. // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/34757#issuecomment-488848720
  18. var Icon = /*#__PURE__*/React.forwardRef(function (props, ref) {
  19. var className = props.className,
  20. icon = props.icon,
  21. spin = props.spin,
  22. rotate = props.rotate,
  23. tabIndex = props.tabIndex,
  24. onClick = props.onClick,
  25. twoToneColor = props.twoToneColor,
  26. restProps = _objectWithoutProperties(props, _excluded);
  27. var _React$useContext = React.useContext(Context),
  28. _React$useContext$pre = _React$useContext.prefixCls,
  29. prefixCls = _React$useContext$pre === void 0 ? 'anticon' : _React$useContext$pre,
  30. rootClassName = _React$useContext.rootClassName;
  31. var classString = classNames(rootClassName, prefixCls, _defineProperty(_defineProperty({}, "".concat(prefixCls, "-").concat(icon.name), !!icon.name), "".concat(prefixCls, "-spin"), !!spin || icon.name === 'loading'), className);
  32. var iconTabIndex = tabIndex;
  33. if (iconTabIndex === undefined && onClick) {
  34. iconTabIndex = -1;
  35. }
  36. var svgStyle = rotate ? {
  37. msTransform: "rotate(".concat(rotate, "deg)"),
  38. transform: "rotate(".concat(rotate, "deg)")
  39. } : undefined;
  40. var _normalizeTwoToneColo = normalizeTwoToneColors(twoToneColor),
  41. _normalizeTwoToneColo2 = _slicedToArray(_normalizeTwoToneColo, 2),
  42. primaryColor = _normalizeTwoToneColo2[0],
  43. secondaryColor = _normalizeTwoToneColo2[1];
  44. return /*#__PURE__*/React.createElement("span", _extends({
  45. role: "img",
  46. "aria-label": icon.name
  47. }, restProps, {
  48. ref: ref,
  49. tabIndex: iconTabIndex,
  50. onClick: onClick,
  51. className: classString
  52. }), /*#__PURE__*/React.createElement(ReactIcon, {
  53. icon: icon,
  54. primaryColor: primaryColor,
  55. secondaryColor: secondaryColor,
  56. style: svgStyle
  57. }));
  58. });
  59. Icon.displayName = 'AntdIcon';
  60. Icon.getTwoToneColor = getTwoToneColor;
  61. Icon.setTwoToneColor = setTwoToneColor;
  62. export default Icon;