UNPKG

react-period-of-stay-input

Version:

React.js component for entering a period of stay in a hotel: check-in + check-out date

97 lines (96 loc) 5.55 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); var react_datepicker_1 = require("react-datepicker"); var react_intl_1 = require("react-intl"); var momentLocale_1 = require("./momentLocale"); var Day_1 = require("./Day"); function CalendarIcon() { return (React.createElement("i", { className: 'fa fa-calendar calendar-icon' })); } function datePickerData(props) { return { locale: momentLocale_1.default(props.locale), mCheckIn: props.model.checkInDate.toMoment(), mCheckOut: props.model.checkOutDate.toMoment() }; } function CheckIn(props) { if (props.useInputTypeDate) { return (React.createElement("input", { type: 'date', value: props.model.checkInDate.toString(), onChange: props.handleNativeCheckInChange })); } var _a = datePickerData(props), locale = _a.locale, mCheckIn = _a.mCheckIn, mCheckOut = _a.mCheckOut; return (React.createElement(react_datepicker_1.default, { locale: locale, selected: mCheckIn, selectsStart: true, startDate: mCheckIn, endDate: mCheckOut, onChange: props.handleCheckInChange })); } function CheckOut(props) { if (props.useInputTypeDate) { return (React.createElement("input", { type: 'date', value: props.model.checkOutDate.toString(), onChange: props.handleNativeCheckOutChange })); } var _a = datePickerData(props), locale = _a.locale, mCheckIn = _a.mCheckIn, mCheckOut = _a.mCheckOut; return (React.createElement(react_datepicker_1.default, { locale: locale, selected: mCheckOut, selectsEnd: true, startDate: mCheckIn, endDate: mCheckOut, onChange: props.handleCheckOutChange })); } var PeriodOfStayInput = /** @class */ (function (_super) { __extends(PeriodOfStayInput, _super); function PeriodOfStayInput(props) { var _this = _super.call(this, props) || this; _this.handleCheckInChange = _this.handleCheckInChange.bind(_this); _this.handleCheckOutChange = _this.handleCheckOutChange.bind(_this); _this.handleNativeCheckInChange = _this.handleNativeCheckInChange.bind(_this); _this.handleNativeCheckOutChange = _this.handleNativeCheckOutChange.bind(_this); return _this; } PeriodOfStayInput.prototype.render = function () { var className = 'period-of-stay-input' + (this.props.className ? " " + this.props.className : ''); return (React.createElement("div", __assign({}, { className: className }), React.createElement("div", { className: 'period-of-stay-check-in' }, React.createElement("label", null, React.createElement(react_intl_1.FormattedMessage, { id: 'react-period-of-stay-input.checkInDay' })), React.createElement(CheckIn, __assign({}, __assign({}, this.props, { handleCheckInChange: this.handleCheckInChange, handleNativeCheckInChange: this.handleNativeCheckInChange }))), React.createElement(CalendarIcon, null)), React.createElement("div", { className: 'period-of-stay-check-out' }, React.createElement("label", null, React.createElement(react_intl_1.FormattedMessage, { id: 'react-period-of-stay-input.checkOutDay' })), React.createElement(CheckOut, __assign({}, __assign({}, this.props, { handleCheckOutChange: this.handleCheckOutChange, handleNativeCheckOutChange: this.handleNativeCheckOutChange }))), React.createElement(CalendarIcon, null)), React.createElement("span", { className: 'period-of-stay-nights' }, React.createElement(react_intl_1.FormattedMessage, { id: 'react-period-of-stay-input.period', values: { count: this.props.model.nightsCount() } })))); }; PeriodOfStayInput.prototype.handleCheckInChange = function (newValue) { this.props.onChange(this.props.model.newCheckIn(newValue.format(Day_1.FORMAT), this.props.environment)); }; PeriodOfStayInput.prototype.handleCheckOutChange = function (newValue) { this.props.onChange(this.props.model.newCheckOut(newValue.format(Day_1.FORMAT), this.props.environment)); }; PeriodOfStayInput.prototype.handleNativeCheckInChange = function (ev) { this.props.onChange(this.props.model.newCheckIn(ev.target.value, this.props.environment)); }; PeriodOfStayInput.prototype.handleNativeCheckOutChange = function (ev) { this.props.onChange(this.props.model.newCheckOut(ev.target.value, this.props.environment)); }; return PeriodOfStayInput; }(React.Component)); exports.default = PeriodOfStayInput;