UNPKG

react-np-datepicker

Version:

Integrate Nepali Datepicker in your React app easily.

92 lines (82 loc) 3.36 kB
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; import _inherits from "@babel/runtime/helpers/esm/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } import React from 'react'; import cs from 'classnames'; import Cell from './Cell'; import ViewHeader from './ViewHeader'; import BSMoment from './BSDate'; var MonthView = /*#__PURE__*/function (_React$Component) { _inherits(MonthView, _React$Component); var _super = _createSuper(MonthView); function MonthView() { _classCallCheck(this, MonthView); return _super.apply(this, arguments); } _createClass(MonthView, [{ key: "getMonth", value: function getMonth() { var month = this.props.date.month(); return BSMoment.monthsShortName().map(function (item, i) { return { label: item, curr: i === month - 1 }; }); } }, { key: "cellClick", value: function cellClick(e) { var month = e.target.innerHTML, monthNumber = BSMoment.monthsShortName().findIndex(function (name) { return name === month; }) + 1, date = this.props.date.month(monthNumber); this.props.prevView(date); } }, { key: "next", value: function next() { var nextDate = this.props.date.add(1, 'year'); this.props.setInternalDate(nextDate); } }, { key: "prev", value: function prev() { var prevDate = this.props.date.subtract(1, 'year'); this.props.setInternalDate(prevDate); } }, { key: "render", value: function render() { var currentDate = this.props.date.year(); var months = this.getMonth().map(function (item, i) { return /*#__PURE__*/React.createElement(Cell, { className: cs({ month: true, current: item.curr }), key: i, value: item.label }); }); return /*#__PURE__*/React.createElement("div", { className: "months-view" }, /*#__PURE__*/React.createElement(ViewHeader, { data: currentDate, next: this.next.bind(this), prev: this.prev.bind(this), titleAction: this.props.nextView }), /*#__PURE__*/React.createElement("div", { className: "months", onClick: this.cellClick.bind(this) }, months)); } }]); return MonthView; }(React.Component); export { MonthView as default };