Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/DateRangePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const DateRangePicker = React.createClass({
defaultState: React.PropTypes.string,
disableNavigation: React.PropTypes.bool,
firstOfWeek: React.PropTypes.oneOf([0, 1, 2, 3, 4, 5, 6]),
fullDayStates: React.PropTypes.bool,
helpMessage: React.PropTypes.string,
initialDate: React.PropTypes.instanceOf(Date),
initialFromValue: React.PropTypes.bool,
Expand Down Expand Up @@ -64,6 +65,7 @@ const DateRangePicker = React.createClass({
bemBlock: 'DateRangePicker',
numberOfCalendars: 1,
firstOfWeek: 0,
fullDayStates: false,
disableNavigation: false,
nextLabel: '',
previousLabel: '',
Expand Down Expand Up @@ -145,6 +147,12 @@ const DateRangePicker = React.createClass({
let maxDate = absoluteMaximum;
let dateCursor = moment(minDate).startOf('day');

// If states should always include the full day at the edges, we need to
// use different boundaries for the "default state" ranges we generate
// here. Otherwise the rendering code in CalenderDate cannot know if the
// day is at a boundary or not.
let shiftDays = this.props.fullDayStates ? 1 : 0;

let defs = Immutable.fromJS(stateDefinitions);

dateStates.forEach(function(s) {
Expand All @@ -156,8 +164,8 @@ const DateRangePicker = React.createClass({
actualStates.push({
state: defaultState,
range: moment.range(
dateCursor,
start
moment(dateCursor).add(shiftDays, 'day'),
moment(start).subtract(shiftDays, 'day')
),
});
}
Expand All @@ -168,7 +176,7 @@ const DateRangePicker = React.createClass({
actualStates.push({
state: defaultState,
range: moment.range(
dateCursor,
moment(dateCursor).add(shiftDays, 'day'),
maxDate
),
});
Expand Down Expand Up @@ -207,6 +215,12 @@ const DateRangePicker = React.createClass({
* which direction to work
*/
let blockedRanges = this.nonSelectableStateRanges().map(r => r.get('range'));
if (this.props.fullDayStates)
// range.intersect() ignores when one range ends on the same day
// the other begins; for the block to work, we have to extend the
// ranges by one day.
blockedRanges = blockedRanges.map(r => {
r = r.clone(); r.start.subtract(1, 'day'); r.end.add(1, 'day'); return r; })
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it might be more readable to split this up into multiple lines.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miracle2k if you could just split these lines up for readability

let intersect;

if (forwards) {
Expand Down Expand Up @@ -423,6 +437,7 @@ const DateRangePicker = React.createClass({
bemBlock,
bemNamespace,
firstOfWeek,
fullDayStates,
numberOfCalendars,
selectionType,
value
Expand Down Expand Up @@ -474,6 +489,7 @@ const DateRangePicker = React.createClass({
dateStates,
enabledRange,
firstOfWeek,
fullDayStates,
hideSelection,
highlightedDate,
highlightedRange,
Expand Down
4 changes: 2 additions & 2 deletions src/calendar/CalendarDate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const CalendarDate = React.createClass({
highlightModifier = 'single';
}

if (numStates === 1) {
if (this.props.fullDayStates || numStates === 1) {
// If there's only one state, it means we're not at a boundary
color = states.getIn([0, 'color']);

Expand Down Expand Up @@ -209,7 +209,7 @@ const CalendarDate = React.createClass({
onMouseEnter={this.mouseEnter}
onMouseLeave={this.mouseLeave}
onMouseDown={this.mouseDown}>
{numStates > 1 &&
{(numStates > 1 && !this.props.fullDayStates) &&
<div className={this.cx({element: "HalfDateStates"})}>
<CalendarDatePeriod period="am" color={amColor} />
<CalendarDatePeriod period="pm" color={pmColor} />
Expand Down