ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
633 lines (625 loc) • 20.2 kB
JavaScript
import { __decorate, __metadata, __extends, __spread } from 'tslib';
import { Component, ViewEncapsulation, ChangeDetectionStrategy, forwardRef, ElementRef, Renderer2, ChangeDetectorRef, ViewChild, Input, HostListener, ContentChildren, NgModule } from '@angular/core';
import { FocusMonitor } from '@angular/cdk/a11y';
import { NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms';
import { Subject, merge } from 'rxjs';
import { InputBoolean, isNotNil } from 'ng-zorro-antd/core';
import { startWith, takeUntil } from 'rxjs/operators';
import { CommonModule } from '@angular/common';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NzRadioComponent = /** @class */ (function () {
/* tslint:disable-next-line:no-any */
function NzRadioComponent(elementRef, renderer, cdr, focusMonitor) {
this.elementRef = elementRef;
this.renderer = renderer;
this.cdr = cdr;
this.focusMonitor = focusMonitor;
this.select$ = new Subject();
this.touched$ = new Subject();
this.checked = false;
this.isNgModel = false;
this.onChange = (/**
* @return {?}
*/
function () { return null; });
this.onTouched = (/**
* @return {?}
*/
function () { return null; });
this.nzDisabled = false;
this.nzAutoFocus = false;
this.renderer.addClass(elementRef.nativeElement, 'ant-radio-wrapper');
}
/**
* @return {?}
*/
NzRadioComponent.prototype.updateAutoFocus = /**
* @return {?}
*/
function () {
if (this.inputElement) {
if (this.nzAutoFocus) {
this.renderer.setAttribute(this.inputElement.nativeElement, 'autofocus', 'autofocus');
}
else {
this.renderer.removeAttribute(this.inputElement.nativeElement, 'autofocus');
}
}
};
/**
* @param {?} event
* @return {?}
*/
NzRadioComponent.prototype.onClick = /**
* @param {?} event
* @return {?}
*/
function (event) {
// Prevent label click triggered twice.
event.stopPropagation();
event.preventDefault();
if (!this.nzDisabled && !this.checked) {
this.select$.next(this);
if (this.isNgModel) {
this.checked = true;
this.onChange(true);
}
}
};
/**
* @return {?}
*/
NzRadioComponent.prototype.focus = /**
* @return {?}
*/
function () {
this.focusMonitor.focusVia(this.inputElement, 'keyboard');
};
/**
* @return {?}
*/
NzRadioComponent.prototype.blur = /**
* @return {?}
*/
function () {
this.inputElement.nativeElement.blur();
};
/**
* @return {?}
*/
NzRadioComponent.prototype.markForCheck = /**
* @return {?}
*/
function () {
this.cdr.markForCheck();
};
/**
* @param {?} isDisabled
* @return {?}
*/
NzRadioComponent.prototype.setDisabledState = /**
* @param {?} isDisabled
* @return {?}
*/
function (isDisabled) {
this.nzDisabled = isDisabled;
this.cdr.markForCheck();
};
/**
* @param {?} value
* @return {?}
*/
NzRadioComponent.prototype.writeValue = /**
* @param {?} value
* @return {?}
*/
function (value) {
this.checked = value;
this.cdr.markForCheck();
};
/**
* @param {?} fn
* @return {?}
*/
NzRadioComponent.prototype.registerOnChange = /**
* @param {?} fn
* @return {?}
*/
function (fn) {
this.isNgModel = true;
this.onChange = fn;
};
/**
* @param {?} fn
* @return {?}
*/
NzRadioComponent.prototype.registerOnTouched = /**
* @param {?} fn
* @return {?}
*/
function (fn) {
this.onTouched = fn;
};
/**
* @return {?}
*/
NzRadioComponent.prototype.ngAfterViewInit = /**
* @return {?}
*/
function () {
var _this = this;
this.focusMonitor.monitor(this.elementRef, true).subscribe((/**
* @param {?} focusOrigin
* @return {?}
*/
function (focusOrigin) {
if (!focusOrigin) {
Promise.resolve().then((/**
* @return {?}
*/
function () { return _this.onTouched(); }));
_this.touched$.next();
}
}));
this.updateAutoFocus();
};
/**
* @param {?} changes
* @return {?}
*/
NzRadioComponent.prototype.ngOnChanges = /**
* @param {?} changes
* @return {?}
*/
function (changes) {
if (changes.nzAutoFocus) {
this.updateAutoFocus();
}
};
/**
* @return {?}
*/
NzRadioComponent.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this.focusMonitor.stopMonitoring(this.elementRef);
};
NzRadioComponent.decorators = [
{ type: Component, args: [{
selector: '[nz-radio]',
exportAs: 'nzRadio',
preserveWhitespaces: false,
template: "<span class=\"ant-radio\" [class.ant-radio-checked]=\"checked\" [class.ant-radio-disabled]=\"nzDisabled\">\n <input #inputElement type=\"radio\" class=\"ant-radio-input\" [disabled]=\"nzDisabled\" [checked]=\"checked\" [attr.name]=\"name\">\n <span class=\"ant-radio-inner\"></span>\n</span>\n<span><ng-content></ng-content></span>",
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef((/**
* @return {?}
*/
function () { return NzRadioComponent; })),
multi: true
}
],
host: {
'[class.ant-radio-wrapper-checked]': 'checked',
'[class.ant-radio-wrapper-disabled]': 'nzDisabled'
}
}] }
];
/** @nocollapse */
NzRadioComponent.ctorParameters = function () { return [
{ type: ElementRef },
{ type: Renderer2 },
{ type: ChangeDetectorRef },
{ type: FocusMonitor }
]; };
NzRadioComponent.propDecorators = {
inputElement: [{ type: ViewChild, args: ['inputElement', { static: false },] }],
nzValue: [{ type: Input }],
nzDisabled: [{ type: Input }],
nzAutoFocus: [{ type: Input }],
onClick: [{ type: HostListener, args: ['click', ['$event'],] }]
};
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzRadioComponent.prototype, "nzDisabled", void 0);
__decorate([
InputBoolean(),
__metadata("design:type", Object)
], NzRadioComponent.prototype, "nzAutoFocus", void 0);
return NzRadioComponent;
}());
if (false) {
/** @type {?} */
NzRadioComponent.prototype.select$;
/** @type {?} */
NzRadioComponent.prototype.touched$;
/** @type {?} */
NzRadioComponent.prototype.checked;
/** @type {?} */
NzRadioComponent.prototype.name;
/** @type {?} */
NzRadioComponent.prototype.isNgModel;
/** @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.renderer;
/**
* @type {?}
* @private
*/
NzRadioComponent.prototype.cdr;
/**
* @type {?}
* @private
*/
NzRadioComponent.prototype.focusMonitor;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NzRadioButtonComponent = /** @class */ (function (_super) {
__extends(NzRadioButtonComponent, _super);
/* tslint:disable-next-line:no-any */
function NzRadioButtonComponent(elementRef, renderer, cdr, focusMonitor) {
var _this = _super.call(this, elementRef, renderer, cdr, focusMonitor) || this;
renderer.removeClass(elementRef.nativeElement, 'ant-radio-wrapper');
renderer.addClass(elementRef.nativeElement, 'ant-radio-button-wrapper');
return _this;
}
NzRadioButtonComponent.decorators = [
{ type: Component, args: [{
selector: '[nz-radio-button]',
exportAs: 'nzRadioButton',
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef((/**
* @return {?}
*/
function () { return NzRadioComponent; })),
multi: true
},
{
provide: NzRadioComponent,
useExisting: forwardRef((/**
* @return {?}
*/
function () { return NzRadioButtonComponent; }))
}
],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
preserveWhitespaces: false,
template: "<span class=\"ant-radio-button\" [class.ant-radio-button-checked]=\"checked\" [class.ant-radio-button-disabled]=\"nzDisabled\">\n <input type=\"radio\" #inputElement class=\"ant-radio-button-input\" [disabled]=\"nzDisabled\" [checked]=\"checked\" [attr.name]=\"name\">\n <span class=\"ant-radio-button-inner\"></span>\n</span>\n<span><ng-content></ng-content></span>",
host: {
'[class.ant-radio-button-wrapper-checked]': 'checked',
'[class.ant-radio-button-wrapper-disabled]': 'nzDisabled'
}
}] }
];
/** @nocollapse */
NzRadioButtonComponent.ctorParameters = function () { return [
{ type: ElementRef },
{ type: Renderer2 },
{ type: ChangeDetectorRef },
{ type: FocusMonitor }
]; };
return NzRadioButtonComponent;
}(NzRadioComponent));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NzRadioGroupComponent = /** @class */ (function () {
function NzRadioGroupComponent(cdr, renderer, elementRef) {
this.cdr = cdr;
this.destroy$ = new Subject();
this.onChange = (/**
* @return {?}
*/
function () { return null; });
this.onTouched = (/**
* @return {?}
*/
function () { return null; });
this.nzButtonStyle = 'outline';
this.nzSize = 'default';
renderer.addClass(elementRef.nativeElement, 'ant-radio-group');
}
/**
* @return {?}
*/
NzRadioGroupComponent.prototype.updateChildrenStatus = /**
* @return {?}
*/
function () {
var _this = this;
if (this.radios) {
Promise.resolve().then((/**
* @return {?}
*/
function () {
_this.radios.forEach((/**
* @param {?} radio
* @return {?}
*/
function (radio) {
radio.checked = radio.nzValue === _this.value;
if (isNotNil(_this.nzDisabled)) {
radio.nzDisabled = _this.nzDisabled;
}
if (_this.nzName) {
radio.name = _this.nzName;
}
radio.markForCheck();
}));
}));
}
};
/**
* @return {?}
*/
NzRadioGroupComponent.prototype.ngAfterContentInit = /**
* @return {?}
*/
function () {
var _this = this;
this.radios.changes
.pipe(startWith(null), takeUntil(this.destroy$))
.subscribe((/**
* @return {?}
*/
function () {
_this.updateChildrenStatus();
if (_this.selectSubscription) {
_this.selectSubscription.unsubscribe();
}
_this.selectSubscription = merge.apply(void 0, __spread(_this.radios.map((/**
* @param {?} radio
* @return {?}
*/
function (radio) { return radio.select$; })))).pipe(takeUntil(_this.destroy$))
.subscribe((/**
* @param {?} radio
* @return {?}
*/
function (radio) {
if (_this.value !== radio.nzValue) {
_this.value = radio.nzValue;
_this.updateChildrenStatus();
_this.onChange(_this.value);
}
}));
if (_this.touchedSubscription) {
_this.touchedSubscription.unsubscribe();
}
_this.touchedSubscription = merge.apply(void 0, __spread(_this.radios.map((/**
* @param {?} radio
* @return {?}
*/
function (radio) { return radio.touched$; })))).pipe(takeUntil(_this.destroy$))
.subscribe((/**
* @return {?}
*/
function () {
Promise.resolve().then((/**
* @return {?}
*/
function () { return _this.onTouched(); }));
}));
}));
};
/**
* @param {?} changes
* @return {?}
*/
NzRadioGroupComponent.prototype.ngOnChanges = /**
* @param {?} changes
* @return {?}
*/
function (changes) {
if (changes.nzDisabled || changes.nzName) {
this.updateChildrenStatus();
}
};
/**
* @return {?}
*/
NzRadioGroupComponent.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this.destroy$.next();
this.destroy$.complete();
};
/* tslint:disable-next-line:no-any */
/* tslint:disable-next-line:no-any */
/**
* @param {?} value
* @return {?}
*/
NzRadioGroupComponent.prototype.writeValue = /* tslint:disable-next-line:no-any */
/**
* @param {?} value
* @return {?}
*/
function (value) {
this.value = value;
this.updateChildrenStatus();
this.cdr.markForCheck();
};
/**
* @param {?} fn
* @return {?}
*/
NzRadioGroupComponent.prototype.registerOnChange = /**
* @param {?} fn
* @return {?}
*/
function (fn) {
this.onChange = fn;
};
/**
* @param {?} fn
* @return {?}
*/
NzRadioGroupComponent.prototype.registerOnTouched = /**
* @param {?} fn
* @return {?}
*/
function (fn) {
this.onTouched = fn;
};
/**
* @param {?} isDisabled
* @return {?}
*/
NzRadioGroupComponent.prototype.setDisabledState = /**
* @param {?} isDisabled
* @return {?}
*/
function (isDisabled) {
this.nzDisabled = 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: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef((/**
* @return {?}
*/
function () { return NzRadioGroupComponent; })),
multi: true
}
],
host: {
'[class.ant-radio-group-large]': "nzSize === 'large'",
'[class.ant-radio-group-small]': "nzSize === 'small'",
'[class.ant-radio-group-solid]': "nzButtonStyle === 'solid'"
}
}] }
];
/** @nocollapse */
NzRadioGroupComponent.ctorParameters = function () { return [
{ type: ChangeDetectorRef },
{ type: Renderer2 },
{ type: ElementRef }
]; };
NzRadioGroupComponent.propDecorators = {
radios: [{ type: ContentChildren, args: [forwardRef((/**
* @return {?}
*/
function () { return NzRadioComponent; })), { descendants: true },] }],
nzDisabled: [{ type: Input }],
nzButtonStyle: [{ type: Input }],
nzSize: [{ type: Input }],
nzName: [{ type: Input }]
};
__decorate([
InputBoolean(),
__metadata("design:type", Boolean)
], NzRadioGroupComponent.prototype, "nzDisabled", void 0);
return NzRadioGroupComponent;
}());
if (false) {
/**
* @type {?}
* @private
*/
NzRadioGroupComponent.prototype.value;
/**
* @type {?}
* @private
*/
NzRadioGroupComponent.prototype.destroy$;
/**
* @type {?}
* @private
*/
NzRadioGroupComponent.prototype.selectSubscription;
/**
* @type {?}
* @private
*/
NzRadioGroupComponent.prototype.touchedSubscription;
/** @type {?} */
NzRadioGroupComponent.prototype.onChange;
/** @type {?} */
NzRadioGroupComponent.prototype.onTouched;
/** @type {?} */
NzRadioGroupComponent.prototype.radios;
/** @type {?} */
NzRadioGroupComponent.prototype.nzDisabled;
/** @type {?} */
NzRadioGroupComponent.prototype.nzButtonStyle;
/** @type {?} */
NzRadioGroupComponent.prototype.nzSize;
/** @type {?} */
NzRadioGroupComponent.prototype.nzName;
/**
* @type {?}
* @private
*/
NzRadioGroupComponent.prototype.cdr;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NzRadioModule = /** @class */ (function () {
function NzRadioModule() {
}
NzRadioModule.decorators = [
{ type: NgModule, args: [{
imports: [CommonModule, FormsModule],
exports: [NzRadioComponent, NzRadioButtonComponent, NzRadioGroupComponent],
declarations: [NzRadioComponent, NzRadioButtonComponent, NzRadioGroupComponent]
},] }
];
return NzRadioModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { NzRadioButtonComponent, NzRadioComponent, NzRadioGroupComponent, NzRadioModule };
//# sourceMappingURL=ng-zorro-antd-radio.js.map