File tree 2 files changed +19
-5
lines changed 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @codingapi/ui-framework" ,
3
- "version" : " 0.0.27 " ,
3
+ "version" : " 0.0.28 " ,
4
4
"description" : " A UI Framework built with React and Typescript" ,
5
5
"keywords" : [
6
6
" ui" ,
Original file line number Diff line number Diff line change 1
1
import React from "react" ;
2
- import { FormItemProps } from "./types" ;
2
+ import { FormField , FormItemProps } from "./types" ;
3
3
4
4
export class FormFactory {
5
- private readonly items = new Map < string , React . Component < FormItemProps > > ;
5
+ private readonly items = new Map < string , React . ComponentType < FormItemProps > > ;
6
6
7
7
private constructor ( ) {
8
8
@@ -14,12 +14,26 @@ export class FormFactory {
14
14
return this . instance ;
15
15
}
16
16
17
- public addItem ( type : string , item : React . Component < FormItemProps > ) : void {
17
+ public addItem ( type : string , item : React . ComponentType < FormItemProps > ) : void {
18
18
this . items . set ( type , item ) ;
19
19
}
20
20
21
- public getItem ( type : string ) : React . Component < FormItemProps > | undefined {
21
+ public getItem ( type : string ) : React . ComponentType < FormItemProps > | undefined {
22
22
return this . items . get ( type ) ;
23
23
}
24
24
25
+ public create ( filed :FormField ) {
26
+ const type = filed . type ;
27
+ const props = filed . props ;
28
+
29
+ const item = this . getItem ( type ) ;
30
+ if ( item ) {
31
+ return React . createElement ( item , {
32
+ ...props ,
33
+ key : props . name as string
34
+ } ) ;
35
+ }
36
+ return null ;
37
+ }
38
+
25
39
}
You can’t perform that action at this time.
0 commit comments