Building a Robust Notification System: The Intuit Toast Component
In modern financial applications, real-time feedback is crucial for user experience. Whether it's confirming a successful transaction, alerting about an impending session timeout, or notifying of a data synchronization error, clear and timely communication keeps users informed and confident. This problem focuses on building a versatile and accessible toast notification system, a common UI component, to enhance user feedback within an Intuit product.
Your task is to implement a flexible and robust Toast Notification system using React and TypeScript. This system should consist of a ToastProvider component and a useToast hook, allowing any component within the provider's scope to easily trigger notifications.
Specifically, you need to implement the following:
ToastProvider Component: This component will manage the state of all active and queued toasts. It should render a container for toasts, positioned on the screen.useToast Hook: A custom React hook that provides an addToast function to trigger new notifications from any child component.success, error, info, and warning, each with unique visual styling.addToast is called when the maximum is reached, new toasts should be queued and appear once space becomes available.success, error, info, warning) must have clearly distinguishable visual cues (e.g., different border colors, icons – though icons are optional if colors are clear).addToast is called, a new toast appears on the screen with the specified message and type.duration or when the close button is clicked.maxVisibleToasts are displayed at any given time; additional toasts are queued and appear sequentially.success, error, info, warning) renders with distinct styling.useToast hook can be consumed by multiple components, and all toasts are managed by a single ToastProvider instance.Constraints
react-toastify, notistack). Implement the core logic from scratch.ToastProvider props (default to 3).ReactNode.ToastProvider and useToast hook are designed for reusability and separation of concerns.Loading editor...