52 lines
2.4 KiB
JavaScript
52 lines
2.4 KiB
JavaScript
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
|
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
|
|
import * as React from 'react';
|
|
import Icon from './Icon';
|
|
var customCache = new Set();
|
|
export default function create() {
|
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
var scriptUrl = options.scriptUrl,
|
|
_options$extraCommonP = options.extraCommonProps,
|
|
extraCommonProps = _options$extraCommonP === void 0 ? {} : _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 = React.forwardRef(function (props, ref) {
|
|
var type = props.type,
|
|
children = props.children,
|
|
restProps = _objectWithoutProperties(props, ["type", "children"]); // children > type
|
|
|
|
|
|
var content = null;
|
|
|
|
if (props.type) {
|
|
content = React.createElement("use", {
|
|
xlinkHref: "#".concat(type)
|
|
});
|
|
}
|
|
|
|
if (children) {
|
|
content = children;
|
|
}
|
|
|
|
return React.createElement(Icon, Object.assign({}, extraCommonProps, restProps, {
|
|
ref: ref
|
|
}), content);
|
|
});
|
|
Iconfont.displayName = 'Iconfont';
|
|
return Iconfont;
|
|
} |