mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-15 01:11:26 +08:00
5cc338e177
* feat: add warningContext * refactor: part refactor * chore: fix compile * chore: part of it * chore: part of it * chore: part of it * chore: fix lint * chore: fix test * chore: clean uo * chore: hide warning def tmp * chore: comment test * chore: fix lint * chore: refactor select icons * chore: fix warning message * test: update test * chore: rm dead code
34 lines
990 B
TypeScript
34 lines
990 B
TypeScript
import { useContext } from 'react';
|
|
import type { ValidateStatus } from 'antd/es/form/FormItem';
|
|
|
|
import { devUseWarning } from '../../_util/warning';
|
|
import { FormItemInputContext } from '../context';
|
|
|
|
type UseFormItemStatus = () => {
|
|
status?: ValidateStatus;
|
|
errors: React.ReactNode[];
|
|
warnings: React.ReactNode[];
|
|
};
|
|
|
|
const useFormItemStatus: UseFormItemStatus = () => {
|
|
const { status, errors = [], warnings = [] } = useContext(FormItemInputContext);
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
const warning = devUseWarning();
|
|
|
|
warning(
|
|
status !== undefined,
|
|
'Form.Item',
|
|
'usage',
|
|
'Form.Item.useStatus should be used under Form.Item component. For more information: https://u.ant.design/form-item-usestatus',
|
|
);
|
|
}
|
|
|
|
return { status, errors, warnings };
|
|
};
|
|
|
|
// Only used for compatible package. Not promise this will work on future version.
|
|
(useFormItemStatus as any).Context = FormItemInputContext;
|
|
|
|
export default useFormItemStatus;
|