mirror of
https://github.com/Novattz/creamlinux-installer.git
synced 2026-05-14 18:32:44 -04:00
Formatting
This commit is contained in:
+51
-36
@@ -10,19 +10,19 @@ export type ToastType = 'success' | 'error' | 'warning' | 'info'
|
||||
* Toast interface
|
||||
*/
|
||||
export interface Toast {
|
||||
id: string;
|
||||
message: string;
|
||||
type: ToastType;
|
||||
duration?: number;
|
||||
title?: string;
|
||||
id: string
|
||||
message: string
|
||||
type: ToastType
|
||||
duration?: number
|
||||
title?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Toast options interface
|
||||
*/
|
||||
export interface ToastOptions {
|
||||
title?: string;
|
||||
duration?: number;
|
||||
title?: string
|
||||
duration?: number
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,51 +36,66 @@ export function useToasts() {
|
||||
* Removes a toast by ID
|
||||
*/
|
||||
const removeToast = useCallback((id: string) => {
|
||||
setToasts(currentToasts => currentToasts.filter(toast => toast.id !== id))
|
||||
setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id))
|
||||
}, [])
|
||||
|
||||
/**
|
||||
* Adds a new toast with the specified type and options
|
||||
*/
|
||||
const addToast = useCallback((toast: Omit<Toast, 'id'>) => {
|
||||
const id = uuidv4()
|
||||
const newToast = { ...toast, id }
|
||||
|
||||
setToasts(currentToasts => [...currentToasts, newToast])
|
||||
|
||||
// Auto-remove toast after its duration expires
|
||||
if (toast.duration !== Infinity) {
|
||||
setTimeout(() => {
|
||||
removeToast(id)
|
||||
}, toast.duration || 5000) // Default 5 seconds
|
||||
}
|
||||
|
||||
return id
|
||||
}, [removeToast])
|
||||
|
||||
const addToast = useCallback(
|
||||
(toast: Omit<Toast, 'id'>) => {
|
||||
const id = uuidv4()
|
||||
const newToast = { ...toast, id }
|
||||
|
||||
setToasts((currentToasts) => [...currentToasts, newToast])
|
||||
|
||||
// Auto-remove toast after its duration expires
|
||||
if (toast.duration !== Infinity) {
|
||||
setTimeout(() => {
|
||||
removeToast(id)
|
||||
}, toast.duration || 5000) // Default 5 seconds
|
||||
}
|
||||
|
||||
return id
|
||||
},
|
||||
[removeToast]
|
||||
)
|
||||
|
||||
/**
|
||||
* Shorthand method for success toasts
|
||||
*/
|
||||
const success = useCallback((message: string, options: ToastOptions = {}) =>
|
||||
addToast({ message, type: 'success', ...options }), [addToast])
|
||||
|
||||
const success = useCallback(
|
||||
(message: string, options: ToastOptions = {}) =>
|
||||
addToast({ message, type: 'success', ...options }),
|
||||
[addToast]
|
||||
)
|
||||
|
||||
/**
|
||||
* Shorthand method for error toasts
|
||||
*/
|
||||
const error = useCallback((message: string, options: ToastOptions = {}) =>
|
||||
addToast({ message, type: 'error', ...options }), [addToast])
|
||||
|
||||
const error = useCallback(
|
||||
(message: string, options: ToastOptions = {}) =>
|
||||
addToast({ message, type: 'error', ...options }),
|
||||
[addToast]
|
||||
)
|
||||
|
||||
/**
|
||||
* Shorthand method for warning toasts
|
||||
*/
|
||||
const warning = useCallback((message: string, options: ToastOptions = {}) =>
|
||||
addToast({ message, type: 'warning', ...options }), [addToast])
|
||||
|
||||
const warning = useCallback(
|
||||
(message: string, options: ToastOptions = {}) =>
|
||||
addToast({ message, type: 'warning', ...options }),
|
||||
[addToast]
|
||||
)
|
||||
|
||||
/**
|
||||
* Shorthand method for info toasts
|
||||
*/
|
||||
const info = useCallback((message: string, options: ToastOptions = {}) =>
|
||||
addToast({ message, type: 'info', ...options }), [addToast])
|
||||
const info = useCallback(
|
||||
(message: string, options: ToastOptions = {}) =>
|
||||
addToast({ message, type: 'info', ...options }),
|
||||
[addToast]
|
||||
)
|
||||
|
||||
return {
|
||||
toasts,
|
||||
@@ -91,4 +106,4 @@ export function useToasts() {
|
||||
warning,
|
||||
info,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user