mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Fix: Fixed an issue where knowledge base could not be shared #9634 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import {
|
|
FormControl,
|
|
FormField,
|
|
FormItem,
|
|
FormLabel,
|
|
FormMessage,
|
|
} from '@/components/ui/form';
|
|
import { cn } from '@/lib/utils';
|
|
import { ReactNode, cloneElement, isValidElement } from 'react';
|
|
import { ControllerRenderProps, useFormContext } from 'react-hook-form';
|
|
|
|
type RAGFlowFormItemProps = {
|
|
name: string;
|
|
label: ReactNode;
|
|
tooltip?: ReactNode;
|
|
children: ReactNode | ((field: ControllerRenderProps) => ReactNode);
|
|
horizontal?: boolean;
|
|
};
|
|
|
|
export function RAGFlowFormItem({
|
|
name,
|
|
label,
|
|
tooltip,
|
|
children,
|
|
horizontal = false,
|
|
}: RAGFlowFormItemProps) {
|
|
const form = useFormContext();
|
|
return (
|
|
<FormField
|
|
control={form.control}
|
|
name={name}
|
|
render={({ field }) => (
|
|
<FormItem
|
|
className={cn({
|
|
'flex items-center': horizontal,
|
|
})}
|
|
>
|
|
<FormLabel tooltip={tooltip} className={cn({ 'w-1/4': horizontal })}>
|
|
{label}
|
|
</FormLabel>
|
|
<FormControl>
|
|
{typeof children === 'function'
|
|
? children(field)
|
|
: isValidElement(children)
|
|
? cloneElement(children, { ...field })
|
|
: children}
|
|
</FormControl>
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
);
|
|
}
|