59 lines
1.9 KiB
Java
59 lines
1.9 KiB
Java
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
|
import Icon from './index';
|
|
import { mergeProps } from '../_util/props-util';
|
|
|
|
var customCache = new Set();
|
|
|
|
export default function create(options) {
|
|
var scriptUrl = options.scriptUrl,
|
|
_options$extraCommonP = options.extraCommonProps,
|
|
extraCommonProps = _options$extraCommonP === undefined ? {} : _options$extraCommonP;
|
|
|
|
/**
|
|
* 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',
|
|
props: Icon.props,
|
|
render: function render(h, context) {
|
|
var props = context.props,
|
|
slots = context.slots,
|
|
listeners = context.listeners,
|
|
data = context.data;
|
|
|
|
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;
|
|
}
|
|
var iconProps = mergeProps(extraCommonProps, data, { props: restProps, on: listeners });
|
|
return h(
|
|
Icon,
|
|
iconProps,
|
|
[content]
|
|
);
|
|
}
|
|
};
|
|
return Iconfont;
|
|
} |