An opinionated toast component for React.
Add loading toast (#122)
Emil Kowalskibce6437cfdec
diff --git a/src/index.tsx b/src/index.tsxindex a31e555..c900e38 100644--- a/src/index.tsx+++ b/src/index.tsx@@ -317,7 +317,7 @@ const Toast = (props: ToastProps) => {<>{toastType || toast.icon || toast.promise ? (<div data-icon="">- {toast.promise ? <Loader visible={toastType === 'loading'} /> : null}+ {toast.promise || toast.type === 'loading' ? <Loader visible={toastType === 'loading'} /> : null}{toast.icon || getAsset(toastType)}</div>) : null}diff --git a/src/state.ts b/src/state.tsindex fa1ae70..0099cf0 100644--- a/src/state.ts+++ b/src/state.ts@@ -77,6 +77,10 @@ class Observer {return this.create({ ...data, type: 'success', message });};+ loading = (message: string | React.ReactNode, data?: ExternalToast) => {+ return this.create({ ...data, type: 'loading', message });+ };+promise = <ToastData>(promise: PromiseT<ToastData>, data?: PromiseData<ToastData>) => {const id = this.create({ ...data, promise, type: 'loading', message: data.loading });const p = promise instanceof Promise ? promise : promise();@@ -92,7 +96,7 @@ class Observer {return id;};- // We can't provide the toast we just created as a prop as we didn't creat it yet, so we can create a default toast object, I just don't know how to use function in argument when calling()?+ // We can't provide the toast we just created as a prop as we didn't create it yet, so we can create a default toast object, I just don't know how to use function in argument when calling()?custom = (jsx: (id: number | string) => React.ReactElement, data?: ExternalToast) => {const id = data?.id || toastsCounter++;this.publish({ jsx: jsx(id), id, ...data });@@ -123,4 +127,5 @@ export const toast = Object.assign(basicToast, {message: ToastState.message,promise: ToastState.promise,dismiss: ToastState.dismiss,+ loading: ToastState.loading,});