Overview
Apple's operating systems rely heavily on timely and engaging notifications to keep users informed and productive. A well-designed Notification Center is crucial for delivering critical alerts, updates, and messages without overwhelming the user. This problem challenges you to build a simplified Notification Center component, focusing on core functionalities like display, dismissal, and state management, mirroring the user experience of a real Apple product.
What you need to do / Task
Your goal is to implement a NotificationCenter React component that displays a list of notifications and allows users to manage them.
- Display Notifications: Render a list of notifications, each showing its title, message, timestamp, and type.
- Dismiss Individual Notifications: Implement a mechanism (e.g., a button or icon) to dismiss a single notification from the list.
- Clear All Notifications: Add a "Clear All" button that, when clicked, removes all currently displayed notifications.
- Notification Types: Support at least three distinct notification types (e.g.,
info, warning, error). Each type should have a unique visual indicator or styling.
- Read/Unread State: Implement a visual distinction for "read" vs. "unread" notifications. Initially, all notifications are "unread". A notification becomes "read" when it is clicked or dismissed.
UI/UX expectations
- Layout: Notifications should be stacked vertically within a container. The "Clear All" button should be easily accessible, perhaps at the top or bottom of the list.
- Notification Card: Each notification should be presented as a distinct card or item, clearly separating it from others.
- Dismiss Button: An 'x' icon or similar clear button should be present on each notification for individual dismissal.
- Visual Cues:
- Different background colors, border styles, or icons for
info, warning, and error types.
- A subtle visual cue (e.g., a lighter background, a small dot, or a different font weight) to differentiate unread from read notifications.
- Timestamps: Display timestamps in a human-readable format (e.g., "5 minutes ago", "Yesterday at 3:00 PM"). A helper function
formatTimestamp is provided for convenience.
- Accessibility: Ensure interactive elements (buttons) have appropriate
aria-label attributes where necessary.
Acceptance criteria
- The
NotificationCenter component renders a list of notifications from the initial mock data.
- Each notification displays its title, message, and a human-readable timestamp.
- Clicking the "Clear All" button removes all notifications from the display.
- Clicking an individual dismiss button removes only that specific notification.
- Notifications of type
info, warning, and error are visually distinguishable.
- Initially, all notifications are marked as unread with a visual indicator.
- Clicking on an unread notification or dismissing it marks it as read, updating its visual state.
- The component gracefully handles an empty notification list (e.g., displays a "No new notifications" message).