IconFont.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
  6. var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
  7. exports['default'] = create;
  8. var _index = require('./index');
  9. var _index2 = _interopRequireDefault(_index);
  10. var _propsUtil = require('../_util/props-util');
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  12. var customCache = new Set();
  13. function create(options) {
  14. var scriptUrl = options.scriptUrl,
  15. _options$extraCommonP = options.extraCommonProps,
  16. extraCommonProps = _options$extraCommonP === undefined ? {} : _options$extraCommonP;
  17. /**
  18. * DOM API required.
  19. * Make sure in browser environment.
  20. * The Custom Icon will create a <script/>
  21. * that loads SVG symbols and insert the SVG Element into the document body.
  22. */
  23. if (typeof document !== 'undefined' && typeof window !== 'undefined' && typeof document.createElement === 'function' && typeof scriptUrl === 'string' && scriptUrl.length && !customCache.has(scriptUrl)) {
  24. var script = document.createElement('script');
  25. script.setAttribute('src', scriptUrl);
  26. script.setAttribute('data-namespace', scriptUrl);
  27. customCache.add(scriptUrl);
  28. document.body.appendChild(script);
  29. }
  30. var Iconfont = {
  31. functional: true,
  32. name: 'AIconfont',
  33. props: _index2['default'].props,
  34. render: function render(h, context) {
  35. var props = context.props,
  36. slots = context.slots,
  37. listeners = context.listeners,
  38. data = context.data;
  39. var type = props.type,
  40. restProps = (0, _objectWithoutProperties3['default'])(props, ['type']);
  41. var slotsMap = slots();
  42. var children = slotsMap['default'];
  43. // component > children > type
  44. var content = null;
  45. if (type) {
  46. content = h('use', { attrs: { 'xlink:href': '#' + type } });
  47. }
  48. if (children) {
  49. content = children;
  50. }
  51. var iconProps = (0, _propsUtil.mergeProps)(extraCommonProps, data, { props: restProps, on: listeners });
  52. return h(
  53. _index2['default'],
  54. iconProps,
  55. [content]
  56. );
  57. }
  58. };
  59. return Iconfont;
  60. }