UNPKG

ng-zorro-antd

Version:

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

934 lines (927 loc) • 23.8 kB
import * as i0 from "@angular/core"; import { ChangeDetectorRef, Component, ContentChild, Directive, EventEmitter, Input, NgModule, Output, TemplateRef, ViewEncapsulation, booleanAttribute, forwardRef, inject } from "@angular/core"; import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; import * as i1$1 from "@angular/forms"; import { FormsModule, NG_VALUE_ACCESSOR } from "@angular/forms"; import { NzStringTemplateOutletDirective } from "ng-zorro-antd/core/outlet"; import { CandyDate, NzDateAdapter } from "ng-zorro-antd/core/time"; import { NzI18nPipe, NzI18nService } from "ng-zorro-antd/i18n"; import * as i3 from "ng-zorro-antd/radio"; import { NzRadioModule } from "ng-zorro-antd/radio"; import * as i2 from "ng-zorro-antd/select"; import { NzSelectModule } from "ng-zorro-antd/select"; import { Directionality } from "@angular/cdk/bidi"; import * as i1 from "ng-zorro-antd/date-picker"; import { LibPackerModule } from "ng-zorro-antd/date-picker"; var NzDateCellDirective = class NzDateCellDirective { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzDateCellDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.2.2", type: NzDateCellDirective, isStandalone: true, selector: "[nzDateCell]", exportAs: ["nzDateCell"], ngImport: i0 }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzDateCellDirective, decorators: [{ type: Directive, args: [{ selector: "[nzDateCell]", exportAs: "nzDateCell" }] }] }); var NzMonthCellDirective = class NzMonthCellDirective { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzMonthCellDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.2.2", type: NzMonthCellDirective, isStandalone: true, selector: "[nzMonthCell]", exportAs: ["nzMonthCell"], ngImport: i0 }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzMonthCellDirective, decorators: [{ type: Directive, args: [{ selector: "[nzMonthCell]", exportAs: "nzMonthCell" }] }] }); var NzDateFullCellDirective = class NzDateFullCellDirective { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzDateFullCellDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.2.2", type: NzDateFullCellDirective, isStandalone: true, selector: "[nzDateFullCell]", exportAs: ["nzDateFullCell"], ngImport: i0 }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzDateFullCellDirective, decorators: [{ type: Directive, args: [{ selector: "[nzDateFullCell]", exportAs: "nzDateFullCell" }] }] }); var NzMonthFullCellDirective = class NzMonthFullCellDirective { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzMonthFullCellDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.2.2", type: NzMonthFullCellDirective, isStandalone: true, selector: "[nzMonthFullCell]", exportAs: ["nzMonthFullCell"], ngImport: i0 }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzMonthFullCellDirective, decorators: [{ type: Directive, args: [{ selector: "[nzMonthFullCell]", exportAs: "nzMonthFullCell" }] }] }); var NzCalendarHeaderComponent = class NzCalendarHeaderComponent { dateAdapter = inject(NzDateAdapter); mode = "month"; fullscreen = true; activeDate = new CandyDate(); nzCustomHeader; modeChange = new EventEmitter(); yearChange = new EventEmitter(); monthChange = new EventEmitter(); yearOffset = 10; yearTotal = 20; years = []; months = []; get activeYear() { return this.activeDate.getYear(); } get activeMonth() { return this.activeDate.getMonth(); } get size() { return this.fullscreen ? "default" : "small"; } constructor() { this.dateAdapter.localeChanges.pipe(takeUntilDestroyed()).subscribe(() => { this.setUpYears(); this.setUpMonths(); }); } ngOnInit() { this.setUpYears(); this.setUpMonths(); } ngOnChanges(changes) { const { activeDate } = changes; if (activeDate) { if (activeDate.previousValue?.getYear() !== activeDate.currentValue?.getYear()) this.setUpYears(); } } 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.dateAdapter.format(dateInMonth.nativeDate, "MMM"); this.months.push({ label: monthText, value: i }); } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzCalendarHeaderComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.2.2", type: NzCalendarHeaderComponent, isStandalone: true, selector: "nz-calendar-header", inputs: { mode: "mode", fullscreen: [ "fullscreen", "fullscreen", booleanAttribute ], activeDate: "activeDate", nzCustomHeader: "nzCustomHeader" }, outputs: { modeChange: "modeChange", yearChange: "yearChange", monthChange: "monthChange" }, host: { properties: { "style.display": "'block'" }, classAttribute: "ant-fullcalendar-header" }, exportAs: ["nzCalendarHeader"], usesOnChanges: true, ngImport: i0, template: ` @if (nzCustomHeader) { <ng-container *nzStringTemplateOutlet="nzCustomHeader">{{ nzCustomHeader }}</ng-container> } @else { <div class="ant-picker-calendar-header"> <nz-select class="ant-picker-calendar-year-select" [nzSize]="size" [nzDropdownMatchSelectWidth]="false" [ngModel]="activeYear" [ngModelOptions]="{ standalone: true }" (ngModelChange)="updateYear($event)" > @for (year of years; track year.value) { <nz-option [nzLabel]="year.label" [nzValue]="year.value" /> } </nz-select> @if (mode === 'month') { <nz-select class="ant-picker-calendar-month-select" [nzSize]="size" [nzDropdownMatchSelectWidth]="false" [ngModel]="activeMonth" [ngModelOptions]="{ standalone: true }" (ngModelChange)="monthChange.emit($event)" > @for (month of months; track month.value) { <nz-option [nzLabel]="month.label" [nzValue]="month.value" /> } </nz-select> } <nz-radio-group class="ant-picker-calendar-mode-switch" [(ngModel)]="mode" [ngModelOptions]="{ standalone: true }" (ngModelChange)="modeChange.emit($event)" [nzSize]="size" > <label nz-radio-button nzValue="month">{{ 'Calendar.lang.month' | nzI18n }}</label> <label nz-radio-button nzValue="year">{{ 'Calendar.lang.year' | nzI18n }}</label> </nz-radio-group> </div> } `, isInline: true, dependencies: [ { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1$1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1$1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: [ "name", "disabled", "ngModel", "ngModelOptions" ], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "ngmodule", type: NzSelectModule }, { kind: "component", type: i2.NzOptionComponent, selector: "nz-option", inputs: [ "nzTitle", "nzLabel", "nzValue", "nzKey", "nzDisabled", "nzHide", "nzCustomContent" ], exportAs: ["nzOption"] }, { kind: "component", type: i2.NzSelectComponent, selector: "nz-select", inputs: [ "nzId", "nzSize", "nzStatus", "nzVariant", "nzOptionHeightPx", "nzOptionOverflowSize", "nzDropdownClassName", "nzDropdownMatchSelectWidth", "nzDropdownStyle", "nzNotFoundContent", "nzPlaceHolder", "nzPlacement", "nzMaxTagCount", "nzDropdownRender", "nzCustomTemplate", "nzPrefix", "nzSuffixIcon", "nzClearIcon", "nzRemoveIcon", "nzMenuItemSelectedIcon", "nzTokenSeparators", "nzMaxTagPlaceholder", "nzMaxMultipleCount", "nzMode", "nzFilterOption", "compareWith", "nzAllowClear", "nzShowSearch", "nzLoading", "nzAutoFocus", "nzAutoClearSearchValue", "nzServerSearch", "nzDisabled", "nzOpen", "nzSelectOnTab", "nzBackdrop", "nzOptions", "nzShowArrow" ], outputs: [ "nzOnSearch", "nzScrollToBottom", "nzOpenChange", "nzBlur", "nzFocus", "nzOnClear" ], exportAs: ["nzSelect"] }, { kind: "ngmodule", type: NzRadioModule }, { kind: "component", type: i3.NzRadioComponent, selector: "[nz-radio],[nz-radio-button]", inputs: [ "nzValue", "nzDisabled", "nzAutoFocus", "nz-radio-button" ], exportAs: ["nzRadio"] }, { kind: "component", type: i3.NzRadioGroupComponent, selector: "nz-radio-group", inputs: [ "nzDisabled", "nzButtonStyle", "nzSize", "nzName" ], exportAs: ["nzRadioGroup"] }, { kind: "directive", type: NzStringTemplateOutletDirective, selector: "[nzStringTemplateOutlet]", inputs: ["nzStringTemplateOutletContext", "nzStringTemplateOutlet"], exportAs: ["nzStringTemplateOutlet"] }, { kind: "pipe", type: NzI18nPipe, name: "nzI18n" } ], encapsulation: i0.ViewEncapsulation.None }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzCalendarHeaderComponent, decorators: [{ type: Component, args: [{ selector: "nz-calendar-header", exportAs: "nzCalendarHeader", imports: [ FormsModule, NzI18nPipe, NzSelectModule, NzRadioModule, NzStringTemplateOutletDirective ], encapsulation: ViewEncapsulation.None, template: ` @if (nzCustomHeader) { <ng-container *nzStringTemplateOutlet="nzCustomHeader">{{ nzCustomHeader }}</ng-container> } @else { <div class="ant-picker-calendar-header"> <nz-select class="ant-picker-calendar-year-select" [nzSize]="size" [nzDropdownMatchSelectWidth]="false" [ngModel]="activeYear" [ngModelOptions]="{ standalone: true }" (ngModelChange)="updateYear($event)" > @for (year of years; track year.value) { <nz-option [nzLabel]="year.label" [nzValue]="year.value" /> } </nz-select> @if (mode === 'month') { <nz-select class="ant-picker-calendar-month-select" [nzSize]="size" [nzDropdownMatchSelectWidth]="false" [ngModel]="activeMonth" [ngModelOptions]="{ standalone: true }" (ngModelChange)="monthChange.emit($event)" > @for (month of months; track month.value) { <nz-option [nzLabel]="month.label" [nzValue]="month.value" /> } </nz-select> } <nz-radio-group class="ant-picker-calendar-mode-switch" [(ngModel)]="mode" [ngModelOptions]="{ standalone: true }" (ngModelChange)="modeChange.emit($event)" [nzSize]="size" > <label nz-radio-button nzValue="month">{{ 'Calendar.lang.month' | nzI18n }}</label> <label nz-radio-button nzValue="year">{{ 'Calendar.lang.year' | nzI18n }}</label> </nz-radio-group> </div> } `, host: { class: "ant-fullcalendar-header", "[style.display]": `'block'` } }] }], ctorParameters: () => [], propDecorators: { mode: [{ type: Input }], fullscreen: [{ type: Input, args: [{ transform: booleanAttribute }] }], activeDate: [{ type: Input }], nzCustomHeader: [{ type: Input }], modeChange: [{ type: Output }], yearChange: [{ type: Output }], monthChange: [{ type: Output }] } }); var NzCalendarComponent = class NzCalendarComponent { cdr = inject(ChangeDetectorRef); i18n = inject(NzI18nService); dir = inject(Directionality).valueSignal; locale; activeDate = new CandyDate(); prefixCls = "ant-picker-calendar"; onChangeFn = () => {}; onTouchFn = () => {}; nzMode = "month"; nzValue; nzDisabledDate; nzModeChange = new EventEmitter(); nzPanelChange = new EventEmitter(); nzSelectChange = new EventEmitter(); nzValueChange = new EventEmitter(); nzDateCell; nzDateCellChild; get dateCell() { return this.nzDateCell || this.nzDateCellChild; } nzDateFullCell; nzDateFullCellChild; get dateFullCell() { return this.nzDateFullCell || this.nzDateFullCellChild; } nzMonthCell; nzMonthCellChild; get monthCell() { return this.nzMonthCell || this.nzMonthCellChild; } nzMonthFullCell; nzMonthFullCellChild; get monthFullCell() { return this.nzMonthFullCell || this.nzMonthFullCellChild; } nzCustomHeader; nzFullscreen = true; constructor() { this.i18n.localeChange.pipe(takeUntilDestroyed()).subscribe(() => { this.locale = this.i18n.getLocaleData("Calendar", {}).lang; this.cdr.markForCheck(); }); } 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) { this.updateDate(date); } writeValue(value) { this.updateDate(new CandyDate(value), false); } 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); } this.cdr.markForCheck(); } ngOnChanges(changes) { if (changes.nzValue) this.updateDate(new CandyDate(this.nzValue), false); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzCalendarComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.2.2", type: NzCalendarComponent, isStandalone: true, selector: "nz-calendar", inputs: { nzMode: "nzMode", nzValue: "nzValue", nzDisabledDate: "nzDisabledDate", nzDateCell: "nzDateCell", nzDateFullCell: "nzDateFullCell", nzMonthCell: "nzMonthCell", nzMonthFullCell: "nzMonthFullCell", nzCustomHeader: "nzCustomHeader", nzFullscreen: [ "nzFullscreen", "nzFullscreen", booleanAttribute ] }, outputs: { nzModeChange: "nzModeChange", nzPanelChange: "nzPanelChange", nzSelectChange: "nzSelectChange", nzValueChange: "nzValueChange" }, host: { properties: { "class.ant-picker-calendar-full": "nzFullscreen", "class.ant-picker-calendar-mini": "!nzFullscreen", "class.ant-picker-calendar-rtl": "dir() === 'rtl'" }, classAttribute: "ant-picker-calendar" }, providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => NzCalendarComponent), multi: true }], queries: [ { propertyName: "nzDateCellChild", first: true, predicate: NzDateCellDirective, descendants: true, read: TemplateRef }, { propertyName: "nzDateFullCellChild", first: true, predicate: NzDateFullCellDirective, descendants: true, read: TemplateRef }, { propertyName: "nzMonthCellChild", first: true, predicate: NzMonthCellDirective, descendants: true, read: TemplateRef }, { propertyName: "nzMonthFullCellChild", first: true, predicate: NzMonthFullCellDirective, descendants: true, read: TemplateRef } ], exportAs: ["nzCalendar"], usesOnChanges: true, ngImport: i0, template: ` <nz-calendar-header [fullscreen]="nzFullscreen" [activeDate]="activeDate" [nzCustomHeader]="nzCustomHeader" [(mode)]="nzMode" (modeChange)="onModeChange($event)" (yearChange)="onYearSelect($event)" (monthChange)="onMonthSelect($event)" /> <div class="ant-picker-panel"> <div class="ant-picker-{{ nzMode === 'month' ? 'date' : 'month' }}-panel"> <div class="ant-picker-body"> @if (nzMode === 'month') { <!-- TODO(@wenqi73) [cellRender] [fullCellRender] --> <date-table [prefixCls]="prefixCls" [value]="activeDate" [activeDate]="activeDate" [locale]="locale" [cellRender]="$any(dateCell)" [fullCellRender]="$any(dateFullCell)" [disabledDate]="nzDisabledDate" (valueChange)="onDateSelect($event)" /> } @else { <month-table [prefixCls]="prefixCls" [value]="activeDate" [activeDate]="activeDate" [locale]="locale" [cellRender]="$any(monthCell)" [fullCellRender]="$any(monthFullCell)" (valueChange)="onDateSelect($event)" /> } </div> </div> </div> `, isInline: true, dependencies: [ { kind: "component", type: NzCalendarHeaderComponent, selector: "nz-calendar-header", inputs: [ "mode", "fullscreen", "activeDate", "nzCustomHeader" ], outputs: [ "modeChange", "yearChange", "monthChange" ], exportAs: ["nzCalendarHeader"] }, { kind: "ngmodule", type: LibPackerModule }, { kind: "component", type: i1.ɵDateTableComponent, selector: "date-table", inputs: ["format"] }, { kind: "component", type: i1.ɵMonthTableComponent, selector: "month-table" } ], encapsulation: i0.ViewEncapsulation.None }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzCalendarComponent, decorators: [{ type: Component, args: [{ selector: "nz-calendar", exportAs: "nzCalendar", providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => NzCalendarComponent), multi: true }], imports: [NzCalendarHeaderComponent, LibPackerModule], template: ` <nz-calendar-header [fullscreen]="nzFullscreen" [activeDate]="activeDate" [nzCustomHeader]="nzCustomHeader" [(mode)]="nzMode" (modeChange)="onModeChange($event)" (yearChange)="onYearSelect($event)" (monthChange)="onMonthSelect($event)" /> <div class="ant-picker-panel"> <div class="ant-picker-{{ nzMode === 'month' ? 'date' : 'month' }}-panel"> <div class="ant-picker-body"> @if (nzMode === 'month') { <!-- TODO(@wenqi73) [cellRender] [fullCellRender] --> <date-table [prefixCls]="prefixCls" [value]="activeDate" [activeDate]="activeDate" [locale]="locale" [cellRender]="$any(dateCell)" [fullCellRender]="$any(dateFullCell)" [disabledDate]="nzDisabledDate" (valueChange)="onDateSelect($event)" /> } @else { <month-table [prefixCls]="prefixCls" [value]="activeDate" [activeDate]="activeDate" [locale]="locale" [cellRender]="$any(monthCell)" [fullCellRender]="$any(monthFullCell)" (valueChange)="onDateSelect($event)" /> } </div> </div> </div> `, host: { class: "ant-picker-calendar", "[class.ant-picker-calendar-full]": "nzFullscreen", "[class.ant-picker-calendar-mini]": "!nzFullscreen", "[class.ant-picker-calendar-rtl]": `dir() === 'rtl'` }, encapsulation: ViewEncapsulation.None }] }], ctorParameters: () => [], 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 }] }], nzCustomHeader: [{ type: Input }], nzFullscreen: [{ type: Input, args: [{ transform: booleanAttribute }] }] } }); const CELL_DIRECTIVES = [ NzDateCellDirective, NzDateFullCellDirective, NzMonthCellDirective, NzMonthFullCellDirective ]; var NzCalendarModule = class NzCalendarModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzCalendarModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.2.2", ngImport: i0, type: NzCalendarModule, imports: [ NzCalendarHeaderComponent, NzCalendarComponent, NzDateCellDirective, NzDateFullCellDirective, NzMonthCellDirective, NzMonthFullCellDirective ], exports: [ NzCalendarComponent, NzDateCellDirective, NzDateFullCellDirective, NzMonthCellDirective, NzMonthFullCellDirective ] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzCalendarModule, imports: [NzCalendarHeaderComponent, NzCalendarComponent] }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzCalendarModule, decorators: [{ type: NgModule, args: [{ imports: [ NzCalendarHeaderComponent, NzCalendarComponent, ...CELL_DIRECTIVES ], exports: [NzCalendarComponent, ...CELL_DIRECTIVES] }] }] }); export { NzCalendarComponent, NzCalendarHeaderComponent, NzCalendarModule, NzDateCellDirective, NzDateFullCellDirective, NzMonthCellDirective, NzMonthFullCellDirective }; //# sourceMappingURL=ng-zorro-antd-calendar.mjs.map