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-timer-machine

v1.0.2

Published

React Timer Machine is a fully controllable and customizable timer component for react

Downloads

235

Readme

react-timer-machine

React Timer Machine is a fully controllable and customizable timer component for react

NPM JavaScript Style Guide Build Status Build Status Maintainability Test Coverage

Install

npm install --save react-timer-machine

or

yarn add react-timer-machine

Usage

import React, { Component } from 'react'

import TimerMachine from 'react-timer-machine'

import moment from "moment";
import momentDurationFormatSetup from "moment-duration-format";

momentDurationFormatSetup(moment);

class Example extends Component {
  render () {
    return (
      <TimerMachine
        timeStart={10 * 1000} // start at 10 seconds
        timeEnd={20 * 1000} // end at 20 seconds
        started={true}
        paused={false}
        countdown={false} // use as stopwatch
        interval={1000} // tick every 1 second
        formatTimer={(time, ms) =>
          moment.duration(ms, "milliseconds").format("h:mm:ss")
        }
        onStart={time =>
          console.info(`Timer started: ${JSON.stringify(time)}`)
        }
        onStop={time =>
          console.info(`Timer stopped: ${JSON.stringify(time)}`)
        }
        onTick={time =>
          console.info(`Timer ticked: ${JSON.stringify(time)}`)
        }
        onPause={time =>
          console.info(`Timer paused: ${JSON.stringify(time)}`)
        }
        onResume={time =>
          console.info(`Timer resumed: ${JSON.stringify(time)}`)
        }
        onComplete={time =>
          console.info(`Timer completed: ${JSON.stringify(time)}`)
        }
    />
    )
  }
}

User guide

TimerMachine

Renders a React Fragment to be fully customized. You can easily style the timer states thanks to the provided function callbacks.

By default, TimerMachine displays the time formatted as: hh:mm:ss.SSS. The format can be changed using the formatTimer property. See usage example above.

Props

| Name | Type | Default | Description | |---------------------- |------------ |---------------------------------------------- |------------------------------------------------------------------------------------------------------------------ | | timeStart required | number | - | The initial time on which the timer is set (in ms) | | timeEnd | number | 0 | The time on which the timer will complete (in ms) | | countdown | boolean | false | When true, sets the timer to countdown instead of counting up | | interval | number | 1000 | The time between each ticks (in ms) | | started | boolean | false | Starts the timer when set to true, stops it when set to false | | paused | boolean | false | Pauses the timer when set to true, resumes it when set to false | | formatTimer | function | (timer: Timer, ms: number) => 'hh:mm:ss.SSS'| Function to format the timer before it renders. You can use moment-duration as shown above or write your own | | onStart | function | (timer: Timer) => void | Callback function called on timer start | | onTick | function | (timer: Timer) => void | Callback function called on each timer tick | | onPause | function | (timer: Timer) => void | Callback function called on timer pause | | onResume | function | (timer: Timer) => void | Callback function called when timer resumes | | onStop | function | (timer: Timer) => void | Callback function called on timer stop | | onComplete | function | (timer: Timer) => void | Callback function called on timer complete |

Types

| Name | Example values | |----------------|-----------------------------------| | Timer object | { h: 1, m: 30, s: 30, ms: 0 } |

Versioning

react-timer-machine is maintained under the Semantic Versioning guidelines.

Contributing

Love react-timer-machine and would like to help? Check out the contribution guidelines for this project, everything should be there!

Contributors

Yassine Doghri (creator)

Copyright and licence

Code and documentation copyright 2018, Yassine Doghri. Code released under the MIT License.