pushtell / react-bootstrap-date-picker

React-Bootstrap based date picker.
MIT License
347 stars 195 forks source link

React-Bootstrap based date picker.

NPM Version Circle CI Coverage Status Dependency Status NPM Downloads

See the demo at pushtell.github.io/react-bootstrap-date-picker.

Demo

Please ★ on GitHub!

Using this module in production? We'd love to hear about it.

Table of Contents

Installation

react-bootstrap-date-picker is compatible with React 0.14.x and 0.15.x.

npm install react-bootstrap-date-picker

Usage

var DatePicker = require("react-bootstrap-date-picker");

var App = React.createClass({
  getInitialState: function(){
    var value = new Date().toISOString();
    return {
      value: value
    }
  },
  handleChange: function(value, formattedValue) {
    this.setState({
      value: value, // ISO String, ex: "2016-11-19T12:00:00.000Z"
      formattedValue: formattedValue // Formatted String, ex: "11/19/2016"
    });
  },
  componentDidUpdate: function(){
    // Access ISO String and formatted values from the DOM.
    var hiddenInputElement = document.getElementById("example-datepicker");
    console.log(hiddenInputElement.value); // ISO String, ex: "2016-11-19T12:00:00.000Z"
    console.log(hiddenInputElement.getAttribute('data-formattedvalue')) // Formatted String, ex: "11/19/2016"
  },
  render: function(){
    return <FormGroup>
      <ControlLabel>Label</ControlLabel>
      <DatePicker id="example-datepicker" value={this.state.value} onChange={this.handleChange} />
      <HelpBlock>Help</HelpBlock>
    </FormGroup>;
  }
});

API Reference

<DatePicker />

DatePicker component. Renders as a React-Bootstrap InputGroup.

InputGroup properties are passed through to the input group.

Tests

Browser Coverage

Karma tests are performed on Browserstack in the following browsers:

Please let us know if a different configuration should be included here.

Running Tests

Locally:


npm test

On Browserstack:


BROWSERSTACK_USERNAME=YOUR_USERNAME BROWSERSTACK_ACCESS_KEY=YOUR_ACCESS_KEY npm test