Browse Source

refactor: split form context (#43023)

pull/43027/head
二货爱吃白萝卜 1 year ago
committed by GitHub
parent
commit
96a93260d3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      components/config-provider/index.tsx
  2. 5
      components/form/Form.tsx
  3. 4
      components/form/context.tsx
  4. 7
      components/form/validateMessagesContext.tsx

2
components/config-provider/index.tsx

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

5
components/form/Form.tsx

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

4
components/form/context.tsx

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

7
components/form/validateMessagesContext.tsx

@ -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);
Loading…
Cancel
Save