mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-12 17:08:14 +00:00
fix: 兼容 icon 为 esmodule 功能
This commit is contained in:
parent
b11331fdbf
commit
e2af81e680
@ -2,6 +2,7 @@ import { isValidElement, ReactNode, createElement, cloneElement } from 'react';
|
||||
import { Icon } from '@alifd/next';
|
||||
import { IconType } from '@ali/lowcode-types';
|
||||
import { isReactComponent } from './is-react';
|
||||
import { isESModule } from './is-es-module';
|
||||
|
||||
const URL_RE = /^(https?:)\/\//i;
|
||||
|
||||
@ -9,6 +10,9 @@ export function createIcon(icon?: IconType | null, props?: Record<string, unknow
|
||||
if (!icon) {
|
||||
return null;
|
||||
}
|
||||
if (isESModule(icon)) {
|
||||
icon = icon.default;
|
||||
}
|
||||
if (typeof icon === 'string') {
|
||||
if (URL_RE.test(icon)) {
|
||||
return <img src={icon} {...props} />;
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
export function isESModule(obj: any): obj is { [key: string]: any } {
|
||||
export type ESModule = {
|
||||
__esModule: true;
|
||||
default: any;
|
||||
};
|
||||
export function isESModule(obj: any): obj is ESModule {
|
||||
return obj && obj.__esModule;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user