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

circular-timer-progress-bar

v1.0.7

Published

SVG-based native JS circular timer progress bar.

Downloads

542

Readme

circular-timer-progress-bar

SVG-based circular timer progress bar based. Implemented in native JavaScript. Tested in Google Chrome, Mozilla Firefox, Safari, Microsoft Edge and Opera.

NPM JavaScript Style Guide

Installation

npm

npm install --save circular-timer-progress-bar

yarn

yarn add circular-timer-progress-bar

Examples

Check out a live demo here: https://volkmaster.github.io/circular-timer-progress-bar/

You can use the timer by creating a CircularTimerProgressBar object and calling run function to start the execution. See the documentation for additional information.

React

For more information check out the code in the example folder.

import { useEffect, useRef } from "react"
import CircularTimerProgressBar from "circular-timer-progress-bar"

const Example = () => {
  const progressBarRef = useRef(null)

  useEffect(() => {
    if (progressBarRef.current) {
      new CircularTimerProgressBar(
        {
          container: progressBarRef.current,
          widthContainer: 300,
          heightContainer: 200,
          strokeWidth: 20,
          colorContainer: "#5e5e5e",
          colorCircle: "#c4c3c3",
          colorPath: "#2c2c2c",
          colorText: "#2c2c2c",
          fontFamily: "GothamRounded-Light",
        },
        2,
      ).run(7000)
    }
  }, [])

  return <svg ref={progressBarRef} />
}

export default Example

HTML & Native JS

Every CircularTimerProgressBar class instance needs to be provided with an SVG container object, which functions as a placeholder for other SVG elements:

<svg id="container"></svg>
  1. Timer that runs infinitely:
const timer = new CircularTimerProgressBar({
  container: document.getElementById("container"),
})
timer.run("inf")
  1. Timer that runs for 5 seconds and displays the number of seconds left (color of text changes to alert color with only 2 seconds left) in the middle of the circle with additional options specified (more):
const timer = new CircularTimerProgressBar({
  container: document.getElementById("container"),
  widthContainer: 200,
  heightContainer: 200,
  fontFamily: "GothamRounded-Bold",
})
timer.run(5000, 2000)
  1. Timer that runs for 8 seconds without any text in the middle of the circle with additional options specified (more):
const timer = new CircularTimerProgressBar(
  {
    container: document.getElementById("container"),
    widthContainer: 250,
    heightContainer: 350,
    strokeWidth: 25,
    colorContainer: "#2c2c2c",
    colorCircle: "#c4c3c3",
    colorPath: "#5e5e5e",
  },
  0,
  false,
)
timer.run(8000)
  1. An example of a timer that runs for 6 seconds with a hidden circle and displaying the number of seconds left (with 1 decimal place; color of text changes to alert color with only 2.5 seconds left) in the middle of the circle with additional options specified (more):
const timer = new CircularTimerProgressBar(
  {
    container: document.getElementById("container"),
    widthContainer: 150,
    heightContainer: 150,
    colorContainer: "#c0c0c0",
    colorAlert: "#dc143c",
    fontSize: 50,
    fontFamily: "GothamRounded-Book",
  },
  1,
  true,
  false,
)
timer.run(6000, 2500)
  1. An example of a timer that runs for 7 seconds and displays the number of seconds left (with 2 decimal places) in the middle of the circle with additional options specified (more):
const timer = new CircularTimerProgressBar(
  {
    container: document.getElementById("container"),
    widthContainer: 300,
    heightContainer: 200,
    strokeWidth: 20,
    colorContainer: "#5e5e5e",
    colorCircle: "#c4c3c3",
    colorPath: "#2c2c2c",
    colorText: "#2c2c2c",
    fontFamily: "GothamRounded-Light",
  },
  2,
)
timer.run(7000)

Documentation

The constructor of the CircularTimerProgressBar class initializes the timer.

CircularTimerProgressBar(options, nDecimals = 0, displayText = true, displayCircle = true)
  • options: CircularTimerProgressBarOptions object may contain the following attributes:

    • container: SVGElement: an SVG object, which functions as a placeholder for other SVG elements (required),
    • widthContainer?: number: width of the SVG placeholder in px (optional; default: 300px),
    • heightContainer?: number: height of the SVG placeholder in px (optional; default: 300px),
    • strokeWidth?: number: width of the timer progress bar in px (optional; default: 1/10 of the shortest of the container's dimensions),
    • colorContainer?: string: background color of the placeholder SVG element (optional; default: color inherited from parent),
    • colorCircle?: string: stroke color of the underlying circle SVG element (optional; default: lightgray),
    • colorPath?: string: stroke color of the path SVG element (optional; default: black),
    • colorText?: string: fill color of the text SVG element (optional; default: black),
    • colorAlert?: string: fill color of the text SVG element when time is under 3 seconds (optional; default: red),
    • fontSize?: number: size of the text font in px (optional; default: 1/6 of the shortest of the container's dimensions),
    • fontFamily?: string: font family of the text font (optional; default: sans-serif)
  • nDecimals?: number: number of decimals of the text representing the time left (optional; default: 0)

  • displayText?: boolean: flag indicating whether the text in the middle of the circle representing the time left (in seconds) is displayed (optional; default: true)

  • displayCircle?: boolean: flag indicating whether the circle indicating progress is displayed (optional; default: true)


The run function of the CircularTimerProgressBar class start the execution of the timer.

run(time, alertTime = 0)
  • time: number | string: number of milliseconds defining the timer duration (if 'inf', then the timer will be executed for indefinite duration; required)
  • alertTime?: number: number of milliseconds defining how much time before the end of the timer should the text in the middle of the circle change its color (optional; default: 0)

The pause function of the CircularTimerProgressBar class pauses the execution of the timer.

pause()

The resume function of the CircularTimerProgressBar class resumes the execution of the timer.

resume()

The isRunning function of the CircularTimerProgressBar class tells whether the timer is already running.

isRunning()

The isPaused function of the CircularTimerProgressBar class tells whether the timer is already paused.

isPaused()

License

MIT © volkmaster