1.2.1 • Published 6 years ago

react-custom-date-picker v1.2.1

Weekly downloads
227
License
MIT
Repository
github
Last release
6 years ago

React Custom Date Picker

Build

A simple date picker that is customizable.

Getting Started

Install

npm install react-custom-date-picker --save

or

yarn add react-custom-date-picker

Import

import DatePicker from 'react-custom-date-picker';

Dependencies

  • moment

Usage

This is the minimum requirement for using the react-custom-date-picker

Single Date Picker

import React, { Component } from 'react';
import DatePicker from 'react-custom-date-picker';

class App extends Component {
  state = {
    date: null,
  }

  handleDateChange = (date) => {
    this.setState({ date });
  }

  render() {
    return (
      <DatePicker
        date={this.state.date}
        handleDateChange={this.handleDateChange}
      />
    );
  }
}

export default App;

Custom Theming

import React, { Component } from 'react';
import DatePicker from 'react-custom-date-picker';

class App extends Component {
  state = {
    date: null,
  }

  handleDateChange = (date) => {
    this.setState({ date });
  }

  render() {
    return (
      <DatePicker
        color="#296b3e"
        date={this.state.date}
        errorColor="#c32c27"
        handleDateChange={this.handleDateChange}
        hoverWeek
        inputStyle={{
          borderRadius: 0,
        }}
        lightHeader
      />
    );
  }
}

export default App;

Date Range

import React, { Component } from 'react';
import DatePicker from 'react-custom-date-picker';

class App extends Component {
  state = {
    date: null,
    endDate: null,
  }

  handleDateChange = ([date, endDate]) => {
    this.setState({
      date,
      endDate,
    });
  }

  render() {
    return (
      <DatePicker
        date={this.state.date}
        endDate={this.state.endDate}
        handleDateChange={this.handleDateChange}
        range
      />
    );
  }
}

export default App;

Props

PropDescriptionTypeDefaultRequired
colorThe primary color of the date pickerString'#46b2e9'No
dateThe date (or start date if using the 'range' prop)Date ObjectnullYes
endDateThe end date if using the 'range' propDate ObjectnullYes
errorColorThe color displayed if date is invalid and using the 'required' propString'#ff0000'No
errorMessageThe error message to display if there is an errorString'Invalid Date'No
forceErrorHow to generate an error without user blurring the inputBooleanfalseNo
handleDateChangeUsed to control value of date (or array of two dates if using 'range' prop)Functionn/aYes
hoverWeekHighlights entire week on hoverBooleanfalseNo
inputStyleAll CSS attributes for input DOM element availableObject{}No
keepOpenPrevent the calendar from closing on selection or outside clickBooleanfalseNo
lightHeaderUse white font for header and selected date (recommend if 'color' prop is a dark color)BooleanfalseNo
maxDateSet the max date allowed (as a string 'YYYY-MM-DD')StringnullNo
minDateSet the min date allowed (as a string 'YYYY-MM-DD')StringnullNo
modalDisplay the calendar in a modal view (does not work with the prop 'keepOpen')BooleanfalseNo
placeholderPlaceholder text for inputString'Date (MM/DD/YYYY)'No
rangeAllow user to select start date and end dateBooleanfalseNo
requiredDisplays error on blur if date is invalidBooleanfalseNo
startOfWeekSet the starting day of the week (0 = Sunday, 1 = Monday, etc.)Number0No
widthSet width of datepicker windowNumber400No
1.2.1

6 years ago

1.1.20

6 years ago

1.1.19

6 years ago

1.1.18

6 years ago

1.1.17

6 years ago

1.1.16

6 years ago

1.1.15

6 years ago

1.1.14

6 years ago

1.1.13

6 years ago

1.1.11

6 years ago

1.1.10

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago