import * as React from 'react'; import Icon, { IconBaseProps } from './Icon'; const customCache = new Set(); export interface CustomIconOptions { scriptUrl?: string | string[]; extraCommonProps?: { [key: string]: any }; } export interface IconFontProps extends IconBaseProps { type: string; } function isValidCustomScriptUrl(scriptUrl: string): boolean { return Boolean( typeof scriptUrl === 'string' && scriptUrl.length && !customCache.has(scriptUrl), ); } function createScriptUrlElements( scriptUrls: string[], index: number = 0, ): void { const currentScriptUrl = scriptUrls[index]; if (isValidCustomScriptUrl(currentScriptUrl)) { const script = document.createElement('script'); script.setAttribute('src', currentScriptUrl); script.setAttribute('data-namespace', currentScriptUrl); if (scriptUrls.length > index + 1) { script.onload = () => { createScriptUrlElements(scriptUrls, index + 1); }; script.onerror = () => { createScriptUrlElements(scriptUrls, index + 1); }; } customCache.add(currentScriptUrl); document.body.appendChild(script); } } export default function create( options: CustomIconOptions = {}, ): React.SFC { const { scriptUrl, extraCommonProps = {} } = options; /** * DOM API required. * Make sure in browser environment. * The Custom Icon will create a