ant-design/components/form/context.tsx
二货机器人 7a3bf8287f
feat: Form rule support warningOnly that not block form submit (#30829)
* chore: bump rc-field-form

* docs: Demo driven

* refactor: Use event instead

* chore: collection logic update

* chore: clean up

* chore: show warning

* chore: warning no need required mark

* feat: warning example

* docs: mix error

* chore: tmp list

* chore: magic code

* chore: fix motion

* chore: fix style

* chore: clean up useless code

* chore: RM useless import

* chore: RM useless file

* test: Update snapshot

* chore: Should reset

* fix: Memo logic

* fix: Form basic test case

* fix: lint

* chore: back of ref

* test: Update snapshot

* test: RM ueseless test case

* chore: RM useless code
2021-06-04 14:44:41 +08:00

52 lines
1.7 KiB
TypeScript

import * as React from 'react';
import omit from 'rc-util/lib/omit';
import { Meta } from 'rc-field-form/lib/interface';
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';
import { RequiredMark } from './Form';
import { ValidateStatus } from './FormItem';
/** Form Context. Set top form style and pass to Form Item usage. */
export interface FormContextProps {
vertical: boolean;
name?: string;
colon?: boolean;
labelAlign?: FormLabelAlign;
labelCol?: ColProps;
wrapperCol?: ColProps;
requiredMark?: RequiredMark;
itemRef: (name: (string | number)[]) => (node: React.ReactElement) => void;
}
export const FormContext = React.createContext<FormContextProps>({
labelAlign: 'right',
vertical: false,
itemRef: (() => {}) as any,
});
/** `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);
/** Form Provider */
export interface FormProviderProps extends Omit<RcFormProviderProps, 'validateMessages'> {
prefixCls?: string;
}
export const FormProvider: React.FC<FormProviderProps> = props => {
const providerProps = omit(props, ['prefixCls']);
return <RcFormProvider {...providerProps} />;
};
/** Used for ErrorList only */
export interface FormItemPrefixContextProps {
prefixCls: string;
status?: ValidateStatus;
}
export const FormItemPrefixContext = React.createContext<FormItemPrefixContextProps>({
prefixCls: '',
});