Interactive Tweet Card: Tooltip & Popover
Twitter's user experience thrives on rich, interactive elements that provide context without overwhelming the main content. For L4 engineers, building these foundational UI components efficiently and robustly is critical. This problem focuses on enhancing a basic Tweet Card by integrating a Tooltip for quick user information and a Popover for more detailed profile previews, demonstrating your ability to build composable, accessible, and well-structured React components.
Your task is to implement and integrate two core UI components, Tooltip and Popover, into a TweetCard component.
Tooltip component:
content (the text/JSX to display) and children (the trigger element).children element is hovered, the content should appear. It should disappear on mouse leave.Popover component:
content (the text/JSX to display) and children (the trigger element).children element is clicked, the content should appear. It should disappear when clicking outside of the popover or its trigger, or when the Escape key is pressed.TweetCard:
username (@{author.username}) with the Tooltip component to display the author.fullName on hover.profile picture with the Popover component to display a detailed user preview (provided in the sandpackFiles as user-popover-details) on click.mouseenter of the username, disappears on mouseleave.click of the profile picture, disappears on click outside or Escape key press.user-popover-details.Escape key.aria attributes if time permits, e.g., aria-describedby for the tooltip (optional, but a plus).Tooltip component correctly displays the author's full name when hovering over the username.Tooltip disappears when the mouse leaves the username area.Popover component correctly displays the user details when the profile picture is clicked.Popover disappears when clicking anywhere outside of the popover content or its trigger.Popover disappears when the Escape key is pressed.Tooltip and Popover are positioned logically relative to their trigger elements.TweetCard layout remains functional and readable.Constraints
TweetCard component.TweetCard instance is rendered for simplicity.position: absolute with top/left offsets) is expected. No need for full-fledged auto-positioning logic that handles viewport collisions.Tooltip and Popover are encapsulated, reusable, and follow React best practices.useState, useRef, and useEffect for managing visibility and event listeners.Escape key dismissal.Loading editor...