UNPKG

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