Skip to content

Commit 2aaba44

Browse files
committed
fix #1
1 parent 15d1f6e commit 2aaba44

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codingapi/ui-framework",
3-
"version": "0.0.27",
3+
"version": "0.0.28",
44
"description": "A UI Framework built with React and Typescript",
55
"keywords": [
66
"ui",

src/Form/fatory.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from "react";
2-
import {FormItemProps} from "./types";
2+
import {FormField, FormItemProps} from "./types";
33

44
export class FormFactory {
5-
private readonly items = new Map<string, React.Component<FormItemProps>>;
5+
private readonly items = new Map<string, React.ComponentType<FormItemProps>>;
66

77
private constructor() {
88

@@ -14,12 +14,26 @@ export class FormFactory {
1414
return this.instance;
1515
}
1616

17-
public addItem(type: string, item: React.Component<FormItemProps>): void {
17+
public addItem(type: string, item: React.ComponentType<FormItemProps>): void {
1818
this.items.set(type, item);
1919
}
2020

21-
public getItem(type: string): React.Component<FormItemProps> | undefined {
21+
public getItem(type: string): React.ComponentType<FormItemProps> | undefined {
2222
return this.items.get(type);
2323
}
2424

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+
2539
}

0 commit comments

Comments
 (0)