Icon.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = void 0;
  6. var _vue = require("vue");
  7. var _utils = require("../utils");
  8. var _Context = require("./Context");
  9. var _InsertStyle = require("./InsertStyle");
  10. var _excluded = ["class", "component", "viewBox", "spin", "rotate", "tabindex", "onClick"];
  11. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? Object(arguments[i]) : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  12. 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; }
  13. function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
  14. function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
  15. var Icon = function Icon(props, context) {
  16. var _classString;
  17. var attrs = context.attrs,
  18. slots = context.slots;
  19. var _props$attrs = _objectSpread({}, props, attrs),
  20. cls = _props$attrs["class"],
  21. Component = _props$attrs.component,
  22. viewBox = _props$attrs.viewBox,
  23. spin = _props$attrs.spin,
  24. rotate = _props$attrs.rotate,
  25. tabindex = _props$attrs.tabindex,
  26. onClick = _props$attrs.onClick,
  27. restProps = _objectWithoutProperties(_props$attrs, _excluded);
  28. var _useInjectIconContext = (0, _Context.useInjectIconContext)(),
  29. prefixCls = _useInjectIconContext.prefixCls,
  30. rootClassName = _useInjectIconContext.rootClassName;
  31. var children = slots["default"] && slots["default"]();
  32. var hasChildren = children && children.length;
  33. var slotsComponent = slots.component;
  34. (0, _utils.warning)(Boolean(Component || hasChildren || slotsComponent), 'Should have `component` prop/slot or `children`.');
  35. var classString = (_classString = {}, _defineProperty(_classString, rootClassName.value, !!rootClassName.value), _defineProperty(_classString, prefixCls.value, true), _classString);
  36. var svgClassString = _defineProperty({}, "".concat(prefixCls.value, "-spin"), spin === '' || !!spin);
  37. var svgStyle = rotate ? {
  38. msTransform: "rotate(".concat(rotate, "deg)"),
  39. transform: "rotate(".concat(rotate, "deg)")
  40. } : undefined;
  41. var innerSvgProps = _objectSpread({}, _utils.svgBaseProps, {
  42. viewBox: viewBox,
  43. "class": svgClassString,
  44. style: svgStyle
  45. });
  46. if (!viewBox) {
  47. delete innerSvgProps.viewBox;
  48. }
  49. var renderInnerNode = function renderInnerNode() {
  50. if (Component) {
  51. return (0, _vue.createVNode)(Component, innerSvgProps, {
  52. "default": function _default() {
  53. return [children];
  54. }
  55. });
  56. }
  57. if (slotsComponent) {
  58. return slotsComponent(innerSvgProps);
  59. }
  60. if (hasChildren) {
  61. (0, _utils.warning)(Boolean(viewBox) || children.length === 1 && children[0] && children[0].type === 'use', 'Make sure that you provide correct `viewBox`' + ' prop (default `0 0 1024 1024`) to the icon.');
  62. return (0, _vue.createVNode)("svg", _objectSpread({}, innerSvgProps, {
  63. "viewBox": viewBox
  64. }), [children]);
  65. }
  66. return null;
  67. };
  68. var iconTabIndex = tabindex;
  69. if (iconTabIndex === undefined && onClick) {
  70. iconTabIndex = -1;
  71. restProps.tabindex = iconTabIndex;
  72. }
  73. return (0, _vue.createVNode)("span", _objectSpread({
  74. "role": "img"
  75. }, restProps, {
  76. "onClick": onClick,
  77. "class": [classString, cls]
  78. }), [renderInnerNode(), (0, _vue.createVNode)(_InsertStyle.InsertStyles, null, null)]);
  79. };
  80. Icon.props = {
  81. spin: Boolean,
  82. rotate: Number,
  83. viewBox: String,
  84. ariaLabel: String
  85. };
  86. Icon.inheritAttrs = false;
  87. Icon.displayName = 'Icon';
  88. var _default2 = Icon;
  89. exports["default"] = _default2;