mirror of
https://github.com/harivansh-afk/Austens-Wedding-Guide.git
synced 2026-04-16 16:01:00 +00:00
improved all pages and changed content to match syllabus
This commit is contained in:
parent
43bd803759
commit
b9eb7cf738
32 changed files with 1290 additions and 300 deletions
56
src/components/ui/use-toast.ts
Normal file
56
src/components/ui/use-toast.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import { useState, useEffect } from 'react';
|
||||
|
||||
interface Toast {
|
||||
id: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
action?: React.ReactNode;
|
||||
variant?: 'default' | 'destructive';
|
||||
}
|
||||
|
||||
interface ToastOptions {
|
||||
title?: string;
|
||||
description?: string;
|
||||
action?: React.ReactNode;
|
||||
variant?: 'default' | 'destructive';
|
||||
duration?: number;
|
||||
}
|
||||
|
||||
const DEFAULT_TOAST_DURATION = 5000; // 5 seconds
|
||||
|
||||
export function useToast() {
|
||||
const [toasts, setToasts] = useState<Toast[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
const timeouts = toasts.map((toast) => {
|
||||
return setTimeout(() => {
|
||||
setToasts((current) => current.filter((t) => t.id !== toast.id));
|
||||
}, DEFAULT_TOAST_DURATION);
|
||||
});
|
||||
|
||||
return () => {
|
||||
timeouts.forEach((timeout) => clearTimeout(timeout));
|
||||
};
|
||||
}, [toasts]);
|
||||
|
||||
function toast(options: ToastOptions) {
|
||||
const id = Math.random().toString(36).slice(2);
|
||||
setToasts((current) => [
|
||||
...current,
|
||||
{
|
||||
id,
|
||||
...options,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
function dismiss(toastId: string) {
|
||||
setToasts((current) => current.filter((t) => t.id !== toastId));
|
||||
}
|
||||
|
||||
return {
|
||||
toasts,
|
||||
toast,
|
||||
dismiss,
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue