UNPKG

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