UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

374 lines (362 loc) 13.5 kB
import { Directionality, BidiModule } from '@angular/cdk/bidi'; import { CommonModule } from '@angular/common'; import { Directive, EventEmitter, Component, ViewEncapsulation, ChangeDetectionStrategy, ElementRef, Input, Output, forwardRef, ChangeDetectorRef, Optional, ContentChild, TemplateRef, NgModule } from '@angular/core'; import { NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms'; import { LibPackerModule } from 'ng-zorro-antd/date-picker'; import { NzI18nService, DateHelperService, NzI18nModule } from 'ng-zorro-antd/i18n'; import { NzRadioModule } from 'ng-zorro-antd/radio'; import { NzSelectModule } from 'ng-zorro-antd/select'; import { CandyDate } from 'ng-zorro-antd/core/time'; import { __decorate, __metadata } from 'tslib'; import { InputBoolean } from 'ng-zorro-antd/core/util'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; /** * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ class NzDateCellDirective { } NzDateCellDirective.decorators = [ { type: Directive, args: [{ selector: '[nzDateCell]', exportAs: 'nzDateCell' },] } ]; class NzMonthCellDirective { } NzMonthCellDirective.decorators = [ { type: Directive, args: [{ selector: '[nzMonthCell]', exportAs: 'nzMonthCell' },] } ]; class NzDateFullCellDirective { } NzDateFullCellDirective.decorators = [ { type: Directive, args: [{ selector: '[nzDateFullCell]', exportAs: 'nzDateFullCell' },] } ]; class NzMonthFullCellDirective { } NzMonthFullCellDirective.decorators = [ { type: Directive, args: [{ selector: '[nzMonthFullCell]', exportAs: 'nzMonthFullCell' },] } ]; /** * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ class NzCalendarHeaderComponent { constructor(i18n, dateHelper, elementRef) { this.i18n = i18n; this.dateHelper = dateHelper; this.elementRef = elementRef; this.mode = 'month'; this.fullscreen = true; this.activeDate = new CandyDate(); this.modeChange = new EventEmitter(); this.yearChange = new EventEmitter(); this.monthChange = new EventEmitter(); // @Output() readonly valueChange: EventEmitter<CandyDate> = new EventEmitter(); this.yearOffset = 10; this.yearTotal = 20; this.years = []; this.months = []; // TODO: move to host after View Engine deprecation this.elementRef.nativeElement.classList.add('ant-fullcalendar-header'); } get activeYear() { return this.activeDate.getYear(); } get activeMonth() { return this.activeDate.getMonth(); } get size() { return this.fullscreen ? 'default' : 'small'; } get yearTypeText() { return this.i18n.getLocale().Calendar.lang.year; } get monthTypeText() { return this.i18n.getLocale().Calendar.lang.month; } ngOnInit() { this.setUpYears(); this.setUpMonths(); } updateYear(year) { this.yearChange.emit(year); this.setUpYears(year); } setUpYears(year) { const start = (year || this.activeYear) - this.yearOffset; const end = start + this.yearTotal; this.years = []; for (let i = start; i < end; i++) { this.years.push({ label: `${i}`, value: i }); } } setUpMonths() { this.months = []; for (let i = 0; i < 12; i++) { const dateInMonth = this.activeDate.setMonth(i); const monthText = this.dateHelper.format(dateInMonth.nativeDate, 'MMM'); this.months.push({ label: monthText, value: i }); } } } NzCalendarHeaderComponent.decorators = [ { type: Component, args: [{ encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, selector: 'nz-calendar-header', exportAs: 'nzCalendarHeader', template: ` <div class="ant-picker-calendar-header"> <nz-select class="ant-picker-calendar-year-select" [nzSize]="size" [nzDropdownMatchSelectWidth]="false" [ngModel]="activeYear" (ngModelChange)="updateYear($event)" > <nz-option *ngFor="let year of years" [nzLabel]="year.label" [nzValue]="year.value"></nz-option> </nz-select> <nz-select *ngIf="mode === 'month'" class="ant-picker-calendar-month-select" [nzSize]="size" [nzDropdownMatchSelectWidth]="false" [ngModel]="activeMonth" (ngModelChange)="monthChange.emit($event)" > <nz-option *ngFor="let month of months" [nzLabel]="month.label" [nzValue]="month.value"></nz-option> </nz-select> <nz-radio-group class="ant-picker-calendar-mode-switch" [(ngModel)]="mode" (ngModelChange)="modeChange.emit($event)" [nzSize]="size"> <label nz-radio-button nzValue="month">{{ monthTypeText }}</label> <label nz-radio-button nzValue="year">{{ yearTypeText }}</label> </nz-radio-group> </div> `, host: { '[style.display]': `'block'` } },] } ]; NzCalendarHeaderComponent.ctorParameters = () => [ { type: NzI18nService }, { type: DateHelperService }, { type: ElementRef } ]; NzCalendarHeaderComponent.propDecorators = { mode: [{ type: Input }], fullscreen: [{ type: Input }], activeDate: [{ type: Input }], modeChange: [{ type: Output }], yearChange: [{ type: Output }], monthChange: [{ type: Output }] }; /** * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ class NzCalendarComponent { constructor(cdr, elementRef, directionality) { this.cdr = cdr; this.elementRef = elementRef; this.directionality = directionality; this.activeDate = new CandyDate(); this.prefixCls = 'ant-picker-calendar'; this.destroy$ = new Subject(); this.dir = 'ltr'; this.onChangeFn = () => { }; this.onTouchFn = () => { }; this.nzMode = 'month'; this.nzModeChange = new EventEmitter(); this.nzPanelChange = new EventEmitter(); this.nzSelectChange = new EventEmitter(); this.nzValueChange = new EventEmitter(); this.nzFullscreen = true; // TODO: move to host after View Engine deprecation this.elementRef.nativeElement.classList.add('ant-picker-calendar'); } get dateCell() { return (this.nzDateCell || this.nzDateCellChild); } get dateFullCell() { return (this.nzDateFullCell || this.nzDateFullCellChild); } get monthCell() { return (this.nzMonthCell || this.nzMonthCellChild); } get monthFullCell() { return (this.nzMonthFullCell || this.nzMonthFullCellChild); } ngOnInit() { var _a; this.dir = this.directionality.value; (_a = this.directionality.change) === null || _a === void 0 ? void 0 : _a.pipe(takeUntil(this.destroy$)).subscribe(() => { this.dir = this.directionality.value; }); } onModeChange(mode) { this.nzModeChange.emit(mode); this.nzPanelChange.emit({ date: this.activeDate.nativeDate, mode }); } onYearSelect(year) { const date = this.activeDate.setYear(year); this.updateDate(date); } onMonthSelect(month) { const date = this.activeDate.setMonth(month); this.updateDate(date); } onDateSelect(date) { // Only activeDate is enough in calendar // this.value = date; this.updateDate(date); } writeValue(value) { this.updateDate(new CandyDate(value), false); this.cdr.markForCheck(); } registerOnChange(fn) { this.onChangeFn = fn; } registerOnTouched(fn) { this.onTouchFn = fn; } updateDate(date, touched = true) { this.activeDate = date; if (touched) { this.onChangeFn(date.nativeDate); this.onTouchFn(); this.nzSelectChange.emit(date.nativeDate); this.nzValueChange.emit(date.nativeDate); } } ngOnChanges(changes) { if (changes.nzValue) { this.updateDate(new CandyDate(this.nzValue), false); } } ngOnDestroy() { this.destroy$.next(); this.destroy$.complete(); } } NzCalendarComponent.decorators = [ { type: Component, args: [{ encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, selector: 'nz-calendar', exportAs: 'nzCalendar', template: ` <nz-calendar-header [fullscreen]="nzFullscreen" [activeDate]="activeDate" [(mode)]="nzMode" (modeChange)="onModeChange($event)" (yearChange)="onYearSelect($event)" (monthChange)="onMonthSelect($event)" ></nz-calendar-header> <div class="ant-picker-panel"> <div class="ant-picker-{{ nzMode === 'month' ? 'date' : 'month' }}-panel"> <div class="ant-picker-body"> <ng-container *ngIf="nzMode === 'month'; then monthModeTable; else yearModeTable"></ng-container> </div> </div> </div> <ng-template #monthModeTable> <!-- TODO(@wenqi73) [cellRender] [fullCellRender] --> <date-table [prefixCls]="prefixCls" [value]="activeDate" [activeDate]="activeDate" [cellRender]="$any(dateCell)" [fullCellRender]="$any(dateFullCell)" [disabledDate]="nzDisabledDate" (valueChange)="onDateSelect($event)" ></date-table> </ng-template> <!-- TODO(@wenqi73) [cellRender] [fullCellRender] --> <ng-template #yearModeTable> <month-table [prefixCls]="prefixCls" [value]="activeDate" [activeDate]="activeDate" [cellRender]="$any(monthCell)" [fullCellRender]="$any(monthFullCell)" (valueChange)="onDateSelect($event)" ></month-table> </ng-template> `, host: { '[class.ant-picker-calendar-full]': 'nzFullscreen', '[class.ant-picker-calendar-mini]': '!nzFullscreen', '[class.ant-picker-calendar-rtl]': `dir === 'rtl'` }, providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => NzCalendarComponent), multi: true }] },] } ]; NzCalendarComponent.ctorParameters = () => [ { type: ChangeDetectorRef }, { type: ElementRef }, { type: Directionality, decorators: [{ type: Optional }] } ]; NzCalendarComponent.propDecorators = { nzMode: [{ type: Input }], nzValue: [{ type: Input }], nzDisabledDate: [{ type: Input }], nzModeChange: [{ type: Output }], nzPanelChange: [{ type: Output }], nzSelectChange: [{ type: Output }], nzValueChange: [{ type: Output }], nzDateCell: [{ type: Input }], nzDateCellChild: [{ type: ContentChild, args: [NzDateCellDirective, { static: false, read: TemplateRef },] }], nzDateFullCell: [{ type: Input }], nzDateFullCellChild: [{ type: ContentChild, args: [NzDateFullCellDirective, { static: false, read: TemplateRef },] }], nzMonthCell: [{ type: Input }], nzMonthCellChild: [{ type: ContentChild, args: [NzMonthCellDirective, { static: false, read: TemplateRef },] }], nzMonthFullCell: [{ type: Input }], nzMonthFullCellChild: [{ type: ContentChild, args: [NzMonthFullCellDirective, { static: false, read: TemplateRef },] }], nzFullscreen: [{ type: Input }] }; __decorate([ InputBoolean(), __metadata("design:type", Boolean) ], NzCalendarComponent.prototype, "nzFullscreen", void 0); /** * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ class NzCalendarModule { } NzCalendarModule.decorators = [ { type: NgModule, args: [{ declarations: [ NzCalendarHeaderComponent, NzCalendarComponent, NzDateCellDirective, NzDateFullCellDirective, NzMonthCellDirective, NzMonthFullCellDirective ], exports: [NzCalendarComponent, NzDateCellDirective, NzDateFullCellDirective, NzMonthCellDirective, NzMonthFullCellDirective], imports: [BidiModule, CommonModule, FormsModule, NzI18nModule, NzRadioModule, NzSelectModule, LibPackerModule] },] } ]; /** * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ /** * Generated bundle index. Do not edit. */ export { NzCalendarComponent, NzCalendarHeaderComponent, NzCalendarModule, NzDateCellDirective, NzDateFullCellDirective, NzMonthCellDirective, NzMonthFullCellDirective }; //# sourceMappingURL=ng-zorro-antd-calendar.js.map