From 2aaba44147bd2183eb8bf68a6ce9f9f594219a2e Mon Sep 17 00:00:00 2001 From: lorne <1991wangliang@gmail.com> Date: Wed, 14 May 2025 20:59:03 +0800 Subject: [PATCH] fix #1 --- package.json | 2 +- src/Form/fatory.ts | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index b1aa475..58fa8b1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/Form/fatory.ts b/src/Form/fatory.ts index 006a70e..c461e12 100644 --- a/src/Form/fatory.ts +++ b/src/Form/fatory.ts @@ -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>; + private readonly items = new Map>; private constructor() { @@ -14,12 +14,26 @@ export class FormFactory { return this.instance; } - public addItem(type: string, item: React.Component): void { + public addItem(type: string, item: React.ComponentType): void { this.items.set(type, item); } - public getItem(type: string): React.Component | undefined { + public getItem(type: string): React.ComponentType | 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; + } + }