mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-26 04:00:13 +08:00
37e042358d
* feat: remove form status style && input support status * test: update snapshot * feat: update status prop in config provider * fix: form item validateStatus support * chore: code clean * feat: status classname change * test: update snapshot * refactor: move formItemStatusContext to form folder * refactor: merge utils * refactor: rename statusUtils * chore: code clean * test: fix coverage * chore: remove status prop of Form.Item * chore: code clean * docs: update demo * test: fix lint * feat: status only success and warning * test: fix lint * docs: update deamo
60 lines
1.9 KiB
TypeScript
60 lines
1.9 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;
|
|
labelWrap?: boolean;
|
|
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: '',
|
|
});
|
|
|
|
export interface FormItemStatusContextProps {
|
|
status?: ValidateStatus;
|
|
hasFeedback?: boolean;
|
|
}
|
|
|
|
export const FormItemStatusContext = React.createContext<FormItemStatusContextProps>({});
|