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

francescocioria avatar gabro avatar giogonzo avatar veej avatar sawsanias avatar wernerldev avatar djkirby avatar ascariandrea avatar antoinejaussoin avatar gcedo avatar ingro avatar utaal avatar francescogior avatar lucacioria 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.