2024-05-06 14:19:06 +02:00
|
|
|
export function useAlert () {
|
2023-12-31 12:39:01 +01:00
|
|
|
|
2024-05-06 14:19:06 +02:00
|
|
|
function success (message, autoClose = 10000, options = {}) {
|
|
|
|
|
return useToast().add({
|
|
|
|
|
icon: 'i-heroicons-check-circle',
|
|
|
|
|
title: options.title ?? 'Success',
|
|
|
|
|
description: message,
|
|
|
|
|
color: 'green',
|
|
|
|
|
timeout: autoClose,
|
|
|
|
|
...options
|
2023-12-31 12:39:01 +01:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-06 14:19:06 +02:00
|
|
|
function error (message, autoClose = 10000, options = {}) {
|
|
|
|
|
return useToast().add({
|
|
|
|
|
icon: 'i-heroicons-exclamation-circle',
|
|
|
|
|
title: options.title ?? 'Error',
|
|
|
|
|
description: message,
|
|
|
|
|
color: 'red',
|
|
|
|
|
timeout: autoClose,
|
|
|
|
|
...options
|
2023-12-31 12:39:01 +01:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-06 14:19:06 +02:00
|
|
|
function warning (message, autoClose = 10000, options = {}) {
|
|
|
|
|
return useToast().add({
|
|
|
|
|
icon: 'i-heroicons-exclamation-triangle',
|
|
|
|
|
title: options.title ?? 'Warning',
|
|
|
|
|
description: message,
|
|
|
|
|
color: 'yellow',
|
|
|
|
|
timeout: autoClose,
|
|
|
|
|
...options
|
2023-12-31 12:39:01 +01:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-06 14:19:06 +02:00
|
|
|
function confirm (
|
|
|
|
|
message,
|
|
|
|
|
onSuccess,
|
|
|
|
|
onFailure = null,
|
|
|
|
|
autoClose = 10000,
|
|
|
|
|
options = {}
|
|
|
|
|
) {
|
|
|
|
|
return useToast().add({
|
|
|
|
|
icon: 'i-heroicons-question-mark-circle',
|
|
|
|
|
title: options.title ?? 'Are you sure?',
|
|
|
|
|
description: message,
|
|
|
|
|
color: 'blue',
|
|
|
|
|
timeout: autoClose,
|
|
|
|
|
actions: [
|
|
|
|
|
{ label: options.successLabel ?? 'Yes', click: onSuccess },
|
|
|
|
|
...(onFailure ? [{ label: options.failureLabel ?? 'No', click: onFailure }] : [])
|
|
|
|
|
],
|
|
|
|
|
...options
|
2023-12-31 12:39:01 +01:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-06 14:19:06 +02:00
|
|
|
function remove (id) {
|
|
|
|
|
useToast().remove(id)
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-31 12:39:01 +01:00
|
|
|
return {
|
|
|
|
|
success,
|
|
|
|
|
error,
|
|
|
|
|
warning,
|
2024-04-15 19:39:03 +02:00
|
|
|
confirm,
|
2024-05-06 14:19:06 +02:00
|
|
|
remove
|
2023-12-31 12:39:01 +01:00
|
|
|
}
|
|
|
|
|
}
|