2021-01-31 19:13:35 +01:00
|
|
|
import {
|
|
|
|
CheckCircleFilled,
|
|
|
|
ExclamationCircleFilled,
|
|
|
|
LoadingOutlined,
|
|
|
|
WarningOutlined,
|
|
|
|
} from '@ant-design/icons';
|
2021-01-31 04:33:01 +01:00
|
|
|
|
|
|
|
export const STATUS_RESET_TIMEOUT = 3000;
|
|
|
|
|
|
|
|
export const STATUS_ERROR = 'error';
|
|
|
|
export const STATUS_INVALID = 'invalid';
|
|
|
|
export const STATUS_PROCESSING = 'proessing';
|
|
|
|
export const STATUS_SUCCESS = 'success';
|
|
|
|
export const STATUS_WARNING = 'warning';
|
|
|
|
|
2021-02-01 06:36:14 +01:00
|
|
|
export type InputStatusTypes = 'error' | 'invalid' | 'proessing' | 'success' | 'warning';
|
2021-01-31 04:33:01 +01:00
|
|
|
|
2021-02-07 04:38:58 +01:00
|
|
|
export interface StatusState {
|
2021-01-31 19:13:35 +01:00
|
|
|
type: InputStatusTypes;
|
2021-01-31 04:33:01 +01:00
|
|
|
icon: any; // Element type of sorts?
|
|
|
|
message: string;
|
2021-02-07 04:38:58 +01:00
|
|
|
}
|
|
|
|
interface InputStates {
|
|
|
|
[key: string]: StatusState;
|
|
|
|
}
|
2021-01-31 04:33:01 +01:00
|
|
|
|
2021-02-07 04:38:58 +01:00
|
|
|
export const INPUT_STATES: InputStates = {
|
2021-01-31 04:33:01 +01:00
|
|
|
[STATUS_SUCCESS]: {
|
2021-02-01 06:36:14 +01:00
|
|
|
type: STATUS_SUCCESS,
|
2021-01-31 04:33:01 +01:00
|
|
|
icon: <CheckCircleFilled style={{ color: 'green' }} />,
|
|
|
|
message: 'Success!',
|
|
|
|
},
|
|
|
|
[STATUS_ERROR]: {
|
2021-02-01 06:36:14 +01:00
|
|
|
type: STATUS_ERROR,
|
2021-01-31 04:33:01 +01:00
|
|
|
icon: <ExclamationCircleFilled style={{ color: 'red' }} />,
|
2021-01-31 19:13:35 +01:00
|
|
|
message: 'An error occurred.',
|
2021-01-31 04:33:01 +01:00
|
|
|
},
|
|
|
|
[STATUS_INVALID]: {
|
2021-02-01 06:36:14 +01:00
|
|
|
type: STATUS_INVALID,
|
2021-01-31 04:33:01 +01:00
|
|
|
icon: <ExclamationCircleFilled style={{ color: 'red' }} />,
|
2021-01-31 19:13:35 +01:00
|
|
|
message: 'An error occurred.',
|
2021-01-31 04:33:01 +01:00
|
|
|
},
|
|
|
|
[STATUS_PROCESSING]: {
|
2021-02-01 06:36:14 +01:00
|
|
|
type: STATUS_PROCESSING,
|
2021-01-31 04:33:01 +01:00
|
|
|
icon: <LoadingOutlined />,
|
|
|
|
message: '',
|
|
|
|
},
|
|
|
|
[STATUS_WARNING]: {
|
2021-02-01 06:36:14 +01:00
|
|
|
type: STATUS_WARNING,
|
2021-01-31 04:33:01 +01:00
|
|
|
icon: <WarningOutlined style={{ color: '#fc0' }} />,
|
2021-01-31 19:13:35 +01:00
|
|
|
message: '',
|
2021-01-31 04:33:01 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Don't like any of the default messages in INPUT_STATES? Create a state with custom message by providing an icon style with your message.
|
2021-01-31 09:48:39 +01:00
|
|
|
export function createInputStatus(type: InputStatusTypes, message?: string): StatusState {
|
2021-01-31 04:33:01 +01:00
|
|
|
if (!type || !INPUT_STATES[type]) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-01-31 19:13:35 +01:00
|
|
|
if (!message) {
|
2021-01-31 04:33:01 +01:00
|
|
|
return INPUT_STATES[type];
|
|
|
|
}
|
|
|
|
return {
|
2021-01-31 19:13:35 +01:00
|
|
|
type,
|
2021-01-31 04:33:01 +01:00
|
|
|
icon: INPUT_STATES[type].icon,
|
|
|
|
message,
|
|
|
|
};
|
|
|
|
}
|