mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-12 12:37:14 +00:00
feat: add prefix icon support to RenderInput component
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import { IFlowNodeParameter } from '@/types/flow';
|
import { IFlowNodeParameter } from '@/types/flow';
|
||||||
import { convertKeysToCamelCase } from '@/utils/flow';
|
import { convertKeysToCamelCase } from '@/utils/flow';
|
||||||
import { Input } from 'antd';
|
import { Input } from 'antd';
|
||||||
|
import * as Icons from '@ant-design/icons';
|
||||||
|
import { FC } from 'react';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
data: IFlowNodeParameter;
|
data: IFlowNodeParameter;
|
||||||
@@ -8,9 +10,27 @@ type Props = {
|
|||||||
onChange: (value: any) => void;
|
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) => {
|
export const RenderInput = (params: Props) => {
|
||||||
const { data, defaultValue, onChange } = params;
|
const { data, defaultValue, onChange } = params;
|
||||||
const attr = convertKeysToCamelCase(data.ui?.attr || {});
|
const attr = convertKeysToCamelCase(data.ui?.attr || {});
|
||||||
|
attr.prefix = getIconComponent(data.ui?.attr?.prefix || '');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Input
|
<Input
|
||||||
|
Reference in New Issue
Block a user