From dfa3d28b55abb1ad1a52cea5b9efd3a0115aec4c Mon Sep 17 00:00:00 2001 From: gingervitis Date: Sat, 30 Jan 2021 19:33:01 -0800 Subject: [PATCH] add input status utils --- web/utils/input-statuses.tsx | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 web/utils/input-statuses.tsx diff --git a/web/utils/input-statuses.tsx b/web/utils/input-statuses.tsx new file mode 100644 index 000000000..63a59aff5 --- /dev/null +++ b/web/utils/input-statuses.tsx @@ -0,0 +1,58 @@ +import { CheckCircleFilled, ExclamationCircleFilled, LoadingOutlined, WarningOutlined } from '@ant-design/icons'; + +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'; + +export type InputStatusTypes = + typeof STATUS_ERROR | + typeof STATUS_INVALID | + typeof STATUS_PROCESSING | + typeof STATUS_SUCCESS | + typeof STATUS_WARNING; + +export type StatusState = { + icon: any; // Element type of sorts? + message: string; +}; + +export const INPUT_STATES = { + [STATUS_SUCCESS]: { + icon: , + message: 'Success!', + }, + [STATUS_ERROR]: { + icon: , + message: 'An error occurred.', + }, + [STATUS_INVALID]: { + icon: , + message: 'An error occurred.', + }, + [STATUS_PROCESSING]: { + icon: , + message: '', + }, + [STATUS_WARNING]: { + icon: , + message: '', + }, +}; + +// 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. +export function createInputStatus(type: InputStatusTypes, message: string): StatusState { + if (!type || !INPUT_STATES[type]) { + return null; + } + if (message === null) { + return INPUT_STATES[type]; + } + return { + icon: INPUT_STATES[type].icon, + message, + }; +}