1.0.2 • Published 3 years ago

@abucarub/react-circle-countdown v1.0.2

Weekly downloads
3
License
ISC
Repository
-
Last release
3 years ago

React Circle Countdown

React Circle Countdown is a customizable animated countdown component.

Installation

npm i @abucarub/react-circle-countdown

Usage

import CircleCountdown from '@abucarub/react-circle-countdown';

const YourComponent = () => (
      <CircleCountdown
        seconds={10}
        size={150}
        font="bold 20px Arial"
        fontColor="#D7ECE6"
        barColor="rgb(51, 255, 153, 0.5)"
        barWidth={15}
        barTrailColor="#64867B"
        barEndShape="round"
        isPaused={false}
        pausedText="Wait"
        endText="Finished"
        onComplete={() => {
          console.log('Do something');
        }}
      />
)

Props

NameTypeDefaultDescription
secondsNumberrequiredThe seconds to count down ( min value: 1)
sizenumber130The width and height of the component
fontstring"20px sans-serif"Just like the CSS 'font' property
fontColorstring#fff '#fff'Takes any valid color format (HEX, rgb, rgba)
barColorstring#8ac4e1 '#8ac4e1'Takes any valid color format (HEX, rgb, rgba)
barTrailColorstring#6e818b '#6e818b'Takes any valid color format (HEX, rgb, rgba)
barWidthnumber15Path bar width
barEndShaperound | buttbuttThe shape of bar end
isPausedbooleantruePause and play animation
pausedTextstringCurrent timeThe displayed text when the animation is paused
endTextstring"Time over"The displayed when the countdown is over
showMaskbooleantrueIf set false, it show just a countdown without any mask
onCompletefunctionCalled when the countdown is over

Recipes

To restart de countdown

Could be restarted at any time, by using a useRef hook.

import React, { useRef } from 'react';
import CountDown, { IInputHandles } from "../components/CountDown";

const YourComponent = () => {
  const restartRef = useRef<IInputHandles>(null);

  const handleRestart = () => {
    restartRef.current?.restart();
  };

  return (
    <>
      <button onClick={() => handleRestart()}>
        Restart
      </button>
      <CircleCountDown
        ref={restartRef}
        seconds={80}      
      />
    </>
  )
}
...
1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago