Giter VIP home page Giter VIP logo

ryanhefner / react-timer-wrapper Goto Github PK

View Code? Open in Web Editor NEW
17.0 3.0 0.0 2.92 MB

Composable React Timer component that passes status props to children, in addition to some basic callbacks. Can be used at a countdown timer ⏲ or as stopwatch ⏱ to track time while active.

Home Page: https://ryanhefner.github.io/react-timer-wrapper/

License: MIT License

JavaScript 77.08% HTML 4.36% CSS 18.56%
react react-component timer countdown countdown-timer react-timer react-timer-wrapper react-timecode react-indicators

react-timer-wrapper's Introduction

⏳ react-timer-wrapper

npm NPM npm Coveralls github CircleCI Snyk Vulnerabilities for GitHub Repo

Composable React Timer component that passes status props to children, in addition to some basic callbacks. Can be used at a countdown timer ⏲ or as stopwatch ⏱ to track time while active.

Install

Via npm

npm install --save react-timer-wrapper

Via Yarn

yarn add react-timer-wrapper

How to use

The Timer can be used in a couple different ways. You could use it as a standalone timer and setup callbacks to trigger things to happen in your project. Or, wrap child components in Timer component, where those children will receive props passed in by the Timer.

It can be used as a countdown timer, which will fire the onFinish event upon completion. Or, you can use it to track the time that occurs while it’s active.

Properties

  • active:Boolean - Start/stop the timer. (Default: false)
  • component:String | Element - Element or React component used to render/wrap the children. (Default: div)
  • duration:Number - Enables countdown mode and is the number of milliseconds to count before firing onFinish. (Default: 10000)
  • loop:Boolean - Enable looping of the countdown timer. (Default: false)
  • time:Number - Either used as a time offset for the duration when used as a countdown timer, or the initial time to start from when used for tracking time. (Default: 0)
  • onFinish:Function - Callback fired when the timer has finished. (Fired in countdown mode only)
  • onStart:Function - Callback fired when the timer is started.
  • onStop:Function - Callback fired when the timer is stopped.
  • onTimeUpdate:Function - Callback fired when time updates.

Examples

Standalone

import Timer from 'react-timer-wrapper';

...

  onTimerStart({duration, progress, time}) {

  }

  onTimerStop({duration, progress, time}) {

  }

  onTimerTimeUpdate({duration, progress, time}) {

  }

  onTimerFinish({duration, progress, time}) {

  }

  render() {
    const {
      timerActive,
    } = this.state;

    return (
      <Timer
        active={timerActive}
        onFinish={this.onTimerFinish}
        onStart={this.onTimerStart}
        onStop={this.onTimerStop}
        onTimeUpdate={this.onTimerTimeUpdate}
      />
    );
  }

...

With children

import Timer from 'react-timer-wrapper';
import CircleIndicator from 'react-indicators';

...

  render() {
    const {
      timerShouldRun,
    } = this.state;

    return (
      <Timer active={timerShouldRun}>
        <CircleIndicator />
      </Timer>
    );
  }

...

Children

The Timer allows you to easily compose components that provide a visual status of the timer. Each children receives the following props that you can use to communicate the status of the timer.

  • duration:Number - Duration of the countdown timer. (Available for countdown timers only, null passed when used for time tracking)
  • progress:Number - Current percentage of timer complete. (Available for countdown timers only, null passed when used for time tracking)
  • time:Number - Current time on the timer in milliseconds.

Pairs well with...

License

MIT © Ryan Hefner

react-timer-wrapper's People

Contributors

greenkeeper[bot] avatar greenkeeperio-bot avatar ryanhefner avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-timer-wrapper's Issues

Reverse timer

Let say we have 45 min duration. How can we implement reverse countdown for this ?

An in-range update of jsdom is breaking the build 🚨

Version 11.12.0 of jsdom was just published.

Branch Build failing 🚨
Dependency jsdom
Current Version 11.11.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

jsdom is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: Your tests failed on CircleCI (Details).

Commits

The new version differs by 22 commits.

  • 4d26c67 Version 11.12.0
  • d6688e5 Implement Element.prototype.closest()
  • 9191218 Upgrade NWSAPI to v2.0.7
  • 500a209 Change storageQuota to operate on code units, not bytes
  • 23d67eb Add the storageQuota option
  • b4db242 Remove unused form-data-symbols.js file
  • 70fd739 Fix a few entries in the changelog
  • eae1062 Upgrades cssstyle dependency to ^1.0.0
  • 022c204 Update hosts in Travis configuration
  • 2761d3c HashChangeEvent and PopStateEvent should no longer bubble
  • f1270e7 Roll Web Platform Tests
  • d6f8a97 Enable Blob-slice.html test in Node.js v10
  • 3afbc0f Implement Web storage - localStorage, sessionStorage, StorageEvent
  • 7b4db76 Handle Node.js v6 timeout in execution-timing tests
  • a5a7785 Run failing tests to confirm their status

There are 22 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

statefull solution

What would be the solution to make this clock running at the same values even after page refresh?

An in-range update of rollup-plugin-json is breaking the build 🚨

The devDependency rollup-plugin-json was updated from 3.0.0 to 3.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

rollup-plugin-json is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: Your tests failed on CircleCI (Details).

Commits

The new version differs by 7 commits.

  • bb64f65 3.1.0
  • 97615d6 Update changelog
  • 1bcf81b Update dependencies and make tests rollup1.0 compatible (#46)
  • 4df5395 Update changelog
  • 2a528e3 Expose the "compact" and "namedExports" options (#45)
  • e9c01b9 Update changelog
  • 8de10c0 Update rollup-pluginutils to support null values in json (#44)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of rollup-plugin-commonjs is breaking the build 🚨

The devDependency rollup-plugin-commonjs was updated from 9.1.7 to 9.1.8.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

rollup-plugin-commonjs is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: Your tests failed on CircleCI (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of react is breaking the build 🚨

Version 16.5.0 of the react packages was just published.

Branch Build failing 🚨
Monorepo release group react
Current Version 16.4.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

This monorepo update includes releases of one or more dependencies which all belong to the react group definition.

react is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: Your tests failed on CircleCI (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of enzyme is breaking the build 🚨

Version 3.4.2 of the enzyme packages was just published.

Branch Build failing 🚨
Monorepo release group enzyme
Current Version 3.4.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

This monorepo update includes releases of one or more dependencies which all belong to the enzyme group definition.

enzyme is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: Your tests failed on CircleCI (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of enzyme is breaking the build 🚨

Version 3.4.1 of the enzyme packages was just published.

Branch Build failing 🚨
Monorepo release group enzyme
Current Version 3.4.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

This monorepo update includes releases of one or more dependencies which all belong to the enzyme group definition.

enzyme is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: Your tests failed on CircleCI (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of lolex is breaking the build 🚨

The devDependency lolex was updated from 2.7.4 to 2.7.5.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

lolex is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: Your tests failed on CircleCI (Details).

Commits

The new version differs by 9 commits.

  • 927609c 2.7.5
  • 76c212d Updated release files for 2.7.5
  • c4ee56d fix: handle floating point in hrtime (#210)
  • cbaa8ba Merge pull request #208 from SimenB/run-to-last-loop
  • f1f80da fix: reset high resolution timer on clock.reset (#209)
  • a6c0308 clarify test
  • ee3862e simplify test
  • 4983ee8 fix: runToLast should respect current time
  • 1278eaa Add an error when creating a clock with no Date object (#205)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of react-timecode is breaking the build 🚨

The devDependency react-timecode was updated from 1.1.10 to 1.1.11.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

react-timecode is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: Your tests failed on CircleCI (Details).

Commits

The new version differs by 11 commits.

  • a2beda9 1.1.11
  • 1686796 Update dependencies and exclude all test files from npm
  • 7ba6290 Merge pull request #31 from ryanhefner/greenkeeper/rollup-plugin-uglify-6.0.0
  • 983d2b2 Merge pull request #30 from ryanhefner/greenkeeper/rollup-0.66.0
  • 779ccce Merge pull request #34 from ryanhefner/greenkeeper/monorepo.enzyme-1.5.0
  • 275db5b chore(package): update lockfile yarn.lock
  • a9bbe64 chore(package): update rollup-plugin-uglify to version 6.0.0
  • 00c0560 chore(package): update lockfile yarn.lock
  • 5abc708 chore(package): update rollup to version 0.66.0
  • aa06b96 chore(package): update enzyme-adapter-react-16 to version 1.5.0
  • 30a1589 chore(package): update enzyme to version 3.6.0

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.