Skip to content

hassantauqeer/react-awesome-countdowntimer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

41 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

React Awesome Countdown Timer

A modern, customizable countdown timer component for React with custom renderer, callbacks, and zero dependencies.

npm version License: MIT

Live Demo

Demo Image

โœจ Features

  • ๐ŸŽฏ Modern React with hooks
  • ๐ŸŽจ Fully customizable (CSS classes + inline styles)
  • ๐ŸŽญ Custom renderer with render props
  • ๐Ÿ”” Lifecycle callbacks (onComplete, onTick, onStart, onPause, onStop, onMount)
  • ๐ŸŽฎ Imperative API (start, pause, stop)
  • ๐Ÿ‘ถ Completion children
  • ๐Ÿ“ฆ Zero dependencies
  • โšก Lightweight (~1.6KB gzipped)
  • ๐Ÿ”ง TypeScript ready

๐Ÿ“ฆ Installation

npm install react-awesome-countdowntimer
# or
pnpm add react-awesome-countdowntimer
# or
yarn add react-awesome-countdowntimer

๐Ÿš€ Quick Start

import CountdownTimer from 'react-awesome-countdowntimer';
import 'react-awesome-countdowntimer/dist/index.css';

function App() {
  const endDate = new Date('2026-12-31T23:59:59');
  return <CountdownTimer endDate={endDate} />;
}

๐Ÿ“– Examples

Custom Styling

// With CSS classes
<CountdownTimer 
  endDate={endDate}
  timerClassName="my-timer"
  sectionClassName="my-section"
/>

// With inline styles
<CountdownTimer 
  endDate={endDate}
  timerStyle={{ background: '#f0f4f8', padding: '30px' }}
  sectionStyle={{ background: '#3b82f6', borderRadius: '12px' }}
/>

Custom Renderer

<CountdownTimer 
  endDate={endDate}
  renderer={({ days, hours, minutes, seconds, completed }) => {
    if (completed) return <div>๐ŸŽ‰ Time's up!</div>;
    return <div>{days}d {hours}:{minutes}:{seconds}</div>;
  }}
/>

Callbacks

<CountdownTimer 
  endDate={endDate}
  onComplete={() => console.log('Done!')}
  onTick={(delta) => console.log(delta.seconds)}
/>

Completion Children

<CountdownTimer endDate={endDate}>
  <div>โœจ Complete! โœจ</div>
</CountdownTimer>

Imperative Control

const timerRef = useRef();

<CountdownTimer ref={timerRef} endDate={endDate} autoStart={false} />
<button onClick={() => timerRef.current.start()}>Start</button>
<button onClick={() => timerRef.current.pause()}>Pause</button>

Advanced Features

// Overtime mode (continue past zero)
<CountdownTimer endDate={endDate} overtime={true} />

// Days in hours (show 48h instead of 2d)
<CountdownTimer endDate={endDate} daysInHours={true} />

// Custom padding
<CountdownTimer endDate={endDate} zeroPadTime={3} /> // 001:002:003

๐ŸŽ›๏ธ API Reference

Props

Prop Type Default Description
endDate Date required Target date/time
renderer function - Custom render function
children ReactNode - Content shown when complete
onComplete function - Callback when finished
onTick function - Callback every second
onStart function - Callback when started
onPause function - Callback when paused
onStop function - Callback when stopped
onMount function - Callback on mount
autoStart boolean true Auto-start countdown
zeroPadTime number 2 Zero-padding digits (1-3)
overtime boolean false Continue past zero
daysInHours boolean false Show hours instead of days
timerClassName string '' Timer container class
sectionClassName string '' Section class
timeClassName string '' Time number class
labelClassName string '' Label class
timerStyle object - Timer container styles
sectionStyle object - Section styles
timeStyle object - Time number styles
labelStyle object - Label styles

Render Props

The renderer function receives:

{
  total: number;      // Milliseconds remaining
  days: number;       // Days remaining
  hours: number;      // Hours remaining
  minutes: number;    // Minutes remaining
  seconds: number;    // Seconds remaining
  completed: boolean; // Is complete
  formatted: {        // Zero-padded strings
    days: string;
    hours: string;
    minutes: string;
    seconds: string;
  }
}

Imperative API

const ref = useRef();
ref.current.start();      // Start countdown
ref.current.pause();      // Pause countdown
ref.current.stop();       // Stop countdown
ref.current.isPaused();   // Returns boolean
ref.current.isStopped();  // Returns boolean
ref.current.isCompleted(); // Returns boolean

Default CSS Classes

  • .react-countdown-timer - Main container
  • .react-countdown-section - Time unit box
  • .react-countdown-time - Number display
  • .react-countdown-label - Label text

๐Ÿ“„ License

MIT ยฉ Hassan Tauqeer

โญ Support

Give a โญ๏ธ if this project helped you!

About

The most lightweight and 0 deps Countdown Timer component for ReactJS.

Topics

Resources

Stars

Watchers

Forks

Contributors