Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
abdmmar committed Dec 27, 2021
1 parent 95c11d8 commit 3b48a37
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 63 deletions.
54 changes: 5 additions & 49 deletions src/toast.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,54 +42,9 @@ export type ToastOptions = {
*/
declare function toast(message: string, options?: ToastOptions): string;
declare namespace toast {
function loading(message: any, options?: {
icon: {
type: string;
content: string;
};
duration: string;
closeable: boolean;
theme: {
type: string;
style: {
background: string;
color: string;
stroke: string;
};
};
}): any;
function success(message: any, options?: {
icon: {
type: string;
content: string;
};
duration: string;
closeable: boolean;
theme: {
type: string;
style: {
background: string;
color: string;
stroke: string;
};
};
}): any;
function error(message: any, options?: {
icon: {
type: string;
content: string;
};
duration: string;
closeable: boolean;
theme: {
type: string;
style: {
background: string;
color: string;
stroke: string;
};
};
}): any;
function loading(message: string, options?: ToastOptions): string;
function success(message: string, options?: ToastOptions): string;
function error(message: string, options?: ToastOptions): string;
/**
* Dismiss toast by id
* @param {string} id
Expand All @@ -103,13 +58,14 @@ declare namespace toast {
/**
* Automatically add loading toast, success or error toast in promise
* @param {Promise} promise
* @param {object} message
* @param {string} message.loading
* @param {string} message.success
* @param {string} message.error
* @param {ToastOptions} [options]
* @returns {Promise}
*/
function promise(promise: Promise<any>, message?: {
function promise(promise: Promise<any>, message: {
loading: string;
success: string;
error: string;
Expand Down
22 changes: 8 additions & 14 deletions src/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,12 @@ function createToastCloseButton(toastItem) {
* @param {'blank' | 'success' | 'loading' | 'error' | 'custom'} type
*/
function createHandler(type) {
return function (
message,
options = {
icon: { type: '', content: '' },
duration: '',
closeable: false,
theme: { type: 'light', style: { background: '', color: '', stroke: '' } }
}
) {
/**
* @param {string} message
* @param {ToastOptions} [options]
* @returns {string}
*/
return function (message, options) {
const toast = createToast(message, type, options);
return toast.id;
};
Expand Down Expand Up @@ -152,17 +149,14 @@ toast.dismiss = function (toastId) {
/**
* Automatically add loading toast, success or error toast in promise
* @param {Promise} promise
* @param {object} message
* @param {string} message.loading
* @param {string} message.success
* @param {string} message.error
* @param {ToastOptions} [options]
* @returns {Promise}
*/
toast.promise = async function (
promise,
message = { loading: '', success: '', error: '' },
options
) {
toast.promise = async function (promise, message, options) {
const id = toast.loading(message.loading, { ...options });

try {
Expand Down

0 comments on commit 3b48a37

Please sign in to comment.