支持原生 HTML 标签作为组件

This commit is contained in:
金禅 2020-08-16 16:56:44 +08:00
parent 05f4103cda
commit a3015961ed
2 changed files with 12 additions and 12 deletions

View File

@ -13425,15 +13425,7 @@
"props": {
"href": "https://fusion.design",
"target": "_blank",
"children": {
"type": "JSSlot",
"value": {
"componentName": "Typography.Text",
"props": {
"children": "这是一个超链接"
}
}
}
"children": "这是一个超链接"
}
}
}

View File

@ -1,5 +1,5 @@
import { ComponentType } from 'react';
import { NpmInfo} from '@ali/lowcode-types';
import { ComponentType, forwardRef, createElement } from 'react';
import { NpmInfo } from '@ali/lowcode-types';
import { isReactComponent } from './is-react';
import { isESModule } from './is-es-module';
@ -11,8 +11,16 @@ function accessLibrary(library: string | object) {
if (typeof library !== 'string') {
return library;
}
return (window as any)[library] || generateHtmlComp(library);
}
return (window as any)[library] || library;
export function generateHtmlComp(library: string) {
if (['a', 'img', 'div', 'span', 'svg'].includes(library)) {
return forwardRef((props, ref) => {
return createElement(library, { ref, ...props }, props.children);
});
}
}
export function getSubComponent(library: any, paths: string[]) {