Giter Site home page Giter Site logo

react-cntdwn's Introduction

react-cntdwn

A simple React component that displays a countdown timer which is customizable.

Installation

npm install --save react-cntdwn

If you are using yarn,

yarn add react-cntdwn

Usage example

Below is an example of how this component might be used.

import Countdown fro 'react-cntdwn';

const handleFinish = function () {
  console.log('Skynet has become self-aware!');
}

<Countdown
  targetDate={new Date('August 29, 1997')}
  startDelay={2000}
  interval={1000}
  timeSeparator={':'}
  leadingZero
  onFinished={handleFinish}
/>

Props

targetDate

The datetime to count until.

  • type: Date
  • required

[format]

The format used to display the remaining time. It is an object with keys day, hour, minute, and second.

  • type: Object
  • optional
  • default:
{
  hour: 'HH',
  minute: 'MM',
  second: 'SS'
}

The component uses millisec npm module to convert the remaining time into human a readable format. You can use any format type supported by millisec to customize the output to a great degree.

Find all available formats here.

[startDelay]

The time in millisecond until the countdown begins.

  • type: Number
  • optional
  • default: 0

[interval]

The interval in millisecond for each tick in countdown.

  • type: Number
  • optional
  • default: 1000

[onFinished]

The callback function to be called when the countdown ends.

  • type: Function
  • optional

[timeSeparator]

The string used to separate the different parts of the time

  • type: String
  • optional
  • default: &nbsp;

[leadingZero]

Prepends a leading zero onto the time elements for consistant width

  • type: Bool
  • optional
  • default:

Contribution guide

The source code for the component is found in src/cntdwn.jsx. It is using es6 and is compiled using babel before being published to npm.

You may run npm run compile at any time to compile src/cntdwn.jsx to dist/cntdwn.jsx. But most likely you won't need to, because it is run automatically before npm publish.

License

MIT

react-cntdwn's People

Contributors

davecarlson avatar

Watchers

João Figueiredo avatar James Cloos avatar

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.