import * as React from 'react'; import classNames from 'classnames'; import omit from 'omit.js'; import { Omit } from '../_util/type'; import { IconProps } from './index'; export interface CustomIconProps extends Omit { viewBox?: string; component?: React.ComponentType; } export interface CustomIconComponentProps { width: Readonly; height: Readonly; fill: Readonly; viewBox: Readonly; } // These props make sure that the SVG behaviours like general text. // Reference: https://blog.prototypr.io/align-svg-icons-to-text-and-say-goodbye-to-font-icons-d44b3d7b26b4 const svgBaseProps = { width: '1em', height: '1em', fill: 'currentColor', ['aria-hidden']: 'true', }; const CustomIcon: React.SFC = (props) => { const { className = '', spin, // ⬇️ Todo, what's the best default value? // ⬇️ "0 0 24 24" for material-ui or "0 0 1024 1024" for ant-design viewBox = '0 0 1024 1024', children, component: Component, } = props; const classString = classNames({ anticon: true, 'anticon-spin': !!spin, }, className); let content = ( {children} ); if (Component) { content = {children}; } return ( {content} ); }; const customCache = new Set(); export interface CustomIconOptions { namespace?: string; prefix?: string; scriptUrl?: string; extraCommonProps?: { [key: string]: any }; } export function create(options: CustomIconOptions = {}): React.ComponentClass { const { namespace, prefix = '', scriptUrl, extraCommonProps = {} } = options; class Custom extends React.Component { render() { const { type, className = '', spin } = this.props; const classString = classNames({ anticon: true, 'anticon-spin': !!spin || type === 'loading', }, className); return ( ); } componentDidMount() { /** * DOM API required. * Make sure in browser environment. * The Custom Icon will create a