Giter Club home page Giter Club logo

react-datepicker's Introduction

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

yarn add @y0c/react-datepicker
# or 
npm install --save @y0c/react-datepicker

πŸ’‘ Examples

Simple DatePicker

// import Calendar Component 
import React, { Component } from 'react';
import { DatePicker } from '@y0c/react-datepicker';
// import calendar style 
// You can customize style by copying asset folder.
import '@y0c/react-datepicker/assets/styles/calendar.scss';

class DatePickerExample extends Component {

  onChange = (date) => {
    // Day.js object
    console.log(date);

    // to normal Date object
    console.log(date.toDate());
  }
  
  render() {
    return (
      <DatePicker onChange={this.onChange}/>
    )
  }
}

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

// use day.js locale
import 'dayjs/locale/ko'

// delivery prop locale string  
<DatePicker locale="ko" />

// or define customize locale object 
const locale = {
  name: 'ko',
  weekdays: 'μΌμš”μΌ_μ›”μš”μΌ_ν™”μš”μΌ_μˆ˜μš”μΌ_λͺ©μš”일_κΈˆμš”μΌ_ν† μš”μΌ'.split('_'),
  weekdaysShort: '일_μ›”_ν™”_수_λͺ©_금_ν† '.split('_'),
  months: '1μ›”_2μ›”_3μ›”_4μ›”_5μ›”_6μ›”_7μ›”_8μ›”_9μ›”_10μ›”_11μ›”_12μ›”'.split('_'),
};

// delivery propr locale object
<DatePicker locale={locale} />

Defaults locale en

🎨 Themeing

  1. Copy this project asset folder under scss file
  2. Override scss variable you want(_variable.scss) ( red theme examples )
// red_theme.scss
$base-font-size: 12px;
$title-font-size: 1.3em;

// override scss variable
$primary-color-dark: #e64a19;
$primary-color: #ff5722;
$primary-color-light: #ffccbc;
$primary-color-text: #ffffff;
$accent-color: #ff5252;
$primary-text-color: #212121;
$secondary-text-color: #757575;
$divider-color: #e4e4e4;
$today-bg-color: #fff9c4;

// import mixin 
@import "../node_modules/@y0c/react-datepicker/assets/styles/_mixin.scss";
// import app scss
// if you want other style customize 
// app.scss copy & rewrite !
@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

# clone this project
git clone https://github.com/y0c/react-datepicker.git
# install dependency
yarn
# start storybook 
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

react-datepicker's People

Contributors

dependabot[bot] avatar flo-l avatar gitter-badger avatar ravisojitrawork avatar vilnytskyi avatar y0c avatar ziegfiroyt 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  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

react-datepicker's Issues

Clicking on backdrop fills input even if i didn't select any date, but fails to fire onChange.

Describe the bug
When i open datepicker and if i click on backdrop without selecting any date then it fills today's date in input but it doesn't fire handleChange. Either both should be done or none(this would be the right one since i didn't select any date). It's creating problem in form validation where date is auto filled but it's value is still null|undefined.

To Reproduce
Steps to reproduce the behavior:
https://codesandbox.io/s/react-datepicker-forked-okr9d?file=/src/index.js
0. Clear date input

  1. Focus date input again
  2. Click outside without selecting any date
  3. It fills date input with current date but doesn't fire handleChange

Expected behavior
When i click outside without selecting any date, It should not fill input to today's date.

Desktop (please complete the following information):

  • OS: ubuntu
  • Browser chrome
  • Version 86.0.4240.183

Accessibility attributes for modals

Given that the behavior of the control is effectively a modal, you should add the appropriate ARIA-* attributes for modal elements and behaviors.

Range where start and end day are the same

I would like to have a range with the same start and end dates in the RangeDatePicker.
But clicking on the same day did not change anything.

You can satisfy my requirements by changing the following in your code:

public handleDateChange = (actions: PickerAction) => (date: moment.Moment) => {
...
if (!start) {
      startDate = date;
    } else {
      if (end) {
        startDate = date;
        endDate = undefined;
      } else {
//      Original
//      if (isDayAfter(date, start)) { 
         if (!isDayBefore(date, start)) {
          endDate = date;
        } else {
          startDate = date;
        }
      }
    }
...
}

initialdate does not work. Within the range date picker

Is not initialdate an option to work with the range date picker?
My input is still empty.

state = {
        startDate: moment().subtract(7, 'days'),
        endDate: moment(),
    }


                <RangeDatePicker
                locale={"ko"}
                initialStartDate={startDate.toDate()}
                initialEndDate={endDate.toDate()}
                onChange={this.handleDateChange}/>

More modular scss files

Is your feature request related to a problem? Please describe.
Describe alternatives you've considered
I wouldn't like to have to duplicate all the app.scss code to just delete the Lato font import, or if I have light/dark themes in the site, having to either import the complete app.scss under different selectors or duplicate the rules related to colors (which would lead to having to keep a look on styles updates if you update the component)

Describe the solution you'd like
If app.scss is split in 2 files: non theming related and theme related, you could have multiple themes with less css output, and without needing to duplicate the stylesheet (leading to easier upgrades later on). The default font family could be set in the default scss file like calendar.scss, but not in the modular files, to avoid downloading a font you might not want to use.

Time formatting in DatePicker input.

I'm not sure if this is a bug or a feature request but I am having trouble formatting a datetime input.

Is your feature request related to a problem? Please describe.
Basically I need the time part of a datetime formatted in 24 hour format, and not AM/PM. I have updated the dateFormat parameter to include my desired format but the input shows the date formatted with that plus also the time repeated using the AM/PM format afterwards. This sandbox illustrates the problem, https://codesandbox.io/s/l4oq8z505q

Describe the solution you'd like
I think if the date format includes a time element then the time should not be displayed again. Either that or there needs to be separate timeFormat prop for the time picker. Likewise really there should probably be a calendarFormat or monthFormat prop for the calendar component since the default of 2019.03 is a strange and rarely used format in the UK and probably elsewhere. Neither the time or month formats appear to be
affected by changing the locale.

Missing configuration props

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
There are few props missing that would make this library nice to use & configure:

  • be able to customise the icon between inputs as well the icon for prev and next month (in RangeDatePicker)
  • be able to prevent 10px padding on inputs, currently it's set via style={{}} which is impossible to override from outside
  • be able to have custom formatting for calendar header date (at the moment it's set as YYYY.MM, which isn't perfect for all of the cases)

Describe the solution you'd like
I've prepared a PR with all those changes above along with type declaration adjustments & some good renames.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Open prop

It would be helpful if data range picker has open prop as state.

don't work locate="ru"

Describe the bug
In Russia DataFormat="DD.MM.YYYY", but use: import "dayjs/locale/ru"; and by specifying in the settings RangeDatePicker locale="ru", DataFormat="YYYY.MM.DD". If specify dateFormat="DD.MM.YYYY" , that format turn "MM.DD.YYYY".

When Datepicker is wrapped in <form>, navigating month fires submit event.

Describe the bug
When Datepicker is wrapped in <form>, navigating month fires submit event. this should not happen. apply type="button" property.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/react-datepicker-forked-97z69
  2. open any datepicker, and try to navigate to next or prev. month
  3. It will refresh the page

Expected behavior
It should not refresh the page when wrapped inside <form> tag

Desktop (please complete the following information):

  • OS: ubuntu
  • Browser: chrome

Additional context
Just apply type="button" property to those navigating arrows, or to wherever there are buttons.

showMonthCnt ꡬ쑰 λ¦¬νŒ©ν† λ§

  • Calendar 내뢀에 CalendarContainerλ₯Ό ν¬ν•¨ν•˜λŠ” ꡬ쑰둜 λ³€κ²½ 및 μ»΄ν¬λ„ŒνŠΈ λͺ…μΉ­ λ³€κ²½
  • prevIcon, nextIcon을 μ˜΅μ…˜κ°’μœΌλ‘œ μ„€μ • (첫번째 μΊ˜λ¦°λ”μ— prev, λ§ˆμ§€λ§‰ μΊ˜λ¦°λ”μ— next)
  • λ³΄μ΄λŠ” Calendar Component 의 monthκ°€ λ™μ‹œμ— μ»¨νŠΈλ‘€λ˜λ„λ‘ λ³€κ²½

Set first day of the week

Is your feature request related to a problem? Please describe.
Currently, the week starts from Sunday to Saturday in the calendar.
It would be better to have an option to set the first day of the week.

Describe the solution you'd like
We can have a prop to define the first day.

Thanks!

I am using rangedatepicker but not able to show default date on load!!!

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Clear date inputs dosn't fire onChange props method!

Using RangeDatePicker in combination with props clear, the event fire doesn't call the method onChange . I am using this library and it is great but is very necessary for me to have that feature.
A props *onClear should be great, which is called when handleInputClear (inside the RangeDatePicker) is fired

Year, Month, Day Select κΈ°λŠ₯ μΆ”κ°€

ν˜„μž¬ Day만 선택가λŠ₯ν•œ ꡬ쑰λ₯Ό 개편

  • Header ν΄λ¦­μ‹œ Year -> Month -> Day 순차적으둜 μ„ νƒν•˜λ„λ‘ λ³€κ²½

Keyboard accessibility

Describe the bug
The datepicker appears to be impossible to use with keyboard which makes it totally inaccessible.

To Reproduce
Steps to reproduce the behavior:

  1. Try to tab into the component
  2. Click on a date and attempt to navigate to another day or control with tabs and arrow keys

Expected behavior
In order for people who can only use keyboard or assisted devices to use the component it must not be reliant on mouse events only.

Desktop (please complete the following information):

  • OS: macOS Mojave
  • Browser Chrome
  • Version 73.x

Unit Test Code μž‘μ„±

Jest, Enzyme을 ν†΅ν•œ λ‹¨μœ„ ν…ŒμŠ€νŠΈ μ½”λ“œ μž‘μ„± 및 Travis CI 연동

Month selector picks wrong month

Describe the bug
Selecting a month beyond March chooses the wrong month

To Reproduce
Steps to reproduce the behavior:

  1. Go to example codepen from readme
  2. Click on 'Simple Date picker' area
  3. Click (e.g.) 2020.05 to choose new month
  4. Click e.g. June, note that date selected is 2020.04

Mapping appears to be:

Jan => Jan
Feb => Feb
Mar => Mar
Apr => Feb
May => Mar
Jun => Apr
July => Mar
Aug => Apr
Sep => May
Oct => Apr
Nov => May
Dec => Jun

Expected behaviour
I expect to select the month I click on.

Screenshots
n/a

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome
  • Version: 81.0.4044.138 (Official Build) (64-bit)

Switch between date and time tabs trigger form submit event

Describe the bug
I am trying to use datepicker with includeTime option inside a form. When i try switch between date and time tabs, the component is triggering the submit event.

To Reproduce
Steps to reproduce the behavior:

  1. Access CodeSandbox link [https://codesandbox.io/s/react-datepicker-gknwu?file=/src/index.js]
  2. Switch from date tab to time tab

Desktop (please complete the following information):

  • OS: Windows
  • Browser: Google Chrome

Keep popup open when selecting start & end dates

Is your feature request related to a problem? Please describe.
It appears selecting a date range requires the user to select a start date, and then click again to select an end date.

Describe the solution you'd like
A nicer user experience would be to keep the popup open until both the start and end dates have been selected.

Describe alternatives you've considered
Check out something like the Google date picker for flights.google.com. The user is able to choose both dates as needed (and in this example the popup actually includes a "done" button).

Additional context
I think it should probably be up to the developer to decide if the popup closes automatically or not in all states. So more configurable options is best. For example. keeping the popup open until the user decides to close it could be an option as well (like a Done button as exemplified via Google Flights mention above)

RangeDatePicker Input blur does not call onChange

With a RangeDatePicker, writing a formatted date into the Input Fields will update the internal state of the component, but will not notify listeners via the onChange prop, making it impossible to change the observed date range without clicking into the Calendar widget.

This should easily be fixed by calling onChange in handleInputBlur or handleInputChange.

Localization with first day of week different from Sunday is broken

Describe the bug
If a locale does specify a differen first day of the week than sunday, the calendar is showing wrong date/weekday combinations.

To Reproduce
Steps to reproduce the behavior:

  1. use a locale that sets a different weekday than sunday as first day of the week, eg. en-GB.
  2. look at the calendar and check if date and weekday match

Expected behavior
The grid of days should be shifted, such that eg. mondays are in the first column.

Screenshots
image

Desktop (please complete the following information):

  • OS: Linux & Windows
  • Browser Chrome & Firefox
  • Version any

Smartphone (please complete the following information):

  • Device: Android
  • OS: any
  • Browser stock & firefox
  • Version any

Additional context
I introduced this bug with #46 . I'll try and fix it as soon as I have time.

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.