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

simple-circle-timer

v0.3.1

Published

Lightweight, easily implemented countdown timer with circular progress bar. Optional Play, Pause, and Reset buttons.

Downloads

22

Readme

Simple React Circle Timer

Lightweight, easily implemented countdown timer with circular progress bar. Optional Play, Pause, and Reset buttons.

demo

Accurate timekeeping:

Instead of relying on the component's state to keep track of time, which is very prone to bugs and innaccuracies, this timer uses interval checks on the current Date object, ensuring accurate results down to the millisecond.

Play/Pause/Reset:

Most importantly, this timer differs from others in the amount of control it gives the user. See below for how to implement your own buttons or trigger the Play, Pause, Reset functions.

Scalable display:

The progress bar animation is handled by pure CSS (including the play/pause display). The entire component itself is scalable to any size (using the 'size' and 'fontSize' props) and color (using the 'fillColor' and 'bgColor' props). The font family and other styling will inherit from your parent component.

Installation

yarn add simple-circle-timer

or

npm install simple-circle-timer

Basic Usage

import {Timer} from 'simple-circle-timer'

const YourComponent = () => (
  <Timer/>
)

Props

size : (int) length and width of component in pixels
fontSize : (int) size of text inside the circle
minutes : (float) number of minutes you want the timer to run for (whole numbers or decimals)
fillColor : (str) color of progress bar & countdown text (hex code or color)
bgColor : (str) color inside the circle (hex code or color)
showMs : (bool) show milliseconds in the displayed time
onComplete : (function) runs when the timer reaches 00:00
completeMsg : (str) text displayed when the time runs out
running : (bool) whether or not the timer is counting down
setRunning : (function) needs to be passed to Timer for play, pause, reset (see below)
reset : (bool) set to true momentarily to trigger reset (see below)
setReset : (function) needs to be passed to Timer for reset (see below)

Play, Pause, Reset

This component is designed to give the user control over the timer. Below is an example of how to set up buttons using React hooks to play, pause, reset, and mount the timer with different settings.

import React, { useState } from 'react';
import {Timer} from 'simple-circle-timer'

const YourComponent = () => {
  const [ timerExists, setTimerExists ] = useState( false )
  const [ running, setRunning ] = useState( true )
  const [ reset, setReset ] = useState( false )

  //new timer is loaded in a paused state, awaiting 'play' command
  const mountPaused = () => {
    setTimerExists( true )
    setRunning( false )
  }

  //new timer is loaded already in a running state
  const mountRunning = () => {
    setTimerExists( true )
    setRunning( true )
  }

  //replace any/all of these buttons with your own components, or trigger the same state changes with functions from elsewhere in your app. 
  return (
    <>
      <div style={{ display: 'grid' }}>
        <button onClick={() => mountRunning()}>Load New Timer (running)</button>
        <button onClick={() => mountPaused()}>Load New Timer (paused)</button>
        <button onClick={() => setTimerExists( false )}>Remove Timer</button>
        <button onClick={() => setRunning( true )}>Play</button>
        <button onClick={() => setRunning( false )}>Pause</button>
        <button onClick={() => setReset( true )}>Reset</button>
      </div>
      {timerExists ? <Timer running={running} setRunning={setRunning} reset={reset} setReset={setReset} /> : null}
    </>
  )
}