@shinyongjun/react-datepicker
Version:
DatePicker component in React App.
52 lines • 2.47 kB
JavaScript
'use client';
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { NAME_SPACE } from '../../constants/core';
import { formatLabel } from '../../utils/datetime';
import { setCenturyPage, setDecadePage, setMonthPage, setYearPage, } from '../../utils/page';
import { addLeadingZero } from '../../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 = setMonthPage(date);
var year = Math.ceil((monthPage + addMonth) / 12);
var month = addLeadingZero((monthPage + addMonth) % 12 || 12);
return formatLabel("".concat(year, "-").concat(month), labelFormat);
};
var setLabel = function (date, type) {
if (type === 'century') {
var centuryPage = setCenturyPage(date);
var start = centuryPage * 100 - 99;
var end = centuryPage * 100;
return "".concat(start, " - ").concat(end);
}
if (type === 'decade') {
var decadePage = setDecadePage(date);
var start = decadePage * 10 - 9;
var end = decadePage * 10;
return "".concat(start, " - ").concat(end);
}
if (type === 'year') {
var yearPage = 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 (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "".concat(NAME_SPACE, "__controller-label"), onClick: handleLabelClick, disabled: viewType === 'century', children: setLabel(viewDate, viewType) }), showsMultipleCalendar && viewType === 'month' && (_jsx("button", { type: "button", className: "".concat(NAME_SPACE, "__controller-label"), onClick: handleLabelClick, children: setMonthLabel(viewDate, 1) }))] }));
}
export default ControllerLabel;
//# sourceMappingURL=Label.js.map