mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-02 15:59:38 +08:00
6a7acfbf6e
* feat: inputNumber support status * test: fix test * feat: custom status first * refactor: getMergedStatus pass status in params
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import React from 'react';
|
|
import CheckCircleFilled from '@ant-design/icons/CheckCircleFilled';
|
|
import ExclamationCircleFilled from '@ant-design/icons/ExclamationCircleFilled';
|
|
import CloseCircleFilled from '@ant-design/icons/CloseCircleFilled';
|
|
import LoadingOutlined from '@ant-design/icons/LoadingOutlined';
|
|
import classNames from 'classnames';
|
|
import { ValidateStatus } from '../form/FormItem';
|
|
import { tuple } from './type';
|
|
|
|
const InputStatuses = tuple('warning', 'error', '');
|
|
export type InputStatus = typeof InputStatuses[number];
|
|
|
|
const iconMap = {
|
|
success: CheckCircleFilled,
|
|
warning: ExclamationCircleFilled,
|
|
error: CloseCircleFilled,
|
|
validating: LoadingOutlined,
|
|
};
|
|
|
|
export const getFeedbackIcon = (prefixCls: string, status?: ValidateStatus) => {
|
|
const IconNode = status && iconMap[status];
|
|
return IconNode ? (
|
|
<span className={`${prefixCls}-feedback-icon`}>
|
|
<IconNode />
|
|
</span>
|
|
) : null;
|
|
};
|
|
|
|
export function getStatusClassNames(
|
|
prefixCls: string,
|
|
status?: ValidateStatus,
|
|
hasFeedback?: boolean,
|
|
) {
|
|
return classNames({
|
|
[`${prefixCls}-status-success`]: status === 'success',
|
|
[`${prefixCls}-status-warning`]: status === 'warning',
|
|
[`${prefixCls}-status-error`]: status === 'error',
|
|
[`${prefixCls}-status-validating`]: status === 'validating',
|
|
[`${prefixCls}-has-feedback`]: hasFeedback,
|
|
});
|
|
}
|
|
|
|
export const getMergedStatus = (contextStatus?: ValidateStatus, customStatus?: InputStatus) =>
|
|
customStatus || contextStatus;
|