项目作者: chih-hsi-chen

项目描述 :
A simple datepicker for react
高级语言: JavaScript
项目地址: git://github.com/chih-hsi-chen/react-dater.git
创建时间: 2020-05-04T13:58:12Z
项目社区:https://github.com/chih-hsi-chen/react-dater

开源协议:MIT License

下载


react-dater

A simple datepicker for react

NPM JavaScript Style Guide dependencies Status Build Status

Install

  1. npm install --save react-dater

Usage

  1. import React, { Component } from 'react';
  2. import DatePicker from 'react-dater';
  3. import 'react-dater/dist/index.css';
  4. class Example extends Component {
  5. constructor(props) {
  6. super(props);
  7. this.state = {
  8. date: new Date(),
  9. };
  10. }
  11. render() {
  12. return (
  13. <DatePicker
  14. onChange = {(newDate) => this.setState({ date: newDate })}
  15. />
  16. );
  17. }
  18. }

Props

showMonthYearSeparate - (boolean)

If true, it will show current month and year separately with their own prev/next buttons.

dateFormatCalendar - (string)

The format of header of calendar, the default value is LLL yyyy.

dateFormatInput - (string)

The format of value in input field (or your custom input component).
Default value is MM/dd/yyyy.

onChange - (function)

This function will be invoked when some date is selected.
Default value is a dummy arrow function.

selected - (Date object)

When this prop is set, the calendar will first use its value as currently selected date.

locale - (Locale object)

We have date-fns as dependency, so you can import the locale object from it.
If not provided, the default locale is en-US.

Here is example

  1. import { enGB } from 'date-fns/locale';
  2. ...
  3. ...
  4. class Example extends Component {
  5. ...
  6. render() {
  7. return (
  8. <DatePicker
  9. locale = {enGB}
  10. ></DatePicker>
  11. );
  12. }
  13. }

Browser Support

PopperJS can support modern versions of Chrome, Firefox, Safari and Edge. However, it cannot directly support IE11 or IE9. Therefore, we can add some polyfills to make it work without errors.

Here we assume you use Create-React-App to create your project.
You can follow the official guidelines to use react-app-polyfill

IE11

  1. // These two must be top in src/index.js
  2. import 'react-app-polyfill/stable';
  3. import 'react-app-polyfill/ie11';

IE9

  1. // These two must be top in src/index.js
  2. import 'react-app-polyfill/stable';
  3. // this also includes ie11, so you don't have to include ie11 additionally.
  4. import 'react-app-polyfill/ie9';

For IE9, we need to add polyfill for classList because it isn’t supported by IE9.
Add the following source to a new script tag:
polyfill@1.2.20180112/classList.min.js"">https://cdn.jsdelivr.net/npm/eligrey-classlist-js-polyfill@1.2.20180112/classList.min.js

License

MIT © chih-hsi-chen