szboynono / mosha-vue-toastify

A light weight and fun Vue 3 toast or notification or snack bar or however you wanna call it library.

Home Page:https://szboynono.github.io/mosha-vue-toastify/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to set default options

apm29 opened this issue · comments

commented

is there any api to set the default options, for example: set default duration to 10000ms.

hello, i tried manually this :

import 'mosha-vue-toastify/dist/style.css';
import { clearToasts } from "mosha-vue-toastify"

const toast = {
	success: (message: string, duration: number = 3000) => {
		createToast(message, {
			hideProgressBar: false,
			showIcon: true,
			position: 'top-center',
			type: 'success',
			transition: 'bounce',
			swipeClose: true,
			timeout: duration
		});
	},
	error: (message: string, duration: number = 3000) => {
		createToast(message, {
			hideProgressBar: false,
			showIcon: true,
			position: 'top-center',
			type: 'danger',
			transition: 'bounce',
			swipeClose: true,
			timeout: duration
		});
	},
	warning: (message: string, duration: number = 3000) => {
		createToast(message, {
			hideProgressBar: false,
			showIcon: true,
			position: 'top-center',
			type: 'warning',
			transition: 'bounce',
			swipeClose: true,
			timeout: duration
		});
	},
	info: (message: string, duration: number = 3000) => {
		createToast(message, {
			hideProgressBar: false,
			showIcon: true,
			position: 'top-center',
			type: 'info',
			transition: 'bounce',
			swipeClose: true,
			timeout: duration
		});
	},
	loading: (message: string) => {
		createToast(message, {
			hideProgressBar: false,
			showIcon: true,
			position: 'top-center',
			type: 'info',
			transition: 'bounce',
			timeout: -1,
		});
	},
	clearAll: () => {
		clearToasts()
	}
}

export default toast;```

And maybe u can define default duration in props on Toast object