ant-design-vue
Version:
An enterprise-class UI design language and Vue-based implementation
53 lines (46 loc) • 1.58 kB
JavaScript
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
import Icon from './index';
var customCache = new Set();
export default function create(options) {
var scriptUrl = options.scriptUrl;
/**
* DOM API required.
* Make sure in browser environment.
* The Custom Icon will create a <script/>
* that loads SVG symbols and insert the SVG Element into the document body.
*/
if (typeof document !== 'undefined' && typeof window !== 'undefined' && typeof document.createElement === 'function' && typeof scriptUrl === 'string' && scriptUrl.length && !customCache.has(scriptUrl)) {
var script = document.createElement('script');
script.setAttribute('src', scriptUrl);
script.setAttribute('data-namespace', scriptUrl);
customCache.add(scriptUrl);
document.body.appendChild(script);
}
var Iconfont = {
functional: true,
name: 'AIconfont',
render: function render(h, context) {
var props = context.props,
slots = context.slots,
listeners = context.listeners;
var type = props.type,
restProps = _objectWithoutProperties(props, ['type']);
var slotsMap = slots();
var children = slotsMap['default'];
// component > children > type
var content = null;
if (type) {
content = h('use', { attrs: { 'xlink:href': '#' + type } });
}
if (children) {
content = children;
}
return h(
Icon,
{ props: restProps, on: listeners },
[content]
);
}
};
return Iconfont;
}