port-nimara-client-portal/composables/useToast.ts

52 lines
829 B
TypeScript

import { ref } from 'vue'
interface Toast {
show: boolean
message: string
color: string
timeout: number
}
const toast = ref<Toast>({
show: false,
message: '',
color: 'success',
timeout: 3000
})
export const useToast = () => {
const showToast = (message: string, color: string = 'success', timeout: number = 3000) => {
toast.value = {
show: true,
message,
color,
timeout
}
}
const success = (message: string) => {
showToast(message, 'success')
}
const error = (message: string) => {
showToast(message, 'error')
}
const info = (message: string) => {
showToast(message, 'info')
}
const warning = (message: string) => {
showToast(message, 'warning')
}
return {
toast,
showToast,
success,
error,
info,
warning
}
}