2019-07-03 20:14:39 +08:00
|
|
|
import * as React from 'react';
|
2021-01-13 21:00:30 +08:00
|
|
|
import omit from 'rc-util/lib/omit';
|
2021-06-04 14:44:41 +08:00
|
|
|
import { Meta } from 'rc-field-form/lib/interface';
|
2019-07-03 20:14:39 +08:00
|
|
|
import { FormProvider as RcFormProvider } from 'rc-field-form';
|
|
|
|
import { FormProviderProps as RcFormProviderProps } from 'rc-field-form/lib/FormContext';
|
|
|
|
import { ColProps } from '../grid/col';
|
|
|
|
import { FormLabelAlign } from './interface';
|
2020-08-21 12:58:14 +08:00
|
|
|
import { RequiredMark } from './Form';
|
2020-09-11 21:27:51 +08:00
|
|
|
import { ValidateStatus } from './FormItem';
|
2019-07-03 20:14:39 +08:00
|
|
|
|
2020-12-28 15:30:18 +08:00
|
|
|
/** Form Context. Set top form style and pass to Form Item usage. */
|
2019-07-03 20:14:39 +08:00
|
|
|
export interface FormContextProps {
|
|
|
|
vertical: boolean;
|
|
|
|
name?: string;
|
|
|
|
colon?: boolean;
|
|
|
|
labelAlign?: FormLabelAlign;
|
|
|
|
labelCol?: ColProps;
|
|
|
|
wrapperCol?: ColProps;
|
2020-08-21 12:58:14 +08:00
|
|
|
requiredMark?: RequiredMark;
|
2020-06-05 18:06:52 +08:00
|
|
|
itemRef: (name: (string | number)[]) => (node: React.ReactElement) => void;
|
2019-07-03 20:14:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export const FormContext = React.createContext<FormContextProps>({
|
|
|
|
labelAlign: 'right',
|
|
|
|
vertical: false,
|
2020-06-05 18:06:52 +08:00
|
|
|
itemRef: (() => {}) as any,
|
2019-07-03 20:14:39 +08:00
|
|
|
});
|
|
|
|
|
2021-06-04 14:44:41 +08:00
|
|
|
/** `noStyle` Form Item Context. Used for error collection */
|
|
|
|
export type ReportMetaChange = (meta: Meta, uniqueKeys: React.Key[]) => void;
|
|
|
|
export const NoStyleItemContext = React.createContext<ReportMetaChange | null>(null);
|
2019-07-03 20:14:39 +08:00
|
|
|
|
2020-12-28 15:30:18 +08:00
|
|
|
/** Form Provider */
|
2021-01-13 21:00:30 +08:00
|
|
|
export interface FormProviderProps extends Omit<RcFormProviderProps, 'validateMessages'> {
|
|
|
|
prefixCls?: string;
|
|
|
|
}
|
2019-07-03 20:14:39 +08:00
|
|
|
|
|
|
|
export const FormProvider: React.FC<FormProviderProps> = props => {
|
|
|
|
const providerProps = omit(props, ['prefixCls']);
|
|
|
|
return <RcFormProvider {...providerProps} />;
|
|
|
|
};
|
2020-09-11 21:27:51 +08:00
|
|
|
|
2020-12-28 15:30:18 +08:00
|
|
|
/** Used for ErrorList only */
|
2020-09-11 21:27:51 +08:00
|
|
|
export interface FormItemPrefixContextProps {
|
|
|
|
prefixCls: string;
|
|
|
|
status?: ValidateStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const FormItemPrefixContext = React.createContext<FormItemPrefixContextProps>({
|
|
|
|
prefixCls: '',
|
|
|
|
});
|