From 0723cda2d81ca844ff790807befe9d33eaa4b523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A8=E6=AC=A3?= Date: Tue, 20 Aug 2024 23:05:06 +0800 Subject: [PATCH] feat: add prefix icon support to RenderInput component --- web/components/flow/node-renderer/input.tsx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/web/components/flow/node-renderer/input.tsx b/web/components/flow/node-renderer/input.tsx index 60c559baa..436899fc1 100644 --- a/web/components/flow/node-renderer/input.tsx +++ b/web/components/flow/node-renderer/input.tsx @@ -1,6 +1,8 @@ import { IFlowNodeParameter } from '@/types/flow'; import { convertKeysToCamelCase } from '@/utils/flow'; import { Input } from 'antd'; +import * as Icons from '@ant-design/icons'; +import { FC } from 'react'; type Props = { data: IFlowNodeParameter; @@ -8,9 +10,27 @@ type Props = { onChange: (value: any) => void; }; +const isValidIconComponent = (component: any): component is FC => { + console.log('222', typeof component); + + return component && typeof component === 'function'; +}; + +const getIconComponent = (iconString: string) => { + const match = iconString.match(/^icon:(\w+)$/); + if (match) { + const iconName = match[1] as keyof typeof Icons; + const IconComponent = Icons[iconName]; + // @ts-ignore + return IconComponent ? : null; + } + return null; +}; + export const RenderInput = (params: Props) => { const { data, defaultValue, onChange } = params; const attr = convertKeysToCamelCase(data.ui?.attr || {}); + attr.prefix = getIconComponent(data.ui?.attr?.prefix || ''); return (