FlashCard component is an interactive, animated flashcard that displays vocabulary terms with their definitions. It supports flip animations, swipe gestures, and text-to-speech functionality.
Features
- Flip Animation: Click or swipe left to flip between term and definition
- Swipe Gestures: Swipe right to mark as known, swipe left to flip
- Text-to-Speech: Listen to term pronunciation and definition
- ELI5 Mode: Display simplified definitions for complex terms
- Visual Feedback: Glowing effects during swipe gestures
- Responsive Design: Adapts to different screen sizes
Props
The vocabulary term object containing:
term(string): The vocabulary worddefinition(string): Standard definitioneli5Definition(string, optional): Simplified explanationexample(string, optional): ASCII visual example
Current card number in the deck (displayed as “Term #01”, “Term #02”, etc.)
Total number of cards in the current category
Tailwind CSS color class for the card background (e.g.,
"bg-gradient-to-br from-blue-400 to-indigo-500")When enabled, displays simplified definitions instead of standard definitions
Callback function triggered when user swipes right. Used to mark card as known and advance to next card.
Optional callback function triggered when user swipes left to flip the card
Ref Methods
The component exposes aFlashCardRef interface via forwardRef:
Programmatically flip the card. Useful for keyboard shortcuts.
Usage Example
Swipe Gestures
The component uses Framer Motion’s drag functionality with the following thresholds:- Swipe Right (>120px): Marks card as known and triggers
onSwipeRightcallback - Swipe Left (<-120px): Flips the card to show definition
- Below Threshold: Returns card to center position
Visual Feedback
- Green Glow: Appears when swiping right (indicates “I know this”)
- Blue Glow: Appears when swiping left (indicates “flip to definition”)
- Opacity: Card opacity decreases as you drag further from center
Card Structure
Front Side (Term)
- Category color gradient background
- Card number indicator (e.g., “TERM #01”)
- Large, bold term display
- Swipe instructions footer
- Speaker button for text-to-speech
- Decorative visual elements
Back Side (Definition)
- Neutral card background
- “DEFINITION” label with optional “ELI5” badge
- Definition text (standard or simplified)
- ASCII visual example (if provided)
- Swipe instructions footer
- Speaker button for text-to-speech
Text-to-Speech
The component integrates with theuseSpeech hook:
- Front Side: Speaks only the term
- Back Side: Speaks both term and definition
- Visual Indicator: Button pulses when speaking
- Stop Functionality: Click again to stop speech
Animations
Powered by Framer Motion:- Flip Animation: 3D rotateY transform with spring physics
- Drag Animation: Smooth x-axis translation with rotation
- Return Animation: Spring-based return to center
- Exit Animation: Slides out when marked as known
Accessibility
- Click-to-flip functionality for users who can’t swipe
- Keyboard navigation via exposed
flip()ref method - Speech synthesis support detection
- High contrast borders and text
- Semantic HTML structure
Implementation Notes
Drag Configuration
- Restricts dragging to horizontal axis only
- Elastic drag feel with 0.7 resistance
- Constraints prevent permanent displacement
Motion Transforms
Source Code Reference
See the full implementation in/workspace/source/src/components/FlashCard.tsx