Giter Site home page Giter Site logo

react-dates / react-dates Goto Github PK

View Code? Open in Web Editor NEW
12.2K 146.0 1.7K 37.93 MB

An easily internationalizable, mobile-friendly datepicker library for the web

Home Page: https://react-dates.github.io/react-dates/

License: MIT License

JavaScript 99.95% SCSS 0.05%
react datepicker react-component react-dates dates calendar

react-dates's Introduction

react-dates Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

An easily internationalizable, accessible, mobile-friendly datepicker library for the web.

react-dates in action

Live Playground

For examples of the datepicker in action, go to react-dates.github.io.

OR

To run that demo on your own computer:

Getting Started

Install dependencies

Ensure packages are installed with correct version numbers by running (from your command line):

(
  export PKG=react-dates;
  npm info "$PKG" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g; s/ *//g' | xargs npm install --save "$PKG"
)

Which produces and runs a command like:

npm install --save react-dates moment@>=#.## react@>=#.## react-dom@>=#.##

If you are running Windows, that command will not work, but if you are running npm 5 or higher, you can run npx install-peerdeps react-dates on any platform

Initialize

import 'react-dates/initialize';

As of v13.0.0 of react-dates, this project relies on react-with-styles. If you want to continue using CSS stylesheets and classes, there is a little bit of extra set-up required to get things going. As such, you need to import react-dates/initialize to set up class names on our components. This import should go at the top of your application as you won't be able to import any react-dates components without it.

Note: This component assumes box-sizing: border-box is set globally in your page's CSS.

Include component

import { DateRangePicker, SingleDatePicker, DayPickerRangeController } from 'react-dates';

Webpack

Using Webpack with CSS loader, add the following import to your app:

import 'react-dates/lib/css/_datepicker.css';

Without Webpack:

Create a CSS file with the contents of require.resolve('react-dates/lib/css/_datepicker.css') and include it in your html <head> section.

To see this in action, you can check out https://github.com/majapw/react-dates-demo which adds react-dates on top of a simple create-react-app setup.

Overriding Base Class

By default react-dates will use PureComponent conditionally if it is available. However, it is possible to override this setting and use Component and shouldComponentUpdate instead. It is also possible to override the logic in build/util/baseClass if you know that you are using a React version with PureComponent.

  import React from 'react';
  export default React.PureComponent;
  export const pureComponentAvailable = true;

Overriding styles

Right now, the easiest way to tweak react-dates to your heart's content is to create another stylesheet to override the default react-dates styles. For example, you could create a file named react_dates_overrides.css with the following contents (Make sure when you import said file to your app.js, you import it after the react-dates styles):

// NOTE: the order of these styles DO matter

// Will edit everything selected including everything between a range of dates
.CalendarDay__selected_span {
  background: #82e0aa; //background
  color: white; //text
  border: 1px solid $light-red; //default styles include a border
}

// Will edit selected date or the endpoints of a range of dates
.CalendarDay__selected {
  background: $dark-red;
  color: white;
}

// Will edit when hovered over. _span style also has this property
.CalendarDay__selected:hover {
  background: orange;
  color: white;
}

// Will edit when the second date (end date) in a range of dates
// is not yet selected. Edits the dates between your mouse and said date
.CalendarDay__hovered_span:hover,
.CalendarDay__hovered_span {
  background: brown;
}

This would override the background and text colors applied to highlighted calendar days. You can use this method with the default set-up to override any aspect of the calendar to have it better fit to your particular needs. If there are any styles that you need that aren't listed here, you can always check the source css of each element.

Make some awesome datepickers

We provide a handful of components for your use. If you supply essential props to each component, you'll get a full featured interactive date picker. With additional optional props, you can customize the look and feel of the inputs, calendar, etc. You can see what each of the props do in the live demo or explore how to properly wrap the pickers in the examples folder.

DateRangePicker

The DateRangePicker is a fully controlled component that allows users to select a date range. You can control the selected dates using the startDate, endDate, and onDatesChange props as shown below. The DateRangePicker also manages internal state for partial dates entered by typing (although onDatesChange will not trigger until a date has been entered completely in that case). Similarly, you can control which input is focused as well as calendar visibility (the calendar is only visible if focusedInput is defined) with the focusedInput and onFocusChange props as shown below.

Here is the minimum REQUIRED setup you need to get the DateRangePicker working:

<DateRangePicker
  startDate={this.state.startDate} // momentPropTypes.momentObj or null,
  startDateId="your_unique_start_date_id" // PropTypes.string.isRequired,
  endDate={this.state.endDate} // momentPropTypes.momentObj or null,
  endDateId="your_unique_end_date_id" // PropTypes.string.isRequired,
  onDatesChange={({ startDate, endDate }) => this.setState({ startDate, endDate })} // PropTypes.func.isRequired,
  focusedInput={this.state.focusedInput} // PropTypes.oneOf([START_DATE, END_DATE]) or null,
  onFocusChange={focusedInput => this.setState({ focusedInput })} // PropTypes.func.isRequired,
/>

The following is a list of other OPTIONAL props you may provide to the DateRangePicker to customize appearance and behavior to your heart's desire. All constants (indicated by ALL_CAPS) are provided as named exports in react-dates/constants. Please explore the storybook for more information on what each of these props do.

// input related props
startDatePlaceholderText: PropTypes.string,
endDatePlaceholderText: PropTypes.string,
startDateAriaLabel: PropTypes.string,
endDateAriaLabel: PropTypes.string,
startDateTitleText: PropTypes.string,
endDateTitleText: PropTypes.string,
disabled: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf([START_DATE, END_DATE])]),
required: PropTypes.bool,
readOnly: PropTypes.bool,
screenReaderInputMessage: PropTypes.string,
showClearDates: PropTypes.bool,
showDefaultInputIcon: PropTypes.bool,
customInputIcon: PropTypes.node,
customArrowIcon: PropTypes.node,
customCloseIcon: PropTypes.node,
inputIconPosition: PropTypes.oneOf([ICON_BEFORE_POSITION, ICON_AFTER_POSITION]),
noBorder: PropTypes.bool,
block: PropTypes.bool,
small: PropTypes.bool,
regular: PropTypes.bool,
autoComplete: PropTypes.string,

// calendar presentation and interaction related props
renderMonthText: mutuallyExclusiveProps(PropTypes.func, 'renderMonthText', 'renderMonthElement'), // (month) => PropTypes.string,
orientation: PropTypes.oneOf([HORIZONTAL_ORIENTATION, VERTICAL_ORIENTATION]),
anchorDirection: PropTypes.oneOf([ANCHOR_LEFT, ANCHOR_RIGHT]),
openDirection: PropTypes.oneOf([OPEN_DOWN, OPEN_UP]),
horizontalMargin: PropTypes.number,
withPortal: PropTypes.bool,
withFullScreenPortal: PropTypes.bool,
appendToBody: PropTypes.bool,
disableScroll: PropTypes.bool,
daySize: nonNegativeInteger,
isRTL: PropTypes.bool,
initialVisibleMonth: PropTypes.func,
firstDayOfWeek: PropTypes.oneOf([0, 1, 2, 3, 4, 5, 6]),
numberOfMonths: PropTypes.number,
keepOpenOnDateSelect: PropTypes.bool,
reopenPickerOnClearDates: PropTypes.bool,
renderCalendarInfo: PropTypes.func,
renderMonthElement: mutuallyExclusiveProps(PropTypes.func, 'renderMonthText', 'renderMonthElement'), PropTypes.func, // ({ month, onMonthSelect, onYearSelect, isVisible }) => PropTypes.node,
hideKeyboardShortcutsPanel: PropTypes.bool,
verticalSpacing: PropTypes.number,

// navigation related props
navPrev: PropTypes.node,
navNext: PropTypes.node,
onPrevMonthClick: PropTypes.func,
onNextMonthClick: PropTypes.func,
onClose: PropTypes.func,
transitionDuration: nonNegativeInteger, // milliseconds

// day presentation and interaction related props
renderCalendarDay: PropTypes.func,
renderDayContents: PropTypes.func,
minimumNights: PropTypes.number,
minDate: momentPropTypes.momentObj,
maxDate: momentPropTypes.momentObj,
enableOutsideDays: PropTypes.bool,
isDayBlocked: PropTypes.func,
isOutsideRange: PropTypes.func,
isDayHighlighted: PropTypes.func,

// internationalization props
displayFormat: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
monthFormat: PropTypes.string,
weekDayFormat: PropTypes.string,
phrases: PropTypes.shape(getPhrasePropTypes(DateRangePickerPhrases)),
dayAriaLabelFormat: PropTypes.string,

SingleDatePicker

The SingleDatePicker is a fully controlled component that allows users to select a single date. You can control the selected date using the date and onDateChange props as shown below. The SingleDatePicker also manages internal state for partial dates entered by typing (although onDateChange will not trigger until a date has been entered completely in that case). Similarly, you can control whether or not the input is focused (calendar visibility is also controlled with the same props) with the focused and onFocusChange props as shown below.

Here is the minimum REQUIRED setup you need to get the SingleDatePicker working:

<SingleDatePicker
  date={this.state.date} // momentPropTypes.momentObj or null
  onDateChange={date => this.setState({ date })} // PropTypes.func.isRequired
  focused={this.state.focused} // PropTypes.bool
  onFocusChange={({ focused }) => this.setState({ focused })} // PropTypes.func.isRequired
  id="your_unique_id" // PropTypes.string.isRequired,
/>

The following is a list of other OPTIONAL props you may provide to the SingleDatePicker to customize appearance and behavior to your heart's desire. All constants (indicated by ALL_CAPS) are provided as named exports in react-dates/constants. Please explore the storybook for more information on what each of these props do.

// input related props
placeholder: PropTypes.string,
ariaLabel: PropTypes.string,
titleText: PropTypes.string,
disabled: PropTypes.bool,
required: PropTypes.bool,
readOnly: PropTypes.bool,
screenReaderInputMessage: PropTypes.string,
showClearDate: PropTypes.bool,
customCloseIcon: PropTypes.node,
showDefaultInputIcon: PropTypes.bool,
customInputIcon: PropTypes.node,
inputIconPosition: PropTypes.oneOf([ICON_BEFORE_POSITION, ICON_AFTER_POSITION]),
noBorder: PropTypes.bool,
block: PropTypes.bool,
small: PropTypes.bool,
regular: PropTypes.bool,
autoComplete: PropTypes.string,

// calendar presentation and interaction related props
renderMonthText: mutuallyExclusiveProps(PropTypes.func, 'renderMonthText', 'renderMonthElement'), // (month) => PropTypes.string,
orientation: PropTypes.oneOf([HORIZONTAL_ORIENTATION, VERTICAL_ORIENTATION]),
anchorDirection: PropTypes.oneOf([ANCHOR_LEFT, ANCHOR_RIGHT]),
openDirection: PropTypes.oneOf([OPEN_DOWN, OPEN_UP]),
horizontalMargin: PropTypes.number,
withPortal: PropTypes.bool,
withFullScreenPortal: PropTypes.bool,
appendToBody: PropTypes.bool,
disableScroll: PropTypes.bool,
initialVisibleMonth: PropTypes.func,
firstDayOfWeek: PropTypes.oneOf([0, 1, 2, 3, 4, 5, 6]),
numberOfMonths: PropTypes.number,
keepOpenOnDateSelect: PropTypes.bool,
reopenPickerOnClearDate: PropTypes.bool,
renderCalendarInfo: PropTypes.func,
renderMonthElement: mutuallyExclusiveProps(PropTypes.func, 'renderMonthText', 'renderMonthElement'), // ({ month, onMonthSelect, onYearSelect, isVisible }) => PropTypes.node,
hideKeyboardShortcutsPanel: PropTypes.bool,
daySize: nonNegativeInteger,
isRTL: PropTypes.bool,
verticalSpacing: PropTypes.number,

// navigation related props
navPrev: PropTypes.node,
navNext: PropTypes.node,
onPrevMonthClick: PropTypes.func,
onNextMonthClick: PropTypes.func,
onClose: PropTypes.func,
transitionDuration: nonNegativeInteger, // milliseconds

// day presentation and interaction related props
renderCalendarDay: PropTypes.func,
renderDayContents: PropTypes.func,
enableOutsideDays: PropTypes.bool,
isDayBlocked: PropTypes.func,
isOutsideRange: PropTypes.func,
isDayHighlighted: PropTypes.func,

// internationalization props
displayFormat: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
monthFormat: PropTypes.string,
weekDayFormat: PropTypes.string,
phrases: PropTypes.shape(getPhrasePropTypes(SingleDatePickerPhrases)),
dayAriaLabelFormat: PropTypes.string,

DayPickerRangeController

The DayPickerRangeController is a calendar-only version of the DateRangePicker. There are no inputs (which also means that currently, it is not keyboard accessible) and the calendar is always visible, but you can select a date range much in the same way you would with the DateRangePicker. You can control the selected dates using the startDate, endDate, and onDatesChange props as shown below. Similarly, you can control which input is focused with the focusedInput and onFocusChange props as shown below. The user will only be able to select a date if focusedInput is provided.

Here is the minimum REQUIRED setup you need to get the DayPickerRangeController working:

<DayPickerRangeController
  startDate={this.state.startDate} // momentPropTypes.momentObj or null,
  endDate={this.state.endDate} // momentPropTypes.momentObj or null,
  onDatesChange={({ startDate, endDate }) => this.setState({ startDate, endDate })} // PropTypes.func.isRequired,
  focusedInput={this.state.focusedInput} // PropTypes.oneOf([START_DATE, END_DATE]) or null,
  onFocusChange={focusedInput => this.setState({ focusedInput })} // PropTypes.func.isRequired,
  initialVisibleMonth={() => moment().add(2, "M")} // PropTypes.func or null,
/>

The following is a list of other OPTIONAL props you may provide to the DayPickerRangeController to customize appearance and behavior to your heart's desire. Again, please explore the storybook for more information on what each of these props do.

  // calendar presentation and interaction related props
  enableOutsideDays: PropTypes.bool,
  numberOfMonths: PropTypes.number,
  orientation: ScrollableOrientationShape,
  withPortal: PropTypes.bool,
  initialVisibleMonth: PropTypes.func,
  renderCalendarInfo: PropTypes.func,
  renderMonthElement: mutuallyExclusiveProps(PropTypes.func, 'renderMonthText', 'renderMonthElement'), // ({ month, onMonthSelect, onYearSelect, isVisible }) => PropTypes.node,
  onOutsideClick: PropTypes.func,
  keepOpenOnDateSelect: PropTypes.bool,
  noBorder: PropTypes.bool,

  // navigation related props
  navPrev: PropTypes.node,
  navNext: PropTypes.node,
  onPrevMonthClick: PropTypes.func,
  onNextMonthClick: PropTypes.func,
  transitionDuration: nonNegativeInteger, // milliseconds

  // day presentation and interaction related props
  renderCalendarDay: PropTypes.func,
  renderDayContents: PropTypes.func,
  minimumNights: PropTypes.number,
  isOutsideRange: PropTypes.func,
  isDayBlocked: PropTypes.func,
  isDayHighlighted: PropTypes.func,

  // internationalization props
  monthFormat: PropTypes.string,
  weekDayFormat: PropTypes.string,
  phrases: PropTypes.shape(getPhrasePropTypes(DayPickerPhrases)),
  dayAriaLabelFormat: PropTypes.string,
/>

Localization

Moment.js is a peer dependency of react-dates. The latter then uses a single instance of moment which is imported in oneโ€™s project. Loading a locale is done by calling moment.locale(..) in the component where moment is imported, with the locale key of choice. For instance:

moment.locale('pl'); // Polish

However, this only solves date localization. For complete internationalization of the components, react-dates defines a certain amount of user interface strings in English which can be changed through the phrases prop (explore the storybook for examples). For accessibility and usability concerns, all these UI elements should be translated.

Advanced

react-dates no longer relies strictly on CSS, but rather relies on react-with-styles as an abstraction layer between how styles are applied and how they are written. The instructions above will get the project working out of the box, but there's a lot more customization that can be done.

Interfaces

The react-dates/initialize script actually relies on react-with-styles-interface-css under the hood. If you are interested in a different solution for styling in your project, you can do your own initialization of a another interface. At Airbnb, for instance, we rely on Aphrodite under the hood and therefore use the Aphrodite interface for react-with-styles. If you want to do the same, you would use the following pattern:

import ThemedStyleSheet from 'react-with-styles/lib/ThemedStyleSheet';
import aphroditeInterface from 'react-with-styles-interface-aphrodite';
import DefaultTheme from 'react-dates/lib/theme/DefaultTheme';

ThemedStyleSheet.registerInterface(aphroditeInterface);
ThemedStyleSheet.registerTheme(DefaultTheme);

The above code has to be run before any react-dates component is imported. Otherwise, you will get an error. Also note that if you register any custom interface manually, you must also manually register a theme.

Theming

react-dates also now supports a different way to theme. You can see the default theme values in this file and you would override them in the following manner:

import ThemedStyleSheet from 'react-with-styles/lib/ThemedStyleSheet';
import aphroditeInterface from 'react-with-styles-interface-aphrodite';
import DefaultTheme from 'react-dates/lib/theme/DefaultTheme';

ThemedStyleSheet.registerInterface(aphroditeInterface);
ThemedStyleSheet.registerTheme({
  reactDates: {
    ...DefaultTheme.reactDates,
    color: {
      ...DefaultTheme.reactDates.color,
      highlighted: {
        backgroundColor: '#82E0AA',
        backgroundColor_active: '#58D68D',
        backgroundColor_hover: '#58D68D',
        color: '#186A3B',
        color_active: '#186A3B',
        color_hover: '#186A3B',
      },
    },
  },
});

The above code would use shades of green instead of shades of yellow for the highlight color on CalendarDay components. Note that you must register an interface if you manually register a theme. One will not work without the other.

A note on using react-with-styles-interface-css

The default interface that react-dates ships with is the CSS interface. If you want to use this interface along with the theme registration method, you will need to rebuild the core _datepicker.css file. We do not currently expose a utility method to build this file, but you can follow along with the code in https://github.com/react-dates/react-dates/blob/HEAD/scripts/buildCSS.js to build your own custom themed CSS file.

react-dates's People

Contributors

alanhamlett avatar aloktakshak avatar b0gok avatar chiumax avatar danedavid avatar dart-wakar avatar greenkeeper[bot] avatar iliran11 avatar ingiulio avatar jlyman avatar joaovieira avatar kevinthepan avatar koba04 avatar krissalvador27 avatar krtcom avatar lencioni avatar ljharb avatar m-avila avatar majapw avatar marcos0x avatar mariepw avatar matttarget avatar mikelambert avatar mmarkelov avatar moonboots avatar nkinser avatar noratarano avatar pedroabreu avatar timhwang21 avatar v47 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  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

react-dates's Issues

Discussion on Date format.

I checked out documentation and It looks like Datepicker take moment object.
I do not understand why Date picker of this world cannot adopt the world most simple and unconfusing format.
YYYY-MM-DD.
As per my experience, IMHO, A date picker must communicate in YYYY-MM-DD format which is most simple and minimum sufficient.

Change the start of the week to Monday

Hey,

Great set of components here, love how easy it is to use!

A small thing that I'd like to implement is to change the start of the week to Monday instead of Sunday. Is this currently possible? I don't see any documentation about it. If not, consider it a feature request!

Thanks

Allow theming

PR opened here: #10.

A simple change that will let people easily override the included scss variables with their own. If there's a better way of achieving this please let me know. Great project!

Disable current and previous days on DayPicker component?

Hello,

Is there a way to disable current/previous days on the component?

This is the way I'm currently calling it:

<DayPicker onDayClick={this.onDateChange} enableOutsideDays={false} numberOfMonths={1} />;

Any help would be greatly appreciated.

Thanks!

Current month should update when passed values change

Moving this conversation over from #17.

Because SingleDatePicker and DateRangePicker month props are controlled internally, there's no way of programmatically changing the month once the component has already been mounted and used. #17 solves the initialVisibleMonth but there are still use cases not covered.

Examples:

  • A form has multiple datepickers. Even after initially opening, if one of the datepickers is selected, all the other form inputs should set their currentMonth to match
  • Allowing a HoC to control currentMonth will make it easier to arbitrarily jump n months back (see #29)

One proposal I have is to overhaul the API so that animation effects are triggered by watching for the currentMonth prop to change. We'd let a HoC always control the displayed month and pressing the "next month" button would just trigger a callback that the HoC would have to use to update currentMonth. Maybe if currentMonth is passed as a prop, use that instead of https://github.com/airbnb/react-dates/blob/master/src/components/DayPicker.jsx#L77?

DateRangePicker initialises itself outside viewport width

As you can seen in the screenshot below, the DateRangePicker component seems to (sometimes) initalise itself without regard to viewport width. In my case, it is actually placing itself in such a way that my entire page breaks (the dark edge is the edge of my viewport, were it not to be expanded by the DateRangePicker).

No, I am not initialising it in a hidden component or anything like that - I am using it completely as intended/expected.

This happens even at screen widths as high as 1000px, if the input is placed close enough to the edge.

In fact, this impacts my entire page even when the datepicker is closed, because of the use of visibility: hidden instead of display: none.

Sorry for not including a live example, but I haven't yet found a decent sandbox to use for npm/es6 stuff.

screen shot 2016-09-13 at 13 28 52

Getting started instructions

Sorry, I'm missing any getting started instructions.

Import right component

I figured out that SingleDatePicker is exported from node_modules. So step 1 for example is:

import { SingleDatePicker } from 'react-dates';

CSS styling

But what about CSS? My page currently looks like the image below.
image

I cannot find any custom steps I have to undertake after npm install --save react-dates.
It can be solved by copying contents of node_modules/react-dates/lib/css/_datepicker.css to a css file and include that myself, but I guess it would be nice if it worked out of the box?

Should users build this project first or...?

Firefox displaying October 15th two times

I was just testing this using the github pages and realized that when the calendar is opened using Firefox (48.0.2), it is displaying two times the "October 15th" day. Here is a screenshot:

2016-09-02_14-37-24

I don't know if it has something to do with my timezone but I'm running this at BRT Timezone (GMT-03:00).

I'm running this using a windows machine, but I tested that in Firefox developer edition (in a Mint VM) and I can reproduce the problem.

If you need more info, just tell me! :)

Minimum and maximum allowed dates

I needed to prevent the user from selecting any future dates or any dates before six months.

PR #12
Added two props to specify minimum and maximum allowed dates, removed allowPastDates prop. Minimum allowed date is set to today by default.

DayPicker height incorrectly set if element is hidden when rendered

I'm using DateRangePicker, and the container I rendered it in had display:none initially. This meant that when adjustDayPickerHeight() was called, the calculated height was very small. When the container was then shown, the day picker retained this initial height and didn't function correctly.

For now I've just made the component render when the container is shown, but it'd be good if this workaround wasn't necessary :)

Very unintuitive text selection happening

See attached screenshot for an example of what I mean. This behaviour can be seen directly on your sandbox example. Open the picker, click either the forward or backward arrow a few times in quick succession. You'll see either the weekday abbreviations or the months get selected/highlighted.

This remedied by a few lines of CSS, at least for the "default" picker:

.DayPicker__week-header, .CalendarMonth__caption {
  -webkit-user-select: none; /* Chrome/Safari */
  -moz-user-select: none; /* Firefox */
  -ms-user-select: none; /* IE10+ */
}

I don't see any advantage to not disabling selection on these kind of "read only" values, and I have already done so in my own projects. Thoughts?

image

Allow Year/month navigation

This allows for a quick way to jump to another year or month without having to use the nav keys and go one month at a time.

Here is an example. Clicking on the year or month displays another dialog showing the years/months.

React DatePicker

"Hover styling" breaks after last date selected.

Using this as an example the turquoise highlighting that initially follows the mouse to show the time period no longer works after the last date is selected. After which point it gets "locked" on the last date and mouse movements have no impact on it. Selecting a new date will expand the time period correctly but the initial behavior can only be restored by clearing one of the dates.

DateRangePicker/SingleDatePicker should close on Escape Keypress

So I think this can be discussed, but it seems to make sense for the DayPicker to hide on escape press. However, DayPicker visibility is intrinsically tied to focus right now which is maybe not what we want.

So one option we could do is just to blur the input on escape. The better option, I think, would be to decouple visibility from focus, such that the focus state remains when you hit escape, but the DayPicker would close. This begs the question of how you would reopen it from this state... arrow down maybe? I am not sure right now.

Month caption not showing properly

Hi,

I'm using the react-dates for a personal project and when I was checking the component out the month tag is rendering a bit off.

image

Also could you give me a code snippet on how to use the isOutsideRange prop so that I could pick dates before todays date ?

I apologize if I missed out on something obvious.

Thank you.

Missing dependency `react-addons-shallow-compare`

Tried pulling this into a project today and I'm getting a build error:

Error: Cannot resolve module 'react-addons-shallow-compare'

Looks like that dependency is used in several of the components, but it's listed as one of the devDependencies in package.json...seems like that needs to be moved to one of the dependencies so it can be installed for use in production. Am I missing something?

Can't run live playground

After running "npm install" i get errors when trying to run the storybook.

This is the errors I get:

ERROR in multi preview
Module not found: Error: Cannot resolve module 'webpack-hot-middleware/client' in /Users/sindre/projects/experiments/react-dates
 @ multi preview

ERROR in ./~/@kadira/storybook/dist/client/preview/index.js
Module not found: Error: Cannot resolve module 'redux' in /Users/sindre/projects/experiments/react-dates/node_modules/@kadira/storybook/dist/client/preview
 @ ./~/@kadira/storybook/dist/client/preview/index.js 42:13-29


ERROR in ./src/svg/arrow-right.svg
Module build failed: ReferenceError: Unknown plugin "syntax-jsx" specified in "base" at 0, attempted to resolve relative to "/Users/sindre/projects/experiments/react-dates"
    at /Users/sindre/projects/experiments/react-dates/node_modules/babel-core/lib/transformation/file/options/option-manager.js:177:17
    at Array.map (native)
    at Function.normalisePlugins (/Users/sindre/projects/experiments/react-dates/node_modules/babel-core/lib/transformation/file/options/option-manager.js:153:20)
    at OptionManager.mergeOptions (/Users/sindre/projects/experiments/react-dates/node_modules/babel-core/lib/transformation/file/options/option-manager.js:245:36)
    at OptionManager.init (/Users/sindre/projects/experiments/react-dates/node_modules/babel-core/lib/transformation/file/options/option-manager.js:383:12)
    at File.initOptions (/Users/sindre/projects/experiments/react-dates/node_modules/babel-core/lib/transformation/file/index.js:223:65)
    at new File (/Users/sindre/projects/experiments/react-dates/node_modules/babel-core/lib/transformation/file/index.js:140:24)
    at Pipeline.transform (/Users/sindre/projects/experiments/react-dates/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
    at /Users/sindre/projects/experiments/react-dates/node_modules/react-svg-loader/lib/loader.js:71:37
 @ ./src/components/DayPicker.jsx 43:18-51


ERROR in ./src/svg/arrow-left.svg
...

ERROR in ./src/svg/chevron-up.svg
...

ERROR in ./src/svg/close.svg
...

ERROR in ./src/svg/chevron-down.svg
...

Cannot indicate which month is visible on open

Ideally this should be a controlled prop that would default to the current month. That way you can close the <DayPicker /> and reopen to where you were previously

My vision is that this would be a currentMonth prop on the SingleDatePicker and on the DateRangePicker that would take in a moment object. If a parent component wanted to keep track of this in the state then, they could do so using the onPrevMonthClick and onNextMonthClick callbacks.

No CSS variable for input height

So, as per the README, the inputs can be customised via SASS variables in css/variables.scss. Currently, the first two lines pertain to picker width, and the rest are all colour-related. So there is no mention of height, nor any obvious way to affect it.

Actually, trying to do it without one of these variables proves somewhat difficult, as the nested heights are a bit complicated. Any advice on this?

EDIT: Same goes for font-size, and a number of other things.

Left/Right Arrow click improvements.

I noticed, When I click on Left and right Arrows,

  1. It jump 2 month in default mode.
  2. Sun-Mon.....Sat stay (kind of fixed)

when we click, it is better to jump only 1 month. which is better in IMO. again it is your choice.
Sun, Mon.... Sat is Fixed, when we click on Arrow, User expect them to move too.

Styles not updating according to variables

I am importing the scss like so (using sass-loader and webpack 2.1.0.beta-20).

$react-dates-color-primary-dark: green;
$react-dates-color-primary: red;
$react-dates-color-secondary: blue;
$react-dates-color-primary-shade-1: red;
$react-dates-color-primary-shade-2: red;
$react-dates-color-primary-shade-3: red;
$react-dates-color-primary-shade-4: red;

@import '~react-dates/css/variables';
@import '~react-dates/css/styles';

Not sure what is causing this, but I am doing a similar thing with bootstrap and it works fine.

Focus/Selectable state on DayPicker?

Hello,

I was wondering if there was a way to have a selectable/focusable state when the user clicks on a date in the <DayPicker /> component?

For example, the <DateRangePicker /> component has a focus prop, but it doesn't seem like it's possible with the <DayPicker />.

Thanks.

Set date range

Is it possible to set the usable date range? (e.g. jan 01, 2017 -> dec 31, 2017)

Lets say i want the DateRangePicker to start from jan 01, 2017 and anything before that should not be selectable. Therefore the calendar opens up by default at jan 01, 2017, rather than today.

I see there is a property called isOutsideRange, but i'm not sure how that works.

Auto Hide when selecting end Date is not good at all.

When We select end date, Calendar autohide. this is not a Good user experience.
when User click, on start and end Date, he expect too duration basically visually. Seeing shaded portion after clicking on end date is a mental reconfirmation by user. When He click first date, popup stay as it is. So he expect same behaviour when he click end date too. Once he mentally confirm that he selected correct duration, he will click outside and then you can hide the popup.

[Feature Request] Preset date ranges

One thing that is necessary for an app that I am building is preset date ranges. For what I am doing, it is a bad UX to force users to pick specific dates always; oftentimes they want just the data from the last week/month/etc. I understand that for Airbnb this is not a valid use case, but for many other styles of it is. A good mockup for how this might look is from bootstrap-daterange-picker:

calendar-with-presets

Would the maintainers be open to accepting a PR with the feature if it was not part of the default configuration?

Highlight certain dates

Hi,
Great lib! Currently you have blockedByDefault api, that blocks certain dates. I would like to know, if there could be some API that you could add certain styling on certain dates (e.g. for highlighting, or some other stuff). And perhaps custom tooltip would also be nice. Just like with jQuery UI, where datepicker has method beforeShowDay.

CSS issues

I am trying to use react-dates (SingleDatePicker) in one of my projects. I did the normal import {SingleDatePicker} from 'react-dates', which enabled me to use the control in my code. The problem is that the CSS isn't picked up. I forced import the CSS by using import '../node_modules/react-dates/lib/css/_datepicker.css';

This does render the date picker with CSS but the Month caption is hidden behind the left selector arrow. I'm pretty new to React so I am allowing that I don't know what I'm doing. Any suggestions?

type error when set date null and focused false of SingleDatePicker props

Error in console:

React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of SingleDatePickerWrapper.

code is:

 import React from 'react';
import SingleDatePicker from 'react-dates';

class SingleDatePickerWrapper extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      focused: false,
      date: null,
    };

    this.onDateChange = this.onDateChange.bind(this);
    this.onFocusChange = this.onFocusChange.bind(this);
  }

  onDateChange(date) {
    this.setState({ date });
  }

  onFocusChange({ focused }) {
    this.setState({ focused });
  }

  render() {
    const { focused, date } = this.state;

    return (
        <SingleDatePicker
            {...this.props}
            id="date_input"
            date={date}
            focused={focused}
            onDateChange={this.onDateChange}
            onFocusChange={this.onFocusChange}
        />
    );
  }
}

export default SingleDatePickerWrapper;

Newer to React and have no idea why this happened

Add Disabled functionality

Thanks for open sourcing this! After the tech talk last night, I immediately went home and replaced our old date picker. One our use cases requires disabling/preventing the user from opening the calendar.

I have created a PR w/ the new props, styles, & tests from my fork: #5

https://github.com/alexbonine/react-dates

Thanks again!

Month displayed is not synced with the provided date

Hello and thanks for this well designed library!
Anyway I found a bug (or maybe it is a design choice?).

If I pass a date as props to SingleDatePicker that it outside the current month(s), like this:

<SingleDatePicker
    focused
    date={moment().add(70, 'days')}
/>

The DayPicker keep showing the current month(s) without displaying the selected date, and that may confuse the user.

I think that the right behaviour is that if a date is provided then the DayPicker should show the month of that date instead the current one.

Option to not re-open the date picker when the clear dates button is clicked.

Currently when clicking on the clear button to clear the dates, the dates are cleared and the date picker is re-opened. It would be nice to allow an option for when the close button is clicked, the picker is not re-opened. The property could be called 'reopenPickerOnClear'.

Thank you for a great component!

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.