Coder Social home page Coder Social logo

rc-datepicker's Introduction

NPM

React Datepicker

A decent and pretty date picker to be used with React

image

import 'moment/locale/it.js';
import { DatePicker, DatePickerInput } from 'rc-datepicker';

const date = '2015-06-26' // or Date or Moment.js

onChange = (jsDate, dateString) => {
  // ...
}

React.renderComponent(
  <div>
    // this renders the full component (input and datepicker)
    <DatePickerInput
      onChange={onChange}
      value={date}
      className='my-custom-datepicker-component'
      {...anyReactInputProps}
    />

    // this renders only a fixed datepicker
    <DatePicker onChange={onChange} value={date} />
  </div>,
  document.body
);

You can see a live demo here

or check the full examples here

FOR WEBPACK USERS: webpack by default imports every locale. Please take a look at this question on Stack Overflow for possible solutions.

Install

npm install --save rc-datepicker

The npm package is compiled in JavaScript 5

Changelog

See CHANGELOG.md

DatePickerInput API

See this readme

Locales

DatePicker and DatePickerInput use Moment.js, therefore they support any locale inside "moment/locale".

To select a locale you need to require it before requiring the datepicker or moment anywhere in your app: this way it will be automatically selected as current locale.

import 'moment/locale/fr.js' // or 'rc-datepicker/node_modules/moment/locale/fr.js' if you don't have it in your node_modules folder

import { DatePickerInput } from 'rc-datepicker';

DatePickerInput will now use French locale by default.

Switch between locales

You can switch between locales by passing the prop "locale" to DatePickerInput or DatePicker.

WATCH OUT this method requires the wanted locale to be already available in your bundle which is only true if you had already imported it or if you're using moment-with-locales.min.js

import 'moment/locale/fr.js'
import 'moment/locale/es.js'

<DatePicker locale='es' />

Style

DatePickerInput and DatePicker come with their own default style. In order to use it you should import it in your project as follows:

import 'rc-datepicker/lib/style.css';

Examples

$ npm install
$ npm start
$ open http://localhost:8080

rc-datepicker's People

Contributors

antoinejaussoin avatar ascariandrea avatar cloudsoh avatar djkirby avatar francescocioria avatar francescogior avatar gabro avatar gcedo avatar giogonzo avatar ingro avatar ivanghisleni avatar lucacioria avatar matteoturri avatar sawsanias avatar utaal avatar veej avatar wernerldev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rc-datepicker's Issues

closeOnClickOutside not triggered when clicking into another DatePickerInput

Say I have 2 DatePickerInputs that are set to closeOnClickOutside={true}. If I click the first one, the DatePicker pops up, and then if I leave it up and click the second DatePickerInput, the first DatePicker stays up and the second DatePicker is displayed as well. I'm not sure if this is the expected behavior but I would expect the first DatePicker to close in this scenario, just like it would if I clicked outside to a normal <input>.

CI is failing due to lint error

build   15-Jul-2015 16:15:02    ERROR in ./src/DatePicker.js
build   15-Jul-2015 16:15:02    
build   15-Jul-2015 16:15:02    /wd/src/DatePicker.js
build   15-Jul-2015 16:15:02      58:41  error  Multiple spaces found before '{'  no-multi-spaces
build   15-Jul-2015 16:15:02    
build   15-Jul-2015 16:15:02    ✖ 1 problem (1 error, 0 warnings)

Use Radium

As of today, the component is shipped with an optional css stylesheet. I also saw that in DatePicker and DatePickerInput, there is the style prop, meant to override the style.

How about switching to Radium? In this way you could pack your component with a default style that does not depend on an external file. If the user wants to override that style, he can pass a style object to the root component that will be merged with the base style, overriding the values of the matching keys.

If you agree I can work on a PR to achieve this.

Find an alternative to valueLink

Since valueLink has been deprecated in React 15.0 and it will be removed in 16.0 it would be nice to find an alternative since it's currently used in rc-datepicker.

An easy upgrade path would be, as suggested by React's changelog, to use this library without changing much in the current code.

January calendar wrong with moment 2.11+

Hello! I'm using your datepicker and found a strange bug. Doesn't matter which locale I choose, january always start on the first day as 1, here's a screenshot:
datepicker

Aftwer some investigation and seeing that the demo online was working I found that the problem was introduced by moment 2.11.0 (2.11.1 also didn't fix the problem). Reverting back to a 2.10.x version of moment solved the problem. The other months seems fine.

[IE] datepicker returns InvalidDate at first click

description

first click triggers an onChangeInput with dateString: ''

specs

handle case where dateString === '' and we still don't have a valid date stored in state

misc

{optional: other useful info}

3.1.0 break change mode button

After updating to 3.1.0 I noticed the following problem: clicking on the change mode button closes the datepicker!

The problem is not present on the online demo, I suspect they are still running on 3.0.2, but I cloned the repo and then ran the examples locally and I can reproduce the problem.

add clearable

requirements

user should be able to clear DatePickerInput value

specs

  • add icon-clear button on the left of current icon button
    • iconClearClassName
    • onClear -> callback
  • render only if prop.onClear exists

React 15.x compatibility

Hello!

Rc-datepicker works fine with React 0.14.x even if it throws deprecation warnings here and there.
Anyway those warnings became errors on React 15.x.

Those warnings regards the use of require('react/addons') in src/DatePicker.js (which is a typo I guess) and the use of the function React.findDOMNode in src/DatePickerInput.js which has been moved to the dedicated react-dom package.

Moreover this is not needed anymore in React 0.14.x because this.refs.datePickerInput returns the DOM node by default.

So I guess it's needed a release that enforce React 0.14+, to gain also the compatibility with React 15.

I could create a pull request but those are breaking changes so I wanted to discuss here first.

Let me know if I can proceed or if you prefeer to follow another path!

Thanks.

How can I use this module in IE9?

Many thanks,UI is perfect for my project! but I notice that the code has used some new features of es6, so how can I implement this module in IE9 with ReactJs ? :)

Add 'name' prop to DatePickerInput

This should be passed to the underlying input field.
It's useful when doing form validation with Semantic UI, which is relies on the field name.

New build system based on karma/webpack/babel

Work in progress. Key points are

  • run in a real browser
    • Chrome by default, Firefox on Travis
  • allow for breakpoints in sourcemaps
  • run tests on source (now it's on build)
  • test coverage reports on coverall.io

code clean

  • adapt props to es-lint key-spacing rule and remove various /* eslint-disable key-spacing */ all around
  • iconClassName is not being checked in DatePickerInput props
  • do some cleaning (unused comments, trailing spaces/lines ...)

improve DatePicker and DatePickerInput API

Right now both components accept a large number of props. This might be due to a poor API design.

DatePickerInput:

  onChange:             React.PropTypes.func.isRequired,
  onShow:               React.PropTypes.func,
  onHide:               React.PropTypes.func,
  date:                 DateUtils.evaluateDateProp,
  initialDate:          DateUtils.evaluateDateProp,
  minDate:              DateUtils.evaluateDateProp,
  maxDate:              DateUtils.evaluateDateProp,
  locale:               React.PropTypes.string,
  startMode:            React.PropTypes.string,
  fixedMode:            React.PropTypes.bool,
  format:               React.PropTypes.string,
  showOnInputClick:     React.PropTypes.bool,
  closeOnClickOutside:  React.PropTypes.bool,
  showInputButton:      React.PropTypes.bool,
  autoClose:            React.PropTypes.bool,
  floating:             React.PropTypes.bool,
  className:            React.PropTypes.string,
  style:                React.PropTypes.object

DatePicker:

  onChange:            React.PropTypes.func.isRequired,
  date:                DateUtils.evaluateDateProp,
  initialDate:         DateUtils.evaluateDateProp,
  minDate:             DateUtils.evaluateDateProp,
  maxDate:             DateUtils.evaluateDateProp,
  locale:              React.PropTypes.string,
  startMode:           React.PropTypes.string,
  fixedMode:           React.PropTypes.bool,
  floating:            React.PropTypes.bool,
  closeOnClickOutside: React.PropTypes.bool, // used only with DatePickerInput
  className:           React.PropTypes.string,
  style:               React.PropTypes.object

\cc @gabro @gcanti

note: date and initialDate will soon become value and initialValue as described in this issue: #13

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.