Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-countdown-circle-timer

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-countdown-circle-timer

Lightweight React countdown timer component with color and progress animation based on SVG

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
31K
decreased by-8.08%
Maintainers
1
Weekly downloads
 
Created
Source

React Countdown Circle Timer

npm bundle size Codecov npm

React countdown timer component in a circle shape with color and progress animation to urge with pleasure your users.

  • Performance optimized with single requestAnimationFrame loop to animate color and progress (no setInterval used)
  • Transition between colors during the countdown
  • Support for linear gradient
  • Fully customizable content in the center of the circle
  • a11y support

Installation

yarn add react-countdown-circle-timer

or

npm install react-countdown-circle-timer

Demo

Check the demo on CodeSandbox to get started
Edit stoic-cache-e7cie

Basic usage

import { CountdownCircleTimer } from 'react-countdown-circle-timer';

const UrgeWithPleasureComponent = () => (
    <CountdownCircleTimer
        isPlaying
        durationSeconds={10}
        colors={[
            ['#004777', .33],
            ['#F7B801', .33],
            ['#A30000']
        ]}
    />
);

Props

Prop NameTypeDefaultDescription
durationSecondsnumberrequiredCountdown duration in seconds
colorsArray<[color HEX: string, transition duration: float number between 0 and 1]>requiredArray of tuples: 1st param - color in HEX format; 2nd param - time to transition to next color represented as a fraction of the total duration
startAtnumber0Set the start time to a different value than 0
sizenumber180Width and height of the SVG element
strokeWidthnumber12Path stroke width
strokeLinecapEnum{ 'round', 'square' }roundPath stroke line cap
trailColorstring#d9d9d9Circle trail color - takes any valid color format (HEX, rgb, rgba, etc.)
isPlayingbooleanfalsePlay and pause animation
* isLinearGradientbooleanfalse* Apples linear gradient on top of the circle. The gradient doesn't follow the circle path. Works best with two colors.
gradientUniqueKeystring-Unique ID for the linearGradient element. It takes random ID if it's not provided.
renderTimefunction(remainingTime: number, elapsedTime: number, isPlaying: boolean): number|string|ReactNode-Render prop function to customize the content in the center of the circle. The content is centered using flexbox.
onCompletefunction(): undefined | [shouldRepeat: boolean, delay: number]-On complete handler. It can be used to repeat the countdown by returning an array where the first element shouldRepeat indicates if the loop should start over and second element delay specifies the delay before looping again in milliseconds.
ariaLabelstringCountdown timerAria label for the whole component
renderAriaTimefunction(remainingTime: number, elapsedTime: number, isPlaying: boolean): string-Render prop function to customize the text message that will be read by the screen reader during the countdown.

Recipes

Restart timer at any given time

Pass a key prop to CountdownCircleTimer and change the key when the timer should be restarted.

Repeat timer when countdown is completed

Return an array from onComplete handler, which indicates if the animation should be repeated. Example:

const UrgeWithPleasureComponent = () => (
    <CountdownCircleTimer
        onComplete={() => {
            // do your stuff here
            return [true, 1500]; // repeat animation in 1.5 seconds
        }}
        isPlaying
        durationSeconds={10}
        colors={[['#A30000']]}
    />
);

Set initial start time different than 0

Pass the initial start time to startAt prop. Example:

const UrgeWithPleasureComponent = () => (
    <CountdownCircleTimer
        isPlaying
        durationSeconds={60}
        startAt={20}
        colors={[['#A30000']]}
    />
);

In the example above, the countdown will start at 20 seconds and it will animate for the rest of the time (40 seconds) until it reaches the duration of 60 seconds.

Roadmap

  • Typescript type definitions

Keywords

FAQs

Package last updated on 22 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc