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

react-svg-timer

v2.1.1

Published

SVG Timer React component

Downloads

35

Readme

React SVG Timer

NPM

A React component to provide an SVG-based timer button with visual feedback of elapsed time.

This is an improved iteration of previous projects:

All have their foundation in this fiddle.

Demo

Demo: markau.github.io/react-svg-timer

Installation

yarn add react-svg-timer or npm install react-svg-timer

Usage

The minimum declaration is:

import ReactSvgTimer from 'react-svg-timer';

<ReactSvgTimer timerCount={# seconds}/>

Properties

The component can take additional, optional props:

  • countdownColor: string: the color of the countdown ring. Type can be hex, rgb, rgba - whatever an SVG can use.
  • innerColor: string: the color of the inner circle ring.
  • outerColor: string: the color of the outer ring.
  • resetTimerRequested: bool: Whether the user has requested the timer be reset.
  • resetTimer: func: A callback function to further handle the timer reset event.
  • completeTimer: bool: Indicates whether the timer has reached the desired time.
  • timerDuration: int: The elapsed duration in milliseconds.
  • displayCountdown: bool: Shows/hides the numerical countdown.

A more complete implementation could therefore be:


// To keep track of the milliseconds elapsed
let timer = 0
let [resetRequested, setResetRequested] = useState(false)
let [timerIsComplete, setTimerIsComplete] = useState(false)
let [logMilliseconds, setLogMilliseconds] = useState(true)

onComplete(status) {
  setTimerIsComplete(status)
}

onReset() {
  setResetRequested(false)
}

timerValue(value) {
  timer = value;
  if (logMilliseconds) {
    console.log(value);
  }
}

onResetRequest() {
  setResetRequested(true)
  timer = 0;
}

return (

  <ReactSvgTimer
    timerCount={6}
    countdownColor="#00ffa8"
    innerColor="#fff"
    outerColor="#000"
    resetTimer={onReset}
    completeTimer={onComplete}
    resetTimerRequested={resetRequested}
    timerDuration={timerValue}
    displayCountdown={displayCountdown}
  />

)

The optional props are designed to provide flexibility for implementation. You can use the timer as a discrete component, and just listen for the timerComplete callback. Alternatively, for example, you could choose to hide the numerical display countdown with displayCountdown={false}, and use the timerDuration callback to provide your own numerical countdown.

Development

Built with create-react-library check that project to see how to build and run this module locally.

License

MIT © markau