material-ui-datetime-range-picker
Version:
React Datetime Range Picker Component that Implements Google's Material Design Via Material-UI.
193 lines (161 loc) • 17.9 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _MenuItem = require('@material-ui/core/MenuItem');
var _MenuItem2 = _interopRequireDefault(_MenuItem);
var _reactDom = require('react-dom');
var _reactDom2 = _interopRequireDefault(_reactDom);
var _dateUtils = require('./dateUtils');
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; }
var RangeTimePicker = function (_Component) {
_inherits(RangeTimePicker, _Component);
function RangeTimePicker() {
_classCallCheck(this, RangeTimePicker);
return _possibleConstructorReturn(this, (RangeTimePicker.__proto__ || Object.getPrototypeOf(RangeTimePicker)).apply(this, arguments));
}
_createClass(RangeTimePicker, [{
key: 'getStyles',
value: function getStyles() {
var datePicker = this.context.muiTheme.datePicker;
return {
root: {
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-start',
fontWeight: 400,
height: 228,
lineHeight: 2,
position: 'relative',
textAlign: 'center',
MozPaddingStart: 0,
overflowY: 'scroll'
},
hour: {
height: 34,
marginBottom: 2
},
blockedTimeMessage: {
color: datePicker.color,
fontWeight: 'bold',
height: 48,
lineHeight: 3
}
};
}
}, {
key: 'shouldDisableTime',
value: function shouldDisableTime(hour) {
var _props = this.props,
blockedDateTimeRanges = _props.blockedDateTimeRanges,
edit = _props.edit,
start = _props.start;
var selectedDate = this.props[edit].selectedDate;
var adjustedDate = (0, _dateUtils.cloneDate)(selectedDate);
adjustedDate.setHours(hour, 0, 0, 0);
if (edit === 'start') {
return (0, _dateUtils.isBeforeDateTime)(adjustedDate, new Date()) || (0, _dateUtils.isDateTimeInRanges)(blockedDateTimeRanges, adjustedDate);
} else {
var selectedStartDate = start.selectedDate;
var closestRange = (0, _dateUtils.closestRangeAfterStart)(blockedDateTimeRanges, selectedStartDate);
if (closestRange) {
return (0, _dateUtils.isEqualDateTime)(start.selectedDate, adjustedDate) || (0, _dateUtils.isBeforeDateTime)(adjustedDate, selectedStartDate) || (0, _dateUtils.isAfterDateTime)(adjustedDate, closestRange.start);
} else {
return (0, _dateUtils.isEqualDateTime)(start.selectedDate, adjustedDate) || (0, _dateUtils.isBeforeDateTime)(adjustedDate, selectedStartDate);
}
}
}
}, {
key: 'hasBlockedTime',
value: function hasBlockedTime() {
var _props2 = this.props,
blockedDateTimeRanges = _props2.blockedDateTimeRanges,
edit = _props2.edit;
var selectedDate = this.props[edit].selectedDate;
if (selectedDate === null) return false;
return (0, _dateUtils.dateBordersRange)(blockedDateTimeRanges, selectedDate);
}
}, {
key: 'getTimeElements',
value: function getTimeElements(styles) {
var _this2 = this;
var hourArray = [];
var hoursInDay = 24;
for (var i = 0; i < hoursInDay; i++) {
hourArray.push(i);
}
return hourArray.map(function (hour, i) {
return _react2.default.createElement(
'div',
{ ref: 'hour' + hour, key: i, style: styles.hour },
_this2.getHourElement(hour)
);
}, this);
}
}, {
key: 'getHourElement',
value: function getHourElement(hour) {
var _props3 = this.props,
edit = _props3.edit,
end = _props3.end,
locale = _props3.locale,
start = _props3.start;
var date = new Date();
date.setHours(hour, 0, 0, 0);
var formattedDate = date.toLocaleString(locale, { hour: 'numeric', hour12: true });
return _react2.default.createElement(
_MenuItem2.default,
{
disabled: this.shouldDisableTime(hour),
onClick: this.props.onTouchTapHour.bind(this, hour)
},
formattedDate
);
}
}, {
key: 'render',
value: function render() {
var _this3 = this;
var styles = this.getStyles();
setTimeout(function () {
var hour = _reactDom2.default.findDOMNode(_this3.refs.hour12);
if (hour) {
hour.scrollIntoView(true);
}
}, 0);
return _react2.default.createElement(
'div',
{ style: styles.root },
this.hasBlockedTime() && _react2.default.createElement(
'div',
{ style: styles.blockedTimeMessage },
'This day contains other reservations'
),
this.getTimeElements(styles)
);
}
}]);
return RangeTimePicker;
}(_react.Component);
RangeTimePicker.propTypes = {
blockedDateTimeRanges: _propTypes2.default.array,
edit: _propTypes2.default.string.isRequired,
end: _propTypes2.default.object.isRequired,
locale: _propTypes2.default.string.isRequired,
onTouchTapHour: _propTypes2.default.func.isRequired,
start: _propTypes2.default.object.isRequired,
utils: _propTypes2.default.object.isRequired
};
RangeTimePicker.contextTypes = {
muiTheme: _propTypes2.default.object.isRequired
};
exports.default = RangeTimePicker;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9EYXRlUGlja2VyL1JhbmdlVGltZVBpY2tlci5qcyJdLCJuYW1lcyI6WyJSYW5nZVRpbWVQaWNrZXIiLCJkYXRlUGlja2VyIiwiY29udGV4dCIsIm11aVRoZW1lIiwicm9vdCIsImRpc3BsYXkiLCJmbGV4RGlyZWN0aW9uIiwianVzdGlmeUNvbnRlbnQiLCJmb250V2VpZ2h0IiwiaGVpZ2h0Ii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