npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

custom-countdown

v1.3.0

Published

A simple and customizable React circular countdown

Downloads

3

Readme

Build Status Coverage Status

react-countdown360

A simple and customizable React circular countdown that counts down a number of seconds. This is a React implementation of John Schult's original jquery.countdown360

Examples

You can find some examples in the examples directory.

Basic example Stylized example Formatter example

Quickstart

Install with npm:

npm install react-countdown360

Render your countdown:

import Countdown360 from 'react-countdown360'

const App = () => {
  return <Countdown360 seconds={10} />
}

Documentation

Props

| Name | Type | Default | Description | |---------------------|----------|-------------------------|-------------------------------------------------| | seconds | Number | - | Number of seconds for the countdown | | autoStart | Boolean | true | Start the countdown immediatly after rendering | | backgroundColor | String | '#fff' | Color for the center of the circle | | borderFillColor | String | '#f11' | Color for the filled part of the border | | borderUnfillColor | String | '#e6e2e7' | Color for the unfilled part of the border | | borderWidth | Number | 20 | Width in pixels of the border | | clockwise | Boolean | false | Select the direction of rotation you prefer | | fontColor | String | '#111' | Font color for the label | | fontFamily | String | 'sans-serif' | The font to use for the label | | fontSize | Number | 45 | Font size in pixels | | fontWeight | Number | 700 | Font weight for the label | | onComplete | Function | undefined | A callback called when the countdown is over | | smooth | Boolean | false | Update the border once every second or smoothly | | startingAngle | Number | 0 | The angle at which the countdown should start | | timeFormatter | Func | timeFormatterSeconds | A function that returns the value to display | | unitFormatter | Func | unitFormatterSeconds | A function that returns the unit to display | | width | Number | 200 | Width in pixels of the countdown to render |

Time Formatters

You can customize the way the value on the countdown is shown by providing a custom timeFormatter function.

By default, the value shown is the number of seconds remaining rounded to the nearest integer.

A time formatter is a function that takes one single argument, being the number of milliseconds left, and returns the value to show on the countdown.

For instance, the following function is a time formatter that always shows a value with at least two digits:

const timeFormatterTwoDigits = timeLeft => {
  return Math.round(timeLeft / 1000).toString().padStart(2, '0')
}

We already provide a few time formatters that you can import from the package.

| Name | Description | Examples | Suggested unit formatter | |-----------------------------|-----------------------------------------------|----------------------------|--------------------------| | timeFormatterSeconds | Rounded number of seconds (default behaviour) | 0, 1, 12 | unitFormatterSeconds | | timeFormatterDigitalClock | MM:SS | 00:00, 00:12, 01: 59 | unitFormatterBlank |

Unit Formatters

You can also customize the unit shown on the countdown by providing a custom unitFormatter function.

A unit formatter is a function that takes one single argument, being the value shown on the countdown (as returned by the given time formatter), and returns the unit to display.

For instance, the following function is a unit formatter to show the number of seconds in Spanish:

const unitFormatterSpanishSeconds = value => {
  return value.toString() === '1' ? 'segundo' : 'segundos'
}

Be careful when choosing your unit formatter that it matches the time formatter in use!

We already provide a few unit formatters that you can import from the package.

| Name | Description | Examples | |------------------------|-----------------------|---------------------| | unitFormatterSeconds | 'second' or 'seconds' | second, seconds | | unitFormatterBlank | An empty string | |

Methods

  • start: start or resume the countdown
  • stop: pause the countdown
  • addSeconds (Number): add or remove (if negative) the given number of seconds to remaining number of seconds
  • extendTimer (Number): add or remove (if negative) the given number of seconds to the total number of seconds