owncast/web/utils/input-statuses.tsx

66 lines
1.6 KiB
TypeScript
Raw Normal View History

2021-01-31 21:13:35 +03:00
import {
CheckCircleFilled,
ExclamationCircleFilled,
LoadingOutlined,
WarningOutlined,
} from '@ant-design/icons';
2021-01-31 06:33:01 +03: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-01-31 21:13:35 +03:00
export type InputStatusTypes =
| typeof STATUS_ERROR
| typeof STATUS_INVALID
| typeof STATUS_PROCESSING
| typeof STATUS_SUCCESS
| typeof STATUS_WARNING;
2021-01-31 06:33:01 +03:00
export type StatusState = {
2021-01-31 21:13:35 +03:00
type: InputStatusTypes;
2021-01-31 06:33:01 +03:00
icon: any; // Element type of sorts?
message: string;
};
export const INPUT_STATES = {
[STATUS_SUCCESS]: {
icon: <CheckCircleFilled style={{ color: 'green' }} />,
message: 'Success!',
},
[STATUS_ERROR]: {
icon: <ExclamationCircleFilled style={{ color: 'red' }} />,
2021-01-31 21:13:35 +03:00
message: 'An error occurred.',
2021-01-31 06:33:01 +03:00
},
[STATUS_INVALID]: {
icon: <ExclamationCircleFilled style={{ color: 'red' }} />,
2021-01-31 21:13:35 +03:00
message: 'An error occurred.',
2021-01-31 06:33:01 +03:00
},
[STATUS_PROCESSING]: {
icon: <LoadingOutlined />,
message: '',
},
[STATUS_WARNING]: {
icon: <WarningOutlined style={{ color: '#fc0' }} />,
2021-01-31 21:13:35 +03:00
message: '',
2021-01-31 06:33:01 +03: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 11:48:39 +03:00
export function createInputStatus(type: InputStatusTypes, message?: string): StatusState {
2021-01-31 06:33:01 +03:00
if (!type || !INPUT_STATES[type]) {
return null;
}
2021-01-31 21:13:35 +03:00
if (!message) {
2021-01-31 06:33:01 +03:00
return INPUT_STATES[type];
}
return {
2021-01-31 21:13:35 +03:00
type,
2021-01-31 06:33:01 +03:00
icon: INPUT_STATES[type].icon,
message,
};
}