feat: add prefix icon support to RenderInput component (#1858)

This commit is contained in:
Dreammy23
2024-08-20 23:13:39 +08:00
committed by GitHub

View File

@@ -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