UNPKG

modo-mobile

Version:

A mobile UI toolkit, based on React

77 lines (62 loc) 2.87 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _extends2 = require('babel-runtime/helpers/extends'); var _extends3 = _interopRequireDefault(_extends2); exports['default'] = create; var _index = require('./index'); var _index2 = _interopRequireDefault(_index); var _react = require('react'); var React = _interopRequireWildcard(_react); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var __rest = undefined && undefined.__rest || function (s, e) { var t = {}; for (var p in s) { if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; }if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]]; }return t; }; var customCache = new Set(); function create() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 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', 'https:' + scriptUrl); script.setAttribute('data-namespace', scriptUrl); customCache.add(scriptUrl); document.body.appendChild(script); } var Iconfont = function Iconfont(props) { var type = props.type, children = props.children, restProps = __rest(props, ["type", "children"]); // component > children > type var content = null; if (props.type) { content = React.createElement('use', { xlinkHref: '#' + type }); } if (children) { content = children; } return React.createElement( _index2['default'], (0, _extends3['default'])({}, restProps, extraCommonProps), content ); }; Iconfont.displayName = 'Iconfont'; return Iconfont; } module.exports = exports['default'];