Card
A versatile card component for displaying content with images, text, and interactive elements.
Card
The Card component is a flexible container for displaying content such as products, articles, or features. It supports different visual styles, interactive behaviors, and can include images, titles, descriptions, prices, ratings, and action buttons.
Features
- Multiple Variants: Classic, overlay, compact, and minimal styles
- Interactive: Optional press handlers and link navigation
- Rich Content: Support for images, text, prices, ratings, and badges
- Customizable: Control for rounded corners, dimensions, and styling
- Image Overlay: Optional gradient overlay for better text visibility
- Action Button: Optional button with custom handler
- Dark Mode Support: Automatic light/dark mode styles
Import
Props
Core Props
Prop | Type | Default | Description |
---|---|---|---|
title | string | Required | The title displayed in the card |
description | string | — | Optional description text |
image | string | Required | URI of the image to display |
onPress | () => void | — | Function called when the card is pressed |
href | string | — | If provided, card acts as a navigation link |
children | React.ReactNode | — | Additional content to render in the card |
Styling Props
Prop | Type | Default | Description |
---|---|---|---|
variant | 'classic' | 'overlay' | 'compact' | 'minimal' | 'classic' | The visual style of the card |
className | string | 'w-full' | Additional Tailwind classes for the container |
style | ViewStyle | — | React Native style object for the container |
rounded | 'none' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'full' | 'lg' | The border radius of the card |
width | number | string | 200 | Width of the card |
imageHeight | number | 200 | Height of the image in pixels |
Content Props
Prop | Type | Default | Description |
---|---|---|---|
price | string | — | Price text to display |
rating | number | — | Rating value (displays with a star icon) |
badge | string | — | Text for a badge overlay on the image |
badgeColor | string | '#FF3B30' | Background color for the badge |
showOverlay | boolean | true | Whether to show a gradient overlay (for overlay variant) |
overlayGradient | [string, string] | ['transparent', 'rgba(0,0,0,0.3)'] | Gradient colors for the overlay |
button | string | — | Text for an action button |
onButtonPress | () => void | — | Function called when the button is pressed |
Variants
Classic
The default variant with image on top and content below:
Overlay
Text displays on top of the image with a gradient overlay:
Compact
A more condensed version of the classic card:
Minimal
The most simplified version with minimal styling:
Usage Examples
Basic Card
Product Card with Price and Rating
Card with Badge
Card with Action Button
Navigation Card
Custom Styling
Gallery Card with Overlay
Grid Layout Example
Use with a FlatList or ScrollView for a grid layout:
Best Practices
Consistent Card Design
Use the same card variant for similar content types:
- Use
classic
for product listings with detailed information - Use
overlay
for featured content or media gallery items - Use
compact
for dense grid layouts or side-scrolling lists - Use
minimal
for simple content previews
Image Quality
Ensure images are properly sized and optimized:
Interactive Feedback
Provide clear feedback for interactive cards:
Implementation Details
The Card component uses React Native's TouchableOpacity
, View
, Text
, and Image
components for rendering. When the href
prop is provided, it uses Expo Router's navigation system.
For the overlay variant, it uses ImageBackground
with a LinearGradient
to create a visually appealing overlay effect that improves text readability on the image.
The component supports both light and dark mode through the useThemeColors
hook and the ThemedText
component.
Notes
- The
image
prop requires a valid URI string - When both
href
andonPress
are provided,href
takes precedence - For the
overlay
variant, the text is displayed directly on the image with a gradient background - The
rating
prop automatically adds a star icon next to the numeric value - The
badge
is positioned in the top-right corner of the image - The default width is 200 pixels, but can be customized with the
width
prop