import { useCallback, useState } from 'react'; import { useField } from 'react-final-form'; import { SchemaFormContext, useSchemaForm } from './context'; import { FieldProps } from './types'; import FieldContainer from './FieldContainer'; import Label from './Label'; import InfoBubble from './InfoBubble'; import { Input, Tooltip } from 'antd'; import { getError } from './utils'; export const FieldAny = ({ JSONEditor, ...props }: FieldProps & { JSONEditor: SchemaFormContext['components']['JSONEditor']; }) => { const Editor = JSONEditor || Input.TextArea; const field = useField(props.name); const [value, setValue] = useState( typeof field.input.value === 'string' ? field.input.value : JSON.stringify(field.input.value, null, ' ') ); const onChange = useCallback((value: string) => { setValue(value); try { const json = JSON.parse(value); field.input.onChange(json); } catch { field.input.onChange(value); } }, []); const hasError = getError(field.meta); return ( onChange(typeof e === 'string' ? e : e.target.value)} status={hasError ? 'error' : ''} /> ); }; const LinkedFieldAny = (props: FieldProps) => { const { components: { JSONEditor }, } = useSchemaForm(); return ; }; export default LinkedFieldAny;