1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _utils = require('../utils');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var twoToneColorPalette = {
primaryColor: '#333',
secondaryColor: '#E6E6E6'
};
var Icon = {
name: 'AntdIcon',
props: ['type', 'primaryColor', 'secondaryColor'],
displayName: 'IconVue',
definitions: new _utils.MiniMap(),
data: function data() {
return {
twoToneColorPalette: twoToneColorPalette
};
},
add: function add() {
for (var _len = arguments.length, icons = Array(_len), _key = 0; _key < _len; _key++) {
icons[_key] = arguments[_key];
}
icons.forEach(function (icon) {
Icon.definitions.set((0, _utils.withSuffix)(icon.name, icon.theme), icon);
});
},
clear: function clear() {
Icon.definitions.clear();
},
get: function get(key) {
var colors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : twoToneColorPalette;
if (key) {
var target = Icon.definitions.get(key);
if (target && typeof target.icon === 'function') {
target = (0, _extends3['default'])({}, target, {
icon: target.icon(colors.primaryColor, colors.secondaryColor)
});
}
return target;
}
},
setTwoToneColors: function setTwoToneColors(_ref) {
var primaryColor = _ref.primaryColor,
secondaryColor = _ref.secondaryColor;
twoToneColorPalette.primaryColor = primaryColor;
twoToneColorPalette.secondaryColor = secondaryColor || (0, _utils.getSecondaryColor)(primaryColor);
},
getTwoToneColors: function getTwoToneColors() {
return (0, _extends3['default'])({}, twoToneColorPalette);
},
render: function render(h) {
var _$props = this.$props,
type = _$props.type,
primaryColor = _$props.primaryColor,
secondaryColor = _$props.secondaryColor;
var target = void 0;
var colors = twoToneColorPalette;
if (primaryColor) {
colors = {
primaryColor: primaryColor,
secondaryColor: secondaryColor || (0, _utils.getSecondaryColor)(primaryColor)
};
}
if ((0, _utils.isIconDefinition)(type)) {
target = type;
} else if (typeof type === 'string') {
target = Icon.get(type, colors);
if (!target) {
// log(`Could not find icon: ${type}`);
return null;
}
}
if (!target) {
(0, _utils.log)('type should be string or icon definiton, but got ' + type);
return null;
}
if (target && typeof target.icon === 'function') {
target = (0, _extends3['default'])({}, target, {
icon: target.icon(colors.primaryColor, colors.secondaryColor)
});
}
return (0, _utils.generate)(h, target.icon, 'svg-' + target.name, {
attrs: {
'data-icon': target.name,
width: '1em',
height: '1em',
fill: 'currentColor',
'aria-hidden': 'true'
},
on: this.$listeners
});
}
};
/* istanbul ignore next */
Icon.install = function (Vue) {
Vue.component(Icon.name, Icon);
};
exports['default'] = Icon;
module.exports = exports['default'];