Overview
ThePokemonCard component displays a Pokemon in a visually appealing card format with type-based gradient backgrounds, hover animations, and an integrated favorite button. It’s optimized for performance using React’s memo API.
Import
Props
Pokemon data object containing id, name, types, and image
Usage Example
Features
Type-Based Theming
The card automatically applies gradient backgrounds based on the Pokemon’s primary type using thegetMostColorfulType utility and POKE_THEMES constant.
Hover Effects
- Image scales and translates upward on hover
- Saturation increases from 80% to 125%
- Smooth transitions for all interactive states
Integrated Components
- SpriteImage: Optimized Next.js Image wrapper with theme-based effects
- TypeBadge: Displays type badges with consistent styling
- FavoriteCardButton: Allows users to favorite/unfavorite the Pokemon
Performance Optimization
The component is wrapped withReact.memo to prevent unnecessary re-renders when props haven’t changed.
Implementation Details
Formatted ID Display
Pokemon IDs are displayed with leading zeros (e.g., #001, #025, #150):Gradient Calculation
The component usesuseMemo to calculate the gradient only when types or ID change:
Link Wrapper
The entire card is wrapped in a Next.jsLink component that navigates to /pokemon/{name}.
Styling
The component uses Tailwind CSS with UnoCSS syntax and custom utilities:font-rajdhani: Custom font familybg-size-[200%_200%]: Custom background sizesaturate-80: Custom saturation filter
Related Components
- PokeGallery - Displays multiple PokemonCards in a grid
- FavoriteButton - Standalone favorite toggle
- TypeBadge - Type display component
Source Location
/src/components/pokemon/PokemonCard.tsx:1-71