Dynamic HoverCard Component with Adaptive Positioning
Tesla's vehicle software and internal tools demand highly intuitive and responsive user interfaces. Components like tooltips and popovers are critical for conveying information efficiently without cluttering the main display. This problem challenges you to build a HoverCard component that intelligently adapts its display based on user interaction duration and available screen space, ensuring a seamless and accessible user experience.
Your goal is to implement a reusable HoverCard React component that wraps any child element. This component should display contextual information in two distinct modes: a brief tooltip and a more detailed popover.
Basic Interaction:
children element is hovered over, a simple textual tooltip should appear after a short delay (e.g., 100ms).children element.children element or the popover itself (if interactive), or when the children element loses focus.Adaptive Positioning:
HoverCard should accept a position prop ('top', 'bottom', 'left', 'right') determining its preferred display location relative to the children.'top' is off-screen, try 'bottom', then 'left', etc.). Prioritize vertical over horizontal adjustments.Dismissal & Accessibility:
Escape key.aria-describedby, role="tooltip") and popovers (aria-haspopup, aria-expanded, role="dialog" with aria-labelledby).HoverCard component is implemented that wraps children.children displays a simple tooltip.children replaces the tooltip with a detailed popover.position prop.Escape.Constraints
lodash if necessary for debouncing/throttling, but it's not required./styles.css or inline styles) for styling.window.innerWidth and window.innerHeight./App.tsx or /HoverCard.tsx.HoverCard components (focus on a single instance).HoverCard component is designed for reusability and clarity.Loading editor...