@skyux/datetime 4.12.3 → 4.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/bundles/skyux-datetime.umd.js +1294 -941
  3. package/bundles/skyux-datetime.umd.js.map +1 -1
  4. package/bundles/skyux-datetime.umd.min.js +2 -2
  5. package/bundles/skyux-datetime.umd.min.js.map +1 -1
  6. package/esm2015/modules/datepicker/datepicker-calendar-change.js +1 -0
  7. package/esm2015/modules/datepicker/datepicker-calendar-inner.component.js +30 -4
  8. package/esm2015/modules/datepicker/datepicker-calendar.component.js +15 -2
  9. package/esm2015/modules/datepicker/datepicker-custom-date.js +1 -0
  10. package/esm2015/modules/datepicker/datepicker-date.js +1 -1
  11. package/esm2015/modules/datepicker/datepicker.component.js +47 -4
  12. package/esm2015/modules/datepicker/datepicker.module.js +20 -9
  13. package/esm2015/modules/datepicker/datepicker.service.js +20 -0
  14. package/esm2015/modules/datepicker/daypicker-button.component.js +26 -0
  15. package/esm2015/modules/datepicker/daypicker-cell.component.js +131 -0
  16. package/esm2015/modules/datepicker/daypicker.component.js +95 -3
  17. package/esm2015/public_api.js +1 -1
  18. package/esm2015/skyux-datetime.js +6 -3
  19. package/esm5/modules/datepicker/datepicker-calendar-change.js +1 -0
  20. package/esm5/modules/datepicker/datepicker-calendar-inner.component.js +30 -4
  21. package/esm5/modules/datepicker/datepicker-calendar.component.js +15 -2
  22. package/esm5/modules/datepicker/datepicker-custom-date.js +1 -0
  23. package/esm5/modules/datepicker/datepicker-date.js +1 -1
  24. package/esm5/modules/datepicker/datepicker.component.js +48 -4
  25. package/esm5/modules/datepicker/datepicker.module.js +20 -9
  26. package/esm5/modules/datepicker/datepicker.service.js +21 -0
  27. package/esm5/modules/datepicker/daypicker-button.component.js +27 -0
  28. package/esm5/modules/datepicker/daypicker-cell.component.js +134 -0
  29. package/esm5/modules/datepicker/daypicker.component.js +99 -3
  30. package/esm5/public_api.js +1 -1
  31. package/esm5/skyux-datetime.js +6 -3
  32. package/fesm2015/skyux-datetime.js +1380 -1039
  33. package/fesm2015/skyux-datetime.js.map +1 -1
  34. package/fesm5/skyux-datetime.js +1289 -938
  35. package/fesm5/skyux-datetime.js.map +1 -1
  36. package/modules/datepicker/datepicker-calendar-change.d.ts +24 -0
  37. package/modules/datepicker/datepicker-calendar-inner.component.d.ts +12 -2
  38. package/modules/datepicker/datepicker-calendar.component.d.ts +6 -0
  39. package/modules/datepicker/datepicker-custom-date.d.ts +21 -0
  40. package/modules/datepicker/datepicker-date.d.ts +2 -0
  41. package/modules/datepicker/datepicker.component.d.ts +13 -0
  42. package/modules/datepicker/datepicker.service.d.ts +12 -0
  43. package/modules/datepicker/daypicker-button.component.d.ts +13 -0
  44. package/modules/datepicker/daypicker-cell.component.d.ts +37 -0
  45. package/modules/datepicker/daypicker.component.d.ts +17 -2
  46. package/package.json +3 -2
  47. package/public_api.d.ts +2 -0
  48. package/skyux-datetime.d.ts +5 -2
  49. package/skyux-datetime.metadata.json +1 -1
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@skyux/i18n'), require('rxjs'), require('rxjs/operators'), require('moment'), require('@angular/common'), require('@angular/forms'), require('@skyux/core'), require('@skyux/forms'), require('@skyux/indicators'), require('@skyux/theme')) :
3
- typeof define === 'function' && define.amd ? define('@skyux/datetime', ['exports', '@angular/core', '@skyux/i18n', 'rxjs', 'rxjs/operators', 'moment', '@angular/common', '@angular/forms', '@skyux/core', '@skyux/forms', '@skyux/indicators', '@skyux/theme'], factory) :
4
- (global = global || self, factory((global.skyux = global.skyux || {}, global.skyux.datetime = {}), global.ng.core, global.i18n, global.rxjs, global.rxjs.operators, global.moment_, global.ng.common, global.ng.forms, global.core$1, global.forms$1, global.indicators, global.theme));
5
- }(this, (function (exports, core, i18n, rxjs, operators, moment_, common, forms, core$1, forms$1, indicators, theme) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@skyux/i18n'), require('rxjs'), require('rxjs/operators'), require('moment'), require('@angular/common'), require('@angular/forms'), require('@skyux/core'), require('@skyux/forms'), require('@skyux/indicators'), require('@skyux/theme'), require('@skyux/popovers')) :
3
+ typeof define === 'function' && define.amd ? define('@skyux/datetime', ['exports', '@angular/core', '@skyux/i18n', 'rxjs', 'rxjs/operators', 'moment', '@angular/common', '@angular/forms', '@skyux/core', '@skyux/forms', '@skyux/indicators', '@skyux/theme', '@skyux/popovers'], factory) :
4
+ (global = global || self, factory((global.skyux = global.skyux || {}, global.skyux.datetime = {}), global.ng.core, global.i18n, global.rxjs, global.rxjs.operators, global.moment_, global.ng.common, global.ng.forms, global.core$1, global.forms$1, global.indicators, global.theme, global.popovers));
5
+ }(this, (function (exports, core, i18n, rxjs, operators, moment_, common, forms, core$1, forms$1, indicators, theme, popovers) { 'use strict';
6
6
 
7
7
  /*! *****************************************************************************
8
8
  Copyright (c) Microsoft Corporation.
@@ -1047,6 +1047,7 @@
1047
1047
  39: 'right',
1048
1048
  40: 'down'
1049
1049
  };
1050
+ this.ngUnsubscribe = new rxjs.Subject();
1050
1051
  }
1051
1052
  Object.defineProperty(SkyDatepickerCalendarInnerComponent.prototype, "selectedDate", {
1052
1053
  get: function () {
@@ -1072,6 +1073,10 @@
1072
1073
  SkyDatepickerCalendarInnerComponent.prototype.ngOnChanges = function (changes) {
1073
1074
  this.refreshView();
1074
1075
  };
1076
+ SkyDatepickerCalendarInnerComponent.prototype.ngOnDestroy = function () {
1077
+ this.ngUnsubscribe.next();
1078
+ this.ngUnsubscribe.complete();
1079
+ };
1075
1080
  SkyDatepickerCalendarInnerComponent.prototype.setCompareHandler = function (handler, type) {
1076
1081
  if (type === 'day') {
1077
1082
  this.compareHandlerDay = handler;
@@ -1175,6 +1180,7 @@
1175
1180
  }
1176
1181
  };
1177
1182
  SkyDatepickerCalendarInnerComponent.prototype.createDateObject = function (date, format, isSecondary, id) {
1183
+ var customDateMatch = this.getCustomDate(date);
1178
1184
  var dateObject = {
1179
1185
  date: new Date(date.getFullYear(), date.getMonth(), date.getDate()),
1180
1186
  label: this.dateFilter(date, format),
@@ -1182,7 +1188,9 @@
1182
1188
  disabled: this.isDisabled(date),
1183
1189
  current: this.compare(date, new Date()) === 0,
1184
1190
  secondary: isSecondary,
1185
- uid: id
1191
+ uid: id,
1192
+ keyDate: customDateMatch ? customDateMatch.keyDate : undefined,
1193
+ keyDateText: customDateMatch ? customDateMatch.keyDateText : []
1186
1194
  };
1187
1195
  return dateObject;
1188
1196
  };
@@ -1269,10 +1277,27 @@
1269
1277
  this.refreshView();
1270
1278
  }
1271
1279
  };
1280
+ /**
1281
+ * Date is disabled if it meets any of these criteria:
1282
+ * 1. Date falls outside the min or max dates set by the SkyDatepickerConfigService.
1283
+ * 2. Date is marked as disabled in the customDates array.
1284
+ */
1272
1285
  SkyDatepickerCalendarInnerComponent.prototype.isDisabled = function (date) {
1273
- return ((this.minDate && this.compare(date, this.minDate) < 0)
1274
- || (this.maxDate && this.compare(date, this.maxDate) > 0));
1286
+ var customDate = this.getCustomDate(date);
1287
+ return ((this.minDate && this.compare(date, this.minDate) < 0) ||
1288
+ (this.maxDate && this.compare(date, this.maxDate) > 0)) ||
1289
+ (customDate && customDate.disabled);
1290
+ };
1291
+ SkyDatepickerCalendarInnerComponent.prototype.getCustomDate = function (date) {
1292
+ if (this.customDates) {
1293
+ return this.customDates.find(function (customDate) {
1294
+ return customDate.date.getTime() === date.getTime();
1295
+ });
1296
+ }
1275
1297
  };
1298
+ __decorate([
1299
+ core.Input()
1300
+ ], SkyDatepickerCalendarInnerComponent.prototype, "customDates", void 0);
1276
1301
  __decorate([
1277
1302
  core.Input()
1278
1303
  ], SkyDatepickerCalendarInnerComponent.prototype, "startingDay", void 0);
@@ -1326,6 +1351,7 @@
1326
1351
  this.config = config;
1327
1352
  this.elementRef = elementRef;
1328
1353
  this.selectedDateChange = new core.EventEmitter(undefined);
1354
+ this.calendarDateRangeChange = new core.EventEmitter();
1329
1355
  this.calendarModeChange = new core.EventEmitter();
1330
1356
  this._now = new Date();
1331
1357
  this.formatter = new SkyDateFormatter();
@@ -1359,6 +1385,9 @@
1359
1385
  SkyDatepickerCalendarComponent.prototype.configureOptions = function () {
1360
1386
  Object.assign(this, this.config);
1361
1387
  };
1388
+ SkyDatepickerCalendarComponent.prototype.onCalendarDateRangeChange = function (event) {
1389
+ this.calendarDateRangeChange.next(event);
1390
+ };
1362
1391
  SkyDatepickerCalendarComponent.prototype.onCalendarModeChange = function (event) {
1363
1392
  this.calendarModeChange.emit(event);
1364
1393
  };
@@ -1386,6 +1415,12 @@
1386
1415
  { type: SkyDatepickerConfigService },
1387
1416
  { type: core.ElementRef }
1388
1417
  ]; };
1418
+ __decorate([
1419
+ core.Input()
1420
+ ], SkyDatepickerCalendarComponent.prototype, "customDates", void 0);
1421
+ __decorate([
1422
+ core.Input()
1423
+ ], SkyDatepickerCalendarComponent.prototype, "isDaypickerWaiting", void 0);
1389
1424
  __decorate([
1390
1425
  core.Input()
1391
1426
  ], SkyDatepickerCalendarComponent.prototype, "minDate", void 0);
@@ -1401,6 +1436,9 @@
1401
1436
  __decorate([
1402
1437
  core.Output()
1403
1438
  ], SkyDatepickerCalendarComponent.prototype, "selectedDateChange", void 0);
1439
+ __decorate([
1440
+ core.Output()
1441
+ ], SkyDatepickerCalendarComponent.prototype, "calendarDateRangeChange", void 0);
1404
1442
  __decorate([
1405
1443
  core.Output()
1406
1444
  ], SkyDatepickerCalendarComponent.prototype, "calendarModeChange", void 0);
@@ -1413,7 +1451,7 @@
1413
1451
  SkyDatepickerCalendarComponent = __decorate([
1414
1452
  core.Component({
1415
1453
  selector: 'sky-datepicker-calendar',
1416
- template: "<div class=\"sky-datepicker-calendar\">\n <sky-datepicker-inner\n [selectedDate]=\"selectedDate\"\n [minDate]=\"minDate\"\n [maxDate]=\"maxDate\"\n [startingDay]=\"startingDay\"\n (selectedDateChange)=\"onSelectedDateChange($event)\"\n (calendarModeChange)=\"onCalendarModeChange($event)\">\n <sky-daypicker tabindex=\"0\"></sky-daypicker>\n <sky-monthpicker tabindex=\"0\"></sky-monthpicker>\n <sky-yearpicker tabindex=\"0\"></sky-yearpicker>\n </sky-datepicker-inner>\n</div>\n",
1454
+ template: "<div class=\"sky-datepicker-calendar\">\n <sky-datepicker-inner\n [customDates]=\"customDates\"\n [selectedDate]=\"selectedDate\"\n [minDate]=\"minDate\"\n [maxDate]=\"maxDate\"\n [startingDay]=\"startingDay\"\n (selectedDateChange)=\"onSelectedDateChange($event)\"\n (calendarModeChange)=\"onCalendarModeChange($event)\"\n >\n <sky-daypicker\n tabindex=\"0\"\n [customDates]=\"customDates\"\n [isWaiting]=\"isDaypickerWaiting\"\n (calendarDateRangeChange)=\"onCalendarDateRangeChange($event)\"\n ></sky-daypicker>\n <sky-monthpicker tabindex=\"0\"></sky-monthpicker>\n <sky-yearpicker tabindex=\"0\"></sky-yearpicker>\n </sky-datepicker-inner>\n</div>\n",
1417
1455
  providers: [SkyDatepickerAdapterService],
1418
1456
  styles: [".sky-datepicker-calendar{display:block}"]
1419
1457
  })
@@ -1421,796 +1459,557 @@
1421
1459
  return SkyDatepickerCalendarComponent;
1422
1460
  }());
1423
1461
 
1462
+ var nextId = 0;
1424
1463
  /**
1425
- * @internal
1464
+ * Creates the datepicker button and calendar.
1465
+ * You must wrap this component around an input with the `skyDatepickerInput` directive.
1426
1466
  */
1427
- var SkyDayPickerComponent = /** @class */ (function () {
1428
- function SkyDayPickerComponent(datepicker) {
1429
- this.labels = [];
1430
- this.rows = [];
1431
- this.weekNumbers = [];
1432
- this.daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
1433
- this.datepicker = datepicker;
1434
- }
1435
- SkyDayPickerComponent.prototype.ngOnInit = function () {
1467
+ var SkyDatepickerComponent = /** @class */ (function () {
1468
+ function SkyDatepickerComponent(affixService, changeDetector, coreAdapter, overlayService, inputBoxHostService, themeSvc) {
1436
1469
  var _this = this;
1437
- this.datepicker.stepDay = { months: 1 };
1438
- this.datepicker.setRefreshViewHandler(function () {
1439
- _this.refreshDayView();
1440
- }, 'day');
1441
- this.datepicker.setCompareHandler(this.compareDays, 'day');
1442
- this.datepicker.setKeydownHandler(function (key, event) {
1443
- _this.keydownDays(key, event);
1444
- }, 'day');
1445
- this.datepicker.refreshView();
1446
- };
1447
- SkyDayPickerComponent.prototype.getDates = function (startDate, n) {
1448
- var dates = new Array(n);
1449
- var current = new Date(startDate.getTime());
1450
- var i = 0;
1451
- var date;
1452
- while (i < n) {
1453
- date = new Date(current.getTime());
1454
- date = this.datepicker.fixTimeZone(date);
1455
- dates[i++] = date;
1456
- current = new Date(current.getFullYear(), current.getMonth(), current.getDate() + 1);
1470
+ this.affixService = affixService;
1471
+ this.changeDetector = changeDetector;
1472
+ this.coreAdapter = coreAdapter;
1473
+ this.overlayService = overlayService;
1474
+ this.inputBoxHostService = inputBoxHostService;
1475
+ /**
1476
+ * Adds a class to the datepicker.
1477
+ */
1478
+ this.pickerClass = '';
1479
+ /**
1480
+ * Fires when the range of displayed dates in the calendar changes. Provides the
1481
+ * current range of displayed dates and a mutable `customDate` property consumers can use
1482
+ * to modify individual dates on the calendar.
1483
+ */
1484
+ this.calendarDateRangeChange = new core.EventEmitter();
1485
+ this.dateChange = new core.EventEmitter();
1486
+ this.isDaypickerWaiting = false;
1487
+ this.isOpen = false;
1488
+ this.isVisible = false;
1489
+ this.ngUnsubscribe = new rxjs.Subject();
1490
+ this._disabled = false;
1491
+ var uniqueId = nextId++;
1492
+ this.calendarId = "sky-datepicker-calendar-" + uniqueId;
1493
+ this.triggerButtonId = "sky-datepicker-button-" + uniqueId;
1494
+ // Update icons when theme changes.
1495
+ themeSvc === null || themeSvc === void 0 ? void 0 : themeSvc.settingsChange.pipe(operators.takeUntil(this.ngUnsubscribe)).subscribe(function () {
1496
+ _this.changeDetector.markForCheck();
1497
+ });
1498
+ }
1499
+ Object.defineProperty(SkyDatepickerComponent.prototype, "buttonIsFocused", {
1500
+ /**
1501
+ * @internal
1502
+ * Indicates if the calendar button element or any of its children have focus.
1503
+ * @deprecated This property will be removed in the next major version release.
1504
+ */
1505
+ get: function () {
1506
+ /* sanity check */
1507
+ /* istanbul ignore if */
1508
+ if (!this.triggerButtonRef) {
1509
+ return false;
1510
+ }
1511
+ var activeEl = document.activeElement;
1512
+ return this.triggerButtonRef.nativeElement === activeEl;
1513
+ },
1514
+ enumerable: true,
1515
+ configurable: true
1516
+ });
1517
+ Object.defineProperty(SkyDatepickerComponent.prototype, "calendarIsFocused", {
1518
+ /**
1519
+ * @internal
1520
+ * Indicates if the calendar element or any of its children have focus.
1521
+ * @deprecated This property will be removed in the next major version release.
1522
+ */
1523
+ get: function () {
1524
+ if (!this.calendarRef) {
1525
+ return false;
1526
+ }
1527
+ var focusedEl = document.activeElement;
1528
+ return this.calendarRef.nativeElement.contains(focusedEl);
1529
+ },
1530
+ enumerable: true,
1531
+ configurable: true
1532
+ });
1533
+ Object.defineProperty(SkyDatepickerComponent.prototype, "calendarIsVisible", {
1534
+ /**
1535
+ * @internal
1536
+ * Indicates if the calendar element's visiblity property is 'visible'.
1537
+ * @deprecated This property will be removed in the next major version release.
1538
+ */
1539
+ get: function () {
1540
+ return this.calendar ? this.calendar.isVisible : false;
1541
+ },
1542
+ enumerable: true,
1543
+ configurable: true
1544
+ });
1545
+ Object.defineProperty(SkyDatepickerComponent.prototype, "disabled", {
1546
+ get: function () {
1547
+ return this._disabled;
1548
+ },
1549
+ set: function (value) {
1550
+ this._disabled = value;
1551
+ this.changeDetector.markForCheck();
1552
+ },
1553
+ enumerable: true,
1554
+ configurable: true
1555
+ });
1556
+ Object.defineProperty(SkyDatepickerComponent.prototype, "selectedDate", {
1557
+ set: function (value) {
1558
+ this._selectedDate = value;
1559
+ if (this.calendar) {
1560
+ this.calendar.writeValue(this._selectedDate);
1561
+ }
1562
+ },
1563
+ enumerable: true,
1564
+ configurable: true
1565
+ });
1566
+ Object.defineProperty(SkyDatepickerComponent.prototype, "calendarRef", {
1567
+ get: function () {
1568
+ return this._calendarRef;
1569
+ },
1570
+ set: function (value) {
1571
+ var _this = this;
1572
+ if (value) {
1573
+ this._calendarRef = value;
1574
+ // Wait for the calendar component to render before gauging dimensions.
1575
+ setTimeout(function () {
1576
+ _this.calendar.writeValue(_this._selectedDate);
1577
+ _this.destroyAffixer();
1578
+ _this.createAffixer();
1579
+ setTimeout(function () {
1580
+ _this.coreAdapter.getFocusableChildrenAndApplyFocus(_this.calendarRef, '.sky-datepicker-calendar-inner', false);
1581
+ _this.isVisible = true;
1582
+ _this.changeDetector.markForCheck();
1583
+ });
1584
+ });
1585
+ }
1586
+ },
1587
+ enumerable: true,
1588
+ configurable: true
1589
+ });
1590
+ SkyDatepickerComponent.prototype.ngOnInit = function () {
1591
+ if (this.inputBoxHostService) {
1592
+ this.inputBoxHostService.populate({
1593
+ inputTemplate: this.inputTemplateRef,
1594
+ buttonsTemplate: this.triggerButtonTemplateRef
1595
+ });
1457
1596
  }
1458
- return dates;
1459
1597
  };
1460
- SkyDayPickerComponent.prototype.compareDays = function (date1, date2) {
1461
- var d1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate());
1462
- var d2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
1463
- return d1.getTime() - d2.getTime();
1598
+ SkyDatepickerComponent.prototype.ngOnDestroy = function () {
1599
+ this.dateChange.complete();
1600
+ this.ngUnsubscribe.next();
1601
+ this.ngUnsubscribe.complete();
1602
+ this.removePickerEventListeners();
1603
+ this.destroyAffixer();
1604
+ this.destroyOverlay();
1464
1605
  };
1465
- SkyDayPickerComponent.prototype.refreshDayView = function () {
1466
- var year = this.datepicker.activeDate.getFullYear();
1467
- var month = this.datepicker.activeDate.getMonth();
1468
- var firstDayOfMonth = new Date(year, month, 1);
1469
- var difference = this.datepicker.startingDay - firstDayOfMonth.getDay();
1470
- var numDisplayedFromPreviousMonth = (difference > 0)
1471
- ? 7 - difference
1472
- : -difference;
1473
- var firstDate = new Date(firstDayOfMonth.getTime());
1474
- /* istanbul ignore else */
1475
- /* sanity check */
1476
- if (numDisplayedFromPreviousMonth > 0) {
1477
- firstDate.setDate(-numDisplayedFromPreviousMonth + 1);
1478
- }
1479
- // 42 is the number of days on a six-week calendar
1480
- var days = this.getDates(firstDate, 42);
1481
- var pickerDates = [];
1482
- for (var i = 0; i < 42; i++) {
1483
- var _dateObject = this.datepicker.createDateObject(days[i], this.datepicker.formatDay, days[i].getMonth() !== month, this.datepicker.datepickerId + '-' + i);
1484
- pickerDates[i] = _dateObject;
1606
+ SkyDatepickerComponent.prototype.onCalendarModeChange = function () {
1607
+ var _this = this;
1608
+ // Let the calendar populate in the DOM before recalculating placement.
1609
+ setTimeout(function () {
1610
+ _this.affixer.reaffix();
1611
+ });
1612
+ };
1613
+ SkyDatepickerComponent.prototype.onSelectedDateChange = function (value) {
1614
+ this.dateChange.emit(value);
1615
+ this.closePicker();
1616
+ };
1617
+ SkyDatepickerComponent.prototype.onTriggerButtonClick = function () {
1618
+ if (this.isOpen) {
1619
+ this.closePicker();
1485
1620
  }
1486
- this.labels = [];
1487
- for (var j = 0; j < 7; j++) {
1488
- this.labels[j] = {};
1489
- this.labels[j].abbr =
1490
- this.datepicker.dateFilter(pickerDates[j].date, this.datepicker.formatDayHeader);
1491
- this.labels[j].full = this.datepicker.dateFilter(pickerDates[j].date, 'EEEE');
1621
+ else {
1622
+ this.openPicker();
1492
1623
  }
1493
- this.title =
1494
- this.datepicker.dateFilter(this.datepicker.activeDate, this.datepicker.formatDayTitle);
1495
- this.rows = this.datepicker.createCalendarRows(pickerDates, 7);
1496
1624
  };
1497
- SkyDayPickerComponent.prototype.keydownDays = function (key, event) {
1498
- var date = this.datepicker.activeDate.getDate();
1625
+ SkyDatepickerComponent.prototype.onCalendarDateRangeChange = function (event) {
1626
+ var _this = this;
1499
1627
  /* istanbul ignore else */
1500
- /* sanity check */
1501
- if (key === 'left') {
1502
- date = date - 1;
1503
- }
1504
- else if (key === 'up') {
1505
- date = date - 7;
1506
- }
1507
- else if (key === 'right') {
1508
- date = date + 1;
1509
- }
1510
- else if (key === 'down') {
1511
- date = date + 7;
1512
- }
1513
- else if (key === 'pageup' || key === 'pagedown') {
1514
- var month = this.datepicker.activeDate.getMonth() + (key === 'pageup' ? -1 : 1);
1515
- this.datepicker.activeDate.setMonth(month, 1);
1516
- date =
1517
- Math.min(this.getDaysInMonth(this.datepicker.activeDate.getFullYear(), this.datepicker.activeDate.getMonth()), date);
1628
+ if (event) {
1629
+ this.cancelCustomDatesSubscription();
1630
+ var args = {
1631
+ startDate: event.startDate,
1632
+ endDate: event.endDate,
1633
+ customDates: undefined
1634
+ };
1635
+ this.calendarDateRangeChange.emit(args);
1636
+ // If consumer has added an observable to the args, watch for incoming custom dates.
1637
+ /* istanbul ignore else */
1638
+ if (args.customDates) {
1639
+ this.isDaypickerWaiting = true;
1640
+ // Avoid an ExpressionChangedAfterItHasBeenCheckedError.
1641
+ this.changeDetector.detectChanges();
1642
+ this.customDatesSubscription = args.customDates
1643
+ .pipe(operators.debounceTime(250))
1644
+ .subscribe(function (result) {
1645
+ _this.customDates = result;
1646
+ _this.isDaypickerWaiting = false;
1647
+ // Trigger change detection in child components to show changes in the calendar.
1648
+ _this.changeDetector.markForCheck();
1649
+ });
1650
+ }
1518
1651
  }
1519
- else if (key === 'home') {
1520
- date = 1;
1521
- }
1522
- else if (key === 'end') {
1523
- date = this.getDaysInMonth(this.datepicker.activeDate.getFullYear(), this.datepicker.activeDate.getMonth());
1524
- }
1525
- this.datepicker.activeDate.setDate(date);
1526
1652
  };
1527
- SkyDayPickerComponent.prototype.getDaysInMonth = function (year, month) {
1528
- return month === 1 && year % 4 === 0 &&
1529
- (year % 400 === 0 || year % 100 !== 0) ? 29 : this.daysInMonth[month];
1653
+ SkyDatepickerComponent.prototype.closePicker = function () {
1654
+ this.destroyAffixer();
1655
+ this.destroyOverlay();
1656
+ this.removePickerEventListeners();
1657
+ this.triggerButtonRef.nativeElement.focus();
1658
+ this.isOpen = false;
1530
1659
  };
1531
- SkyDayPickerComponent.ctorParameters = function () { return [
1532
- { type: SkyDatepickerCalendarInnerComponent }
1533
- ]; };
1534
- SkyDayPickerComponent = __decorate([
1535
- core.Component({
1536
- selector: 'sky-daypicker',
1537
- template: "<div *ngIf=\"datepicker.datepickerMode === 'day'\"\n class=\"sky-daypicker-wrapper\"\n>\n <table\n class=\"sky-daypicker-table\"\n role=\"grid\"\n [attr.aria-labelledby]=\"datepicker.datepickerId+'-title'\"\n [attr.aria-activedescendant]=\"datepicker.activeDateId\"\n >\n <thead>\n <tr>\n <th\n class=\"sky-datepicker-header-left\"\n scope=\"col\"\n >\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-btn-previous\"\n (click)=\"datepicker.moveCalendar($event, -1)\"\n tabindex=\"-1\"\n aria-hidden=\"true\"\n >\n <sky-icon\n class=\"sky-datepicker-chevron-default\"\n icon=\"chevron-left\"\n ></sky-icon>\n <sky-icon\n class=\"sky-datepicker-chevron-modern\"\n icon=\"chevron-left\"\n iconType=\"skyux\"\n ></sky-icon>\n </button>\n </th>\n <th\n scope=\"col\"\n [attr.colspan]=\"5\"\n >\n <button\n [id]=\"datepicker.datepickerId + '-title'\"\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-calendar-title\"\n (click)=\"datepicker.toggleModeCalendar($event)\"\n [disabled]=\"datepicker.datepickerMode === datepicker.maxMode\"\n [ngClass]=\"{'sky-btn-disabled': datepicker.datepickerMode === datepicker.maxMode}\"\n tabindex=\"-1\"\n aria-hidden=\"true\"\n >\n <strong>{{title}}</strong>\n </button>\n </th>\n <th\n class=\"sky-datepicker-header-right\"\n scope=\"col\"\n >\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-btn-next\"\n (click)=\"datepicker.moveCalendar($event, 1)\"\n tabindex=\"-1\"\n aria-hidden=\"true\"\n >\n <sky-icon\n class=\"sky-datepicker-chevron-default\"\n icon=\"chevron-right\"\n ></sky-icon>\n <sky-icon\n class=\"sky-datepicker-chevron-modern\"\n icon=\"chevron-right\"\n iconType=\"skyux\"\n ></sky-icon>\n </button>\n </th>\n </tr>\n <tr>\n <th\n scope=\"col\"\n *ngFor=\"let label of labels\"\n class=\"sky-datepicker-center sky-datepicker-weekdays\">\n <small [attr.aria-label]=\"label.full\">\n <b>{{label.abbr}}</b>\n </small>\n </th>\n </tr>\n </thead>\n <tbody>\n <ng-template\n ngFor\n [ngForOf]=\"rows\"\n let-row=\"$implicit\"\n let-index=\"index\"\n >\n <tr role=\"row\">\n <td\n *ngFor=\"let date of row\"\n class=\"sky-datepicker-center\"\n role=\"gridcell\"\n [id]=\"date.uid\"\n >\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-sm sky-btn-default sky-datepicker-btn-date\"\n [ngClass]=\"{ 'sky-datepicker-btn-selected': date.selected, 'sky-btn-disabled': date.disabled, 'sky-btn-active': datepicker.isActive(date)}\"\n [disabled]=\"date.disabled\"\n (click)=\"datepicker.selectCalendar($event, date.date, true)\"\n tabindex=\"-1\"\n >\n <span\n [ngClass]=\"{'sky-datepicker-secondary': date.secondary }\"\n >{{date.label}}</span>\n </button>\n </td>\n </tr>\n </ng-template>\n </tbody>\n </table>\n</div>\n",
1538
- styles: [":host-context(.sky-theme-modern) :host:focus{outline:0}.sky-theme-modern :host:focus{outline:0}"]
1539
- })
1540
- ], SkyDayPickerComponent);
1541
- return SkyDayPickerComponent;
1542
- }());
1543
-
1544
- /**
1545
- * @internal
1546
- */
1547
- var SkyMonthPickerComponent = /** @class */ (function () {
1548
- function SkyMonthPickerComponent(datepicker) {
1549
- this.rows = [];
1550
- this.datepicker = datepicker;
1551
- }
1552
- SkyMonthPickerComponent.prototype.ngOnInit = function () {
1660
+ SkyDatepickerComponent.prototype.openPicker = function () {
1661
+ this.isVisible = false;
1662
+ this.changeDetector.markForCheck();
1663
+ this.removePickerEventListeners();
1664
+ this.calendarUnsubscribe = new rxjs.Subject();
1665
+ this.destroyOverlay();
1666
+ this.createOverlay();
1667
+ this.isOpen = true;
1668
+ this.changeDetector.markForCheck();
1669
+ };
1670
+ SkyDatepickerComponent.prototype.createAffixer = function () {
1553
1671
  var _this = this;
1554
- this.datepicker.stepMonth = {
1555
- years: 1
1556
- };
1557
- this.datepicker.setRefreshViewHandler(function () {
1558
- _this.refreshMonthView();
1559
- }, 'month');
1560
- this.datepicker.setCompareHandler(this.compareMonth, 'month');
1561
- this.datepicker.refreshView();
1562
- this.datepicker.setKeydownHandler(function (key, event) {
1563
- _this.keydownMonths(key, event);
1564
- }, 'month');
1672
+ var affixer = this.affixService.createAffixer(this.calendarRef);
1673
+ // Hide calendar when trigger button is scrolled off screen.
1674
+ affixer.placementChange
1675
+ .pipe(operators.takeUntil(this.calendarUnsubscribe))
1676
+ .subscribe(function (change) {
1677
+ _this.isVisible = (change.placement !== null);
1678
+ _this.changeDetector.markForCheck();
1679
+ });
1680
+ affixer.affixTo(this.triggerButtonRef.nativeElement, {
1681
+ autoFitContext: core$1.SkyAffixAutoFitContext.Viewport,
1682
+ enableAutoFit: true,
1683
+ horizontalAlignment: 'right',
1684
+ isSticky: true,
1685
+ placement: 'below'
1686
+ });
1687
+ this.affixer = affixer;
1565
1688
  };
1566
- SkyMonthPickerComponent.prototype.compareMonth = function (date1, date2) {
1567
- var d1 = new Date(date1.getFullYear(), date1.getMonth());
1568
- var d2 = new Date(date2.getFullYear(), date2.getMonth());
1569
- return d1.getTime() - d2.getTime();
1689
+ SkyDatepickerComponent.prototype.destroyAffixer = function () {
1690
+ /*istanbul ignore else*/
1691
+ if (this.affixer) {
1692
+ this.affixer.destroy();
1693
+ this.affixer = undefined;
1694
+ }
1570
1695
  };
1571
- SkyMonthPickerComponent.prototype.refreshMonthView = function () {
1572
- var months = new Array(12);
1573
- var year = this.datepicker.activeDate.getFullYear();
1574
- var date;
1575
- for (var i = 0; i < 12; i++) {
1576
- date = new Date(year, i, 1);
1577
- date = this.datepicker.fixTimeZone(date);
1578
- months[i] =
1579
- this.datepicker.createDateObject(date, this.datepicker.formatMonth, false, this.datepicker.datepickerId + '-' + i);
1696
+ SkyDatepickerComponent.prototype.createOverlay = function () {
1697
+ var _this = this;
1698
+ var overlay = this.overlayService.create({
1699
+ wrapperClass: this.pickerClass,
1700
+ enableClose: false,
1701
+ enablePointerEvents: false
1702
+ });
1703
+ overlay.backdropClick
1704
+ .pipe(operators.takeUntil(this.calendarUnsubscribe))
1705
+ .subscribe(function () {
1706
+ if (_this.isOpen) {
1707
+ _this.closePicker();
1708
+ }
1709
+ });
1710
+ this.addKeydownListner();
1711
+ overlay.attachTemplate(this.calendarTemplateRef);
1712
+ this.overlay = overlay;
1713
+ };
1714
+ SkyDatepickerComponent.prototype.destroyOverlay = function () {
1715
+ /*istanbul ignore else*/
1716
+ if (this.overlay) {
1717
+ this.overlayService.close(this.overlay);
1718
+ this.overlay = undefined;
1580
1719
  }
1581
- this.title =
1582
- this.datepicker.dateFilter(this.datepicker.activeDate, this.datepicker.formatMonthTitle);
1583
- this.rows = this.datepicker.createCalendarRows(months, this.datepicker.monthColLimit);
1584
1720
  };
1585
- SkyMonthPickerComponent.prototype.keydownMonths = function (key, event) {
1586
- var date = this.datepicker.activeDate.getMonth();
1721
+ SkyDatepickerComponent.prototype.addKeydownListner = function () {
1722
+ var _this = this;
1723
+ this.overlayKeydownListner = rxjs.fromEvent(window.document, 'keydown')
1724
+ .pipe(operators.takeUntil(this.ngUnsubscribe))
1725
+ .subscribe(function (event) {
1726
+ var _a;
1727
+ var key = (_a = event.key) === null || _a === void 0 ? void 0 : _a.toLowerCase();
1728
+ if (key === 'escape' && _this.isOpen) {
1729
+ _this.closePicker();
1730
+ }
1731
+ });
1732
+ };
1733
+ SkyDatepickerComponent.prototype.removePickerEventListeners = function () {
1734
+ var _a;
1587
1735
  /* istanbul ignore else */
1588
- /* sanity check */
1589
- if (key === 'left') {
1590
- date = date - 1;
1591
- }
1592
- else if (key === 'up') {
1593
- date = date - this.datepicker.monthColLimit;
1594
- }
1595
- else if (key === 'right') {
1596
- date = date + 1;
1597
- }
1598
- else if (key === 'down') {
1599
- date = date + this.datepicker.monthColLimit;
1600
- }
1601
- else if (key === 'pageup' || key === 'pagedown') {
1602
- var year = this.datepicker.activeDate.getFullYear() + (key === 'pageup' ? -1 : 1);
1603
- this.datepicker.activeDate.setFullYear(year);
1604
- }
1605
- else if (key === 'home') {
1606
- date = 0;
1736
+ if (this.calendarUnsubscribe) {
1737
+ this.calendarUnsubscribe.next();
1738
+ this.calendarUnsubscribe.complete();
1739
+ this.calendarUnsubscribe = undefined;
1607
1740
  }
1608
- else if (key === 'end') {
1609
- date = 11;
1741
+ (_a = this.overlayKeydownListner) === null || _a === void 0 ? void 0 : _a.unsubscribe();
1742
+ };
1743
+ SkyDatepickerComponent.prototype.cancelCustomDatesSubscription = function () {
1744
+ if (this.customDatesSubscription) {
1745
+ this.customDatesSubscription.unsubscribe();
1746
+ this.customDatesSubscription = undefined;
1610
1747
  }
1611
- this.datepicker.activeDate.setMonth(date);
1612
1748
  };
1613
- SkyMonthPickerComponent.ctorParameters = function () { return [
1614
- { type: SkyDatepickerCalendarInnerComponent }
1749
+ SkyDatepickerComponent.ctorParameters = function () { return [
1750
+ { type: core$1.SkyAffixService },
1751
+ { type: core.ChangeDetectorRef },
1752
+ { type: core$1.SkyCoreAdapterService },
1753
+ { type: core$1.SkyOverlayService },
1754
+ { type: forms$1.SkyInputBoxHostService, decorators: [{ type: core.Optional }] },
1755
+ { type: theme.SkyThemeService, decorators: [{ type: core.Optional }] }
1615
1756
  ]; };
1616
- SkyMonthPickerComponent = __decorate([
1617
- core.Component({
1618
- selector: 'sky-monthpicker',
1619
- template: "<table *ngIf=\"datepicker.datepickerMode==='month'\" role=\"grid\">\n <thead>\n <tr>\n <th\n class=\"sky-datepicker-header-left\"\n >\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-btn-previous\"\n (click)=\"datepicker.moveCalendar($event, -1)\"\n tabindex=\"-1\"\n >\n <sky-icon\n class=\"sky-datepicker-chevron-default\"\n icon=\"chevron-left\"\n ></sky-icon>\n <sky-icon\n class=\"sky-datepicker-chevron-modern\"\n icon=\"chevron-left\"\n iconType=\"skyux\"\n ></sky-icon>\n </button></th>\n <th [attr.colspan]=\"((datepicker.monthColLimit - 2) <= 0) ? 1 : datepicker.monthColLimit - 2\">\n <button\n [id]=\"datepicker.datepickerId + '-title'\"\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-calendar-title\"\n (click)=\"datepicker.toggleModeCalendar($event)\"\n [disabled]=\"datepicker.datepickerMode === maxMode\"\n [ngClass]=\"{'sky-btn-disabled': datepicker.datepickerMode === maxMode}\"\n tabindex=\"-1\"\n >\n <strong>{{title}}</strong>\n </button>\n </th>\n <th\n class=\"sky-datepicker-header-right\"\n >\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-btn-next\"\n (click)=\"datepicker.moveCalendar($event, 1)\"\n tabindex=\"-1\"\n >\n <sky-icon\n class=\"sky-datepicker-chevron-default\"\n icon=\"chevron-right\"\n ></sky-icon>\n <sky-icon\n class=\"sky-datepicker-chevron-modern\"\n icon=\"chevron-right\"\n iconType=\"skyux\"\n ></sky-icon>\n </button>\n </th>\n </tr>\n </thead>\n <tbody>\n <tr *ngFor=\"let row of rows\">\n <td\n *ngFor=\"let date of row\"\n class=\"text-center\"\n role=\"gridcell\"\n id=\"{{date.uid}}\">\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-datepicker-btn-date\"\n [ngClass]=\"{'sky-datepicker-btn-selected': date.selected, 'sky-btn-disabled': date.disabled, 'sky-btn-active': datepicker.isActive(date)}\"\n [disabled]=\"date.disabled\"\n (click)=\"datepicker.selectCalendar($event, date.date)\"\n tabindex=\"-1\"\n >\n <span [ngClass]=\"{'sky-datepicker-current': date.current}\">{{date.label}}</span>\n </button>\n </td>\n </tr>\n </tbody>\n</table>\n",
1620
- styles: [":host-context(.sky-theme-modern) :host:focus{outline:0}.sky-theme-modern :host:focus{outline:0}"]
1757
+ __decorate([
1758
+ core.Input()
1759
+ ], SkyDatepickerComponent.prototype, "pickerClass", void 0);
1760
+ __decorate([
1761
+ core.Output()
1762
+ ], SkyDatepickerComponent.prototype, "calendarDateRangeChange", void 0);
1763
+ __decorate([
1764
+ core.ViewChild(SkyDatepickerCalendarComponent)
1765
+ ], SkyDatepickerComponent.prototype, "calendar", void 0);
1766
+ __decorate([
1767
+ core.ViewChild('calendarRef', {
1768
+ read: core.ElementRef
1621
1769
  })
1622
- ], SkyMonthPickerComponent);
1623
- return SkyMonthPickerComponent;
1770
+ ], SkyDatepickerComponent.prototype, "calendarRef", null);
1771
+ __decorate([
1772
+ core.ViewChild('calendarTemplateRef', {
1773
+ read: core.TemplateRef
1774
+ })
1775
+ ], SkyDatepickerComponent.prototype, "calendarTemplateRef", void 0);
1776
+ __decorate([
1777
+ core.ViewChild('triggerButtonRef', {
1778
+ read: core.ElementRef
1779
+ })
1780
+ ], SkyDatepickerComponent.prototype, "triggerButtonRef", void 0);
1781
+ __decorate([
1782
+ core.ViewChild('inputTemplateRef', {
1783
+ read: core.TemplateRef,
1784
+ static: true
1785
+ })
1786
+ ], SkyDatepickerComponent.prototype, "inputTemplateRef", void 0);
1787
+ __decorate([
1788
+ core.ViewChild('triggerButtonTemplateRef', {
1789
+ read: core.TemplateRef,
1790
+ static: true
1791
+ })
1792
+ ], SkyDatepickerComponent.prototype, "triggerButtonTemplateRef", void 0);
1793
+ SkyDatepickerComponent = __decorate([
1794
+ core.Component({
1795
+ selector: 'sky-datepicker',
1796
+ template: "<div\n class=\"sky-datepicker\"\n>\n <ng-container *ngIf=\"!inputBoxHostService\">\n <div\n class=\"sky-input-group\"\n >\n <ng-container *ngTemplateOutlet=\"inputTemplateRef\"></ng-container>\n <ng-container *ngTemplateOutlet=\"triggerButtonTemplateRef\"></ng-container>\n </div>\n </ng-container>\n</div>\n\n<ng-template #inputTemplateRef>\n <ng-content></ng-content>\n</ng-template>\n\n<ng-template #triggerButtonTemplateRef>\n <div\n class=\"sky-input-group-btn\"\n >\n <button\n aria-haspopup=\"dialog\"\n class=\"sky-btn sky-btn-default sky-input-group-datepicker-btn\"\n type=\"button\"\n [attr.aria-controls]=\"isOpen ? calendarId : null\"\n [attr.aria-expanded]=\"isOpen\"\n [attr.aria-label]=\"'skyux_datepicker_trigger_button_label' | skyLibResources\"\n [attr.id]=\"triggerButtonId\"\n [attr.title]=\"'skyux_datepicker_trigger_button_label' | skyLibResources\"\n [disabled]=\"disabled\"\n (click)=\"onTriggerButtonClick()\"\n #triggerButtonRef\n >\n <sky-icon *skyThemeIf=\"'default'\"\n icon=\"calendar\"\n size=\"lg\"\n ></sky-icon>\n <sky-icon *skyThemeIf=\"'modern'\"\n icon=\"calendar\"\n size=\"lg\"\n iconType=\"skyux\"\n ></sky-icon>\n </button>\n </div>\n</ng-template>\n\n<ng-template #calendarTemplateRef>\n <div\n class=\"sky-datepicker-calendar-container sky-shadow sky-elevation-4\"\n role=\"dialog\"\n [attr.aria-labelledby]=\"triggerButtonId\"\n [attr.id]=\"calendarId\"\n [class.sky-datepicker-hidden]=\"!isVisible\"\n #calendarRef\n >\n <sky-datepicker-calendar\n [customDates]=\"customDates\"\n [isDaypickerWaiting]=\"isDaypickerWaiting\"\n [maxDate]=\"maxDate\"\n [minDate]=\"minDate\"\n [startingDay]=\"startingDay\"\n (calendarDateRangeChange)=\"onCalendarDateRangeChange($event)\"\n (calendarModeChange)=\"onCalendarModeChange()\"\n (selectedDateChange)=\"onSelectedDateChange($event)\"\n >\n </sky-datepicker-calendar>\n </div>\n</ng-template>\n",
1797
+ changeDetection: core.ChangeDetectionStrategy.OnPush,
1798
+ styles: [".sky-datepicker-calendar-container{position:fixed;border-radius:5px}.sky-datepicker-hidden{visibility:hidden}"]
1799
+ }),
1800
+ __param(4, core.Optional()),
1801
+ __param(5, core.Optional())
1802
+ ], SkyDatepickerComponent);
1803
+ return SkyDatepickerComponent;
1624
1804
  }());
1625
1805
 
1626
- /**
1627
- * @internal
1628
- */
1629
- var SkyYearPickerComponent = /** @class */ (function () {
1630
- function SkyYearPickerComponent(datepicker) {
1631
- this.rows = [];
1632
- this.datepicker = datepicker;
1633
- }
1634
- SkyYearPickerComponent.prototype.ngOnInit = function () {
1806
+ var moment$3 = moment_;
1807
+ // tslint:disable:no-forward-ref no-use-before-declare
1808
+ var SKY_DATEPICKER_VALUE_ACCESSOR = {
1809
+ provide: forms.NG_VALUE_ACCESSOR,
1810
+ useExisting: core.forwardRef(function () { return SkyDatepickerInputDirective; }),
1811
+ multi: true
1812
+ };
1813
+ var SKY_DATEPICKER_VALIDATOR = {
1814
+ provide: forms.NG_VALIDATORS,
1815
+ useExisting: core.forwardRef(function () { return SkyDatepickerInputDirective; }),
1816
+ multi: true
1817
+ };
1818
+ // tslint:enable
1819
+ var SkyDatepickerInputDirective = /** @class */ (function () {
1820
+ function SkyDatepickerInputDirective(adapter, changeDetector, configService, elementRef, localeProvider, renderer, resourcesService, datepickerComponent) {
1635
1821
  var _this = this;
1636
- this.datepicker.stepYear = { years: this.datepicker.yearRange };
1637
- this.datepicker.setRefreshViewHandler(function () {
1638
- _this.refreshYearView();
1639
- }, 'year');
1640
- this.datepicker.setCompareHandler(this.compareYears, 'year');
1641
- this.datepicker.setKeydownHandler(function (key, event) {
1642
- _this.keydownYears(key, event);
1643
- }, 'year');
1644
- this.datepicker.refreshView();
1645
- };
1646
- SkyYearPickerComponent.prototype.getStartingYear = function (year) {
1647
- return Math.floor((year - 1) / this.datepicker.yearRange) * this.datepicker.yearRange + 1;
1648
- };
1649
- SkyYearPickerComponent.prototype.compareYears = function (date1, date2) {
1650
- return date1.getFullYear() - date2.getFullYear();
1651
- };
1652
- SkyYearPickerComponent.prototype.refreshYearView = function () {
1653
- var years = new Array(this.datepicker.yearRange);
1654
- var date;
1655
- var start = this.getStartingYear(this.datepicker.activeDate.getFullYear());
1656
- for (var i = 0; i < this.datepicker.yearRange; i++) {
1657
- date = new Date(this.datepicker.activeDate);
1658
- date.setFullYear(start + i, 0, 1);
1659
- years[i] =
1660
- this.datepicker.createDateObject(date, this.datepicker.formatYear, false, this.datepicker.datepickerId + '-' + i);
1661
- }
1662
- this.title = [years[0].label,
1663
- years[this.datepicker.yearRange - 1].label].join(' - ');
1664
- this.rows = this.datepicker.createCalendarRows(years, this.datepicker.yearColLimit);
1665
- };
1666
- SkyYearPickerComponent.prototype.keydownYears = function (key, event) {
1667
- var date = this.datepicker.activeDate.getFullYear();
1668
- /* istanbul ignore else */
1669
- /* sanity check */
1670
- if (key === 'left') {
1671
- date = date - 1;
1672
- }
1673
- else if (key === 'up') {
1674
- date = date - this.datepicker.yearColLimit;
1675
- }
1676
- else if (key === 'right') {
1677
- date = date + 1;
1678
- }
1679
- else if (key === 'down') {
1680
- date = date + this.datepicker.yearColLimit;
1681
- }
1682
- else if (key === 'pageup' || key === 'pagedown') {
1683
- date += (key === 'pageup' ? -1 : 1) * this.datepicker.yearRange;
1684
- }
1685
- else if (key === 'home') {
1686
- date = this.getStartingYear(this.datepicker.activeDate.getFullYear());
1687
- }
1688
- else if (key === 'end') {
1689
- date
1690
- = this.getStartingYear(this.datepicker.activeDate.getFullYear()) + this.datepicker.yearRange - 1;
1691
- }
1692
- this.datepicker.activeDate.setFullYear(date);
1693
- };
1694
- SkyYearPickerComponent.ctorParameters = function () { return [
1695
- { type: SkyDatepickerCalendarInnerComponent }
1696
- ]; };
1697
- SkyYearPickerComponent = __decorate([
1698
- core.Component({
1699
- selector: 'sky-yearpicker',
1700
- template: "<table *ngIf=\"datepicker.datepickerMode==='year'\" role=\"grid\">\n <thead>\n <tr>\n <th\n class=\"sky-datepicker-header-left\"\n >\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-btn-previous\"\n (click)=\"datepicker.moveCalendar($event, -1)\"\n tabindex=\"-1\"\n >\n <sky-icon\n class=\"sky-datepicker-chevron-default\"\n icon=\"chevron-left\"\n ></sky-icon>\n <sky-icon\n class=\"sky-datepicker-chevron-modern\"\n icon=\"chevron-left\"\n iconType=\"skyux\"\n ></sky-icon>\n </button>\n </th>\n <th [attr.colspan]=\"((datepicker.yearColLimit - 2) <= 0) ? 1 : datepicker.yearColLimit - 2\">\n <button\n [id]=\"datepicker.datepickerId + '-title'\"\n role=\"heading\"\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-calendar-title\"\n (click)=\"datepicker.toggleModeCalendar($event)\"\n [disabled]=\"datepicker.datepickerMode === datepicker.maxMode\"\n [ngClass]=\"{'sky-btn-disabled': datepicker.datepickerMode === datepicker.maxMode}\"\n tabindex=\"-1\"\n >\n <strong>{{title}}</strong>\n </button>\n </th>\n <th\n class=\"sky-datepicker-header-right\"\n >\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-btn-next\"\n (click)=\"datepicker.moveCalendar($event, 1)\"\n tabindex=\"-1\"\n >\n <sky-icon\n class=\"sky-datepicker-chevron-default\"\n icon=\"chevron-right\"\n ></sky-icon>\n <sky-icon\n class=\"sky-datepicker-chevron-modern\"\n icon=\"chevron-right\"\n iconType=\"skyux\"\n ></sky-icon>\n </button>\n </th>\n </tr>\n </thead>\n <tbody>\n <tr *ngFor=\"let row of rows\">\n <td\n *ngFor=\"let date of row\"\n class=\"sky-datepicker-row\"\n role=\"gridcell\"\n >\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-datepicker-btn-date\"\n [ngClass]=\"{'sky-datepicker-btn-selected': date.selected, 'sky-btn-disabled': date.disabled, 'sky-btn-active': datepicker.isActive(date)}\"\n [disabled]=\"date.disabled\"\n (click)=\"datepicker.selectCalendar($event, date.date)\"\n tabindex=\"-1\"\n >\n <span\n [ngClass]=\"{'sky-datepicker-current': date.current }\">{{date.label}}</span>\n </button>\n </td>\n </tr>\n </tbody>\n</table>\n",
1701
- styles: [":host-context(.sky-theme-modern) :host:focus{outline:0}.sky-theme-modern :host:focus{outline:0}"]
1702
- })
1703
- ], SkyYearPickerComponent);
1704
- return SkyYearPickerComponent;
1705
- }());
1706
-
1707
- var nextId = 0;
1708
- /**
1709
- * Creates the datepicker button and calendar.
1710
- * You must wrap this component around an input with the `skyDatepickerInput` directive.
1711
- */
1712
- var SkyDatepickerComponent = /** @class */ (function () {
1713
- function SkyDatepickerComponent(affixService, changeDetector, coreAdapter, overlayService, inputBoxHostService, themeSvc) {
1714
- var _this = this;
1715
- this.affixService = affixService;
1822
+ this.adapter = adapter;
1716
1823
  this.changeDetector = changeDetector;
1717
- this.coreAdapter = coreAdapter;
1718
- this.overlayService = overlayService;
1719
- this.inputBoxHostService = inputBoxHostService;
1824
+ this.configService = configService;
1825
+ this.elementRef = elementRef;
1826
+ this.localeProvider = localeProvider;
1827
+ this.renderer = renderer;
1828
+ this.resourcesService = resourcesService;
1829
+ this.datepickerComponent = datepickerComponent;
1720
1830
  /**
1721
- * Adds a class to the datepicker.
1831
+ * Indicates whether to disable date validation on the datepicker input.
1832
+ * @default false
1722
1833
  */
1723
- this.pickerClass = '';
1724
- this.dateChange = new core.EventEmitter();
1725
- this.isOpen = false;
1726
- this.isVisible = false;
1834
+ this.skyDatepickerNoValidate = false;
1835
+ this.dateFormatter = new SkyDateFormatter();
1836
+ this.isFirstChange = true;
1727
1837
  this.ngUnsubscribe = new rxjs.Subject();
1728
- this._disabled = false;
1729
- var uniqueId = nextId++;
1730
- this.calendarId = "sky-datepicker-calendar-" + uniqueId;
1731
- this.triggerButtonId = "sky-datepicker-button-" + uniqueId;
1732
- // Update icons when theme changes.
1733
- themeSvc === null || themeSvc === void 0 ? void 0 : themeSvc.settingsChange.pipe(operators.takeUntil(this.ngUnsubscribe)).subscribe(function () {
1734
- _this.changeDetector.markForCheck();
1838
+ this.onChange = function (_) { };
1839
+ /*istanbul ignore next */
1840
+ this.onTouched = function () { };
1841
+ this.onValidatorChange = function () { };
1842
+ this.initialPlaceholder = this.adapter.getPlaceholder(this.elementRef);
1843
+ this.updatePlaceholder();
1844
+ this.localeProvider.getLocaleInfo()
1845
+ .pipe(operators.takeUntil(this.ngUnsubscribe))
1846
+ .subscribe(function (localeInfo) {
1847
+ SkyDateFormatter.setLocale(localeInfo.locale);
1848
+ _this.preferredShortDateFormat = SkyDateFormatter.getPreferredShortDateFormat();
1849
+ _this.applyDateFormat();
1735
1850
  });
1736
1851
  }
1737
- Object.defineProperty(SkyDatepickerComponent.prototype, "buttonIsFocused", {
1852
+ Object.defineProperty(SkyDatepickerInputDirective.prototype, "dateFormat", {
1853
+ get: function () {
1854
+ return this._dateFormat ||
1855
+ this.configService.dateFormat ||
1856
+ this.preferredShortDateFormat;
1857
+ },
1738
1858
  /**
1739
- * @internal
1740
- * Indicates if the calendar button element or any of its children have focus.
1741
- * @deprecated This property will be removed in the next major version release.
1859
+ * Specifies the date format for the input. Place this attribute on the `input` element
1860
+ * to override the default in the `SkyDatepickerConfigService`.
1861
+ * @default MM/DD/YYYY
1742
1862
  */
1743
- get: function () {
1744
- /* sanity check */
1745
- /* istanbul ignore if */
1746
- if (!this.triggerButtonRef) {
1747
- return false;
1863
+ set: function (value) {
1864
+ if (value !== this._dateFormat) {
1865
+ this._dateFormat = value;
1866
+ this.applyDateFormat();
1748
1867
  }
1749
- var activeEl = document.activeElement;
1750
- return this.triggerButtonRef.nativeElement === activeEl;
1751
1868
  },
1752
1869
  enumerable: true,
1753
1870
  configurable: true
1754
1871
  });
1755
- Object.defineProperty(SkyDatepickerComponent.prototype, "calendarIsFocused", {
1872
+ Object.defineProperty(SkyDatepickerInputDirective.prototype, "disabled", {
1873
+ get: function () {
1874
+ return this._disabled || false;
1875
+ },
1756
1876
  /**
1757
- * @internal
1758
- * Indicates if the calendar element or any of its children have focus.
1759
- * @deprecated This property will be removed in the next major version release.
1877
+ * Indicates whether to disable the datepicker.
1878
+ * @default false
1760
1879
  */
1761
- get: function () {
1762
- if (!this.calendarRef) {
1763
- return false;
1764
- }
1765
- var focusedEl = document.activeElement;
1766
- return this.calendarRef.nativeElement.contains(focusedEl);
1880
+ set: function (value) {
1881
+ this._disabled = value;
1882
+ this.datepickerComponent.disabled = value;
1883
+ this.renderer.setProperty(this.elementRef.nativeElement, 'disabled', value);
1767
1884
  },
1768
1885
  enumerable: true,
1769
1886
  configurable: true
1770
1887
  });
1771
- Object.defineProperty(SkyDatepickerComponent.prototype, "calendarIsVisible", {
1888
+ Object.defineProperty(SkyDatepickerInputDirective.prototype, "inputIsFocused", {
1772
1889
  /**
1773
1890
  * @internal
1774
- * Indicates if the calendar element's visiblity property is 'visible'.
1775
- * @deprecated This property will be removed in the next major version release.
1891
+ * Indicates if the input element or any of its children have focus.
1776
1892
  */
1777
1893
  get: function () {
1778
- return this.calendar ? this.calendar.isVisible : false;
1894
+ return this.adapter.elementIsFocused();
1779
1895
  },
1780
1896
  enumerable: true,
1781
1897
  configurable: true
1782
1898
  });
1783
- Object.defineProperty(SkyDatepickerComponent.prototype, "disabled", {
1899
+ Object.defineProperty(SkyDatepickerInputDirective.prototype, "maxDate", {
1784
1900
  get: function () {
1785
- return this._disabled;
1901
+ return this._maxDate || this.configService.maxDate;
1786
1902
  },
1903
+ /**
1904
+ * Specifies the latest date that is available in the calendar. Place this attribute on
1905
+ * the `input` element to override the default in `SkyDatepickerConfigService`.
1906
+ */
1787
1907
  set: function (value) {
1788
- this._disabled = value;
1789
- this.changeDetector.markForCheck();
1908
+ this._maxDate = value;
1909
+ this.datepickerComponent.maxDate = this.maxDate;
1910
+ this.onValidatorChange();
1790
1911
  },
1791
1912
  enumerable: true,
1792
1913
  configurable: true
1793
1914
  });
1794
- Object.defineProperty(SkyDatepickerComponent.prototype, "selectedDate", {
1915
+ Object.defineProperty(SkyDatepickerInputDirective.prototype, "minDate", {
1916
+ get: function () {
1917
+ return this._minDate || this.configService.minDate;
1918
+ },
1919
+ /**
1920
+ * Specifies the earliest date that is available in the calendar. Place this attribute on
1921
+ * the `input` element to override the default in `SkyDatepickerConfigService`.
1922
+ */
1795
1923
  set: function (value) {
1796
- this._selectedDate = value;
1797
- if (this.calendar) {
1798
- this.calendar.writeValue(this._selectedDate);
1924
+ this._minDate = value;
1925
+ this.datepickerComponent.minDate = this.minDate;
1926
+ this.onValidatorChange();
1927
+ },
1928
+ enumerable: true,
1929
+ configurable: true
1930
+ });
1931
+ Object.defineProperty(SkyDatepickerInputDirective.prototype, "skyDatepickerInput", {
1932
+ /**
1933
+ * Creates the datepicker input and calendar. Place this directive on an `input` element,
1934
+ * and wrap the input in a `sky-datepicker` component. The value that users select is driven
1935
+ * through the `ngModel` attribute specified on the `input` element.
1936
+ * @required
1937
+ */
1938
+ set: function (value) {
1939
+ if (value) {
1940
+ console.warn('[Deprecation warning] You no longer need to provide a template reference variable ' +
1941
+ 'to the `skyDatepickerInput` attribute (this will be a breaking change in the next ' +
1942
+ 'major version release).\n' +
1943
+ 'Do this instead:\n' +
1944
+ '<sky-datepicker>\n <input skyDatepickerInput />\n</sky-datepicker>');
1799
1945
  }
1800
1946
  },
1801
1947
  enumerable: true,
1802
1948
  configurable: true
1803
1949
  });
1804
- Object.defineProperty(SkyDatepickerComponent.prototype, "calendarRef", {
1950
+ Object.defineProperty(SkyDatepickerInputDirective.prototype, "startingDay", {
1805
1951
  get: function () {
1806
- return this._calendarRef;
1952
+ return this._startingDay || this.configService.startingDay;
1807
1953
  },
1954
+ /**
1955
+ * Specifies the starting day of the week in the calendar, where `0` sets the starting day
1956
+ * to Sunday. Place this attribute on the `input` element to override the default
1957
+ * in `SkyDatepickerConfigService`.
1958
+ * @default 0
1959
+ */
1808
1960
  set: function (value) {
1809
- var _this = this;
1810
- if (value) {
1811
- this._calendarRef = value;
1812
- // Wait for the calendar component to render before gauging dimensions.
1813
- setTimeout(function () {
1814
- _this.calendar.writeValue(_this._selectedDate);
1815
- _this.destroyAffixer();
1816
- _this.createAffixer();
1817
- setTimeout(function () {
1818
- _this.coreAdapter.getFocusableChildrenAndApplyFocus(_this.calendarRef, '.sky-datepicker-calendar-inner', false);
1819
- _this.isVisible = true;
1820
- _this.changeDetector.markForCheck();
1821
- });
1822
- });
1823
- }
1961
+ this._startingDay = value;
1962
+ this.datepickerComponent.startingDay = this.startingDay;
1963
+ this.onValidatorChange();
1824
1964
  },
1825
1965
  enumerable: true,
1826
1966
  configurable: true
1827
1967
  });
1828
- SkyDatepickerComponent.prototype.ngOnInit = function () {
1829
- if (this.inputBoxHostService) {
1830
- this.inputBoxHostService.populate({
1831
- inputTemplate: this.inputTemplateRef,
1832
- buttonsTemplate: this.triggerButtonTemplateRef
1833
- });
1834
- }
1835
- };
1836
- SkyDatepickerComponent.prototype.ngOnDestroy = function () {
1837
- this.dateChange.complete();
1838
- this.ngUnsubscribe.next();
1839
- this.ngUnsubscribe.complete();
1840
- this.removePickerEventListeners();
1841
- this.destroyAffixer();
1842
- this.destroyOverlay();
1843
- };
1844
- SkyDatepickerComponent.prototype.onCalendarModeChange = function () {
1845
- var _this = this;
1846
- // Let the calendar populate in the DOM before recalculating placement.
1847
- setTimeout(function () {
1848
- _this.affixer.reaffix();
1849
- });
1850
- };
1851
- SkyDatepickerComponent.prototype.onSelectedDateChange = function (value) {
1852
- this.dateChange.emit(value);
1853
- this.closePicker();
1854
- };
1855
- SkyDatepickerComponent.prototype.onTriggerButtonClick = function () {
1856
- if (this.isOpen) {
1857
- this.closePicker();
1858
- }
1859
- else {
1860
- this.openPicker();
1861
- }
1862
- };
1863
- SkyDatepickerComponent.prototype.closePicker = function () {
1864
- this.destroyAffixer();
1865
- this.destroyOverlay();
1866
- this.removePickerEventListeners();
1867
- this.triggerButtonRef.nativeElement.focus();
1868
- this.isOpen = false;
1869
- };
1870
- SkyDatepickerComponent.prototype.openPicker = function () {
1871
- this.isVisible = false;
1872
- this.changeDetector.markForCheck();
1873
- this.removePickerEventListeners();
1874
- this.calendarUnsubscribe = new rxjs.Subject();
1875
- this.destroyOverlay();
1876
- this.createOverlay();
1877
- this.isOpen = true;
1878
- this.changeDetector.markForCheck();
1879
- };
1880
- SkyDatepickerComponent.prototype.createAffixer = function () {
1881
- var _this = this;
1882
- var affixer = this.affixService.createAffixer(this.calendarRef);
1883
- // Hide calendar when trigger button is scrolled off screen.
1884
- affixer.placementChange
1885
- .pipe(operators.takeUntil(this.calendarUnsubscribe))
1886
- .subscribe(function (change) {
1887
- _this.isVisible = (change.placement !== null);
1888
- _this.changeDetector.markForCheck();
1889
- });
1890
- affixer.affixTo(this.triggerButtonRef.nativeElement, {
1891
- autoFitContext: core$1.SkyAffixAutoFitContext.Viewport,
1892
- enableAutoFit: true,
1893
- horizontalAlignment: 'right',
1894
- isSticky: true,
1895
- placement: 'below'
1896
- });
1897
- this.affixer = affixer;
1898
- };
1899
- SkyDatepickerComponent.prototype.destroyAffixer = function () {
1900
- /*istanbul ignore else*/
1901
- if (this.affixer) {
1902
- this.affixer.destroy();
1903
- this.affixer = undefined;
1904
- }
1905
- };
1906
- SkyDatepickerComponent.prototype.createOverlay = function () {
1907
- var _this = this;
1908
- var overlay = this.overlayService.create({
1909
- wrapperClass: this.pickerClass,
1910
- enableClose: false,
1911
- enablePointerEvents: false
1912
- });
1913
- overlay.backdropClick
1914
- .pipe(operators.takeUntil(this.calendarUnsubscribe))
1915
- .subscribe(function () {
1916
- if (_this.isOpen) {
1917
- _this.closePicker();
1918
- }
1919
- });
1920
- this.addKeydownListner();
1921
- overlay.attachTemplate(this.calendarTemplateRef);
1922
- this.overlay = overlay;
1923
- };
1924
- SkyDatepickerComponent.prototype.destroyOverlay = function () {
1925
- /*istanbul ignore else*/
1926
- if (this.overlay) {
1927
- this.overlayService.close(this.overlay);
1928
- this.overlay = undefined;
1929
- }
1930
- };
1931
- SkyDatepickerComponent.prototype.addKeydownListner = function () {
1932
- var _this = this;
1933
- this.overlayKeydownListner = rxjs.fromEvent(window.document, 'keydown')
1934
- .pipe(operators.takeUntil(this.ngUnsubscribe))
1935
- .subscribe(function (event) {
1936
- var _a;
1937
- var key = (_a = event.key) === null || _a === void 0 ? void 0 : _a.toLowerCase();
1938
- if (key === 'escape' && _this.isOpen) {
1939
- _this.closePicker();
1940
- }
1941
- });
1942
- };
1943
- SkyDatepickerComponent.prototype.removePickerEventListeners = function () {
1944
- var _a;
1945
- /* istanbul ignore else */
1946
- if (this.calendarUnsubscribe) {
1947
- this.calendarUnsubscribe.next();
1948
- this.calendarUnsubscribe.complete();
1949
- this.calendarUnsubscribe = undefined;
1950
- }
1951
- (_a = this.overlayKeydownListner) === null || _a === void 0 ? void 0 : _a.unsubscribe();
1952
- };
1953
- SkyDatepickerComponent.ctorParameters = function () { return [
1954
- { type: core$1.SkyAffixService },
1955
- { type: core.ChangeDetectorRef },
1956
- { type: core$1.SkyCoreAdapterService },
1957
- { type: core$1.SkyOverlayService },
1958
- { type: forms$1.SkyInputBoxHostService, decorators: [{ type: core.Optional }] },
1959
- { type: theme.SkyThemeService, decorators: [{ type: core.Optional }] }
1960
- ]; };
1961
- __decorate([
1962
- core.Input()
1963
- ], SkyDatepickerComponent.prototype, "pickerClass", void 0);
1964
- __decorate([
1965
- core.ViewChild(SkyDatepickerCalendarComponent)
1966
- ], SkyDatepickerComponent.prototype, "calendar", void 0);
1967
- __decorate([
1968
- core.ViewChild('calendarRef', {
1969
- read: core.ElementRef
1970
- })
1971
- ], SkyDatepickerComponent.prototype, "calendarRef", null);
1972
- __decorate([
1973
- core.ViewChild('calendarTemplateRef', {
1974
- read: core.TemplateRef
1975
- })
1976
- ], SkyDatepickerComponent.prototype, "calendarTemplateRef", void 0);
1977
- __decorate([
1978
- core.ViewChild('triggerButtonRef', {
1979
- read: core.ElementRef
1980
- })
1981
- ], SkyDatepickerComponent.prototype, "triggerButtonRef", void 0);
1982
- __decorate([
1983
- core.ViewChild('inputTemplateRef', {
1984
- read: core.TemplateRef,
1985
- static: true
1986
- })
1987
- ], SkyDatepickerComponent.prototype, "inputTemplateRef", void 0);
1988
- __decorate([
1989
- core.ViewChild('triggerButtonTemplateRef', {
1990
- read: core.TemplateRef,
1991
- static: true
1992
- })
1993
- ], SkyDatepickerComponent.prototype, "triggerButtonTemplateRef", void 0);
1994
- SkyDatepickerComponent = __decorate([
1995
- core.Component({
1996
- selector: 'sky-datepicker',
1997
- template: "<div\n class=\"sky-datepicker\"\n>\n <ng-container *ngIf=\"!inputBoxHostService\">\n <div\n class=\"sky-input-group\"\n >\n <ng-container *ngTemplateOutlet=\"inputTemplateRef\"></ng-container>\n <ng-container *ngTemplateOutlet=\"triggerButtonTemplateRef\"></ng-container>\n </div>\n </ng-container>\n</div>\n\n<ng-template #inputTemplateRef>\n <ng-content></ng-content>\n</ng-template>\n\n<ng-template #triggerButtonTemplateRef>\n <div\n class=\"sky-input-group-btn\"\n >\n <button\n aria-haspopup=\"dialog\"\n class=\"sky-btn sky-btn-default sky-input-group-datepicker-btn\"\n type=\"button\"\n [attr.aria-controls]=\"isOpen ? calendarId : null\"\n [attr.aria-expanded]=\"isOpen\"\n [attr.aria-label]=\"'skyux_datepicker_trigger_button_label' | skyLibResources\"\n [attr.id]=\"triggerButtonId\"\n [attr.title]=\"'skyux_datepicker_trigger_button_label' | skyLibResources\"\n [disabled]=\"disabled\"\n (click)=\"onTriggerButtonClick()\"\n #triggerButtonRef\n >\n <sky-icon *skyThemeIf=\"'default'\"\n icon=\"calendar\"\n size=\"lg\"\n ></sky-icon>\n <sky-icon *skyThemeIf=\"'modern'\"\n icon=\"calendar\"\n size=\"lg\"\n iconType=\"skyux\"\n ></sky-icon>\n </button>\n </div>\n</ng-template>\n\n<ng-template #calendarTemplateRef>\n <div\n class=\"sky-datepicker-calendar-container sky-shadow sky-elevation-4\"\n role=\"dialog\"\n [attr.aria-labelledby]=\"triggerButtonId\"\n [attr.id]=\"calendarId\"\n [class.sky-datepicker-hidden]=\"!isVisible\"\n #calendarRef\n >\n <sky-datepicker-calendar\n [maxDate]=\"maxDate\"\n [minDate]=\"minDate\"\n [startingDay]=\"startingDay\"\n (calendarModeChange)=\"onCalendarModeChange()\"\n (selectedDateChange)=\"onSelectedDateChange($event)\"\n >\n </sky-datepicker-calendar>\n </div>\n</ng-template>\n",
1998
- changeDetection: core.ChangeDetectionStrategy.OnPush,
1999
- styles: [".sky-datepicker-calendar-container{position:fixed;border-radius:5px}.sky-datepicker-hidden{visibility:hidden}"]
2000
- }),
2001
- __param(4, core.Optional()),
2002
- __param(5, core.Optional())
2003
- ], SkyDatepickerComponent);
2004
- return SkyDatepickerComponent;
2005
- }());
2006
-
2007
- var moment$3 = moment_;
2008
- // tslint:disable:no-forward-ref no-use-before-declare
2009
- var SKY_DATEPICKER_VALUE_ACCESSOR = {
2010
- provide: forms.NG_VALUE_ACCESSOR,
2011
- useExisting: core.forwardRef(function () { return SkyDatepickerInputDirective; }),
2012
- multi: true
2013
- };
2014
- var SKY_DATEPICKER_VALIDATOR = {
2015
- provide: forms.NG_VALIDATORS,
2016
- useExisting: core.forwardRef(function () { return SkyDatepickerInputDirective; }),
2017
- multi: true
2018
- };
2019
- // tslint:enable
2020
- var SkyDatepickerInputDirective = /** @class */ (function () {
2021
- function SkyDatepickerInputDirective(adapter, changeDetector, configService, elementRef, localeProvider, renderer, resourcesService, datepickerComponent) {
2022
- var _this = this;
2023
- this.adapter = adapter;
2024
- this.changeDetector = changeDetector;
2025
- this.configService = configService;
2026
- this.elementRef = elementRef;
2027
- this.localeProvider = localeProvider;
2028
- this.renderer = renderer;
2029
- this.resourcesService = resourcesService;
2030
- this.datepickerComponent = datepickerComponent;
2031
- /**
2032
- * Indicates whether to disable date validation on the datepicker input.
2033
- * @default false
2034
- */
2035
- this.skyDatepickerNoValidate = false;
2036
- this.dateFormatter = new SkyDateFormatter();
2037
- this.isFirstChange = true;
2038
- this.ngUnsubscribe = new rxjs.Subject();
2039
- this.onChange = function (_) { };
2040
- /*istanbul ignore next */
2041
- this.onTouched = function () { };
2042
- this.onValidatorChange = function () { };
2043
- this.initialPlaceholder = this.adapter.getPlaceholder(this.elementRef);
2044
- this.updatePlaceholder();
2045
- this.localeProvider.getLocaleInfo()
2046
- .pipe(operators.takeUntil(this.ngUnsubscribe))
2047
- .subscribe(function (localeInfo) {
2048
- SkyDateFormatter.setLocale(localeInfo.locale);
2049
- _this.preferredShortDateFormat = SkyDateFormatter.getPreferredShortDateFormat();
2050
- _this.applyDateFormat();
2051
- });
2052
- }
2053
- Object.defineProperty(SkyDatepickerInputDirective.prototype, "dateFormat", {
1968
+ Object.defineProperty(SkyDatepickerInputDirective.prototype, "strict", {
2054
1969
  get: function () {
2055
- return this._dateFormat ||
2056
- this.configService.dateFormat ||
2057
- this.preferredShortDateFormat;
1970
+ return this._strict || false;
2058
1971
  },
2059
1972
  /**
2060
- * Specifies the date format for the input. Place this attribute on the `input` element
2061
- * to override the default in the `SkyDatepickerConfigService`.
2062
- * @default MM/DD/YYYY
1973
+ * Indicates whether the format of the date value must match the format from the `dateFormat` value.
1974
+ * If this property is `true` and the datepicker input directive cannot find an exact match, then
1975
+ * the input is marked as invalid.
1976
+ * If this property is `false` and the datepicker input directive cannot find an exact match, then
1977
+ * it attempts to format the string based on the [ISO 8601 standard format](https://www.iso.org/iso-8601-date-and-time-format.html).
1978
+ * @default false
2063
1979
  */
2064
1980
  set: function (value) {
2065
- if (value !== this._dateFormat) {
2066
- this._dateFormat = value;
2067
- this.applyDateFormat();
2068
- }
1981
+ this._strict = value;
2069
1982
  },
2070
1983
  enumerable: true,
2071
1984
  configurable: true
2072
1985
  });
2073
- Object.defineProperty(SkyDatepickerInputDirective.prototype, "disabled", {
1986
+ Object.defineProperty(SkyDatepickerInputDirective.prototype, "value", {
2074
1987
  get: function () {
2075
- return this._disabled || false;
1988
+ return this._value;
2076
1989
  },
2077
- /**
2078
- * Indicates whether to disable the datepicker.
2079
- * @default false
2080
- */
2081
1990
  set: function (value) {
2082
- this._disabled = value;
2083
- this.datepickerComponent.disabled = value;
2084
- this.renderer.setProperty(this.elementRef.nativeElement, 'disabled', value);
2085
- },
2086
- enumerable: true,
2087
- configurable: true
2088
- });
2089
- Object.defineProperty(SkyDatepickerInputDirective.prototype, "inputIsFocused", {
2090
- /**
2091
- * @internal
2092
- * Indicates if the input element or any of its children have focus.
2093
- */
2094
- get: function () {
2095
- return this.adapter.elementIsFocused();
2096
- },
2097
- enumerable: true,
2098
- configurable: true
2099
- });
2100
- Object.defineProperty(SkyDatepickerInputDirective.prototype, "maxDate", {
2101
- get: function () {
2102
- return this._maxDate || this.configService.maxDate;
2103
- },
2104
- /**
2105
- * Specifies the latest date that is available in the calendar. Place this attribute on
2106
- * the `input` element to override the default in `SkyDatepickerConfigService`.
2107
- */
2108
- set: function (value) {
2109
- this._maxDate = value;
2110
- this.datepickerComponent.maxDate = this.maxDate;
2111
- this.onValidatorChange();
2112
- },
2113
- enumerable: true,
2114
- configurable: true
2115
- });
2116
- Object.defineProperty(SkyDatepickerInputDirective.prototype, "minDate", {
2117
- get: function () {
2118
- return this._minDate || this.configService.minDate;
2119
- },
2120
- /**
2121
- * Specifies the earliest date that is available in the calendar. Place this attribute on
2122
- * the `input` element to override the default in `SkyDatepickerConfigService`.
2123
- */
2124
- set: function (value) {
2125
- this._minDate = value;
2126
- this.datepickerComponent.minDate = this.minDate;
2127
- this.onValidatorChange();
2128
- },
2129
- enumerable: true,
2130
- configurable: true
2131
- });
2132
- Object.defineProperty(SkyDatepickerInputDirective.prototype, "skyDatepickerInput", {
2133
- /**
2134
- * Creates the datepicker input and calendar. Place this directive on an `input` element,
2135
- * and wrap the input in a `sky-datepicker` component. The value that users select is driven
2136
- * through the `ngModel` attribute specified on the `input` element.
2137
- * @required
2138
- */
2139
- set: function (value) {
2140
- if (value) {
2141
- console.warn('[Deprecation warning] You no longer need to provide a template reference variable ' +
2142
- 'to the `skyDatepickerInput` attribute (this will be a breaking change in the next ' +
2143
- 'major version release).\n' +
2144
- 'Do this instead:\n' +
2145
- '<sky-datepicker>\n <input skyDatepickerInput />\n</sky-datepicker>');
2146
- }
2147
- },
2148
- enumerable: true,
2149
- configurable: true
2150
- });
2151
- Object.defineProperty(SkyDatepickerInputDirective.prototype, "startingDay", {
2152
- get: function () {
2153
- return this._startingDay || this.configService.startingDay;
2154
- },
2155
- /**
2156
- * Specifies the starting day of the week in the calendar, where `0` sets the starting day
2157
- * to Sunday. Place this attribute on the `input` element to override the default
2158
- * in `SkyDatepickerConfigService`.
2159
- * @default 0
2160
- */
2161
- set: function (value) {
2162
- this._startingDay = value;
2163
- this.datepickerComponent.startingDay = this.startingDay;
2164
- this.onValidatorChange();
2165
- },
2166
- enumerable: true,
2167
- configurable: true
2168
- });
2169
- Object.defineProperty(SkyDatepickerInputDirective.prototype, "strict", {
2170
- get: function () {
2171
- return this._strict || false;
2172
- },
2173
- /**
2174
- * Indicates whether the format of the date value must match the format from the `dateFormat` value.
2175
- * If this property is `true` and the datepicker input directive cannot find an exact match, then
2176
- * the input is marked as invalid.
2177
- * If this property is `false` and the datepicker input directive cannot find an exact match, then
2178
- * it attempts to format the string based on the [ISO 8601 standard format](https://www.iso.org/iso-8601-date-and-time-format.html).
2179
- * @default false
2180
- */
2181
- set: function (value) {
2182
- this._strict = value;
2183
- },
2184
- enumerable: true,
2185
- configurable: true
2186
- });
2187
- Object.defineProperty(SkyDatepickerInputDirective.prototype, "value", {
2188
- get: function () {
2189
- return this._value;
2190
- },
2191
- set: function (value) {
2192
- var dateValue = this.getDateValue(value);
2193
- var areDatesEqual = (this._value instanceof Date &&
2194
- dateValue &&
2195
- dateValue.getTime() === this._value.getTime());
2196
- var isValidDateString = this.isDateStringValid(value);
2197
- // If the string value supplied is malformed, do not set the value to its Date equivalent.
2198
- // (JavaScript's Date parser will convert poorly formatted dates to Date objects, such as "abc 123", which isn't ideal.)
2199
- if (!isValidDateString) {
2200
- this._value = value;
2201
- this.notifyUpdatedValue();
2202
- }
2203
- else if (dateValue !== this._value || !areDatesEqual) {
2204
- this._value = (dateValue || value);
2205
- this.notifyUpdatedValue();
2206
- }
2207
- if (dateValue && isValidDateString) {
2208
- var formattedDate = this.dateFormatter.format(dateValue, this.dateFormat);
2209
- this.setInputElementValue(formattedDate);
2210
- }
2211
- else {
2212
- this.setInputElementValue(value || '');
2213
- }
1991
+ var dateValue = this.getDateValue(value);
1992
+ var areDatesEqual = (this._value instanceof Date &&
1993
+ dateValue &&
1994
+ dateValue.getTime() === this._value.getTime());
1995
+ var isValidDateString = this.isDateStringValid(value);
1996
+ // If the string value supplied is malformed, do not set the value to its Date equivalent.
1997
+ // (JavaScript's Date parser will convert poorly formatted dates to Date objects, such as "abc 123", which isn't ideal.)
1998
+ if (!isValidDateString) {
1999
+ this._value = value;
2000
+ this.notifyUpdatedValue();
2001
+ }
2002
+ else if (dateValue !== this._value || !areDatesEqual) {
2003
+ this._value = (dateValue || value);
2004
+ this.notifyUpdatedValue();
2005
+ }
2006
+ if (dateValue && isValidDateString) {
2007
+ var formattedDate = this.dateFormatter.format(dateValue, this.dateFormat);
2008
+ this.setInputElementValue(formattedDate);
2009
+ }
2010
+ else {
2011
+ this.setInputElementValue(value || '');
2012
+ }
2214
2013
  },
2215
2014
  enumerable: true,
2216
2015
  configurable: true
@@ -2707,267 +2506,811 @@
2707
2506
  }
2708
2507
  this.datepickerComponent.selectedDate = dateValue;
2709
2508
  }
2710
- this.setInputElementValue(formattedDate || '');
2509
+ this.setInputElementValue(formattedDate || '');
2510
+ },
2511
+ enumerable: true,
2512
+ configurable: true
2513
+ });
2514
+ SkyFuzzyDatepickerInputDirective.prototype.ngOnInit = function () {
2515
+ var _this = this;
2516
+ if (this.yearRequired) {
2517
+ if (this.dateFormat.toLowerCase().indexOf('y') === -1) {
2518
+ throw new Error('You have configured conflicting settings. Year is required and dateFormat does not include year.');
2519
+ }
2520
+ }
2521
+ if (!this.datepickerComponent) {
2522
+ throw new Error('You must wrap the `skyFuzzyDatepickerInput` directive within a ' +
2523
+ '`<sky-datepicker>` component!');
2524
+ }
2525
+ var element = this.elementRef.nativeElement;
2526
+ this.renderer.addClass(element, 'sky-form-control');
2527
+ var hasAriaLabel = element.getAttribute('aria-label');
2528
+ if (!hasAriaLabel) {
2529
+ this.resourcesService.getString('skyux_date_field_default_label')
2530
+ .pipe(operators.takeUntil(this.ngUnsubscribe))
2531
+ .subscribe(function (value) {
2532
+ _this.renderer.setAttribute(element, 'aria-label', value);
2533
+ });
2534
+ }
2535
+ };
2536
+ SkyFuzzyDatepickerInputDirective.prototype.ngAfterContentInit = function () {
2537
+ var _this = this;
2538
+ this.datepickerComponent.dateChange
2539
+ .pipe(operators.distinctUntilChanged(), operators.takeUntil(this.ngUnsubscribe))
2540
+ .subscribe(function (value) {
2541
+ _this.isFirstChange = false;
2542
+ _this.value = value;
2543
+ _this.onTouched();
2544
+ });
2545
+ };
2546
+ SkyFuzzyDatepickerInputDirective.prototype.ngAfterViewInit = function () {
2547
+ // This is needed to address a bug in Angular 4.
2548
+ // When a control value is set intially, its value is not represented on the view.
2549
+ // See: https://github.com/angular/angular/issues/13792
2550
+ // Of note is the parent check which allows us to determine if the form is reactive.
2551
+ // Without this check there is a changed before checked error
2552
+ /* istanbul ignore else */
2553
+ var _this = this;
2554
+ if (this.control && this.control.parent) {
2555
+ setTimeout(function () {
2556
+ _this.control.setValue(_this.value, {
2557
+ emitEvent: false
2558
+ });
2559
+ _this.changeDetector.markForCheck();
2560
+ });
2561
+ }
2562
+ };
2563
+ SkyFuzzyDatepickerInputDirective.prototype.ngOnDestroy = function () {
2564
+ this.ngUnsubscribe.next();
2565
+ this.ngUnsubscribe.complete();
2566
+ };
2567
+ SkyFuzzyDatepickerInputDirective.prototype.onInputChange = function (event) {
2568
+ this.onValueChange(event.target.value);
2569
+ };
2570
+ SkyFuzzyDatepickerInputDirective.prototype.onInputBlur = function () {
2571
+ this.onTouched();
2572
+ var formattedDate = this.fuzzyDateService.format(this.value, this.dateFormat, this.locale);
2573
+ if (this.control.valid) {
2574
+ this.setInputElementValue(formattedDate || '');
2575
+ }
2576
+ };
2577
+ SkyFuzzyDatepickerInputDirective.prototype.onInputKeyup = function () {
2578
+ this.control.markAsDirty();
2579
+ };
2580
+ SkyFuzzyDatepickerInputDirective.prototype.writeValue = function (value) {
2581
+ this.value = value;
2582
+ };
2583
+ SkyFuzzyDatepickerInputDirective.prototype.validate = function (control) {
2584
+ if (!this.control) {
2585
+ this.control = control;
2586
+ }
2587
+ if (this.skyDatepickerNoValidate) {
2588
+ return;
2589
+ }
2590
+ if (!this.control.value) {
2591
+ return;
2592
+ }
2593
+ var value = control.value;
2594
+ var fuzzyDate;
2595
+ var validationError;
2596
+ if (typeof value === 'string') {
2597
+ fuzzyDate = this.fuzzyDateService.getFuzzyDateFromString(value, this.dateFormat);
2598
+ }
2599
+ else {
2600
+ fuzzyDate = value;
2601
+ }
2602
+ if (!fuzzyDate) {
2603
+ validationError = {
2604
+ 'skyFuzzyDate': {
2605
+ invalid: value
2606
+ }
2607
+ };
2608
+ }
2609
+ if (!validationError && !fuzzyDate.year && this.yearRequired) {
2610
+ validationError = {
2611
+ 'skyFuzzyDate': {
2612
+ yearRequired: value
2613
+ }
2614
+ };
2615
+ }
2616
+ if (!validationError && fuzzyDate.year) {
2617
+ var fuzzyDateRange = void 0;
2618
+ if (this.maxDate) {
2619
+ fuzzyDateRange = this.fuzzyDateService.getFuzzyDateRange(fuzzyDate, this.maxDate);
2620
+ if (!fuzzyDateRange.valid) {
2621
+ validationError = {
2622
+ 'skyFuzzyDate': {
2623
+ maxDate: value
2624
+ }
2625
+ };
2626
+ }
2627
+ }
2628
+ if (!validationError && this.minDate) {
2629
+ fuzzyDateRange = this.fuzzyDateService.getFuzzyDateRange(this.minDate, fuzzyDate);
2630
+ if (!fuzzyDateRange.valid) {
2631
+ validationError = {
2632
+ 'skyFuzzyDate': {
2633
+ minDate: value
2634
+ }
2635
+ };
2636
+ }
2637
+ }
2638
+ if (!validationError && this.futureDisabled) {
2639
+ fuzzyDateRange = this.fuzzyDateService.getFuzzyDateRange(fuzzyDate, this.fuzzyDateService.getCurrentFuzzyDate());
2640
+ if (!fuzzyDateRange.valid) {
2641
+ validationError = {
2642
+ 'skyFuzzyDate': {
2643
+ futureDisabled: value
2644
+ }
2645
+ };
2646
+ }
2647
+ }
2648
+ }
2649
+ if (validationError) {
2650
+ // Mark the invalid control as touched so that the input's invalid CSS styles appear.
2651
+ // (This is only required when the invalid value is set by the FormControl constructor.)
2652
+ this.control.markAsTouched();
2653
+ }
2654
+ return validationError;
2655
+ };
2656
+ SkyFuzzyDatepickerInputDirective.prototype.registerOnChange = function (fn) {
2657
+ this.onChange = fn;
2658
+ };
2659
+ SkyFuzzyDatepickerInputDirective.prototype.registerOnTouched = function (fn) {
2660
+ this.onTouched = fn;
2661
+ };
2662
+ SkyFuzzyDatepickerInputDirective.prototype.registerOnValidatorChange = function (fn) {
2663
+ this.onValidatorChange = fn;
2664
+ };
2665
+ SkyFuzzyDatepickerInputDirective.prototype.setDisabledState = function (disabled) {
2666
+ this.disabled = disabled;
2667
+ this.datepickerComponent.disabled = disabled;
2668
+ };
2669
+ /**
2670
+ * Detects changes to the underlying input element's value and updates the ngModel accordingly.
2671
+ * This is useful if you need to update the ngModel value before the input element loses focus.
2672
+ */
2673
+ SkyFuzzyDatepickerInputDirective.prototype.detectInputValueChange = function () {
2674
+ this.onValueChange(this.elementRef.nativeElement.value);
2675
+ };
2676
+ SkyFuzzyDatepickerInputDirective.prototype.onValueChange = function (newValue) {
2677
+ this.isFirstChange = false;
2678
+ this.value = newValue;
2679
+ };
2680
+ SkyFuzzyDatepickerInputDirective.prototype.setInputElementValue = function (value) {
2681
+ this.renderer.setProperty(this.elementRef.nativeElement, 'value', value);
2682
+ };
2683
+ SkyFuzzyDatepickerInputDirective.prototype.getMaxDate = function () {
2684
+ if (this.maxDate) {
2685
+ var maxDate = this.fuzzyDateService.getMomentFromFuzzyDate(this.maxDate);
2686
+ if (maxDate.isValid()) {
2687
+ return maxDate.toDate();
2688
+ }
2689
+ }
2690
+ else if (this.futureDisabled) {
2691
+ return new Date();
2692
+ }
2693
+ return this.configService.maxDate;
2694
+ };
2695
+ SkyFuzzyDatepickerInputDirective.prototype.getMinDate = function () {
2696
+ if (this.minDate) {
2697
+ var minDate = this.fuzzyDateService.getMomentFromFuzzyDate(this.minDate);
2698
+ if (minDate.isValid()) {
2699
+ return minDate.toDate();
2700
+ }
2701
+ }
2702
+ return this.configService.minDate;
2703
+ };
2704
+ SkyFuzzyDatepickerInputDirective.prototype.fuzzyDatesEqual = function (dateA, dateB) {
2705
+ return dateA && dateB
2706
+ && ((!dateA.day && !dateB.day)
2707
+ || dateA.day === dateB.day)
2708
+ && ((!dateA.month && !dateB.month)
2709
+ || dateA.month === dateB.month)
2710
+ && ((!dateA.year && !dateB.year)
2711
+ || dateA.year === dateB.year);
2712
+ };
2713
+ SkyFuzzyDatepickerInputDirective.ctorParameters = function () { return [
2714
+ { type: core.ChangeDetectorRef },
2715
+ { type: SkyDatepickerConfigService },
2716
+ { type: core.ElementRef },
2717
+ { type: SkyFuzzyDateService },
2718
+ { type: i18n.SkyAppLocaleProvider },
2719
+ { type: core.Renderer2 },
2720
+ { type: i18n.SkyLibResourcesService },
2721
+ { type: SkyDatepickerComponent, decorators: [{ type: core.Optional }] }
2722
+ ]; };
2723
+ __decorate([
2724
+ core.Input()
2725
+ ], SkyFuzzyDatepickerInputDirective.prototype, "dateFormat", null);
2726
+ __decorate([
2727
+ core.Input()
2728
+ ], SkyFuzzyDatepickerInputDirective.prototype, "disabled", null);
2729
+ __decorate([
2730
+ core.Input()
2731
+ ], SkyFuzzyDatepickerInputDirective.prototype, "futureDisabled", null);
2732
+ __decorate([
2733
+ core.Input()
2734
+ ], SkyFuzzyDatepickerInputDirective.prototype, "maxDate", null);
2735
+ __decorate([
2736
+ core.Input()
2737
+ ], SkyFuzzyDatepickerInputDirective.prototype, "minDate", null);
2738
+ __decorate([
2739
+ core.Input()
2740
+ ], SkyFuzzyDatepickerInputDirective.prototype, "skyDatepickerNoValidate", void 0);
2741
+ __decorate([
2742
+ core.Input()
2743
+ ], SkyFuzzyDatepickerInputDirective.prototype, "skyFuzzyDatepickerInput", null);
2744
+ __decorate([
2745
+ core.Input()
2746
+ ], SkyFuzzyDatepickerInputDirective.prototype, "startingDay", null);
2747
+ __decorate([
2748
+ core.Input()
2749
+ ], SkyFuzzyDatepickerInputDirective.prototype, "yearRequired", null);
2750
+ __decorate([
2751
+ core.HostListener('change', ['$event'])
2752
+ ], SkyFuzzyDatepickerInputDirective.prototype, "onInputChange", null);
2753
+ __decorate([
2754
+ core.HostListener('blur')
2755
+ ], SkyFuzzyDatepickerInputDirective.prototype, "onInputBlur", null);
2756
+ __decorate([
2757
+ core.HostListener('keyup')
2758
+ ], SkyFuzzyDatepickerInputDirective.prototype, "onInputKeyup", null);
2759
+ SkyFuzzyDatepickerInputDirective = __decorate([
2760
+ core.Directive({
2761
+ selector: '[skyFuzzyDatepickerInput]',
2762
+ providers: [
2763
+ SKY_FUZZY_DATEPICKER_VALUE_ACCESSOR,
2764
+ SKY_FUZZY_DATEPICKER_VALIDATOR
2765
+ ]
2766
+ }),
2767
+ __param(7, core.Optional())
2768
+ ], SkyFuzzyDatepickerInputDirective);
2769
+ return SkyFuzzyDatepickerInputDirective;
2770
+ }());
2771
+
2772
+ /**
2773
+ * @internal
2774
+ */
2775
+ var SkyDatepickerService = /** @class */ (function () {
2776
+ function SkyDatepickerService() {
2777
+ /**
2778
+ * Specifies if a key date popover is currently displayed.
2779
+ * Useful for communicating across all daypicker siblings when a popover is displayed.
2780
+ */
2781
+ this.keyDatePopoverStream = new rxjs.Subject();
2782
+ }
2783
+ SkyDatepickerService = __decorate([
2784
+ core.Injectable()
2785
+ ], SkyDatepickerService);
2786
+ return SkyDatepickerService;
2787
+ }());
2788
+
2789
+ /**
2790
+ * @internal
2791
+ */
2792
+ var SkyDayPickerButtonComponent = /** @class */ (function () {
2793
+ function SkyDayPickerButtonComponent(datepicker) {
2794
+ this.datepicker = datepicker;
2795
+ }
2796
+ SkyDayPickerButtonComponent.ctorParameters = function () { return [
2797
+ { type: SkyDatepickerCalendarInnerComponent }
2798
+ ]; };
2799
+ __decorate([
2800
+ core.Input()
2801
+ ], SkyDayPickerButtonComponent.prototype, "date", void 0);
2802
+ SkyDayPickerButtonComponent = __decorate([
2803
+ core.Component({
2804
+ selector: 'sky-daypicker-button',
2805
+ template: "<button\n class=\"sky-btn sky-btn-sm sky-btn-default sky-datepicker-btn-date\"\n tabindex=\"-1\"\n type=\"button\"\n [disabled]=\"date.disabled\"\n [ngClass]=\"{\n 'sky-datepicker-btn-selected': date.selected,\n 'sky-btn-disabled': date.disabled,\n 'sky-btn-active': datepicker.isActive(date),\n 'sky-datepicker-btn-disabled': date.disabled,\n 'sky-datepicker-btn-key-date': date.keyDate\n }\"\n (click)=\"datepicker.selectCalendar($event, date.date, true)\"\n>\n <span\n [ngClass]=\"{ 'sky-datepicker-secondary': date.secondary }\"\n >\n {{date.label}}\n </span>\n</button>\n",
2806
+ styles: [".sky-datepicker-btn-disabled{font-style:italic}.sky-datepicker-btn-key-date{position:relative}.sky-datepicker-btn-key-date::before{position:absolute;content:\"\";height:5px;width:5px;background-color:#d93a3d;border-radius:50%;left:15px;top:22px}:host-context(.sky-theme-modern) .sky-datepicker-btn-key-date::before{left:12px}.sky-theme-modern .sky-datepicker-btn-key-date::before{left:12px}"]
2807
+ })
2808
+ ], SkyDayPickerButtonComponent);
2809
+ return SkyDayPickerButtonComponent;
2810
+ }());
2811
+
2812
+ /**
2813
+ * @internal
2814
+ */
2815
+ var SkyDayPickerCellComponent = /** @class */ (function () {
2816
+ function SkyDayPickerCellComponent(datepicker, datepickerService) {
2817
+ this.datepicker = datepicker;
2818
+ this.datepickerService = datepickerService;
2819
+ this.hasTooltip = false;
2820
+ this.popoverController = new rxjs.Subject();
2821
+ this.activeUid = '';
2822
+ this.cancelPopover = false;
2823
+ this.popoverOpen = false;
2824
+ this.ngUnsubscribe = new rxjs.Subject();
2825
+ }
2826
+ SkyDayPickerCellComponent.prototype.ngOnInit = function () {
2827
+ var _this = this;
2828
+ this.hasTooltip =
2829
+ this.date.keyDate &&
2830
+ this.date.keyDateText &&
2831
+ this.date.keyDateText.length > 0 &&
2832
+ this.date.keyDateText[0].length > 0;
2833
+ // show the tooltip if this is the active date and is not the
2834
+ // initial active date (activeDateHasChanged)
2835
+ if (this.datepicker.isActive(this.date) &&
2836
+ this.activeDateHasChanged &&
2837
+ this.hasTooltip) {
2838
+ this.activeUid = this.date.uid;
2839
+ this.showTooltip();
2840
+ }
2841
+ if (this.hasTooltip) {
2842
+ this.datepickerService.keyDatePopoverStream
2843
+ .pipe(operators.takeUntil(this.ngUnsubscribe))
2844
+ .subscribe(function (date) {
2845
+ if (date) {
2846
+ _this.activeUid = date.uid;
2847
+ }
2848
+ else {
2849
+ _this.activeUid = '';
2850
+ }
2851
+ // If this day has an open popover and they have moved off of the day close the popover.
2852
+ if (_this.date.uid !== _this.activeUid) {
2853
+ _this.hideTooltip();
2854
+ }
2855
+ });
2856
+ }
2857
+ };
2858
+ SkyDayPickerCellComponent.prototype.ngOnDestroy = function () {
2859
+ this.ngUnsubscribe.next();
2860
+ this.ngUnsubscribe.complete();
2861
+ };
2862
+ SkyDayPickerCellComponent.prototype.onDayMouseenter = function () {
2863
+ this.cancelPopover = false;
2864
+ if (this.hasTooltip) {
2865
+ this.showTooltip();
2866
+ this.datepickerService.keyDatePopoverStream.next(this.date);
2867
+ }
2868
+ };
2869
+ SkyDayPickerCellComponent.prototype.onDayMouseleave = function () {
2870
+ this.cancelPopover = true;
2871
+ if (this.hasTooltip) {
2872
+ this.hideTooltip();
2873
+ }
2874
+ this.datepickerService.keyDatePopoverStream.next(undefined);
2875
+ };
2876
+ SkyDayPickerCellComponent.prototype.onPopoverClosed = function () {
2877
+ this.popoverOpen = false;
2878
+ };
2879
+ SkyDayPickerCellComponent.prototype.onPopoverOpened = function () {
2880
+ this.popoverOpen = true;
2881
+ /* istanbul ignore else */
2882
+ if (this.cancelPopover) {
2883
+ // If the popover gets opened just as a mouseout event happens, close it.
2884
+ this.hideTooltip();
2885
+ this.cancelPopover = false;
2886
+ }
2887
+ };
2888
+ SkyDayPickerCellComponent.prototype.getKeyDateLabel = function () {
2889
+ if (this.hasTooltip) {
2890
+ return this.date.keyDateText.join(', ');
2891
+ }
2892
+ else {
2893
+ return '';
2894
+ }
2895
+ };
2896
+ SkyDayPickerCellComponent.prototype.hideTooltip = function () {
2897
+ /* istanbul ignore else */
2898
+ if (this.popoverOpen) {
2899
+ this.popoverController.next({ type: popovers.SkyPopoverMessageType.Close });
2900
+ }
2901
+ };
2902
+ SkyDayPickerCellComponent.prototype.showTooltip = function () {
2903
+ var _this = this;
2904
+ /* istanbul ignore else */
2905
+ if (this.hasTooltip &&
2906
+ !this.popoverOpen) {
2907
+ /**
2908
+ * Delay 1/2 second before opening the popover as long as mouse hasn't moved off the date.
2909
+ */
2910
+ setTimeout(function () {
2911
+ if (!_this.cancelPopover &&
2912
+ _this.activeUid === _this.date.uid) {
2913
+ _this.popoverController.next({ type: popovers.SkyPopoverMessageType.Open });
2914
+ }
2915
+ }, 500);
2916
+ }
2917
+ };
2918
+ SkyDayPickerCellComponent.ctorParameters = function () { return [
2919
+ { type: SkyDatepickerCalendarInnerComponent },
2920
+ { type: SkyDatepickerService }
2921
+ ]; };
2922
+ __decorate([
2923
+ core.Input()
2924
+ ], SkyDayPickerCellComponent.prototype, "activeDateHasChanged", void 0);
2925
+ __decorate([
2926
+ core.Input()
2927
+ ], SkyDayPickerCellComponent.prototype, "date", void 0);
2928
+ SkyDayPickerCellComponent = __decorate([
2929
+ core.Component({
2930
+ selector: 'sky-daypicker-cell',
2931
+ template: "<div *ngIf=\"hasTooltip\"\n class=\"sky-daypicker-cell\"\n [attr.aria-label]=\"getKeyDateLabel()\"\n [skyPopover]=\"dayInfoPopover\"\n skyPopoverPlacement=\"left\"\n [skyPopoverMessageStream]=\"popoverController\"\n (mouseenter)=\"onDayMouseenter()\"\n (mouseleave)=\"onDayMouseleave()\"\n>\n <ng-container *ngTemplateOutlet=\"daypickerButtonTemplateRef\"></ng-container>\n <sky-popover\n (popoverClosed)=\"onPopoverClosed()\"\n (popoverOpened)=\"onPopoverOpened()\"\n #dayInfoPopover\n >\n <div *ngFor=\"let text of date.keyDateText\">\n {{text}}\n </div>\n </sky-popover>\n</div>\n<div *ngIf=\"!hasTooltip\"\n class=\"sky-daypicker-cell\"\n (mouseenter)=\"onDayMouseenter()\"\n (mouseleave)=\"onDayMouseleave()\"\n>\n <ng-container *ngTemplateOutlet=\"daypickerButtonTemplateRef\"></ng-container>\n</div>\n\n<ng-template #daypickerButtonTemplateRef>\n <sky-daypicker-button\n [date]=\"date\"\n >\n </sky-daypicker-button>\n</ng-template>\n",
2932
+ changeDetection: core.ChangeDetectionStrategy.OnPush
2933
+ })
2934
+ ], SkyDayPickerCellComponent);
2935
+ return SkyDayPickerCellComponent;
2936
+ }());
2937
+
2938
+ /**
2939
+ * @internal
2940
+ */
2941
+ var SkyDayPickerComponent = /** @class */ (function () {
2942
+ function SkyDayPickerComponent(datepicker) {
2943
+ this.calendarDateRangeChange = new core.EventEmitter();
2944
+ this.isWaiting = false;
2945
+ this.labels = [];
2946
+ this.rows = [];
2947
+ this.weekNumbers = [];
2948
+ this.activeDateHasChanged = false;
2949
+ this.daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
2950
+ this.ngUnsubscribe = new rxjs.Subject();
2951
+ this.datepicker = datepicker;
2952
+ }
2953
+ Object.defineProperty(SkyDayPickerComponent.prototype, "customDates", {
2954
+ set: function (value) {
2955
+ /* istanbul ignore else */
2956
+ if (value) {
2957
+ this.applyCustomDates(value, this.rows);
2958
+ }
2711
2959
  },
2712
2960
  enumerable: true,
2713
2961
  configurable: true
2714
2962
  });
2715
- SkyFuzzyDatepickerInputDirective.prototype.ngOnInit = function () {
2963
+ SkyDayPickerComponent.prototype.ngOnInit = function () {
2716
2964
  var _this = this;
2717
- if (this.yearRequired) {
2718
- if (this.dateFormat.toLowerCase().indexOf('y') === -1) {
2719
- throw new Error('You have configured conflicting settings. Year is required and dateFormat does not include year.');
2720
- }
2965
+ this.datepicker.stepDay = { months: 1 };
2966
+ this.initialDate = this.datepicker.activeDate.getDate();
2967
+ this.datepicker.setRefreshViewHandler(function () {
2968
+ _this.refreshDayView();
2969
+ }, 'day');
2970
+ this.datepicker.setCompareHandler(this.compareDays, 'day');
2971
+ this.datepicker.setKeydownHandler(function (key, event) {
2972
+ _this.keydownDays(key, event);
2973
+ }, 'day');
2974
+ this.datepicker.refreshView();
2975
+ };
2976
+ SkyDayPickerComponent.prototype.ngOnDestroy = function () {
2977
+ this.ngUnsubscribe.next();
2978
+ this.ngUnsubscribe.complete();
2979
+ };
2980
+ SkyDayPickerComponent.prototype.getDates = function (startDate, n) {
2981
+ var dates = new Array(n);
2982
+ var current = new Date(startDate.getTime());
2983
+ var i = 0;
2984
+ var date;
2985
+ while (i < n) {
2986
+ date = new Date(current.getTime());
2987
+ date = this.datepicker.fixTimeZone(date);
2988
+ dates[i++] = date;
2989
+ current = new Date(current.getFullYear(), current.getMonth(), current.getDate() + 1);
2721
2990
  }
2722
- if (!this.datepickerComponent) {
2723
- throw new Error('You must wrap the `skyFuzzyDatepickerInput` directive within a ' +
2724
- '`<sky-datepicker>` component!');
2991
+ return dates;
2992
+ };
2993
+ SkyDayPickerComponent.prototype.compareDays = function (date1, date2) {
2994
+ var d1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate());
2995
+ var d2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
2996
+ return d1.getTime() - d2.getTime();
2997
+ };
2998
+ SkyDayPickerComponent.prototype.refreshDayView = function () {
2999
+ var year = this.datepicker.activeDate.getFullYear();
3000
+ var month = this.datepicker.activeDate.getMonth();
3001
+ var firstDayOfMonth = new Date(year, month, 1);
3002
+ var difference = this.datepicker.startingDay - firstDayOfMonth.getDay();
3003
+ var numDisplayedFromPreviousMonth = (difference > 0)
3004
+ ? 7 - difference
3005
+ : -difference;
3006
+ var firstDate = new Date(firstDayOfMonth.getTime());
3007
+ if (this.datepicker.activeDate.getDate() !== this.initialDate) {
3008
+ this.activeDateHasChanged = true;
2725
3009
  }
2726
- var element = this.elementRef.nativeElement;
2727
- this.renderer.addClass(element, 'sky-form-control');
2728
- var hasAriaLabel = element.getAttribute('aria-label');
2729
- if (!hasAriaLabel) {
2730
- this.resourcesService.getString('skyux_date_field_default_label')
2731
- .pipe(operators.takeUntil(this.ngUnsubscribe))
2732
- .subscribe(function (value) {
2733
- _this.renderer.setAttribute(element, 'aria-label', value);
3010
+ /* istanbul ignore else */
3011
+ /* sanity check */
3012
+ if (numDisplayedFromPreviousMonth > 0) {
3013
+ firstDate.setDate(-numDisplayedFromPreviousMonth + 1);
3014
+ }
3015
+ // 42 is the number of days on a six-week calendar
3016
+ var days = this.getDates(firstDate, 42);
3017
+ var pickerDates = [];
3018
+ for (var i = 0; i < 42; i++) {
3019
+ var _dateObject = this.datepicker.createDateObject(days[i], this.datepicker.formatDay, days[i].getMonth() !== month, this.datepicker.datepickerId + '-' + i);
3020
+ pickerDates[i] = _dateObject;
3021
+ }
3022
+ this.labels = [];
3023
+ for (var j = 0; j < 7; j++) {
3024
+ this.labels[j] = {};
3025
+ this.labels[j].abbr =
3026
+ this.datepicker.dateFilter(pickerDates[j].date, this.datepicker.formatDayHeader);
3027
+ this.labels[j].full = this.datepicker.dateFilter(pickerDates[j].date, 'EEEE');
3028
+ }
3029
+ this.title =
3030
+ this.datepicker.dateFilter(this.datepicker.activeDate, this.datepicker.formatDayTitle);
3031
+ var oldDateRange = this.getDateRange(this.rows);
3032
+ this.rows = this.datepicker.createCalendarRows(pickerDates, 7);
3033
+ var newDateRange = this.getDateRange(this.rows);
3034
+ if (!this.dateRangeRowsAreEqual(oldDateRange, newDateRange)) {
3035
+ this.calendarDateRangeChange.next({
3036
+ startDate: newDateRange.startDate,
3037
+ endDate: newDateRange.endDate
2734
3038
  });
2735
3039
  }
2736
3040
  };
2737
- SkyFuzzyDatepickerInputDirective.prototype.ngAfterContentInit = function () {
2738
- var _this = this;
2739
- this.datepickerComponent.dateChange
2740
- .pipe(operators.distinctUntilChanged(), operators.takeUntil(this.ngUnsubscribe))
2741
- .subscribe(function (value) {
2742
- _this.isFirstChange = false;
2743
- _this.value = value;
2744
- _this.onTouched();
2745
- });
3041
+ SkyDayPickerComponent.prototype.keydownDays = function (key, event) {
3042
+ var date = this.datepicker.activeDate.getDate();
3043
+ /* istanbul ignore else */
3044
+ /* sanity check */
3045
+ if (key === 'left') {
3046
+ date = date - 1;
3047
+ }
3048
+ else if (key === 'up') {
3049
+ date = date - 7;
3050
+ }
3051
+ else if (key === 'right') {
3052
+ date = date + 1;
3053
+ }
3054
+ else if (key === 'down') {
3055
+ date = date + 7;
3056
+ }
3057
+ else if (key === 'pageup' || key === 'pagedown') {
3058
+ var month = this.datepicker.activeDate.getMonth() + (key === 'pageup' ? -1 : 1);
3059
+ this.datepicker.activeDate.setMonth(month, 1);
3060
+ date =
3061
+ Math.min(this.getDaysInMonth(this.datepicker.activeDate.getFullYear(), this.datepicker.activeDate.getMonth()), date);
3062
+ }
3063
+ else if (key === 'home') {
3064
+ date = 1;
3065
+ }
3066
+ else if (key === 'end') {
3067
+ date = this.getDaysInMonth(this.datepicker.activeDate.getFullYear(), this.datepicker.activeDate.getMonth());
3068
+ }
3069
+ this.datepicker.activeDate.setDate(date);
2746
3070
  };
2747
- SkyFuzzyDatepickerInputDirective.prototype.ngAfterViewInit = function () {
2748
- // This is needed to address a bug in Angular 4.
2749
- // When a control value is set intially, its value is not represented on the view.
2750
- // See: https://github.com/angular/angular/issues/13792
2751
- // Of note is the parent check which allows us to determine if the form is reactive.
2752
- // Without this check there is a changed before checked error
3071
+ SkyDayPickerComponent.prototype.getDaysInMonth = function (year, month) {
3072
+ return month === 1 && year % 4 === 0 &&
3073
+ (year % 400 === 0 || year % 100 !== 0) ? 29 : this.daysInMonth[month];
3074
+ };
3075
+ /**
3076
+ * Applies custom date properties to the existing dates displayed in the calendar.
3077
+ */
3078
+ SkyDayPickerComponent.prototype.applyCustomDates = function (customDates, dateRows) {
3079
+ var date;
3080
+ var newDate;
3081
+ var dateIndex;
2753
3082
  /* istanbul ignore else */
2754
- var _this = this;
2755
- if (this.control && this.control.parent) {
2756
- setTimeout(function () {
2757
- _this.control.setValue(_this.value, {
2758
- emitEvent: false
3083
+ if (customDates && dateRows) {
3084
+ customDates.forEach(function (customDate) {
3085
+ dateIndex = -1;
3086
+ dateRows.forEach(function (row) {
3087
+ if (dateIndex === -1) {
3088
+ dateIndex = row.findIndex(function (d) {
3089
+ return d.date.getTime() === customDate.date.getTime();
3090
+ });
3091
+ if (dateIndex > -1) {
3092
+ date = row[dateIndex];
3093
+ // Replace the date with a new instance so the display gets updated.
3094
+ newDate = {
3095
+ current: date.current,
3096
+ date: date.date,
3097
+ disabled: !!date.disabled || !!customDate.disabled,
3098
+ keyDate: !!customDate.keyDate || !!date.keyDate,
3099
+ keyDateText: customDate.keyDateText || date.keyDateText,
3100
+ label: date.label,
3101
+ secondary: date.secondary,
3102
+ selected: date.selected,
3103
+ uid: date.uid
3104
+ };
3105
+ row[dateIndex] = newDate;
3106
+ }
3107
+ }
2759
3108
  });
2760
- _this.changeDetector.markForCheck();
2761
3109
  });
2762
3110
  }
2763
3111
  };
2764
- SkyFuzzyDatepickerInputDirective.prototype.ngOnDestroy = function () {
2765
- this.ngUnsubscribe.next();
2766
- this.ngUnsubscribe.complete();
2767
- };
2768
- SkyFuzzyDatepickerInputDirective.prototype.onInputChange = function (event) {
2769
- this.onValueChange(event.target.value);
3112
+ SkyDayPickerComponent.prototype.dateRangeRowsAreEqual = function (rangeA, rangeB) {
3113
+ /* istanbul ignore if */
3114
+ if (!rangeA && !rangeB) {
3115
+ return true;
3116
+ }
3117
+ else if ((rangeA && !rangeB) || (!rangeA && rangeB)) {
3118
+ return false;
3119
+ }
3120
+ return this.compareDays(rangeA.startDate, rangeB.startDate) === 0 &&
3121
+ this.compareDays(rangeA.endDate, rangeB.endDate) === 0;
2770
3122
  };
2771
- SkyFuzzyDatepickerInputDirective.prototype.onInputBlur = function () {
2772
- this.onTouched();
2773
- var formattedDate = this.fuzzyDateService.format(this.value, this.dateFormat, this.locale);
2774
- if (this.control.valid) {
2775
- this.setInputElementValue(formattedDate || '');
3123
+ SkyDayPickerComponent.prototype.getDateRange = function (rows) {
3124
+ if (rows && rows.length > 0) {
3125
+ return {
3126
+ startDate: rows[0][0].date,
3127
+ endDate: rows[rows.length - 1][rows[rows.length - 1].length - 1].date
3128
+ };
2776
3129
  }
2777
3130
  };
2778
- SkyFuzzyDatepickerInputDirective.prototype.onInputKeyup = function () {
2779
- this.control.markAsDirty();
3131
+ SkyDayPickerComponent.ctorParameters = function () { return [
3132
+ { type: SkyDatepickerCalendarInnerComponent }
3133
+ ]; };
3134
+ __decorate([
3135
+ core.Input()
3136
+ ], SkyDayPickerComponent.prototype, "customDates", null);
3137
+ __decorate([
3138
+ core.Output()
3139
+ ], SkyDayPickerComponent.prototype, "calendarDateRangeChange", void 0);
3140
+ __decorate([
3141
+ core.Input()
3142
+ ], SkyDayPickerComponent.prototype, "isWaiting", void 0);
3143
+ SkyDayPickerComponent = __decorate([
3144
+ core.Component({
3145
+ selector: 'sky-daypicker',
3146
+ template: "<div *ngIf=\"datepicker.datepickerMode === 'day'\"\n class=\"sky-daypicker-wrapper\"\n>\n <table\n class=\"sky-daypicker-table\"\n role=\"grid\"\n [attr.aria-labelledby]=\"datepicker.datepickerId+'-title'\"\n [attr.aria-activedescendant]=\"datepicker.activeDateId\"\n >\n <thead>\n <tr>\n <th\n class=\"sky-datepicker-header-left\"\n scope=\"col\"\n >\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-btn-previous\"\n (click)=\"datepicker.moveCalendar($event, -1)\"\n tabindex=\"-1\"\n aria-hidden=\"true\"\n >\n <sky-icon\n class=\"sky-datepicker-chevron-default\"\n icon=\"chevron-left\"\n ></sky-icon>\n <sky-icon\n class=\"sky-datepicker-chevron-modern\"\n icon=\"chevron-left\"\n iconType=\"skyux\"\n ></sky-icon>\n </button>\n </th>\n <th\n scope=\"col\"\n [attr.colspan]=\"5\"\n >\n <button\n [id]=\"datepicker.datepickerId + '-title'\"\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-calendar-title\"\n (click)=\"datepicker.toggleModeCalendar($event)\"\n [disabled]=\"datepicker.datepickerMode === datepicker.maxMode\"\n [ngClass]=\"{'sky-btn-disabled': datepicker.datepickerMode === datepicker.maxMode}\"\n tabindex=\"-1\"\n aria-hidden=\"true\"\n >\n <strong>{{title}}</strong>\n </button>\n </th>\n <th\n class=\"sky-datepicker-header-right\"\n scope=\"col\"\n >\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-btn-next\"\n (click)=\"datepicker.moveCalendar($event, 1)\"\n tabindex=\"-1\"\n aria-hidden=\"true\"\n >\n <sky-icon\n class=\"sky-datepicker-chevron-default\"\n icon=\"chevron-right\"\n ></sky-icon>\n <sky-icon\n class=\"sky-datepicker-chevron-modern\"\n icon=\"chevron-right\"\n iconType=\"skyux\"\n ></sky-icon>\n </button>\n </th>\n </tr>\n <tr>\n <th\n scope=\"col\"\n *ngFor=\"let label of labels\"\n class=\"sky-datepicker-center sky-datepicker-weekdays\">\n <small [attr.aria-label]=\"label.full\">\n <b>{{label.abbr}}</b>\n </small>\n </th>\n </tr>\n </thead>\n <tbody>\n <!-- Wait indicator for async custom date stream -->\n <sky-wait\n [isWaiting]=\"isWaiting\"\n >\n </sky-wait>\n <ng-template\n ngFor\n [ngForOf]=\"rows\"\n let-row=\"$implicit\"\n let-index=\"index\"\n >\n <tr role=\"row\">\n <td *ngFor=\"let date of row\"\n class=\"sky-datepicker-center\"\n role=\"gridcell\"\n [id]=\"date.uid\"\n >\n <sky-daypicker-cell\n [activeDateHasChanged]=\"activeDateHasChanged\"\n [date]=\"date\"\n >\n </sky-daypicker-cell>\n </td>\n </tr>\n </ng-template>\n </tbody>\n </table>\n</div>\n",
3147
+ styles: [":host-context(.sky-theme-modern) :host:focus{outline:0}.sky-theme-modern :host:focus{outline:0}"]
3148
+ })
3149
+ ], SkyDayPickerComponent);
3150
+ return SkyDayPickerComponent;
3151
+ }());
3152
+
3153
+ /**
3154
+ * @internal
3155
+ */
3156
+ var SkyMonthPickerComponent = /** @class */ (function () {
3157
+ function SkyMonthPickerComponent(datepicker) {
3158
+ this.rows = [];
3159
+ this.datepicker = datepicker;
3160
+ }
3161
+ SkyMonthPickerComponent.prototype.ngOnInit = function () {
3162
+ var _this = this;
3163
+ this.datepicker.stepMonth = {
3164
+ years: 1
3165
+ };
3166
+ this.datepicker.setRefreshViewHandler(function () {
3167
+ _this.refreshMonthView();
3168
+ }, 'month');
3169
+ this.datepicker.setCompareHandler(this.compareMonth, 'month');
3170
+ this.datepicker.refreshView();
3171
+ this.datepicker.setKeydownHandler(function (key, event) {
3172
+ _this.keydownMonths(key, event);
3173
+ }, 'month');
2780
3174
  };
2781
- SkyFuzzyDatepickerInputDirective.prototype.writeValue = function (value) {
2782
- this.value = value;
3175
+ SkyMonthPickerComponent.prototype.compareMonth = function (date1, date2) {
3176
+ var d1 = new Date(date1.getFullYear(), date1.getMonth());
3177
+ var d2 = new Date(date2.getFullYear(), date2.getMonth());
3178
+ return d1.getTime() - d2.getTime();
2783
3179
  };
2784
- SkyFuzzyDatepickerInputDirective.prototype.validate = function (control) {
2785
- if (!this.control) {
2786
- this.control = control;
2787
- }
2788
- if (this.skyDatepickerNoValidate) {
2789
- return;
2790
- }
2791
- if (!this.control.value) {
2792
- return;
3180
+ SkyMonthPickerComponent.prototype.refreshMonthView = function () {
3181
+ var months = new Array(12);
3182
+ var year = this.datepicker.activeDate.getFullYear();
3183
+ var date;
3184
+ for (var i = 0; i < 12; i++) {
3185
+ date = new Date(year, i, 1);
3186
+ date = this.datepicker.fixTimeZone(date);
3187
+ months[i] =
3188
+ this.datepicker.createDateObject(date, this.datepicker.formatMonth, false, this.datepicker.datepickerId + '-' + i);
2793
3189
  }
2794
- var value = control.value;
2795
- var fuzzyDate;
2796
- var validationError;
2797
- if (typeof value === 'string') {
2798
- fuzzyDate = this.fuzzyDateService.getFuzzyDateFromString(value, this.dateFormat);
3190
+ this.title =
3191
+ this.datepicker.dateFilter(this.datepicker.activeDate, this.datepicker.formatMonthTitle);
3192
+ this.rows = this.datepicker.createCalendarRows(months, this.datepicker.monthColLimit);
3193
+ };
3194
+ SkyMonthPickerComponent.prototype.keydownMonths = function (key, event) {
3195
+ var date = this.datepicker.activeDate.getMonth();
3196
+ /* istanbul ignore else */
3197
+ /* sanity check */
3198
+ if (key === 'left') {
3199
+ date = date - 1;
2799
3200
  }
2800
- else {
2801
- fuzzyDate = value;
3201
+ else if (key === 'up') {
3202
+ date = date - this.datepicker.monthColLimit;
2802
3203
  }
2803
- if (!fuzzyDate) {
2804
- validationError = {
2805
- 'skyFuzzyDate': {
2806
- invalid: value
2807
- }
2808
- };
3204
+ else if (key === 'right') {
3205
+ date = date + 1;
2809
3206
  }
2810
- if (!validationError && !fuzzyDate.year && this.yearRequired) {
2811
- validationError = {
2812
- 'skyFuzzyDate': {
2813
- yearRequired: value
2814
- }
2815
- };
3207
+ else if (key === 'down') {
3208
+ date = date + this.datepicker.monthColLimit;
2816
3209
  }
2817
- if (!validationError && fuzzyDate.year) {
2818
- var fuzzyDateRange = void 0;
2819
- if (this.maxDate) {
2820
- fuzzyDateRange = this.fuzzyDateService.getFuzzyDateRange(fuzzyDate, this.maxDate);
2821
- if (!fuzzyDateRange.valid) {
2822
- validationError = {
2823
- 'skyFuzzyDate': {
2824
- maxDate: value
2825
- }
2826
- };
2827
- }
2828
- }
2829
- if (!validationError && this.minDate) {
2830
- fuzzyDateRange = this.fuzzyDateService.getFuzzyDateRange(this.minDate, fuzzyDate);
2831
- if (!fuzzyDateRange.valid) {
2832
- validationError = {
2833
- 'skyFuzzyDate': {
2834
- minDate: value
2835
- }
2836
- };
2837
- }
2838
- }
2839
- if (!validationError && this.futureDisabled) {
2840
- fuzzyDateRange = this.fuzzyDateService.getFuzzyDateRange(fuzzyDate, this.fuzzyDateService.getCurrentFuzzyDate());
2841
- if (!fuzzyDateRange.valid) {
2842
- validationError = {
2843
- 'skyFuzzyDate': {
2844
- futureDisabled: value
2845
- }
2846
- };
2847
- }
2848
- }
3210
+ else if (key === 'pageup' || key === 'pagedown') {
3211
+ var year = this.datepicker.activeDate.getFullYear() + (key === 'pageup' ? -1 : 1);
3212
+ this.datepicker.activeDate.setFullYear(year);
2849
3213
  }
2850
- if (validationError) {
2851
- // Mark the invalid control as touched so that the input's invalid CSS styles appear.
2852
- // (This is only required when the invalid value is set by the FormControl constructor.)
2853
- this.control.markAsTouched();
3214
+ else if (key === 'home') {
3215
+ date = 0;
2854
3216
  }
2855
- return validationError;
2856
- };
2857
- SkyFuzzyDatepickerInputDirective.prototype.registerOnChange = function (fn) {
2858
- this.onChange = fn;
2859
- };
2860
- SkyFuzzyDatepickerInputDirective.prototype.registerOnTouched = function (fn) {
2861
- this.onTouched = fn;
2862
- };
2863
- SkyFuzzyDatepickerInputDirective.prototype.registerOnValidatorChange = function (fn) {
2864
- this.onValidatorChange = fn;
3217
+ else if (key === 'end') {
3218
+ date = 11;
3219
+ }
3220
+ this.datepicker.activeDate.setMonth(date);
2865
3221
  };
2866
- SkyFuzzyDatepickerInputDirective.prototype.setDisabledState = function (disabled) {
2867
- this.disabled = disabled;
2868
- this.datepickerComponent.disabled = disabled;
3222
+ SkyMonthPickerComponent.ctorParameters = function () { return [
3223
+ { type: SkyDatepickerCalendarInnerComponent }
3224
+ ]; };
3225
+ SkyMonthPickerComponent = __decorate([
3226
+ core.Component({
3227
+ selector: 'sky-monthpicker',
3228
+ template: "<table *ngIf=\"datepicker.datepickerMode==='month'\" role=\"grid\">\n <thead>\n <tr>\n <th\n class=\"sky-datepicker-header-left\"\n >\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-btn-previous\"\n (click)=\"datepicker.moveCalendar($event, -1)\"\n tabindex=\"-1\"\n >\n <sky-icon\n class=\"sky-datepicker-chevron-default\"\n icon=\"chevron-left\"\n ></sky-icon>\n <sky-icon\n class=\"sky-datepicker-chevron-modern\"\n icon=\"chevron-left\"\n iconType=\"skyux\"\n ></sky-icon>\n </button></th>\n <th [attr.colspan]=\"((datepicker.monthColLimit - 2) <= 0) ? 1 : datepicker.monthColLimit - 2\">\n <button\n [id]=\"datepicker.datepickerId + '-title'\"\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-calendar-title\"\n (click)=\"datepicker.toggleModeCalendar($event)\"\n [disabled]=\"datepicker.datepickerMode === maxMode\"\n [ngClass]=\"{'sky-btn-disabled': datepicker.datepickerMode === maxMode}\"\n tabindex=\"-1\"\n >\n <strong>{{title}}</strong>\n </button>\n </th>\n <th\n class=\"sky-datepicker-header-right\"\n >\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-btn-next\"\n (click)=\"datepicker.moveCalendar($event, 1)\"\n tabindex=\"-1\"\n >\n <sky-icon\n class=\"sky-datepicker-chevron-default\"\n icon=\"chevron-right\"\n ></sky-icon>\n <sky-icon\n class=\"sky-datepicker-chevron-modern\"\n icon=\"chevron-right\"\n iconType=\"skyux\"\n ></sky-icon>\n </button>\n </th>\n </tr>\n </thead>\n <tbody>\n <tr *ngFor=\"let row of rows\">\n <td\n *ngFor=\"let date of row\"\n class=\"text-center\"\n role=\"gridcell\"\n id=\"{{date.uid}}\">\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-datepicker-btn-date\"\n [ngClass]=\"{'sky-datepicker-btn-selected': date.selected, 'sky-btn-disabled': date.disabled, 'sky-btn-active': datepicker.isActive(date)}\"\n [disabled]=\"date.disabled\"\n (click)=\"datepicker.selectCalendar($event, date.date)\"\n tabindex=\"-1\"\n >\n <span [ngClass]=\"{'sky-datepicker-current': date.current}\">{{date.label}}</span>\n </button>\n </td>\n </tr>\n </tbody>\n</table>\n",
3229
+ styles: [":host-context(.sky-theme-modern) :host:focus{outline:0}.sky-theme-modern :host:focus{outline:0}"]
3230
+ })
3231
+ ], SkyMonthPickerComponent);
3232
+ return SkyMonthPickerComponent;
3233
+ }());
3234
+
3235
+ /**
3236
+ * @internal
3237
+ */
3238
+ var SkyYearPickerComponent = /** @class */ (function () {
3239
+ function SkyYearPickerComponent(datepicker) {
3240
+ this.rows = [];
3241
+ this.datepicker = datepicker;
3242
+ }
3243
+ SkyYearPickerComponent.prototype.ngOnInit = function () {
3244
+ var _this = this;
3245
+ this.datepicker.stepYear = { years: this.datepicker.yearRange };
3246
+ this.datepicker.setRefreshViewHandler(function () {
3247
+ _this.refreshYearView();
3248
+ }, 'year');
3249
+ this.datepicker.setCompareHandler(this.compareYears, 'year');
3250
+ this.datepicker.setKeydownHandler(function (key, event) {
3251
+ _this.keydownYears(key, event);
3252
+ }, 'year');
3253
+ this.datepicker.refreshView();
2869
3254
  };
2870
- /**
2871
- * Detects changes to the underlying input element's value and updates the ngModel accordingly.
2872
- * This is useful if you need to update the ngModel value before the input element loses focus.
2873
- */
2874
- SkyFuzzyDatepickerInputDirective.prototype.detectInputValueChange = function () {
2875
- this.onValueChange(this.elementRef.nativeElement.value);
3255
+ SkyYearPickerComponent.prototype.getStartingYear = function (year) {
3256
+ return Math.floor((year - 1) / this.datepicker.yearRange) * this.datepicker.yearRange + 1;
2876
3257
  };
2877
- SkyFuzzyDatepickerInputDirective.prototype.onValueChange = function (newValue) {
2878
- this.isFirstChange = false;
2879
- this.value = newValue;
3258
+ SkyYearPickerComponent.prototype.compareYears = function (date1, date2) {
3259
+ return date1.getFullYear() - date2.getFullYear();
2880
3260
  };
2881
- SkyFuzzyDatepickerInputDirective.prototype.setInputElementValue = function (value) {
2882
- this.renderer.setProperty(this.elementRef.nativeElement, 'value', value);
3261
+ SkyYearPickerComponent.prototype.refreshYearView = function () {
3262
+ var years = new Array(this.datepicker.yearRange);
3263
+ var date;
3264
+ var start = this.getStartingYear(this.datepicker.activeDate.getFullYear());
3265
+ for (var i = 0; i < this.datepicker.yearRange; i++) {
3266
+ date = new Date(this.datepicker.activeDate);
3267
+ date.setFullYear(start + i, 0, 1);
3268
+ years[i] =
3269
+ this.datepicker.createDateObject(date, this.datepicker.formatYear, false, this.datepicker.datepickerId + '-' + i);
3270
+ }
3271
+ this.title = [years[0].label,
3272
+ years[this.datepicker.yearRange - 1].label].join(' - ');
3273
+ this.rows = this.datepicker.createCalendarRows(years, this.datepicker.yearColLimit);
2883
3274
  };
2884
- SkyFuzzyDatepickerInputDirective.prototype.getMaxDate = function () {
2885
- if (this.maxDate) {
2886
- var maxDate = this.fuzzyDateService.getMomentFromFuzzyDate(this.maxDate);
2887
- if (maxDate.isValid()) {
2888
- return maxDate.toDate();
2889
- }
3275
+ SkyYearPickerComponent.prototype.keydownYears = function (key, event) {
3276
+ var date = this.datepicker.activeDate.getFullYear();
3277
+ /* istanbul ignore else */
3278
+ /* sanity check */
3279
+ if (key === 'left') {
3280
+ date = date - 1;
2890
3281
  }
2891
- else if (this.futureDisabled) {
2892
- return new Date();
3282
+ else if (key === 'up') {
3283
+ date = date - this.datepicker.yearColLimit;
2893
3284
  }
2894
- return this.configService.maxDate;
2895
- };
2896
- SkyFuzzyDatepickerInputDirective.prototype.getMinDate = function () {
2897
- if (this.minDate) {
2898
- var minDate = this.fuzzyDateService.getMomentFromFuzzyDate(this.minDate);
2899
- if (minDate.isValid()) {
2900
- return minDate.toDate();
2901
- }
3285
+ else if (key === 'right') {
3286
+ date = date + 1;
2902
3287
  }
2903
- return this.configService.minDate;
2904
- };
2905
- SkyFuzzyDatepickerInputDirective.prototype.fuzzyDatesEqual = function (dateA, dateB) {
2906
- return dateA && dateB
2907
- && ((!dateA.day && !dateB.day)
2908
- || dateA.day === dateB.day)
2909
- && ((!dateA.month && !dateB.month)
2910
- || dateA.month === dateB.month)
2911
- && ((!dateA.year && !dateB.year)
2912
- || dateA.year === dateB.year);
3288
+ else if (key === 'down') {
3289
+ date = date + this.datepicker.yearColLimit;
3290
+ }
3291
+ else if (key === 'pageup' || key === 'pagedown') {
3292
+ date += (key === 'pageup' ? -1 : 1) * this.datepicker.yearRange;
3293
+ }
3294
+ else if (key === 'home') {
3295
+ date = this.getStartingYear(this.datepicker.activeDate.getFullYear());
3296
+ }
3297
+ else if (key === 'end') {
3298
+ date
3299
+ = this.getStartingYear(this.datepicker.activeDate.getFullYear()) + this.datepicker.yearRange - 1;
3300
+ }
3301
+ this.datepicker.activeDate.setFullYear(date);
2913
3302
  };
2914
- SkyFuzzyDatepickerInputDirective.ctorParameters = function () { return [
2915
- { type: core.ChangeDetectorRef },
2916
- { type: SkyDatepickerConfigService },
2917
- { type: core.ElementRef },
2918
- { type: SkyFuzzyDateService },
2919
- { type: i18n.SkyAppLocaleProvider },
2920
- { type: core.Renderer2 },
2921
- { type: i18n.SkyLibResourcesService },
2922
- { type: SkyDatepickerComponent, decorators: [{ type: core.Optional }] }
3303
+ SkyYearPickerComponent.ctorParameters = function () { return [
3304
+ { type: SkyDatepickerCalendarInnerComponent }
2923
3305
  ]; };
2924
- __decorate([
2925
- core.Input()
2926
- ], SkyFuzzyDatepickerInputDirective.prototype, "dateFormat", null);
2927
- __decorate([
2928
- core.Input()
2929
- ], SkyFuzzyDatepickerInputDirective.prototype, "disabled", null);
2930
- __decorate([
2931
- core.Input()
2932
- ], SkyFuzzyDatepickerInputDirective.prototype, "futureDisabled", null);
2933
- __decorate([
2934
- core.Input()
2935
- ], SkyFuzzyDatepickerInputDirective.prototype, "maxDate", null);
2936
- __decorate([
2937
- core.Input()
2938
- ], SkyFuzzyDatepickerInputDirective.prototype, "minDate", null);
2939
- __decorate([
2940
- core.Input()
2941
- ], SkyFuzzyDatepickerInputDirective.prototype, "skyDatepickerNoValidate", void 0);
2942
- __decorate([
2943
- core.Input()
2944
- ], SkyFuzzyDatepickerInputDirective.prototype, "skyFuzzyDatepickerInput", null);
2945
- __decorate([
2946
- core.Input()
2947
- ], SkyFuzzyDatepickerInputDirective.prototype, "startingDay", null);
2948
- __decorate([
2949
- core.Input()
2950
- ], SkyFuzzyDatepickerInputDirective.prototype, "yearRequired", null);
2951
- __decorate([
2952
- core.HostListener('change', ['$event'])
2953
- ], SkyFuzzyDatepickerInputDirective.prototype, "onInputChange", null);
2954
- __decorate([
2955
- core.HostListener('blur')
2956
- ], SkyFuzzyDatepickerInputDirective.prototype, "onInputBlur", null);
2957
- __decorate([
2958
- core.HostListener('keyup')
2959
- ], SkyFuzzyDatepickerInputDirective.prototype, "onInputKeyup", null);
2960
- SkyFuzzyDatepickerInputDirective = __decorate([
2961
- core.Directive({
2962
- selector: '[skyFuzzyDatepickerInput]',
2963
- providers: [
2964
- SKY_FUZZY_DATEPICKER_VALUE_ACCESSOR,
2965
- SKY_FUZZY_DATEPICKER_VALIDATOR
2966
- ]
2967
- }),
2968
- __param(7, core.Optional())
2969
- ], SkyFuzzyDatepickerInputDirective);
2970
- return SkyFuzzyDatepickerInputDirective;
3306
+ SkyYearPickerComponent = __decorate([
3307
+ core.Component({
3308
+ selector: 'sky-yearpicker',
3309
+ template: "<table *ngIf=\"datepicker.datepickerMode==='year'\" role=\"grid\">\n <thead>\n <tr>\n <th\n class=\"sky-datepicker-header-left\"\n >\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-btn-previous\"\n (click)=\"datepicker.moveCalendar($event, -1)\"\n tabindex=\"-1\"\n >\n <sky-icon\n class=\"sky-datepicker-chevron-default\"\n icon=\"chevron-left\"\n ></sky-icon>\n <sky-icon\n class=\"sky-datepicker-chevron-modern\"\n icon=\"chevron-left\"\n iconType=\"skyux\"\n ></sky-icon>\n </button>\n </th>\n <th [attr.colspan]=\"((datepicker.yearColLimit - 2) <= 0) ? 1 : datepicker.yearColLimit - 2\">\n <button\n [id]=\"datepicker.datepickerId + '-title'\"\n role=\"heading\"\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-calendar-title\"\n (click)=\"datepicker.toggleModeCalendar($event)\"\n [disabled]=\"datepicker.datepickerMode === datepicker.maxMode\"\n [ngClass]=\"{'sky-btn-disabled': datepicker.datepickerMode === datepicker.maxMode}\"\n tabindex=\"-1\"\n >\n <strong>{{title}}</strong>\n </button>\n </th>\n <th\n class=\"sky-datepicker-header-right\"\n >\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-btn-sm sky-datepicker-btn-next\"\n (click)=\"datepicker.moveCalendar($event, 1)\"\n tabindex=\"-1\"\n >\n <sky-icon\n class=\"sky-datepicker-chevron-default\"\n icon=\"chevron-right\"\n ></sky-icon>\n <sky-icon\n class=\"sky-datepicker-chevron-modern\"\n icon=\"chevron-right\"\n iconType=\"skyux\"\n ></sky-icon>\n </button>\n </th>\n </tr>\n </thead>\n <tbody>\n <tr *ngFor=\"let row of rows\">\n <td\n *ngFor=\"let date of row\"\n class=\"sky-datepicker-row\"\n role=\"gridcell\"\n >\n <button\n type=\"button\"\n class=\"sky-btn sky-btn-default sky-datepicker-btn-date\"\n [ngClass]=\"{'sky-datepicker-btn-selected': date.selected, 'sky-btn-disabled': date.disabled, 'sky-btn-active': datepicker.isActive(date)}\"\n [disabled]=\"date.disabled\"\n (click)=\"datepicker.selectCalendar($event, date.date)\"\n tabindex=\"-1\"\n >\n <span\n [ngClass]=\"{'sky-datepicker-current': date.current }\">{{date.label}}</span>\n </button>\n </td>\n </tr>\n </tbody>\n</table>\n",
3310
+ styles: [":host-context(.sky-theme-modern) :host:focus{outline:0}.sky-theme-modern :host:focus{outline:0}"]
3311
+ })
3312
+ ], SkyYearPickerComponent);
3313
+ return SkyYearPickerComponent;
2971
3314
  }());
2972
3315
 
2973
3316
  var SkyDatepickerModule = /** @class */ (function () {
@@ -2983,7 +3326,9 @@
2983
3326
  SkyYearPickerComponent,
2984
3327
  SkyDatepickerComponent,
2985
3328
  SkyDatepickerInputDirective,
2986
- SkyFuzzyDatepickerInputDirective
3329
+ SkyFuzzyDatepickerInputDirective,
3330
+ SkyDayPickerCellComponent,
3331
+ SkyDayPickerButtonComponent
2987
3332
  ],
2988
3333
  imports: [
2989
3334
  common.CommonModule,
@@ -2993,7 +3338,9 @@
2993
3338
  SkyDateTimeResourcesModule,
2994
3339
  core$1.SkyAffixModule,
2995
3340
  core$1.SkyOverlayModule,
2996
- theme.SkyThemeModule
3341
+ theme.SkyThemeModule,
3342
+ popovers.SkyPopoverModule,
3343
+ indicators.SkyWaitModule
2997
3344
  ],
2998
3345
  exports: [
2999
3346
  SkyDatepickerCalendarComponent,
@@ -3003,14 +3350,17 @@
3003
3350
  SkyYearPickerComponent,
3004
3351
  SkyDatepickerComponent,
3005
3352
  SkyDatepickerInputDirective,
3006
- SkyFuzzyDatepickerInputDirective
3353
+ SkyFuzzyDatepickerInputDirective,
3354
+ SkyDayPickerCellComponent,
3355
+ SkyDayPickerButtonComponent
3007
3356
  ],
3008
3357
  providers: [
3009
3358
  core$1.SkyAppWindowRef,
3010
3359
  SkyDatepickerConfigService,
3011
3360
  SkyFuzzyDateService,
3012
3361
  core$1.SkyCoreAdapterService,
3013
- theme.SkyThemeService
3362
+ theme.SkyThemeService,
3363
+ SkyDatepickerService
3014
3364
  ]
3015
3365
  })
3016
3366
  ], SkyDatepickerModule);
@@ -4855,8 +5205,11 @@
4855
5205
  exports.ɵj = SkyDatepickerComponent;
4856
5206
  exports.ɵk = SkyDatepickerInputDirective;
4857
5207
  exports.ɵl = SkyFuzzyDatepickerInputDirective;
4858
- exports.ɵm = SkyTimepickerInputDirective;
4859
- exports.ɵn = SkyTimepickerComponent;
5208
+ exports.ɵm = SkyDayPickerCellComponent;
5209
+ exports.ɵn = SkyDatepickerService;
5210
+ exports.ɵo = SkyDayPickerButtonComponent;
5211
+ exports.ɵp = SkyTimepickerInputDirective;
5212
+ exports.ɵq = SkyTimepickerComponent;
4860
5213
 
4861
5214
  Object.defineProperty(exports, '__esModule', { value: true });
4862
5215