Counter Component
TheCounter is a React component that displays a real-time countdown timer. It calculates the time remaining between a start date and end date, updating every second. The component supports two display variants: a compact “mini” version for cards and a full-featured version for dedicated pages.
Props
The start date of the countdown period. Can be a date string or Date object.
Duration in days from the start date. Used to calculate the end date automatically.
Display variant:
mini: Compact 4-column grid layout for cardsfull: Large individual blocks with glass panel styling
Optional callback function triggered when the countdown reaches zero.
Type Definitions
Component Behavior
Time Calculation
The component calculates remaining time by:- Converting
fecha_inicioto milliseconds - Adding
duracion_dias(converted to milliseconds) to get the end time - Computing the difference between end time and current time
- Updating every second via
setInterval
States
- Active: Displays countdown with days, hours, minutes, and seconds
- Finished: Shows “Versión finalizada” message when countdown reaches zero
Usage Examples
Mini Variant (Home Page)
Full Variant (Game Detail Pages)
Visual Styling
Mini Variant
- Layout: 4-column grid with minimal spacing
- Numbers: 3xl font, bold, countdown-font class
- Labels: Tiny (10px) uppercase with wide letter spacing
- Best for: Compact cards on home/overview pages
Full Variant
- Layout: Individual glass panel blocks
- Numbers: 4xl-5xl font with hover effects
- Effects: Primary glow, hover border transitions, pulse animation on seconds
- Highlight: The seconds block includes special styling with purple theme color (#4b2bee)
- Best for: Dedicated countdown pages with large display
When using in Astro, remember to include
client:load directive to enable client-side hydration for the real-time countdown functionality.Implementation Details
React Hooks
The component uses:useStateto track countdown state and finished statususeEffectto set up interval-based time updates- Cleanup function to clear interval on unmount
Time Object Structure
Source Location
The Counter component is located at:src/components/react/Counter.tsx