@taiga-ui/kit
Version:
Taiga UI Angular main components kit
162 lines (157 loc) • 7.82 kB
JavaScript
import { __decorate, __param } from 'tslib';
import { EventEmitter, Inject, Optional, ChangeDetectorRef, Input, Output, Component, ChangeDetectionStrategy, NgModule } from '@angular/core';
import { ALWAYS_FALSE_HANDLER, TuiMonth, TUI_FIRST_DAY, TUI_LAST_DAY, watch, TuiDestroyService, tuiDefaultProp, TuiMapperPipeModule } from '@taiga-ui/cdk';
import { TUI_DEFAULT_MARKER_HANDLER, TuiScrollbarModule, TuiCalendarModule } from '@taiga-ui/core';
import { TUI_CALENDAR_DATA_STREAM } from '@taiga-ui/kit/tokens';
import { Observable } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
/**
* @internal
*/
var TuiPrimitiveCalendarRangeComponent = /** @class */ (function () {
function TuiPrimitiveCalendarRangeComponent(valueChanges, changeDetectorRef, destroy$) {
var _this = this;
this.disabledItemHandler = ALWAYS_FALSE_HANDLER;
this.markerHandler = TUI_DEFAULT_MARKER_HANDLER;
this.defaultViewedMonthFirst = TuiMonth.currentLocal();
this.defaultViewedMonthSecond = TuiMonth.currentLocal().append({ month: 1 });
this.min = TUI_FIRST_DAY;
this.max = TUI_LAST_DAY;
this.value = null;
this.dayClick = new EventEmitter();
this.hoveredItem = null;
this.monthOffset = function (value, offset) {
return value.append({ month: offset });
};
this.userViewedMonthFirst = this.defaultViewedMonthFirst;
this.userViewedMonthSecond = this.defaultViewedMonthSecond;
if (!valueChanges) {
return;
}
valueChanges
.pipe(watch(changeDetectorRef), takeUntil(destroy$))
.subscribe(function (value) {
_this.value = value;
_this.updateViewedMonths();
});
}
Object.defineProperty(TuiPrimitiveCalendarRangeComponent.prototype, "cappedUserViewedMonthSecond", {
get: function () {
return this.userViewedMonthSecond.monthBefore(this.max)
? this.userViewedMonthSecond
: this.max;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TuiPrimitiveCalendarRangeComponent.prototype, "cappedUserViewedMonthFirst", {
get: function () {
return this.userViewedMonthFirst.monthSameOrBefore(this.userViewedMonthSecond)
? this.userViewedMonthFirst
: this.userViewedMonthSecond;
},
enumerable: true,
configurable: true
});
TuiPrimitiveCalendarRangeComponent.prototype.ngOnInit = function () {
this.updateViewedMonths();
};
TuiPrimitiveCalendarRangeComponent.prototype.onSectionFirstViewedMonth = function (month) {
this.userViewedMonthFirst = month;
if (this.userViewedMonthSecond.year < this.userViewedMonthFirst.year) {
this.userViewedMonthSecond = this.userViewedMonthSecond.append({
year: month.year - this.userViewedMonthSecond.year,
});
}
};
TuiPrimitiveCalendarRangeComponent.prototype.onSectionSecondViewedMonth = function (month) {
this.userViewedMonthSecond = month;
if (this.userViewedMonthFirst.year > this.userViewedMonthSecond.year) {
this.userViewedMonthFirst = this.userViewedMonthFirst.append({
year: month.year - this.userViewedMonthFirst.year,
});
}
};
TuiPrimitiveCalendarRangeComponent.prototype.onDayClick = function (day) {
this.dayClick.emit(day);
};
TuiPrimitiveCalendarRangeComponent.prototype.updateViewedMonths = function () {
this.userViewedMonthFirst =
this.value === null ? this.defaultViewedMonthFirst : this.value.from;
this.userViewedMonthSecond =
this.value === null ? this.defaultViewedMonthSecond : this.value.to;
if (this.userViewedMonthFirst.monthSame(this.userViewedMonthSecond)) {
this.userViewedMonthSecond = this.userViewedMonthSecond.append({ month: 1 });
}
};
TuiPrimitiveCalendarRangeComponent.ctorParameters = function () { return [
{ type: Observable, decorators: [{ type: Inject, args: [TUI_CALENDAR_DATA_STREAM,] }, { type: Optional }] },
{ type: ChangeDetectorRef, decorators: [{ type: Inject, args: [ChangeDetectorRef,] }] },
{ type: TuiDestroyService, decorators: [{ type: Inject, args: [TuiDestroyService,] }] }
]; };
__decorate([
Input(),
tuiDefaultProp()
], TuiPrimitiveCalendarRangeComponent.prototype, "disabledItemHandler", void 0);
__decorate([
Input(),
tuiDefaultProp()
], TuiPrimitiveCalendarRangeComponent.prototype, "markerHandler", void 0);
__decorate([
Input(),
tuiDefaultProp()
], TuiPrimitiveCalendarRangeComponent.prototype, "defaultViewedMonthFirst", void 0);
__decorate([
Input(),
tuiDefaultProp()
], TuiPrimitiveCalendarRangeComponent.prototype, "defaultViewedMonthSecond", void 0);
__decorate([
Input(),
tuiDefaultProp()
], TuiPrimitiveCalendarRangeComponent.prototype, "min", void 0);
__decorate([
Input(),
tuiDefaultProp()
], TuiPrimitiveCalendarRangeComponent.prototype, "max", void 0);
__decorate([
Input(),
tuiDefaultProp()
], TuiPrimitiveCalendarRangeComponent.prototype, "value", void 0);
__decorate([
Output()
], TuiPrimitiveCalendarRangeComponent.prototype, "dayClick", void 0);
TuiPrimitiveCalendarRangeComponent = __decorate([
Component({
selector: 'tui-primitive-calendar-range',
template: "<tui-calendar\n [min]=\"min\"\n [max]=\"max\"\n [month]=\"userViewedMonthFirst\"\n [markerHandler]=\"markerHandler\"\n [maxViewedMonth]=\"cappedUserViewedMonthSecond | tuiMapper: monthOffset: -1\"\n [value]=\"value\"\n [disabledItemHandler]=\"disabledItemHandler\"\n [showAdjacent]=\"false\"\n [(hoveredItem)]=\"hoveredItem\"\n (dayClick)=\"onDayClick($event)\"\n (monthChange)=\"onSectionFirstViewedMonth($event)\"\n></tui-calendar>\n<tui-calendar\n class=\"border\"\n [min]=\"min\"\n [max]=\"max\"\n [month]=\"userViewedMonthSecond\"\n [markerHandler]=\"markerHandler\"\n [minViewedMonth]=\"cappedUserViewedMonthFirst | tuiMapper: monthOffset: 1\"\n [value]=\"value\"\n [disabledItemHandler]=\"disabledItemHandler\"\n [showAdjacent]=\"false\"\n [(hoveredItem)]=\"hoveredItem\"\n (dayClick)=\"onDayClick($event)\"\n (monthChange)=\"onSectionSecondViewedMonth($event)\"\n></tui-calendar>\n",
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [TuiDestroyService],
styles: [":host{display:flex}.border{border-left:1px solid var(--tui-base-03)}"]
}),
__param(0, Inject(TUI_CALENDAR_DATA_STREAM)),
__param(0, Optional()),
__param(1, Inject(ChangeDetectorRef)),
__param(2, Inject(TuiDestroyService))
], TuiPrimitiveCalendarRangeComponent);
return TuiPrimitiveCalendarRangeComponent;
}());
/**
* @internal
*/
var TuiPrimitiveCalendarRangeModule = /** @class */ (function () {
function TuiPrimitiveCalendarRangeModule() {
}
TuiPrimitiveCalendarRangeModule = __decorate([
NgModule({
imports: [TuiMapperPipeModule, TuiScrollbarModule, TuiCalendarModule],
declarations: [TuiPrimitiveCalendarRangeComponent],
exports: [TuiPrimitiveCalendarRangeComponent],
})
], TuiPrimitiveCalendarRangeModule);
return TuiPrimitiveCalendarRangeModule;
}());
/**
* Generated bundle index. Do not edit.
*/
export { TuiPrimitiveCalendarRangeComponent, TuiPrimitiveCalendarRangeModule };
//# sourceMappingURL=taiga-ui-kit-internal-primitive-calendar-range.js.map