"use client";
import { XMarkIcon } from "@heroicons/react/24/solid";
import {
type AriaToastRegionProps,
type AriaToastProps,
useToastRegion,
useToast as reactAriaUseToast,
} from "@react-aria/toast";
import clsx from "clsx";
import { useRef, useState } from "react";
import { Button } from "react-aria-components";
import {
type Toast as ToastContentType,
ToastType,
useToast,
} from "../../hooks/use-toast";
import { ErrorMessage } from "../ErrorMessage";
export const ToastRegion = (props: AriaToastRegionProps) => {
const state = useToast();
const ref = useRef(null);
const { regionProps } = useToastRegion(props, state, ref);
return (
{state.visibleToasts.map((toast) => (
))}
);
};
const Toast = (props: AriaToastProps) => {
const [isTimerStarted, setIsTimerStarted] = useState(false);
const state = useToast();
const ref = useRef(null);
const { toastProps, contentProps, titleProps, closeButtonProps } =
reactAriaUseToast(props, state, ref);
return (
{
if (
props.toast.animation === "entering" ||
props.toast.animation === "queued"
) {
setIsTimerStarted(true);
}
if (props.toast.animation === "exiting") {
state.remove(props.toast.key);
}
}}
>
{
state.close(props.toast.key);
}}
/>
);
};
type ToastContentProps = {
children: ToastContentType;
};
const ToastContent = ({ children }: ToastContentProps) => {
switch (children.type) {
case ToastType.Error: {
return
;
}
case ToastType.Success: {
return children.message;
}
}
};