Giter Club home page Giter Club logo

react-simple-timefield's Introduction

react-simple-timefield

Simple React time input field, check out demo.

Build Status Coverage Status npm npm GitHub license

Demo

Installation

npm install --save react-simple-timefield

#for React <16 use: npm install --save react-simple-timefield@1

Usage

import TimeField from 'react-simple-timefield';
...
<TimeField
    value={time}                       // {String}   required, format '00:00' or '00:00:00'
    onChange={(event, value) => {...}} // {Function} required
    input={<MyCustomInputElement />}   // {Element}  default: <input type="text" />
    inputRef={(ref) => {...}}          // {Function} input's ref
    colon=":"                          // {String}   default: ":"
    showSeconds                        // {Boolean}  default: false
/>

Real world example

import TimeField from 'react-simple-timefield';

class App extends React.Component {
  constructor(...args) {
    super(...args);

    this.state = {
      time: '12:34'
    };

    this.onTimeChange = this.onTimeChange.bind(this);
  }

  onTimeChange(event, time) {
    this.setState({time});
  }

  render() {
    const {time} = this.state;

    return (
      <TimeField value={time} onChange={this.onTimeChange} />
    );
  }
}

Migrate version 2.x to version 3.x

There is a breaking change in version 3. The onChange callback property will be called with two arguments.

// Before:
<TimeField onChange={(value) => console.log(value)} />

// After:
<TimeField onChange={(event, value) => console.log(event, value)} />

Contributing

Run demo:

For running demo locally, replace:

import TimeField from '../';
// to
import TimeField from '../src';

in demo/index.tsx file.

# run development mode
cd demo
npm install
npm install --only=dev
npm run dev

Build:

npm install
npm install --only=dev
npm test
npm run format
npm run build

License

MIT License. Free use and change.

react-simple-timefield's People

Contributors

antonfisher avatar nicholaslyang avatar evilzorge avatar jamesmontalvo3 avatar nikolaybaranovv avatar oleghaidul avatar freshollie 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.