1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.DatePickerCaption = void 0;
|
19 | var tslib_1 = require("tslib");
|
20 | var React = tslib_1.__importStar(require("react"));
|
21 | var core_1 = require("@blueprintjs/core");
|
22 | var Classes = tslib_1.__importStar(require("./common/classes"));
|
23 | var dateUtils_1 = require("./common/dateUtils");
|
24 | var utils_1 = require("./common/utils");
|
25 | var DatePickerCaption = (function (_super) {
|
26 | tslib_1.__extends(DatePickerCaption, _super);
|
27 | function DatePickerCaption() {
|
28 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
29 | _this.state = { monthRightOffset: 0 };
|
30 | _this.handleMonthSelectChange = _this.dateChangeHandler(function (d, month) { return d.setMonth(month); }, _this.props.onMonthChange);
|
31 | _this.handleYearSelectChange = _this.dateChangeHandler(function (d, year) { return d.setFullYear(year); }, _this.props.onYearChange);
|
32 | return _this;
|
33 | }
|
34 | DatePickerCaption.prototype.render = function () {
|
35 | var _this = this;
|
36 | var _a = this.props, date = _a.date, locale = _a.locale, localeUtils = _a.localeUtils, minDate = _a.minDate, maxDate = _a.maxDate, _b = _a.months, months = _b === void 0 ? localeUtils.getMonths(locale) : _b;
|
37 | var minYear = minDate.getFullYear();
|
38 | var maxYear = maxDate.getFullYear();
|
39 | var displayMonth = date.getMonth();
|
40 | var displayYear = date.getFullYear();
|
41 |
|
42 | var startMonth = displayYear === minYear ? minDate.getMonth() : 0;
|
43 | var endMonth = displayYear === maxYear ? maxDate.getMonth() + 1 : undefined;
|
44 | var monthOptionElements = months
|
45 | .map(function (month, i) { return ({ label: month, value: i }); })
|
46 | .slice(startMonth, endMonth);
|
47 | var years = [minYear];
|
48 | for (var year = minYear + 1; year <= maxYear; ++year) {
|
49 | years.push(year);
|
50 | }
|
51 |
|
52 | if (displayYear > maxYear) {
|
53 | years.push({ value: displayYear, disabled: true });
|
54 | }
|
55 | this.displayedMonthText = months[displayMonth];
|
56 | var monthSelect = (React.createElement(core_1.HTMLSelect, { "aria-label": "Month", iconProps: { style: { right: this.state.monthRightOffset } }, className: Classes.DATEPICKER_MONTH_SELECT, key: "month", minimal: true, onChange: this.handleMonthSelectChange, value: displayMonth, options: monthOptionElements }));
|
57 | var yearSelect = (React.createElement(core_1.HTMLSelect, { "aria-label": "Year", className: Classes.DATEPICKER_YEAR_SELECT, key: "year", minimal: true, onChange: this.handleYearSelectChange, value: displayYear, options: years }));
|
58 | var orderedSelects = this.props.reverseMonthAndYearMenus
|
59 | ? [yearSelect, monthSelect]
|
60 | : [monthSelect, yearSelect];
|
61 | return (React.createElement("div", { className: this.props.classNames.caption },
|
62 | React.createElement("div", { className: Classes.DATEPICKER_CAPTION, ref: function (ref) { return (_this.containerElement = ref); } }, orderedSelects),
|
63 | React.createElement(core_1.Divider, null)));
|
64 | };
|
65 | DatePickerCaption.prototype.componentDidMount = function () {
|
66 | var _this = this;
|
67 | this.requestAnimationFrame(function () { return _this.positionArrows(); });
|
68 | };
|
69 | DatePickerCaption.prototype.componentDidUpdate = function () {
|
70 | this.positionArrows();
|
71 | };
|
72 | DatePickerCaption.prototype.positionArrows = function () {
|
73 |
|
74 | var monthTextWidth = (0, utils_1.measureTextWidth)(this.displayedMonthText, Classes.DATEPICKER_CAPTION_MEASURE, this.containerElement);
|
75 | var monthSelectWidth = this.containerElement == null ? 0 : this.containerElement.firstElementChild.clientWidth;
|
76 | var rightOffset = Math.max(2, monthSelectWidth - monthTextWidth - core_1.IconSize.STANDARD - 2);
|
77 | this.setState({ monthRightOffset: rightOffset });
|
78 | };
|
79 | DatePickerCaption.prototype.dateChangeHandler = function (updater, handler) {
|
80 | var _this = this;
|
81 | return function (e) {
|
82 | var _a, _b;
|
83 | var value = parseInt(e.target.value, 10);
|
84 |
|
85 | if (isNaN(value)) {
|
86 | return;
|
87 | }
|
88 | var newDate = (0, dateUtils_1.clone)(_this.props.date);
|
89 | updater(newDate, value);
|
90 | (_b = (_a = _this.props).onDateChange) === null || _b === void 0 ? void 0 : _b.call(_a, newDate);
|
91 | handler === null || handler === void 0 ? void 0 : handler(value);
|
92 | };
|
93 | };
|
94 | return DatePickerCaption;
|
95 | }(core_1.AbstractPureComponent2));
|
96 | exports.DatePickerCaption = DatePickerCaption;
|
97 |
|
\ | No newline at end of file |