UNPKG

4.84 kBJavaScriptView Raw
1import { a as __extends } from './tslib.es6-863e3717.js';
2import { U as Utils } from './Utils-5f9f1f09.js';
3import { select } from 'd3';
4import { D as DateTimePicker } from './DateTimePicker-5f40200d.js';
5import { D as DateTimeButton } from './DateTimeButton-b021f323.js';
6
7var DateTimeButtonRange = /** @class */ (function (_super) {
8 __extends(DateTimeButtonRange, _super);
9 function DateTimeButtonRange(renderTarget) {
10 return _super.call(this, renderTarget) || this;
11 }
12 DateTimeButtonRange.prototype.setButtonText = function (fromMillis, toMillis, isRelative, quickTime) {
13 var fromString = this.buttonDateTimeFormat(fromMillis);
14 var tzAbbr = Utils.createTimezoneAbbreviation(this.chartOptions.offset);
15 var toString = this.buttonDateTimeFormat(toMillis) + ' (' + tzAbbr + ')';
16 if (!isRelative) {
17 this.dateTimeButton.text(fromString + " - " + toString);
18 this.dateTimeButton.attr('aria-label', this.getString('a button to launch a time selection dialog current selected time is ') + " " + fromString + " - " + toString);
19 }
20 else {
21 var quickTimeText = this.dateTimePicker.getQuickTimeText(quickTime);
22 var text = quickTimeText !== null ? quickTimeText + " (" + fromString + " - " + toString + ")" : fromString + " - " + this.getString('Latest') + " (" + toString + ")";
23 this.dateTimeButton.text(text);
24 this.dateTimeButton.attr('aria-label', this.getString('a button to launch a time selection dialog current selected time is ') + " " + text);
25 }
26 };
27 DateTimeButtonRange.prototype.onClose = function () {
28 this.dateTimePickerContainer.style("display", "none");
29 this.dateTimeButton.node().focus();
30 };
31 DateTimeButtonRange.prototype.render = function (chartOptions, minMillis, maxMillis, fromMillis, toMillis, onSet, onCancel) {
32 var _this = this;
33 if (chartOptions === void 0) { chartOptions = {}; }
34 if (fromMillis === void 0) { fromMillis = null; }
35 if (toMillis === void 0) { toMillis = null; }
36 if (onSet === void 0) { onSet = null; }
37 if (onCancel === void 0) { onCancel = null; }
38 _super.prototype.render.call(this, chartOptions, minMillis, maxMillis, onSet);
39 select(this.renderTarget).classed('tsi-dateTimeContainerRange', true);
40 this.fromMillis = fromMillis;
41 this.toMillis = toMillis;
42 this.onCancel = onCancel ? onCancel : function () { };
43 if (!this.dateTimePicker) {
44 this.dateTimePicker = new DateTimePicker(this.dateTimePickerContainer.node());
45 }
46 this.setButtonText(fromMillis, toMillis, toMillis === maxMillis, this.toMillis - this.fromMillis);
47 var targetElement = select(this.renderTarget);
48 var dateTimeTextChildren = (targetElement.select(".tsi-dateTimeContainer")).selectAll("*");
49 select("html").on("click." + Utils.guid(), function () {
50 var pickerContainerChildren = _this.dateTimePickerContainer.selectAll("*");
51 var outside = dateTimeTextChildren.filter(Utils.equalToEventTarget).empty()
52 && targetElement.selectAll(".tsi-dateTimeContainer").filter(Utils.equalToEventTarget).empty()
53 && targetElement.selectAll(".tsi-dateTimeButton").filter(Utils.equalToEventTarget).empty();
54 var inClickTarget = pickerContainerChildren.filter(Utils.equalToEventTarget).empty();
55 if (outside && inClickTarget && (_this.dateTimePickerContainer.style('display') !== 'none')) {
56 _this.onClose();
57 }
58 });
59 this.dateTimeButton.on("click", function () {
60 if (_this.dateTimePickerContainer.style("display") !== "none") {
61 _this.onClose(); // close if already open
62 }
63 else {
64 _this.chartOptions.dTPIsModal = true;
65 _this.dateTimePickerContainer.style("display", "block");
66 _this.dateTimePicker.render(_this.chartOptions, minMillis, maxMillis, _this.fromMillis, _this.toMillis, function (fromMillis, toMillis, offset, isRelative, currentQuickTime) {
67 _this.chartOptions.offset = offset;
68 _this.fromMillis = fromMillis;
69 _this.toMillis = toMillis;
70 _this.setButtonText(fromMillis, toMillis, isRelative, currentQuickTime);
71 _this.onSet(fromMillis, toMillis, offset);
72 _this.onClose();
73 }, function () {
74 _this.onClose();
75 _this.onCancel();
76 });
77 }
78 });
79 };
80 return DateTimeButtonRange;
81}(DateTimeButton));
82
83export { DateTimeButtonRange as D };