(
icon?: IPublicTypeIconType | null,
props?: Record<string, unknown>,
)
| 7 | const URL_RE = /^(https?:)\/\//i; |
| 8 | |
| 9 | export function createIcon( |
| 10 | icon?: IPublicTypeIconType | null, |
| 11 | props?: Record<string, unknown>, |
| 12 | ): ReactNode { |
| 13 | if (!icon) { |
| 14 | return null; |
| 15 | } |
| 16 | if (isESModule(icon)) { |
| 17 | icon = icon.default; |
| 18 | } |
| 19 | if (typeof icon === 'string') { |
| 20 | if (URL_RE.test(icon)) { |
| 21 | return createElement('img', { |
| 22 | src: icon, |
| 23 | class: props?.className, |
| 24 | ...props, |
| 25 | }); |
| 26 | } |
| 27 | return <Icon type={icon} {...props} />; |
| 28 | } |
| 29 | if (isValidElement(icon)) { |
| 30 | return cloneElement(icon, { ...props }); |
| 31 | } |
| 32 | if (isReactComponent(icon)) { |
| 33 | return createElement(icon, { |
| 34 | class: props?.className, |
| 35 | ...props, |
| 36 | }); |
| 37 | } |
| 38 | |
| 39 | return <Icon {...icon} {...props} />; |
| 40 | } |
no test coverage detected
searching dependent graphs…