UNPKG

@shinyongjun/react-datepicker

Version:
54 lines 2.6 kB
"use strict"; 'use client'; Object.defineProperty(exports, "__esModule", { value: true }); var jsx_runtime_1 = require("react/jsx-runtime"); var core_1 = require("../../constants/core"); var datetime_1 = require("../../utils/datetime"); var page_1 = require("../../utils/page"); var string_1 = require("../../utils/string"); function ControllerLabel(_a) { var viewDate = _a.viewDate, viewType = _a.viewType, labelFormat = _a.labelFormat, showsMultipleCalendar = _a.showsMultipleCalendar, setViewType = _a.setViewType; var setMonthLabel = function (date, addMonth) { if (addMonth === void 0) { addMonth = 0; } var monthPage = (0, page_1.setMonthPage)(date); var year = Math.ceil((monthPage + addMonth) / 12); var month = (0, string_1.addLeadingZero)((monthPage + addMonth) % 12 || 12); return (0, datetime_1.formatLabel)("".concat(year, "-").concat(month), labelFormat); }; var setLabel = function (date, type) { if (type === 'century') { var centuryPage = (0, page_1.setCenturyPage)(date); var start = centuryPage * 100 - 99; var end = centuryPage * 100; return "".concat(start, " - ").concat(end); } if (type === 'decade') { var decadePage = (0, page_1.setDecadePage)(date); var start = decadePage * 10 - 9; var end = decadePage * 10; return "".concat(start, " - ").concat(end); } if (type === 'year') { var yearPage = (0, page_1.setYearPage)(date); return "".concat(yearPage); } if (type === 'month') { return setMonthLabel(date); } return ''; }; var handleLabelClick = function () { if (viewType === 'decade') { setViewType('century'); } if (viewType === 'year') { setViewType('decade'); } if (viewType === 'month') { setViewType('year'); } }; return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: "".concat(core_1.NAME_SPACE, "__controller-label"), onClick: handleLabelClick, disabled: viewType === 'century', children: setLabel(viewDate, viewType) }), showsMultipleCalendar && viewType === 'month' && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "".concat(core_1.NAME_SPACE, "__controller-label"), onClick: handleLabelClick, children: setMonthLabel(viewDate, 1) }))] })); } exports.default = ControllerLabel; //# sourceMappingURL=Label.js.map