From 1286c66a83716e5518f1dfbdd359c072530da0ae Mon Sep 17 00:00:00 2001 From: Andrew Ingram Date: Fri, 31 Jul 2015 14:58:22 +0100 Subject: [PATCH] explicit trigger handler for arrows, so that they can define their own events --- dist/DateRangePicker.js | 18 +++--------------- dist/PaginationArrow.js | 6 ++++-- package.json | 2 +- src/DateRangePicker.jsx | 4 ++-- src/PaginationArrow.jsx | 5 +++-- 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/dist/DateRangePicker.js b/dist/DateRangePicker.js index 12877967..1a264c49 100644 --- a/dist/DateRangePicker.js +++ b/dist/DateRangePicker.js @@ -126,7 +126,7 @@ 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 && _immutable2['default'].is(this.state.enabledRange, nextEnabledRange) ? this.state.enabledRange : nextEnabledRange }); + enabledRange: this.state.enabledRange && this.state.enabledRange.isSame(nextEnabledRange) ? this.state.enabledRange : nextEnabledRange }); }, getInitialState: function getInitialState() { @@ -419,12 +419,6 @@ var DateRangePicker = _reactAddons2['default'].createClass({ } }, - moveBackIfSelecting: function moveBackIfSelecting() { - if (this.state.selectedStartDate) { - this.moveBack(); - } - }, - canMoveForward: function canMoveForward() { if (this.getMonthDate().add(this.props.numberOfCalendars, 'months').isAfter(this.state.enabledRange.end)) { return false; @@ -444,12 +438,6 @@ var DateRangePicker = _reactAddons2['default'].createClass({ } }, - moveForwardIfSelecting: function moveForwardIfSelecting() { - if (this.state.selectedStartDate) { - this.moveForward(); - } - }, - changeYear: function changeYear(year) { var _state = this.state; var enabledRange = _state.enabledRange; @@ -560,9 +548,9 @@ var DateRangePicker = _reactAddons2['default'].createClass({ return _reactAddons2['default'].createElement( 'div', { className: this.cx({ element: null }) }, - _reactAddons2['default'].createElement(PaginationArrowComponent, { direction: 'previous', onMouseEnter: this.moveBackIfSelecting, onClick: this.moveBack, disabled: !this.canMoveBack() }), + _reactAddons2['default'].createElement(PaginationArrowComponent, { direction: 'previous', onTrigger: this.moveBack, disabled: !this.canMoveBack() }), calendars.toJS(), - _reactAddons2['default'].createElement(PaginationArrowComponent, { direction: 'next', onMouseEnter: this.moveForwardIfSelecting, onClick: this.moveForward, disabled: !this.canMoveForward() }), + _reactAddons2['default'].createElement(PaginationArrowComponent, { direction: 'next', onTrigger: this.moveForward, disabled: !this.canMoveForward() }), helpMessage ? _reactAddons2['default'].createElement( 'span', { className: this.cx({ element: 'HelpMessage' }) }, diff --git a/dist/PaginationArrow.js b/dist/PaginationArrow.js index fd948f44..34122bf7 100644 --- a/dist/PaginationArrow.js +++ b/dist/PaginationArrow.js @@ -29,6 +29,7 @@ var PaginationArrow = _reactAddons2['default'].createClass({ propTypes: { disabled: _reactAddons2['default'].PropTypes.bool, + onTrigger: _reactAddons2['default'].PropTypes.func, direction: _reactAddons2['default'].PropTypes.oneOf(['next', 'previous']) }, getDefaultProps: function getDefaultProps() { @@ -40,8 +41,9 @@ var PaginationArrow = _reactAddons2['default'].createClass({ var _props = this.props; var disabled = _props.disabled; var direction = _props.direction; + var onTrigger = _props.onTrigger; - var props = _objectWithoutProperties(_props, ['disabled', 'direction']); + var props = _objectWithoutProperties(_props, ['disabled', 'direction', 'onTrigger']); var modifiers = _defineProperty({}, direction, true); var states = { disabled: disabled }; @@ -57,7 +59,7 @@ var PaginationArrow = _reactAddons2['default'].createClass({ return _reactAddons2['default'].createElement( 'div', - _extends({ className: this.cx(elementOpts) }, props), + _extends({ className: this.cx(elementOpts) }, props, { onClick: onTrigger }), _reactAddons2['default'].createElement('div', { className: this.cx(iconOpts) }) ); } }); diff --git a/package.json b/package.json index 50a33384..aa3c03a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-daterange-picker", - "version": "0.10.0", + "version": "0.11.0", "description": "A React based date range picker", "author": "Jonathan Kim ", "contributors": [ diff --git a/src/DateRangePicker.jsx b/src/DateRangePicker.jsx index 5bdc7d84..19167bbc 100644 --- a/src/DateRangePicker.jsx +++ b/src/DateRangePicker.jsx @@ -502,9 +502,9 @@ const DateRangePicker = React.createClass({ return (
- + {calendars.toJS()} - + {helpMessage ? {helpMessage} : null} {showLegend ? : null}
diff --git a/src/PaginationArrow.jsx b/src/PaginationArrow.jsx index 455cd9d2..d11b7778 100644 --- a/src/PaginationArrow.jsx +++ b/src/PaginationArrow.jsx @@ -10,6 +10,7 @@ const PaginationArrow = React.createClass({ propTypes: { disabled: React.PropTypes.bool, + onTrigger: React.PropTypes.func, direction: React.PropTypes.oneOf(['next', 'previous']), }, @@ -20,7 +21,7 @@ const PaginationArrow = React.createClass({ }, render() { - let {disabled, direction, ...props} = this.props; + let {disabled, direction, onTrigger, ...props} = this.props; let modifiers = {[direction]: true}; let states = {disabled}; @@ -36,7 +37,7 @@ const PaginationArrow = React.createClass({ }; return ( -
+
);