Skip to content

Commit

Permalink
Updated dist
Browse files Browse the repository at this point in the history
  • Loading branch information
jkimbo committed Aug 10, 2015
1 parent db9ea7e commit a2506ca
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 113 deletions.
109 changes: 66 additions & 43 deletions dist/DateRangePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ var _reactAddons = require('react/addons');

var _reactAddons2 = _interopRequireDefault(_reactAddons);

var _momentRange = require('moment-range');
var _moment = require('moment');

var _momentRange2 = _interopRequireDefault(_momentRange);
var _moment2 = _interopRequireDefault(_moment);

require('moment-range');

var _immutable = require('immutable');

Expand Down Expand Up @@ -51,8 +53,8 @@ var _utilsIsMomentRange = require('./utils/isMomentRange');
var _utilsIsMomentRange2 = _interopRequireDefault(_utilsIsMomentRange);

var PureRenderMixin = _reactAddons2['default'].addons.PureRenderMixin;
var absoluteMinimum = (0, _momentRange2['default'])(new Date(-8640000000000000 / 2)).startOf('day');
var absoluteMaximum = (0, _momentRange2['default'])(new Date(8640000000000000 / 2)).startOf('day');
var absoluteMinimum = (0, _moment2['default'])(new Date(-8640000000000000 / 2)).startOf('day');
var absoluteMaximum = (0, _moment2['default'])(new Date(8640000000000000 / 2)).startOf('day');

_reactAddons2['default'].initializeTouchEvents(true);

Expand Down Expand Up @@ -89,7 +91,8 @@ var DateRangePicker = _reactAddons2['default'].createClass({
singleDateRange: _reactAddons2['default'].PropTypes.bool,
showLegend: _reactAddons2['default'].PropTypes.bool,
stateDefinitions: _reactAddons2['default'].PropTypes.object,
value: _utilsCustomPropTypes2['default'].momentOrMomentRange },
value: _utilsCustomPropTypes2['default'].momentOrMomentRange
},

getDefaultProps: function getDefaultProps() {
var date = new Date();
Expand All @@ -111,13 +114,16 @@ var DateRangePicker = _reactAddons2['default'].createClass({
'__default': {
color: null,
selectable: true,
label: null } },
selectedLabel: 'Your selected dates',
label: null
}
},
selectedLabel: "Your selected dates",
defaultState: '__default',
dateStates: [],
showLegend: false,
onSelect: noop,
paginationArrowComponent: _PaginationArrow2['default'] };
paginationArrowComponent: _PaginationArrow2['default']
};
},

componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
Expand All @@ -126,7 +132,8 @@ var DateRangePicker = _reactAddons2['default'].createClass({

this.setState({
dateStates: this.state.dateStates && _immutable2['default'].is(this.state.dateStates, nextDateStates) ? this.state.dateStates : nextDateStates,
enabledRange: this.state.enabledRange && this.state.enabledRange.isSame(nextEnabledRange) ? this.state.enabledRange : nextEnabledRange });
enabledRange: this.state.enabledRange && this.state.enabledRange.isSame(nextEnabledRange) ? this.state.enabledRange : nextEnabledRange
});
},

getInitialState: function getInitialState() {
Expand Down Expand Up @@ -165,14 +172,15 @@ var DateRangePicker = _reactAddons2['default'].createClass({
highlightRange: null,
hideSelection: false,
enabledRange: this.getEnabledRange(this.props),
dateStates: this.getDateStates(this.props) };
dateStates: this.getDateStates(this.props)
};
},

getEnabledRange: function getEnabledRange(props) {
var min = props.minimumDate ? (0, _momentRange2['default'])(props.minimumDate).startOf('day') : absoluteMinimum;
var max = props.maximumDate ? (0, _momentRange2['default'])(props.maximumDate).startOf('day') : absoluteMaximum;
var min = props.minimumDate ? (0, _moment2['default'])(props.minimumDate).startOf('day') : absoluteMinimum;
var max = props.maximumDate ? (0, _moment2['default'])(props.maximumDate).startOf('day') : absoluteMaximum;

return _momentRange2['default'].range(min, max);
return _moment2['default'].range(min, max);
},

getDateStates: function getDateStates(props) {
Expand All @@ -183,7 +191,7 @@ var DateRangePicker = _reactAddons2['default'].createClass({
var actualStates = [];
var minDate = absoluteMinimum;
var maxDate = absoluteMaximum;
var dateCursor = (0, _momentRange2['default'])(minDate).startOf('day');
var dateCursor = (0, _moment2['default'])(minDate).startOf('day');

var defs = _immutable2['default'].fromJS(stateDefinitions);

Expand All @@ -195,15 +203,17 @@ var DateRangePicker = _reactAddons2['default'].createClass({
if (!dateCursor.isSame(start, 'day')) {
actualStates.push({
state: defaultState,
range: _momentRange2['default'].range(dateCursor, start) });
range: _moment2['default'].range(dateCursor, start)
});
}
actualStates.push(s);
dateCursor = end;
});

actualStates.push({
state: defaultState,
range: _momentRange2['default'].range(dateCursor, maxDate) });
range: _moment2['default'].range(dateCursor, maxDate)
});

// sanitize date states
return _immutable2['default'].List(actualStates).map(function (s) {
Expand All @@ -212,7 +222,8 @@ var DateRangePicker = _reactAddons2['default'].createClass({
range: s.range,
state: s.state,
selectable: def.get('selectable', true),
color: def.get('color') });
color: def.get('color')
});
});
},

Expand Down Expand Up @@ -253,24 +264,24 @@ var DateRangePicker = _reactAddons2['default'].createClass({
return range.intersect(r);
});
if (intersect) {
return _momentRange2['default'].range(range.start, intersect.start);
return _moment2['default'].range(range.start, intersect.start);
}
} else {
intersect = blockedRanges.findLast(function (r) {
return range.intersect(r);
});

if (intersect) {
return _momentRange2['default'].range(intersect.end, range.end);
return _moment2['default'].range(intersect.end, range.end);
}
}

if (range.start.isBefore(this.state.enabledRange.start)) {
return _momentRange2['default'].range(this.state.enabledRange.start, range.end);
return _moment2['default'].range(this.state.enabledRange.start, range.end);
}

if (range.end.isAfter(this.state.enabledRange.end)) {
return _momentRange2['default'].range(range.start, this.state.enabledRange.end);
return _moment2['default'].range(range.start, this.state.enabledRange.end);
}

return range;
Expand All @@ -279,15 +290,17 @@ var DateRangePicker = _reactAddons2['default'].createClass({
highlightRange: function highlightRange(range) {
this.setState({
highlightedRange: range,
highlightedDate: null });
highlightedDate: null
});
if (typeof this.props.onHighlightRange === 'function') {
this.props.onHighlightRange(range, this.statesForRange(range));
}
},

onUnHighlightDate: function onUnHighlightDate() {
this.setState({
highlightedDate: null });
highlightedDate: null
});
},

onSelectDate: function onSelectDate(date) {
Expand All @@ -300,7 +313,7 @@ var DateRangePicker = _reactAddons2['default'].createClass({
} else if (!this.isDateDisabled(date) && this.isDateSelectable(date)) {
this.startRangeSelection(date);
if (this.props.singleDateRange) {
this.highlightRange(_momentRange2['default'].range(date, date));
this.highlightRange(_moment2['default'].range(date, date));
}
}
} else {
Expand All @@ -323,7 +336,7 @@ var DateRangePicker = _reactAddons2['default'].createClass({
datePair = _immutable2['default'].List.of(selectedStartDate, date).sortBy(function (d) {
return d.unix();
});
range = _momentRange2['default'].range(datePair.get(0), datePair.get(1));
range = _moment2['default'].range(datePair.get(0), datePair.get(1));
forwards = range.start.unix() === selectedStartDate.unix();
range = this.sanitizeRange(range, forwards);
this.highlightRange(range);
Expand All @@ -340,9 +353,10 @@ var DateRangePicker = _reactAddons2['default'].createClass({
startRangeSelection: function startRangeSelection(date) {
this.setState({
hideSelection: true,
selectedStartDate: date });
selectedStartDate: date
});
if (typeof this.props.onSelectStart === 'function') {
this.props.onSelectStart((0, _momentRange2['default'])(date));
this.props.onSelectStart((0, _moment2['default'])(date));
}
},

Expand Down Expand Up @@ -370,7 +384,8 @@ var DateRangePicker = _reactAddons2['default'].createClass({
if (highlightedDate) {
this.setState({
hideSelection: false,
highlightedDate: null });
highlightedDate: null
});
this.props.onSelect(highlightedDate, this.statesForDate(highlightedDate));
}
},
Expand All @@ -383,21 +398,23 @@ var DateRangePicker = _reactAddons2['default'].createClass({
selectedStartDate: null,
highlightedRange: null,
highlightedDate: null,
hideSelection: false });
hideSelection: false
});
this.props.onSelect(range, this.statesForRange(range));
}
},

highlightDate: function highlightDate(date) {
this.setState({
highlightedDate: date });
highlightedDate: date
});
if (typeof this.props.onHighlightDate === 'function') {
this.props.onHighlightDate(date, this.statesForDate(date));
}
},

getMonthDate: function getMonthDate() {
return (0, _momentRange2['default'])(new Date(this.state.year, this.state.month, 1));
return (0, _moment2['default'])(new Date(this.state.year, this.state.month, 1));
},

canMoveBack: function canMoveBack() {
Expand All @@ -415,7 +432,8 @@ var DateRangePicker = _reactAddons2['default'].createClass({
monthDate.subtract(1, 'months');
this.setState({
year: monthDate.year(),
month: monthDate.month() });
month: monthDate.month()
});
}
},

Expand All @@ -434,7 +452,8 @@ var DateRangePicker = _reactAddons2['default'].createClass({
monthDate.add(1, 'months');
this.setState({
year: monthDate.year(),
month: monthDate.month() });
month: monthDate.month()
});
}
},

Expand All @@ -443,22 +462,24 @@ var DateRangePicker = _reactAddons2['default'].createClass({
var enabledRange = _state.enabledRange;
var month = _state.month;

if ((0, _momentRange2['default'])({ years: year, months: month, date: 1 }).unix() < enabledRange.start.unix()) {
if ((0, _moment2['default'])({ years: year, months: month, date: 1 }).unix() < enabledRange.start.unix()) {
month = enabledRange.start.month();
}

if ((0, _momentRange2['default'])({ years: year, months: month + 1, date: 1 }).unix() > enabledRange.end.unix()) {
if ((0, _moment2['default'])({ years: year, months: month + 1, date: 1 }).unix() > enabledRange.end.unix()) {
month = enabledRange.end.month();
}

this.setState({
year: year,
month: month });
month: month
});
},

changeMonth: function changeMonth(date) {
this.setState({
month: date });
month: date
});
},

renderCalendar: function renderCalendar(index) {
Expand All @@ -479,7 +500,7 @@ var DateRangePicker = _reactAddons2['default'].createClass({
var monthDate = this.getMonthDate();
var year = monthDate.year();
var month = monthDate.month();
var key = '' + index + '-' + year + '-' + month;
var key = index + '-' + year + '-' + month;
var props = undefined;

monthDate.add(index, 'months');
Expand All @@ -488,9 +509,9 @@ var DateRangePicker = _reactAddons2['default'].createClass({
var monthDates = _immutable2['default'].fromJS(cal.monthDates(monthDate.year(), monthDate.month()));
var monthStart = monthDates.first().first();
var monthEnd = monthDates.last().last();
var monthRange = _momentRange2['default'].range(monthStart, monthEnd);
var monthRange = _moment2['default'].range(monthStart, monthEnd);

if (_momentRange2['default'].isMoment(value)) {
if (_moment2['default'].isMoment(value)) {
if (!monthRange.contains(value)) {
value = null;
}
Expand All @@ -500,7 +521,7 @@ var DateRangePicker = _reactAddons2['default'].createClass({
}
}

if (!_momentRange2['default'].isMoment(highlightedDate) || !monthRange.contains(highlightedDate)) {
if (!_moment2['default'].isMoment(highlightedDate) || !monthRange.contains(highlightedDate)) {
highlightedDate = null;
}

Expand Down Expand Up @@ -529,7 +550,8 @@ var DateRangePicker = _reactAddons2['default'].createClass({
onHighlightDate: this.onHighlightDate,
onUnHighlightDate: this.onUnHighlightDate,
dateRangesForDate: this.dateRangesForDate,
dateComponent: _calendarCalendarDate2['default'] };
dateComponent: _calendarCalendarDate2['default']
};

return _reactAddons2['default'].createElement(_calendarCalendarMonth2['default'], props);
},
Expand Down Expand Up @@ -558,7 +580,8 @@ var DateRangePicker = _reactAddons2['default'].createClass({
) : null,
showLegend ? _reactAddons2['default'].createElement(_Legend2['default'], { stateDefinitions: stateDefinitions, selectedLabel: selectedLabel }) : null
);
} });
}
});

exports['default'] = DateRangePicker;
module.exports = exports['default'];
9 changes: 6 additions & 3 deletions dist/Legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ var Legend = _reactAddons2['default'].createClass({

propTypes: {
selectedLabel: _reactAddons2['default'].PropTypes.string.isRequired,
stateDefinitions: _reactAddons2['default'].PropTypes.object.isRequired },
stateDefinitions: _reactAddons2['default'].PropTypes.object.isRequired
},

render: function render() {
var _props = this.props;
Expand All @@ -39,7 +40,8 @@ var Legend = _reactAddons2['default'].createClass({
def = stateDefinitions[name];
if (def.label && def.color) {
style = {
backgroundColor: def.color };
backgroundColor: def.color
};
items.push(_reactAddons2['default'].createElement(
'li',
{ className: this.cx({ element: 'LegendItem' }), key: name },
Expand Down Expand Up @@ -68,7 +70,8 @@ var Legend = _reactAddons2['default'].createClass({
),
items
);
} });
}
});

exports['default'] = Legend;
module.exports = exports['default'];
Loading

0 comments on commit a2506ca

Please sign in to comment.