Skip to content

fix #1 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codingapi/ui-framework",
"version": "0.0.27",
"version": "0.0.28",
"description": "A UI Framework built with React and Typescript",
"keywords": [
"ui",
Expand Down
22 changes: 18 additions & 4 deletions src/Form/fatory.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";
import {FormItemProps} from "./types";
import {FormField, FormItemProps} from "./types";

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

private constructor() {

Expand All @@ -14,12 +14,26 @@ export class FormFactory {
return this.instance;
}

public addItem(type: string, item: React.Component<FormItemProps>): void {
public addItem(type: string, item: React.ComponentType<FormItemProps>): void {
this.items.set(type, item);
}

public getItem(type: string): React.Component<FormItemProps> | undefined {
public getItem(type: string): React.ComponentType<FormItemProps> | undefined {
return this.items.get(type);
}

public create(filed:FormField){
const type = filed.type;
const props = filed.props;

const item = this.getItem(type);
if (item) {
return React.createElement(item, {
...props,
key: props.name as string
});
}
return null;
}

}