kaneo (minimalist kanban) fork to experiment adding a tangled integration github.com/usekaneo/kaneo
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 76 lines 1.7 kB view raw
1import { toastManager } from "@/components/ui/toast"; 2 3type ToastVariant = "success" | "error" | "info" | "warning"; 4 5type ToastAction = { 6 label: string; 7 onClick?: () => void; 8}; 9 10type ToastOptions = { 11 description?: string; 12 action?: ToastAction; 13 cancel?: ToastAction; 14}; 15 16function addToast( 17 title: string, 18 variant?: ToastVariant, 19 options?: ToastOptions, 20) { 21 let id = ""; 22 23 const action = options?.action ?? options?.cancel; 24 25 id = toastManager.add({ 26 title, 27 description: options?.description, 28 type: variant, 29 actionProps: action 30 ? { 31 children: action.label, 32 onClick: () => { 33 action.onClick?.(); 34 toastManager.close(id); 35 }, 36 } 37 : undefined, 38 }); 39 40 return id; 41} 42 43type ToastFn = (title: string, options?: ToastOptions) => string; 44type ToastId = string; 45 46const success: ToastFn = (title, options) => 47 addToast(title, "success", options); 48const error: ToastFn = (title, options) => addToast(title, "error", options); 49const info: ToastFn = (title, options) => addToast(title, "info", options); 50const warning: ToastFn = (title, options) => 51 addToast(title, "warning", options); 52const message: ToastFn = (title, options) => 53 addToast(title, undefined, options); 54const loading: ToastFn = (title, options) => 55 toastManager.add({ 56 title, 57 description: options?.description, 58 type: "loading", 59 }); 60const dismiss = (id?: ToastId) => { 61 if (!id) return; 62 toastManager.close(id); 63}; 64 65const toast = Object.assign(message, { 66 success, 67 error, 68 info, 69 warning, 70 message, 71 loading, 72 dismiss, 73}); 74 75export type { ToastOptions }; 76export { toast };