ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
546 lines (534 loc) • 16.7 kB
JavaScript
import { CommonModule } from '@angular/common';
import { Directive, EventEmitter, Component, ViewEncapsulation, ChangeDetectionStrategy, Input, Output, forwardRef, ChangeDetectorRef, 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';
/**
* @fileoverview added by tsickle
* Generated from: calendar-cells.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
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'
},] }
];
/**
* @fileoverview added by tsickle
* Generated from: calendar-header.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzCalendarHeaderComponent {
/**
* @param {?} i18n
* @param {?} dateHelper
*/
constructor(i18n, dateHelper) {
this.i18n = i18n;
this.dateHelper = dateHelper;
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;
}
/**
* @return {?}
*/
get activeYear() {
return this.activeDate.getYear();
}
/**
* @return {?}
*/
get activeMonth() {
return this.activeDate.getMonth();
}
/**
* @return {?}
*/
get size() {
return this.fullscreen ? 'default' : 'small';
}
/**
* @return {?}
*/
get yearTypeText() {
return this.i18n.getLocale().Calendar.year;
}
/**
* @return {?}
*/
get monthTypeText() {
return this.i18n.getLocale().Calendar.month;
}
/**
* @return {?}
*/
ngOnInit() {
this.setUpYears();
this.setUpMonths();
}
/**
* @param {?} year
* @return {?}
*/
updateYear(year) {
this.yearChange.emit(year);
this.setUpYears(year);
}
/**
* @private
* @param {?=} year
* @return {?}
*/
setUpYears(year) {
/** @type {?} */
const start = (year || this.activeYear) - this.yearOffset;
/** @type {?} */
const end = start + this.yearTotal;
this.years = [];
for (let i = start; i < end; i++) {
this.years.push({ label: `${i}`, value: i });
}
}
/**
* @private
* @return {?}
*/
setUpMonths() {
this.months = [];
for (let i = 0; i < 12; i++) {
/** @type {?} */
const dateInMonth = this.activeDate.setMonth(i);
/** @type {?} */
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'`,
'[class.ant-fullcalendar-header]': `true`
}
}] }
];
/** @nocollapse */
NzCalendarHeaderComponent.ctorParameters = () => [
{ type: NzI18nService },
{ type: DateHelperService }
];
NzCalendarHeaderComponent.propDecorators = {
mode: [{ type: Input }],
fullscreen: [{ type: Input }],
activeDate: [{ type: Input }],
modeChange: [{ type: Output }],
yearChange: [{ type: Output }],
monthChange: [{ type: Output }]
};
if (false) {
/** @type {?} */
NzCalendarHeaderComponent.prototype.mode;
/** @type {?} */
NzCalendarHeaderComponent.prototype.fullscreen;
/** @type {?} */
NzCalendarHeaderComponent.prototype.activeDate;
/** @type {?} */
NzCalendarHeaderComponent.prototype.modeChange;
/** @type {?} */
NzCalendarHeaderComponent.prototype.yearChange;
/** @type {?} */
NzCalendarHeaderComponent.prototype.monthChange;
/** @type {?} */
NzCalendarHeaderComponent.prototype.yearOffset;
/** @type {?} */
NzCalendarHeaderComponent.prototype.yearTotal;
/** @type {?} */
NzCalendarHeaderComponent.prototype.years;
/** @type {?} */
NzCalendarHeaderComponent.prototype.months;
/**
* @type {?}
* @private
*/
NzCalendarHeaderComponent.prototype.i18n;
/**
* @type {?}
* @private
*/
NzCalendarHeaderComponent.prototype.dateHelper;
}
/**
* @fileoverview added by tsickle
* Generated from: calendar.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzCalendarComponent {
/**
* @param {?} cdr
*/
constructor(cdr) {
this.cdr = cdr;
this.activeDate = new CandyDate();
this.prefixCls = 'ant-picker-calendar';
this.onChangeFn = (/**
* @return {?}
*/
() => { });
this.onTouchFn = (/**
* @return {?}
*/
() => { });
this.nzMode = 'month';
this.nzModeChange = new EventEmitter();
this.nzPanelChange = new EventEmitter();
this.nzSelectChange = new EventEmitter();
this.nzValueChange = new EventEmitter();
this.nzFullscreen = true;
}
/**
* @return {?}
*/
get dateCell() {
return this.nzDateCell || this.nzDateCellChild;
}
/**
* @return {?}
*/
get dateFullCell() {
return this.nzDateFullCell || this.nzDateFullCellChild;
}
/**
* @return {?}
*/
get monthCell() {
return this.nzMonthCell || this.nzMonthCellChild;
}
/**
* @return {?}
*/
get monthFullCell() {
return this.nzMonthFullCell || this.nzMonthFullCellChild;
}
/**
* @param {?} mode
* @return {?}
*/
onModeChange(mode) {
this.nzModeChange.emit(mode);
this.nzPanelChange.emit({ date: this.activeDate.nativeDate, mode });
}
/**
* @param {?} year
* @return {?}
*/
onYearSelect(year) {
/** @type {?} */
const date = this.activeDate.setYear(year);
this.updateDate(date);
}
/**
* @param {?} month
* @return {?}
*/
onMonthSelect(month) {
/** @type {?} */
const date = this.activeDate.setMonth(month);
this.updateDate(date);
}
/**
* @param {?} date
* @return {?}
*/
onDateSelect(date) {
// Only activeDate is enough in calendar
// this.value = date;
this.updateDate(date);
}
/**
* @param {?} value
* @return {?}
*/
writeValue(value) {
this.updateDate(new CandyDate((/** @type {?} */ (value))), false);
this.cdr.markForCheck();
}
/**
* @param {?} fn
* @return {?}
*/
registerOnChange(fn) {
this.onChangeFn = fn;
}
/**
* @param {?} fn
* @return {?}
*/
registerOnTouched(fn) {
this.onTouchFn = fn;
}
/**
* @private
* @param {?} date
* @param {?=} touched
* @return {?}
*/
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);
}
}
/**
* @param {?} changes
* @return {?}
*/
ngOnChanges(changes) {
if (changes.nzValue) {
this.updateDate(new CandyDate(this.nzValue), false);
}
}
}
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>
<date-table
[prefixCls]="prefixCls"
[value]="activeDate"
[activeDate]="activeDate"
[cellRender]="dateCell"
[fullCellRender]="dateFullCell"
(valueChange)="onDateSelect($event)"
></date-table>
</ng-template>
<ng-template #yearModeTable>
<month-table
[prefixCls]="prefixCls"
[value]="activeDate"
[activeDate]="activeDate"
[cellRender]="monthCell"
[fullCellRender]="monthFullCell"
(valueChange)="onDateSelect($event)"
></month-table>
</ng-template>
`,
host: {
'[class.ant-picker-calendar]': 'true',
'[class.ant-picker-calendar-full]': 'nzFullscreen',
'[class.ant-picker-calendar-mini]': '!nzFullscreen'
},
providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef((/**
* @return {?}
*/
() => NzCalendarComponent)), multi: true }]
}] }
];
/** @nocollapse */
NzCalendarComponent.ctorParameters = () => [
{ type: ChangeDetectorRef }
];
NzCalendarComponent.propDecorators = {
nzMode: [{ type: Input }],
nzValue: [{ 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);
if (false) {
/** @type {?} */
NzCalendarComponent.ngAcceptInputType_nzFullscreen;
/** @type {?} */
NzCalendarComponent.prototype.activeDate;
/** @type {?} */
NzCalendarComponent.prototype.prefixCls;
/**
* @type {?}
* @private
*/
NzCalendarComponent.prototype.onChangeFn;
/**
* @type {?}
* @private
*/
NzCalendarComponent.prototype.onTouchFn;
/** @type {?} */
NzCalendarComponent.prototype.nzMode;
/** @type {?} */
NzCalendarComponent.prototype.nzValue;
/** @type {?} */
NzCalendarComponent.prototype.nzModeChange;
/** @type {?} */
NzCalendarComponent.prototype.nzPanelChange;
/** @type {?} */
NzCalendarComponent.prototype.nzSelectChange;
/** @type {?} */
NzCalendarComponent.prototype.nzValueChange;
/**
* Cannot use \@Input and \@ContentChild on one variable
* because { static: false } will make \@Input property get delayed
*
* @type {?}
*/
NzCalendarComponent.prototype.nzDateCell;
/** @type {?} */
NzCalendarComponent.prototype.nzDateCellChild;
/** @type {?} */
NzCalendarComponent.prototype.nzDateFullCell;
/** @type {?} */
NzCalendarComponent.prototype.nzDateFullCellChild;
/** @type {?} */
NzCalendarComponent.prototype.nzMonthCell;
/** @type {?} */
NzCalendarComponent.prototype.nzMonthCellChild;
/** @type {?} */
NzCalendarComponent.prototype.nzMonthFullCell;
/** @type {?} */
NzCalendarComponent.prototype.nzMonthFullCellChild;
/** @type {?} */
NzCalendarComponent.prototype.nzFullscreen;
/**
* @type {?}
* @private
*/
NzCalendarComponent.prototype.cdr;
}
/**
* @fileoverview added by tsickle
* Generated from: calendar.module.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class NzCalendarModule {
}
NzCalendarModule.decorators = [
{ type: NgModule, args: [{
declarations: [
NzCalendarHeaderComponent,
NzCalendarComponent,
NzDateCellDirective,
NzDateFullCellDirective,
NzMonthCellDirective,
NzMonthFullCellDirective
],
exports: [NzCalendarComponent, NzDateCellDirective, NzDateFullCellDirective, NzMonthCellDirective, NzMonthFullCellDirective],
imports: [CommonModule, FormsModule, NzI18nModule, NzRadioModule, NzSelectModule, LibPackerModule]
},] }
];
/**
* @fileoverview added by tsickle
* Generated from: public-api.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* Generated from: ng-zorro-antd-calendar.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { NzCalendarComponent, NzCalendarHeaderComponent, NzCalendarModule, NzDateCellDirective, NzDateFullCellDirective, NzMonthCellDirective, NzMonthFullCellDirective };
//# sourceMappingURL=ng-zorro-antd-calendar.js.map