mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-25 12:22:58 +03:00
feat(toast): use id for open status toggling (#178)
This commit is contained in:
parent
e388990384
commit
655f07ddd3
@ -18,12 +18,12 @@ export const Toast = ({
|
|||||||
<ToastContext.Provider value={{ publish }}>
|
<ToastContext.Provider value={{ publish }}>
|
||||||
{children}
|
{children}
|
||||||
<AnimatePresence mode="popLayout">
|
<AnimatePresence mode="popLayout">
|
||||||
{toasts.map((toast, index) => {
|
{toasts.map((toast) => {
|
||||||
if (!toast.open) return;
|
if (!toast.open) return;
|
||||||
return (
|
return (
|
||||||
<ToastPrimitive.Root
|
<ToastPrimitive.Root
|
||||||
open={toast.open}
|
open={toast.open}
|
||||||
onOpenChange={(value) => toggleToast(value, index)}
|
onOpenChange={(value) => toggleToast(value, toast.id)}
|
||||||
asChild
|
asChild
|
||||||
forceMount
|
forceMount
|
||||||
key={toast.id}
|
key={toast.id}
|
||||||
|
@ -6,10 +6,10 @@ import { generateToastUniqueId } from "../helpers/generateToastUniqueId";
|
|||||||
export const useToastBuilder = () => {
|
export const useToastBuilder = () => {
|
||||||
const [toasts, setToasts] = useState<ToastContent[]>([]);
|
const [toasts, setToasts] = useState<ToastContent[]>([]);
|
||||||
|
|
||||||
const toggleToast = (value: boolean, index: number) => {
|
const toggleToast = (value: boolean, toastId: string) => {
|
||||||
setToasts((toasts) =>
|
setToasts((toasts) =>
|
||||||
toasts.map((toast, i) => {
|
toasts.map((toast) => {
|
||||||
if (i === index) {
|
if (toast.id === toastId) {
|
||||||
toast.open = value;
|
toast.open = value;
|
||||||
}
|
}
|
||||||
return toast;
|
return toast;
|
||||||
|
Loading…
Reference in New Issue
Block a user