mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-11 13:58:58 +00:00
feat: add prefix icon support to RenderInput component (#1858)
This commit is contained in:
@@ -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 ? <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 (
|
||||
<Input
|
||||
|
Reference in New Issue
Block a user