Overview
TheTypeCalculator component provides an interactive interface for calculating type effectiveness in Pokemon battles. Users can select up to two types and see defensive effectiveness multipliers in real-time.
Import
Props
This component takes no props. All state is managed internally.Usage Example
Features
Type Selection
- Select up to 2 types simultaneously
- Click any type to toggle selection
- Selecting a third type automatically removes the first selected type
- Visual feedback for selected types using type-specific themes
Reset Functionality
- Animated reset button with 360-degree rotation
- Clears all selected types
- Prevents spam-clicking with animation state tracking
Real-Time Effectiveness Calculation
UsesuseMemo to efficiently calculate type effectiveness when selections change:
State Management
Selected Types
['fire', 'flying']).
Reset Animation
Type Toggle Logic
ThehandleToggle function implements smart type selection:
- Type already selected: Remove it
- 2 types already selected: Replace oldest with new selection (FIFO)
- 0-1 types selected: Add the new type
Reset Button
The reset button features animated feedback:Animation
- Duration: 600ms
- Rotation: 360 degrees
- Easing: cubic-bezier(0.4, 0, 0.2, 1)
- Scale increase on hover: 110%
- Color transition: zinc-600 to lime-500
Component Layout
Two-column responsive grid:Effectiveness Calculation
ThegetEffectivities utility function returns:
Example Output
For a Fire/Flying type Pokemon:Child Components
TypeSelector
Props:selectedTypes: Array of currently selected type namesonToggle: Callback function when a type is clicked
EffectivityResults
Props:multipliers: Object containing effectiveness categories
Styling
Section Headers
Dividers
Reset Button
Accessibility
- Clear section headings
- Descriptive button title: “Reset selection”
- Visual feedback for all interactions
- Keyboard accessible (inherits from button elements)
Performance Optimization
UsesuseMemo to prevent unnecessary recalculations:
- Only recalculates when
selectedTypesarray changes - Prevents expensive effectiveness calculations on every render
Example Use Cases
Building a Team
Check defensive coverage for your Pokemon team by testing different type combinations.Battle Strategy
Determine which Pokemon to send out based on opponent’s type combination.Learning Type Chart
Interactive way to learn Pokemon type matchups and memorize the type effectiveness chart.Related Components
- TypeSelector - Type selection grid interface
- EffectivityResults - Results display component
Utility Functions
getEffectivities
Location:@/lib/utils
Signature:
Source Location
/src/components/calculator/TypeCalculator.tsx:1-72