项目作者: y0c

项目描述 :
📅 React DatePicker Library (Flexible, Reusable)
高级语言: TypeScript
项目地址: git://github.com/y0c/react-datepicker.git
创建时间: 2018-12-07T11:12:13Z
项目社区:https://github.com/y0c/react-datepicker

开源协议:MIT License

下载




drawing





React DatePicker






License: MIT npm version
Build Status
codecov
Maintainability
code style: prettier
dependencies Status
devDependencies Status
Storybook
NPM Download
Join the chat at https://gitter.im/react-datepicker/community

Flexible, Reusable, Mobile friendly DatePicker Component

🎬 Intro

DatePicker

datepicker

RangeDatePicker

rangedatepicker

Demo in Storybook

Edit React Datepicker

✨ Major Component

  • RangeDatePicker
  • DatePicker
  • Standalone Calendar

The components that you can use are as follows: If you want to configure the DatePicker yourself, you can configure it any way you want through the Default Calendar component.

🔧 Built With

  • TypeScript
  • Sass
  • React

📦 Dependency

  • Moment.js

In previous versions, moment.js were used. but now it is changed to Day.js to because of bundle size issue (#14)

Day.js is a javascript library for Parse, validate, manipulate, and display dates and times. this component use Day.js library to globalize and control date. You can check the locale list through this link.

📲 Installation

  1. yarn add @y0c/react-datepicker
  2. # or
  3. npm install --save @y0c/react-datepicker

💡 Examples

Simple DatePicker

  1. // import Calendar Component
  2. import React, { Component } from 'react';
  3. import { DatePicker } from '@y0c/react-datepicker';
  4. // import calendar style
  5. // You can customize style by copying asset folder.
  6. import '@y0c/react-datepicker/assets/styles/calendar.scss';
  7. class DatePickerExample extends Component {
  8. onChange = (date) => {
  9. // Day.js object
  10. console.log(date);
  11. // to normal Date object
  12. console.log(date.toDate());
  13. }
  14. render() {
  15. return (
  16. <DatePicker onChange={this.onChange}></DatePicker>
  17. )
  18. }
  19. }

You can find more Exmaples and Demo in story book link

🌎 i18n

Features for i18n are provided by Day.js by default.

see locale list https://github.com/iamkun/dayjs/tree/dev/src/

and you can customize the locale object

  1. // use day.js locale
  2. import 'dayjs/locale/ko'
  3. // delivery prop locale string
  4. <DatePicker locale="ko" ></DatePicker>
  5. // or define customize locale object
  6. const locale = {
  7. name: 'ko',
  8. weekdays: '일요일_월요일_화요일_수요일_목요일_금요일_토요일'.split('_'),
  9. weekdaysShort: '일_월_화_수_목_금_토'.split('_'),
  10. months: '1월_2월_3월_4월_5월_6월_7월_8월_9월_10월_11월_12월'.split('_'),
  11. };
  12. // delivery propr locale object
  13. <DatePicker locale={locale} ></DatePicker>

Defaults locale en

🎨 Themeing

  1. Copy this project asset folder under scss file
  2. Override scss variable you want(_variable.scss)
    ( red theme examples )
  1. // red_theme.scss
  2. $base-font-size: 12px;
  3. $title-font-size: 1.3em;
  4. // override scss variable
  5. $primary-color-dark: #e64a19;
  6. $primary-color: #ff5722;
  7. $primary-color-light: #ffccbc;
  8. $primary-color-text: #ffffff;
  9. $accent-color: #ff5252;
  10. $primary-text-color: #212121;
  11. $secondary-text-color: #757575;
  12. $divider-color: #e4e4e4;
  13. $today-bg-color: #fff9c4;
  14. // import mixin
  15. @import "../node_modules/@y0c/react-datepicker/assets/styles/_mixin.scss";
  16. // import app scss
  17. // if you want other style customize
  18. // app.scss copy & rewrite !
  19. @import "../node_modules/@y0c/react-datepicker/assets/styles/app.scss";

if you want custom css rewrite app.scss file

Try this example!

Edit 1rw1lp8w7j

⚙️ Local Development

This component is managed by a storybook which is combined with develop environment and documentation. If you want develop in local environment, clone project and develop through a storybook

  1. # clone this project
  2. git clone https://github.com/y0c/react-datepicker.git
  3. # install dependency
  4. yarn
  5. # start storybook
  6. yarn run storybook

Open your browser and connect http://localhost:6006

💼 Get Support

Please fork and use https://codesandbox.io/s/pw6n17pk57 to reproduce your problem.

  • Open a new issue(Bug or Feature) on Github
  • Join the Gitter room to chat with other developers.

👨‍👦‍👦 Contribution

Issue and Pull Request are always welcome!

📝 License

MIT