UNPKG

ng-zorro-antd

Version:

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

583 lines (574 loc) 16.8 kB
import { Directive, Injectable, Component, ViewEncapsulation, ChangeDetectionStrategy, forwardRef, ChangeDetectorRef, Input, ElementRef, Optional, ViewChild, NgModule } from '@angular/core'; import { __decorate, __metadata } from 'tslib'; import { NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms'; import { InputBoolean } from 'ng-zorro-antd/core/util'; import { ReplaySubject, Subject } from 'rxjs'; import { FocusMonitor } from '@angular/cdk/a11y'; import { takeUntil } from 'rxjs/operators'; import { CommonModule } from '@angular/common'; /** * @fileoverview added by tsickle * Generated from: radio-button.directive.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzRadioButtonDirective { } NzRadioButtonDirective.decorators = [ { type: Directive, args: [{ selector: '[nz-radio-button]' },] } ]; /** * @fileoverview added by tsickle * Generated from: radio.service.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzRadioService { constructor() { this.selected$ = new ReplaySubject(1); this.touched$ = new Subject(); this.disabled$ = new ReplaySubject(1); this.name$ = new ReplaySubject(1); } /** * @return {?} */ touch() { this.touched$.next(); } /** * @param {?} value * @return {?} */ select(value) { this.selected$.next(value); } /** * @param {?} value * @return {?} */ setDisabled(value) { this.disabled$.next(value); } /** * @param {?} value * @return {?} */ setName(value) { this.name$.next(value); } } NzRadioService.decorators = [ { type: Injectable } ]; if (false) { /** @type {?} */ NzRadioService.prototype.selected$; /** @type {?} */ NzRadioService.prototype.touched$; /** @type {?} */ NzRadioService.prototype.disabled$; /** @type {?} */ NzRadioService.prototype.name$; } /** * @fileoverview added by tsickle * Generated from: radio-group.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzRadioGroupComponent { /** * @param {?} cdr * @param {?} nzRadioService */ constructor(cdr, nzRadioService) { this.cdr = cdr; this.nzRadioService = nzRadioService; this.value = null; this.destroy$ = new Subject(); this.onChange = (/** * @return {?} */ () => { }); this.onTouched = (/** * @return {?} */ () => { }); this.nzDisabled = false; this.nzButtonStyle = 'outline'; this.nzSize = 'default'; this.nzName = null; } /** * @return {?} */ ngOnInit() { this.nzRadioService.selected$.subscribe((/** * @param {?} value * @return {?} */ value => { if (this.value !== value) { this.value = value; this.onChange(this.value); } })); this.nzRadioService.touched$.subscribe((/** * @return {?} */ () => { Promise.resolve().then((/** * @return {?} */ () => this.onTouched())); })); } /** * @param {?} changes * @return {?} */ ngOnChanges(changes) { const { nzDisabled, nzName } = changes; if (nzDisabled) { this.nzRadioService.setDisabled(this.nzDisabled); } if (nzName) { this.nzRadioService.setName((/** @type {?} */ (this.nzName))); } } /** * @return {?} */ ngOnDestroy() { this.destroy$.next(); this.destroy$.complete(); } /** * @param {?} value * @return {?} */ writeValue(value) { this.value = value; this.nzRadioService.select(value); this.cdr.markForCheck(); } /** * @param {?} fn * @return {?} */ registerOnChange(fn) { this.onChange = fn; } /** * @param {?} fn * @return {?} */ registerOnTouched(fn) { this.onTouched = fn; } /** * @param {?} isDisabled * @return {?} */ setDisabledState(isDisabled) { this.nzDisabled = isDisabled; this.nzRadioService.setDisabled(isDisabled); this.cdr.markForCheck(); } } NzRadioGroupComponent.decorators = [ { type: Component, args: [{ selector: 'nz-radio-group', exportAs: 'nzRadioGroup', preserveWhitespaces: false, template: ` <ng-content></ng-content> `, encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, providers: [ NzRadioService, { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef((/** * @return {?} */ () => NzRadioGroupComponent)), multi: true } ], host: { '[class.ant-radio-group]': `true`, '[class.ant-radio-group-large]': `nzSize === 'large'`, '[class.ant-radio-group-small]': `nzSize === 'small'`, '[class.ant-radio-group-solid]': `nzButtonStyle === 'solid'` } }] } ]; /** @nocollapse */ NzRadioGroupComponent.ctorParameters = () => [ { type: ChangeDetectorRef }, { type: NzRadioService } ]; NzRadioGroupComponent.propDecorators = { nzDisabled: [{ type: Input }], nzButtonStyle: [{ type: Input }], nzSize: [{ type: Input }], nzName: [{ type: Input }] }; __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzRadioGroupComponent.prototype, "nzDisabled", void 0); if (false) { /** @type {?} */ NzRadioGroupComponent.ngAcceptInputType_nzDisabled; /** * @type {?} * @private */ NzRadioGroupComponent.prototype.value; /** * @type {?} * @private */ NzRadioGroupComponent.prototype.destroy$; /** @type {?} */ NzRadioGroupComponent.prototype.onChange; /** @type {?} */ NzRadioGroupComponent.prototype.onTouched; /** @type {?} */ NzRadioGroupComponent.prototype.nzDisabled; /** @type {?} */ NzRadioGroupComponent.prototype.nzButtonStyle; /** @type {?} */ NzRadioGroupComponent.prototype.nzSize; /** @type {?} */ NzRadioGroupComponent.prototype.nzName; /** * @type {?} * @private */ NzRadioGroupComponent.prototype.cdr; /** * @type {?} * @private */ NzRadioGroupComponent.prototype.nzRadioService; } /** * @fileoverview added by tsickle * Generated from: radio.component.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzRadioComponent { /** * @param {?} elementRef * @param {?} cdr * @param {?} focusMonitor * @param {?} nzRadioService * @param {?} nzRadioButtonDirective */ constructor(elementRef, cdr, focusMonitor, nzRadioService, nzRadioButtonDirective) { this.elementRef = elementRef; this.cdr = cdr; this.focusMonitor = focusMonitor; this.nzRadioService = nzRadioService; this.nzRadioButtonDirective = nzRadioButtonDirective; this.isNgModel = false; this.destroy$ = new Subject(); this.isChecked = false; this.name = null; this.isRadioButton = !!this.nzRadioButtonDirective; this.onChange = (/** * @return {?} */ () => { }); this.onTouched = (/** * @return {?} */ () => { }); this.nzValue = null; this.nzDisabled = false; this.nzAutoFocus = false; } /** * @param {?} event * @return {?} */ onHostClick(event) { /** prevent label click triggered twice. **/ event.stopPropagation(); event.preventDefault(); if (!this.nzDisabled && !this.isChecked) { if (this.nzRadioService) { this.nzRadioService.select(this.nzValue); } if (this.isNgModel) { this.isChecked = true; this.onChange(true); } } } /** * @return {?} */ focus() { this.focusMonitor.focusVia((/** @type {?} */ (this.inputElement)), 'keyboard'); } /** * @return {?} */ blur() { (/** @type {?} */ (this.inputElement)).nativeElement.blur(); } /** * @param {?} disabled * @return {?} */ setDisabledState(disabled) { this.nzDisabled = disabled; this.cdr.markForCheck(); } /** * @param {?} value * @return {?} */ writeValue(value) { this.isChecked = value; this.cdr.markForCheck(); } /** * @param {?} fn * @return {?} */ registerOnChange(fn) { this.isNgModel = true; this.onChange = fn; } /** * @param {?} fn * @return {?} */ registerOnTouched(fn) { this.onTouched = fn; } /** * @return {?} */ ngOnInit() { if (this.nzRadioService) { this.nzRadioService.name$.pipe(takeUntil(this.destroy$)).subscribe((/** * @param {?} name * @return {?} */ name => { this.name = name; this.cdr.markForCheck(); })); this.nzRadioService.disabled$.pipe(takeUntil(this.destroy$)).subscribe((/** * @param {?} disabled * @return {?} */ disabled => { this.nzDisabled = disabled; this.cdr.markForCheck(); })); this.nzRadioService.selected$.pipe(takeUntil(this.destroy$)).subscribe((/** * @param {?} value * @return {?} */ value => { this.isChecked = this.nzValue === value; this.cdr.markForCheck(); })); } this.focusMonitor.monitor(this.elementRef, true).subscribe((/** * @param {?} focusOrigin * @return {?} */ focusOrigin => { if (!focusOrigin) { Promise.resolve().then((/** * @return {?} */ () => this.onTouched())); if (this.nzRadioService) { this.nzRadioService.touch(); } } })); } /** * @return {?} */ ngAfterViewInit() { if (this.nzAutoFocus) { this.focus(); } } /** * @return {?} */ ngOnDestroy() { this.destroy$.next(); this.destroy$.complete(); this.focusMonitor.stopMonitoring(this.elementRef); } } NzRadioComponent.decorators = [ { type: Component, args: [{ selector: '[nz-radio],[nz-radio-button]', exportAs: 'nzRadio', preserveWhitespaces: false, template: ` <span [class.ant-radio]="!isRadioButton" [class.ant-radio-checked]="isChecked && !isRadioButton" [class.ant-radio-disabled]="nzDisabled && !isRadioButton" [class.ant-radio-button]="isRadioButton" [class.ant-radio-button-checked]="isChecked && isRadioButton" [class.ant-radio-button-disabled]="nzDisabled && isRadioButton" > <input #inputElement type="radio" [attr.autofocus]="nzAutoFocus ? 'autofocus' : null" [class.ant-radio-input]="!isRadioButton" [class.ant-radio-button-input]="isRadioButton" [disabled]="nzDisabled" [checked]="isChecked" [attr.name]="name" /> <span [class.ant-radio-inner]="!isRadioButton" [class.ant-radio-button-inner]="isRadioButton"></span> </span> <span><ng-content></ng-content></span> `, encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef((/** * @return {?} */ () => NzRadioComponent)), multi: true } ], host: { '[class.ant-radio-wrapper]': '!isRadioButton', '[class.ant-radio-button-wrapper]': 'isRadioButton', '[class.ant-radio-wrapper-checked]': 'isChecked && !isRadioButton', '[class.ant-radio-button-wrapper-checked]': 'isChecked && isRadioButton', '[class.ant-radio-wrapper-disabled]': 'nzDisabled && !isRadioButton', '[class.ant-radio-button-wrapper-disabled]': 'nzDisabled && isRadioButton', '(click)': 'onHostClick($event)' } }] } ]; /** @nocollapse */ NzRadioComponent.ctorParameters = () => [ { type: ElementRef }, { type: ChangeDetectorRef }, { type: FocusMonitor }, { type: NzRadioService, decorators: [{ type: Optional }] }, { type: NzRadioButtonDirective, decorators: [{ type: Optional }] } ]; NzRadioComponent.propDecorators = { inputElement: [{ type: ViewChild, args: ['inputElement', { static: false },] }], nzValue: [{ type: Input }], nzDisabled: [{ type: Input }], nzAutoFocus: [{ type: Input }] }; __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzRadioComponent.prototype, "nzDisabled", void 0); __decorate([ InputBoolean(), __metadata("design:type", Object) ], NzRadioComponent.prototype, "nzAutoFocus", void 0); if (false) { /** @type {?} */ NzRadioComponent.ngAcceptInputType_nzDisabled; /** @type {?} */ NzRadioComponent.ngAcceptInputType_nzAutoFocus; /** * @type {?} * @private */ NzRadioComponent.prototype.isNgModel; /** * @type {?} * @private */ NzRadioComponent.prototype.destroy$; /** @type {?} */ NzRadioComponent.prototype.isChecked; /** @type {?} */ NzRadioComponent.prototype.name; /** @type {?} */ NzRadioComponent.prototype.isRadioButton; /** @type {?} */ NzRadioComponent.prototype.onChange; /** @type {?} */ NzRadioComponent.prototype.onTouched; /** @type {?} */ NzRadioComponent.prototype.inputElement; /** @type {?} */ NzRadioComponent.prototype.nzValue; /** @type {?} */ NzRadioComponent.prototype.nzDisabled; /** @type {?} */ NzRadioComponent.prototype.nzAutoFocus; /** * @type {?} * @private */ NzRadioComponent.prototype.elementRef; /** * @type {?} * @private */ NzRadioComponent.prototype.cdr; /** * @type {?} * @private */ NzRadioComponent.prototype.focusMonitor; /** * @type {?} * @private */ NzRadioComponent.prototype.nzRadioService; /** * @type {?} * @private */ NzRadioComponent.prototype.nzRadioButtonDirective; } /** * @fileoverview added by tsickle * Generated from: radio.module.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NzRadioModule { } NzRadioModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule, FormsModule], exports: [NzRadioComponent, NzRadioButtonDirective, NzRadioGroupComponent], declarations: [NzRadioComponent, NzRadioButtonDirective, NzRadioGroupComponent] },] } ]; /** * @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-radio.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { NzRadioButtonDirective, NzRadioComponent, NzRadioGroupComponent, NzRadioModule, NzRadioService }; //# sourceMappingURL=ng-zorro-antd-radio.js.map