UNPKG

4.07 kBJavaScriptView Raw
1import * as _vue from "vue";
2
3function _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; }
4
5function _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; }
6
7function _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; }
8
9function _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; }
10
11import { svgBaseProps, warning, useInsertStyles } from '../utils';
12
13var Icon = function Icon(props, context) {
14 var attrs = context.attrs,
15 slots = context.slots;
16
17 var _props$attrs = _objectSpread({}, props, attrs),
18 cls = _props$attrs["class"],
19 Component = _props$attrs.component,
20 viewBox = _props$attrs.viewBox,
21 spin = _props$attrs.spin,
22 rotate = _props$attrs.rotate,
23 tabindex = _props$attrs.tabindex,
24 onClick = _props$attrs.onClick,
25 restProps = _objectWithoutProperties(_props$attrs, ["class", "component", "viewBox", "spin", "rotate", "tabindex", "onClick"]);
26
27 var children = slots["default"] && slots["default"]();
28 var hasChildren = children && children.length;
29 var slotsComponent = slots.component;
30 warning(Boolean(Component || hasChildren || slotsComponent), 'Should have `component` prop/slot or `children`.');
31 useInsertStyles();
32
33 var classString = _defineProperty({
34 anticon: true
35 }, cls, cls);
36
37 var svgClassString = {
38 'anticon-spin': spin === '' || !!spin
39 };
40 var svgStyle = rotate ? {
41 msTransform: "rotate(".concat(rotate, "deg)"),
42 transform: "rotate(".concat(rotate, "deg)")
43 } : undefined;
44
45 var innerSvgProps = _objectSpread({}, svgBaseProps, {
46 viewBox: viewBox,
47 "class": svgClassString,
48 style: svgStyle
49 });
50
51 if (!viewBox) {
52 delete innerSvgProps.viewBox;
53 }
54
55 var renderInnerNode = function renderInnerNode() {
56 if (Component) {
57 return _vue.createVNode(Component, innerSvgProps, {
58 "default": function _default() {
59 return [children];
60 }
61 });
62 }
63
64 if (slotsComponent) {
65 return slotsComponent(innerSvgProps);
66 }
67
68 if (hasChildren) {
69 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.');
70 return _vue.createVNode("svg", _vue.mergeProps(innerSvgProps, {
71 "viewBox": viewBox
72 }), [children]);
73 }
74
75 return null;
76 };
77
78 var iconTabIndex = tabindex;
79
80 if (iconTabIndex === undefined && onClick) {
81 iconTabIndex = -1;
82 restProps.tabindex = iconTabIndex;
83 }
84
85 return _vue.createVNode("span", _vue.mergeProps(restProps, {
86 "role": "img",
87 "onClick": onClick,
88 "class": classString
89 }), [renderInnerNode()]);
90};
91
92Icon.props = {
93 spin: Boolean,
94 rotate: Number,
95 viewBox: String,
96 ariaLabel: String
97};
98Icon.inheritAttrs = false;
99Icon.displayName = 'Icon';
100export default Icon;
\No newline at end of file