Formatting

This commit is contained in:
Tickbase
2025-05-18 18:23:06 +02:00
parent bbbd7482c1
commit 81519e89b7
61 changed files with 714 additions and 775 deletions
+51 -36
View File
@@ -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,
}
}
}