refactor: split form context (#43023)

This commit is contained in:
二货爱吃白萝卜 2023-06-15 10:26:56 +08:00 committed by GitHub
parent e9bbc588cd
commit 96a93260d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 6 deletions

View File

@ -7,8 +7,8 @@ import type { ReactElement } from 'react';
import * as React from 'react';
import type { Options } from 'scroll-into-view-if-needed';
import warning from '../_util/warning';
import { ValidateMessagesContext } from '../form/context';
import type { RequiredMark } from '../form/Form';
import ValidateMessagesContext from '../form/validateMessagesContext';
import type { Locale } from '../locale';
import LocaleProvider, { ANT_MARK } from '../locale';
import type { LocaleContextProps } from '../locale/context';

View File

@ -12,11 +12,12 @@ import { SizeContextProvider } from '../config-provider/SizeContext';
import useSize from '../config-provider/hooks/useSize';
import type { ColProps } from '../grid/col';
import type { FormContextProps } from './context';
import { FormContext, FormProvider, ValidateMessagesContext } from './context';
import { FormContext, FormProvider } from './context';
import useForm, { type FormInstance } from './hooks/useForm';
import useFormWarning from './hooks/useFormWarning';
import type { FormLabelAlign } from './interface';
import useStyle from './style';
import ValidateMessagesContext from './validateMessagesContext';
export type RequiredMark = boolean | 'optional';
export type FormLayout = 'horizontal' | 'inline' | 'vertical';
@ -186,6 +187,6 @@ const Form = React.forwardRef<FormInstance, FormProps>(InternalForm) as <Values
props: React.PropsWithChildren<FormProps<Values>> & { ref?: React.Ref<FormInstance<Values>> },
) => React.ReactElement;
export { useForm, List, type FormInstance, useWatch };
export { List, useForm, useWatch, type FormInstance };
export default Form;

View File

@ -1,6 +1,6 @@
import { FormProvider as RcFormProvider } from 'rc-field-form';
import type { FormProviderProps as RcFormProviderProps } from 'rc-field-form/lib/FormContext';
import type { Meta, ValidateMessages } from 'rc-field-form/lib/interface';
import type { Meta } from 'rc-field-form/lib/interface';
import omit from 'rc-util/lib/omit';
import type { FC, PropsWithChildren, ReactNode } from 'react';
import * as React from 'react';
@ -92,5 +92,3 @@ export const NoFormStyle: FC<NoFormStyleProps> = ({ children, status, override }
</FormItemInputContext.Provider>
);
};
export const ValidateMessagesContext = React.createContext<ValidateMessages | undefined>(undefined);

View File

@ -0,0 +1,7 @@
import type { ValidateMessages } from 'rc-field-form/lib/interface';
import { createContext } from 'react';
// ZombieJ: We export single file here since
// ConfigProvider use this which will make loop deps
// to import whole `rc-field-form`
export default createContext<ValidateMessages | undefined>(undefined);