Skip to Content
Dashflow Logo

HoverCard Component

A comprehensive guide to using the HoverCard component with examples, props, and best practices.


Overview

The HoverCard component provides a hover-triggered card that displays additional content when users hover over a trigger element. It's commonly used for showing previews, additional information, or quick actions.

Basic Usage

import { HoverCard } from '@dashflowx/core'
export default function HoverCardExample() {
return (
<HoverCard
hoverCardTrigger="Hover me"
hoverCardContent="This is hover card content"
/>
)
}

Preview:

This is hover card content

Props

PropTypeDefaultDescription
hoverCardTriggerstring | JSX.Element'Hover me'The trigger element or text
hoverCardContentstring | JSX.Element'This is hover card content'The content to display in the hover card
classNamestring''Additional CSS classes for the container

Examples

Basic Hover Card

import { HoverCard } from '@dashflowx/core'
export default function BasicHoverCard() {
return (
<HoverCard
hoverCardTrigger="View Profile"
hoverCardContent="John Doe - Software Engineer at Tech Corp"
/>
)
}

Preview:

John Doe - Software Engineer at Tech Corp

User Profile Hover Card

import { HoverCard } from '@dashflowx/core'
export default function UserProfileHoverCard() {
return (
<HoverCard
hoverCardTrigger="👤 @johndoe"
hoverCardContent="John Doe - Software Engineer at Tech Corp. Passionate about React and TypeScript. Based in San Francisco."
/>
)
}

Preview:

John Doe - Software Engineer at Tech Corp. Passionate about React and TypeScript. Based in San Francisco.

Product Preview Hover Card

import { HoverCard } from '@dashflowx/core'
export default function ProductPreviewHoverCard() {
return (
<HoverCard
hoverCardTrigger="📱 iPhone 15 Pro"
hoverCardContent="Latest iPhone with A17 Pro chip, titanium design, and advanced camera system. Starting at $999."
/>
)
}

Preview:

Latest iPhone with A17 Pro chip, titanium design, and advanced camera system. Starting at $999.
import { HoverCard } from '@dashflowx/core'
export default function LinkPreviewHoverCard() {
return (
<HoverCard
hoverCardTrigger="🔗 Visit Website"
hoverCardContent="React - A JavaScript library for building user interfaces. Learn more about React's features and capabilities."
/>
)
}

Preview:

React - A JavaScript library for building user interfaces. Learn more about React's features and capabilities.

Custom Styled Hover Card

import { HoverCard } from '@dashflowx/core'
export default function CustomStyledHoverCard() {
return (
<HoverCard
hoverCardTrigger="🎨 Custom Style"
hoverCardContent="This hover card has custom styling with different colors and layout."
className="border-2 border-blue-500 rounded-xl"
/>
)
}

Preview:

This hover card has custom styling with different colors and layout.

Common Use Cases

User Profile Preview

const userProfileCard = (
<HoverCard
hoverCardTrigger="👤 @username"
hoverCardContent="Full Name - Job Title at Company. Brief bio and location information."
/>
);

Product Information

const productCard = (
<HoverCard
hoverCardTrigger="🛍️ Product Name"
hoverCardContent="Product description, price, and key features. Quick preview without leaving the page."
/>
);
const linkPreviewCard = (
<HoverCard
hoverCardTrigger="🔗 External Link"
hoverCardContent="Website title and description. Preview of the linked content."
/>
);

Tool Information

const toolInfoCard = (
<HoverCard
hoverCardTrigger="🔧 Tool Name"
hoverCardContent="Tool description, features, and usage examples. Quick reference information."
/>
);

Status Information

const statusCard = (
<HoverCard
hoverCardTrigger="🟢 Online"
hoverCardContent="User is currently online. Last seen 2 minutes ago. Available for chat."
/>
);

Best Practices

1. Clear Trigger Text

Use clear and descriptive trigger text.

// ✅ Good - Clear trigger
<HoverCard hoverCardTrigger="View Profile" />
// ❌ Avoid - Unclear trigger
<HoverCard hoverCardTrigger="Click" />

2. Concise Content

Keep hover card content concise and relevant.

// ✅ Good - Concise content
<HoverCard hoverCardContent="John Doe - Software Engineer" />
// ❌ Avoid - Too much content
<HoverCard hoverCardContent="John Doe is a software engineer who works at Tech Corp. He has been working there for 5 years and specializes in React development. He lives in San Francisco with his family and enjoys hiking on weekends..." />

3. Appropriate Timing

Use hover cards for quick previews, not detailed information.

// ✅ Good - Quick preview
<HoverCard hoverCardContent="Product: $29.99 - In Stock" />
// ❌ Avoid - Detailed information
<HoverCard hoverCardContent="This product is made from high-quality materials and includes a 2-year warranty. It's available in 5 colors and ships within 2-3 business days. Customer reviews average 4.5 stars..." />

4. Accessible Content

Ensure hover card content is accessible to all users.

// ✅ Good - Accessible content
<HoverCard hoverCardContent="User profile information" />
// ❌ Avoid - Content that requires hover
<HoverCard hoverCardContent="Hover over this text to see more" />

5. Consistent Styling

Maintain consistent styling across your application.

// ✅ Good - Consistent styling
<HoverCard className="standard-hover-card" />
// ❌ Avoid - Inconsistent styling
<HoverCard className="random-styles" />

Customization

Custom Styling

You can customize the hover card appearance using CSS classes:

<HoverCard
hoverCardTrigger="Custom Styled"
hoverCardContent="Custom content"
className="border-2 border-purple-500 rounded-xl"
/>

Different Themes

Use different themes for different contexts:

// Light theme
<HoverCard className="bg-white border-gray-200" />
// Dark theme
<HoverCard className="bg-gray-900 border-gray-700 text-white" />
// Brand theme
<HoverCard className="bg-blue-50 border-blue-200" />

Size Variations

Use different sizes for different content types:

// Small hover card
<HoverCard className="w-64" />
// Medium hover card
<HoverCard className="w-80" />
// Large hover card
<HoverCard className="w-96" />

Advanced Usage

Dynamic Content

Load hover card content dynamically:

const [hoverContent, setHoverContent] = useState('Loading...');
useEffect(() => {
// Load content based on trigger
loadHoverContent(triggerId).then(setHoverContent);
}, [triggerId]);

Conditional Content

Show different content based on conditions:

const getHoverContent = (user) => {
if (user.isOnline) {
return `${user.name} - Online now`;
}
return `${user.name} - Last seen ${user.lastSeen}`;
};

Rich Content

Include rich content in hover cards:

const richContent = (
<div>
<h4>Product Name</h4>
<p>Description</p>
<div className="flex space-x-2">
<button>Add to Cart</button>
<button>View Details</button>
</div>
</div>
);
  • Tooltip: For simple text tooltips
  • Popover: For click-triggered content
  • Card: For static content cards
  • Button: For trigger elements
  • Avatar: For user profile triggers

API Reference

For the complete API reference and advanced usage patterns, see the HoverCard API documentation.

Edit this page on GitHub