add tsx support
This commit is contained in:
1
doric-js/lib/src/util/index.util.d.ts
vendored
1
doric-js/lib/src/util/index.util.d.ts
vendored
@@ -5,3 +5,4 @@ export * from './log';
|
||||
export * from './types';
|
||||
export * from './uniqueId';
|
||||
export * from './flexbox';
|
||||
export * from './jsx';
|
||||
|
@@ -20,3 +20,4 @@ export * from './log';
|
||||
export * from './types';
|
||||
export * from './uniqueId';
|
||||
export * from './flexbox';
|
||||
export * from './jsx';
|
||||
|
19
doric-js/lib/src/util/jsx.d.ts
vendored
Normal file
19
doric-js/lib/src/util/jsx.d.ts
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { View } from "../ui/view";
|
||||
import { ClassType } from "./types";
|
||||
export declare const jsx: {
|
||||
createElement: <T extends View>(constructor: ClassType<T>, config: Partial<T> | null, ...children: View[]) => T;
|
||||
};
|
||||
declare global {
|
||||
namespace JSX {
|
||||
interface IntrinsicElements {
|
||||
}
|
||||
interface ElementClass extends View {
|
||||
}
|
||||
interface ElementAttributesProperty {
|
||||
props: {};
|
||||
}
|
||||
interface ElementChildrenAttribute {
|
||||
children: View[];
|
||||
}
|
||||
}
|
||||
}
|
20
doric-js/lib/src/util/jsx.js
Normal file
20
doric-js/lib/src/util/jsx.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Group } from "../ui/view";
|
||||
export const jsx = {
|
||||
createElement: function (constructor, config, ...children) {
|
||||
const e = new constructor();
|
||||
if (config) {
|
||||
for (let key in config) {
|
||||
Reflect.set(e, key, Reflect.get(config, key, config), e);
|
||||
}
|
||||
}
|
||||
if (children && children.length > 0) {
|
||||
if (e instanceof Group) {
|
||||
children.forEach((child) => e.addChild(child));
|
||||
}
|
||||
else {
|
||||
throw new Error(`Can only add child to group view, do not support ${constructor.name}`);
|
||||
}
|
||||
}
|
||||
return e;
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user