'use client'; import {mergeProps} from 'react-aria/mergeProps'; import { useToast, useToastRegion, type AriaToastProps, type AriaToastRegionProps } from 'react-aria/useToast'; import {useToastState, type ToastState} from 'react-stately/useToastState'; import {Button} from './Button'; import {X} from 'lucide-react'; import {useRef} from 'react'; import {useFocusRing} from 'react-aria/useFocusRing'; import './Toast.css'; import './Button.css'; export interface ToastProviderProps { children: (state: ToastState) => React.ReactNode; } export function ToastProvider({children}: ToastProviderProps) { let state = useToastState({maxVisibleToasts: 5}); return ( <> {children(state)} {state.visibleToasts.length > 0 && } ); } function ToastRegion({state, ...props}: AriaToastRegionProps & {state: ToastState}) { let ref = useRef(null); /*- begin highlight -*/ let {regionProps} = useToastRegion(props, state, ref); /*- end highlight -*/ let {focusProps, isFocusVisible} = useFocusRing(); return (
{state.visibleToasts.map(toast => ( ))}
); } function Toast({state, toast, ...props}: AriaToastProps & {state: ToastState}) { let ref = useRef(null); /*- begin highlight -*/ let {toastProps, contentProps, titleProps, closeButtonProps} = useToast( {...props, toast}, state, ref ); /*- end highlight -*/ let {focusProps, isFocusVisible} = useFocusRing(); return (
{toast.content}
); } export {Button};