릴리스: v0.1.43 토스트와 즐겨찾기 추가
This commit is contained in:
31
frontend/src/composables/useToast.js
Normal file
31
frontend/src/composables/useToast.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { readonly, ref } from 'vue'
|
||||
|
||||
const toasts = ref([])
|
||||
let toastSeq = 0
|
||||
|
||||
function dismissToast(id) {
|
||||
toasts.value = toasts.value.filter((toast) => toast.id !== id)
|
||||
}
|
||||
|
||||
function showToast(message, { type = 'info', duration = 2600 } = {}) {
|
||||
if (!message) return ''
|
||||
const id = `toast-${++toastSeq}`
|
||||
toasts.value = [...toasts.value, { id, message, type }]
|
||||
|
||||
if (duration > 0) {
|
||||
window.setTimeout(() => dismissToast(id), duration)
|
||||
}
|
||||
|
||||
return id
|
||||
}
|
||||
|
||||
export function useToast() {
|
||||
return {
|
||||
toasts: readonly(toasts),
|
||||
dismissToast,
|
||||
showToast,
|
||||
success: (message, options = {}) => showToast(message, { type: 'success', ...options }),
|
||||
error: (message, options = {}) => showToast(message, { type: 'error', ...options }),
|
||||
info: (message, options = {}) => showToast(message, { type: 'info', ...options }),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user