/
icon-register.js
61 lines (51 loc) · 1.1 KB
/
icon-register.js
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
import svgLayer from './key';
const IconRegister = {
functional: true,
props: {
id: {
type: String,
required: true,
},
// To support custom SVG components
el: {
type: null,
default: 'svg',
},
inline: Boolean,
},
inject: {
svgLayer: {
from: svgLayer,
default: undefined,
},
},
render(h, ctx) {
const {svgLayer} = ctx.injections;
const [child] = ctx.children;
const {props, data} = ctx;
if (props.inline) {
if (data) {
for (const key in data) { // eslint-disable-line guard-for-in
const value = data[key];
if (value && typeof value === 'object') {
child.data[key] = Object.assign(child.data[key] || {}, value);
} else {
child.data[key] = value;
}
}
}
return child;
}
if (!svgLayer) {
throw new Error('IconLayer not found. Make sure the App is wrapped with the IconLayer');
}
const id = svgLayer.register(props.id, child);
ctx.parent.$once('hook:destroyed', () => svgLayer.unregister(id));
return h(props.el, data, [
h('use', {
attrs: {href: `#${id}`},
}),
]);
},
};
export default IconRegister;