@taiga-ui/kit
Version:
Taiga UI Angular main components kit
147 lines (142 loc) • 6.72 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
*/
let TuiPrimitiveCalendarRangeComponent = class TuiPrimitiveCalendarRangeComponent {
constructor(valueChanges, changeDetectorRef, destroy$) {
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 = (value, offset) => value.append({ month: offset });
this.userViewedMonthFirst = this.defaultViewedMonthFirst;
this.userViewedMonthSecond = this.defaultViewedMonthSecond;
if (!valueChanges) {
return;
}
valueChanges
.pipe(watch(changeDetectorRef), takeUntil(destroy$))
.subscribe(value => {
this.value = value;
this.updateViewedMonths();
});
}
get cappedUserViewedMonthSecond() {
return this.userViewedMonthSecond.monthBefore(this.max)
? this.userViewedMonthSecond
: this.max;
}
get cappedUserViewedMonthFirst() {
return this.userViewedMonthFirst.monthSameOrBefore(this.userViewedMonthSecond)
? this.userViewedMonthFirst
: this.userViewedMonthSecond;
}
ngOnInit() {
this.updateViewedMonths();
}
onSectionFirstViewedMonth(month) {
this.userViewedMonthFirst = month;
if (this.userViewedMonthSecond.year < this.userViewedMonthFirst.year) {
this.userViewedMonthSecond = this.userViewedMonthSecond.append({
year: month.year - this.userViewedMonthSecond.year,
});
}
}
onSectionSecondViewedMonth(month) {
this.userViewedMonthSecond = month;
if (this.userViewedMonthFirst.year > this.userViewedMonthSecond.year) {
this.userViewedMonthFirst = this.userViewedMonthFirst.append({
year: month.year - this.userViewedMonthFirst.year,
});
}
}
onDayClick(day) {
this.dayClick.emit(day);
}
updateViewedMonths() {
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 = () => [
{ 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);
/**
* @internal
*/
let TuiPrimitiveCalendarRangeModule = class TuiPrimitiveCalendarRangeModule {
};
TuiPrimitiveCalendarRangeModule = __decorate([
NgModule({
imports: [TuiMapperPipeModule, TuiScrollbarModule, TuiCalendarModule],
declarations: [TuiPrimitiveCalendarRangeComponent],
exports: [TuiPrimitiveCalendarRangeComponent],
})
], TuiPrimitiveCalendarRangeModule);
/**
* Generated bundle index. Do not edit.
*/
export { TuiPrimitiveCalendarRangeComponent, TuiPrimitiveCalendarRangeModule };
//# sourceMappingURL=taiga-ui-kit-internal-primitive-calendar-range.js.map