@attivio/suit
Version:
Attivio SUIT, the Search UI Toolkit, is a library for creating search clients for searching the Attivio platform.
83 lines (60 loc) • 3.01 kB
JavaScript
;
exports.__esModule = true;
exports.default = undefined;
var _class, _temp;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _moment = require('moment');
var _moment2 = _interopRequireDefault(_moment);
require('react-dates/initialize');
require('react-dates/lib/css/_datepicker.css');
var _reactDates = require('react-dates');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
/**
* Component to let the user choose either a single
* date or a starting/ending range.
*/
var DatePicker = (_temp = _class = function (_React$Component) {
_inherits(DatePicker, _React$Component);
function DatePicker(props) {
_classCallCheck(this, DatePicker);
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
_this.state = {
focused: false,
focusedInput: null
};
_this.setFocusedState = _this.setFocusedState.bind(_this);
_this.setDate = _this.setDate.bind(_this);
return _this;
}
DatePicker.prototype.setFocusedState = function setFocusedState(focusedInput) {
this.setState({
focusedInput: focusedInput
});
};
DatePicker.prototype.setDate = function setDate(event) {
this.props.updateDate(new Date(event.startDate), new Date(event.endDate));
};
DatePicker.prototype.render = function render() {
var startDate = (0, _moment2.default)(this.props.startingDate);
var endDate = (0, _moment2.default)(this.props.endingDate);
return _react2.default.createElement(_reactDates.DayPickerRangeController, {
startDate: startDate,
endDate: endDate,
onDatesChange: this.setDate,
focusedInput: this.state.focusedInput || 'startDate',
onFocusChange: this.setFocusedState,
isOutsideRange: function isOutsideRange() {
return false;
},
onOutsideClick: this.props.onClose,
numberOfMonths: 2
});
};
return DatePicker;
}(_react2.default.Component), _class.displayName = 'DatePicker', _temp);
exports.default = DatePicker;
module.exports = exports['default'];