ng-zorro-antd-yj
Version:
An enterprise-class UI components based on Ant Design and Angular
126 lines • 10.8 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, Input, Renderer2, TemplateRef, ViewEncapsulation } from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { isNotNil } from '../core/util/check';
import { NzOptionComponent } from './nz-option.component';
import { NzSelectService } from './nz-select.service';
export class NzOptionLiComponent {
/**
* @param {?} elementRef
* @param {?} nzSelectService
* @param {?} cdr
* @param {?} renderer
*/
constructor(elementRef, nzSelectService, cdr, renderer) {
this.elementRef = elementRef;
this.nzSelectService = nzSelectService;
this.cdr = cdr;
this.el = this.elementRef.nativeElement;
this.selected = false;
this.active = false;
this.destroy$ = new Subject();
renderer.addClass(elementRef.nativeElement, 'ant-select-dropdown-menu-item');
}
/**
* @return {?}
*/
clickOption() {
this.nzSelectService.clickOption(this.nzOption);
}
/**
* @return {?}
*/
ngOnInit() {
this.nzSelectService.listOfSelectedValue$.pipe(takeUntil(this.destroy$)).subscribe((/**
* @param {?} list
* @return {?}
*/
list => {
this.selected = isNotNil(list.find((/**
* @param {?} v
* @return {?}
*/
v => this.nzSelectService.compareWith(v, this.nzOption.nzValue))));
this.cdr.markForCheck();
}));
this.nzSelectService.activatedOption$.pipe(takeUntil(this.destroy$)).subscribe((/**
* @param {?} option
* @return {?}
*/
option => {
if (option) {
this.active = this.nzSelectService.compareWith(option.nzValue, this.nzOption.nzValue);
}
else {
this.active = false;
}
this.cdr.markForCheck();
}));
}
/**
* @return {?}
*/
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
}
NzOptionLiComponent.decorators = [
{ type: Component, args: [{
selector: '[nz-option-li]',
template: "<ng-container *ngIf=\"!nzOption.nzCustomContent; else nzOption.template\">\n {{nzOption.nzLabel}}\n</ng-container>\n<ng-container *ngIf=\"nzSelectService.isMultipleOrTags\">\n <i nz-icon type=\"check\" class=\"ant-select-selected-icon\" *ngIf=\"!nzMenuItemSelectedIcon; else nzMenuItemSelectedIcon\"></i>\n</ng-container>\n",
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
host: {
'[class.ant-select-dropdown-menu-item-selected]': 'selected && !nzOption.nzDisabled',
'[class.ant-select-dropdown-menu-item-disabled]': 'nzOption.nzDisabled',
'[class.ant-select-dropdown-menu-item-active]': 'active && !nzOption.nzDisabled',
'[attr.unselectable]': '"unselectable"',
'[style.user-select]': '"none"',
'(click)': 'clickOption()',
'(mousedown)': '$event.preventDefault()'
}
}] }
];
/** @nocollapse */
NzOptionLiComponent.ctorParameters = () => [
{ type: ElementRef },
{ type: NzSelectService },
{ type: ChangeDetectorRef },
{ type: Renderer2 }
];
NzOptionLiComponent.propDecorators = {
nzOption: [{ type: Input }],
nzMenuItemSelectedIcon: [{ type: Input }]
};
if (false) {
/** @type {?} */
NzOptionLiComponent.prototype.el;
/** @type {?} */
NzOptionLiComponent.prototype.selected;
/** @type {?} */
NzOptionLiComponent.prototype.active;
/** @type {?} */
NzOptionLiComponent.prototype.destroy$;
/** @type {?} */
NzOptionLiComponent.prototype.nzOption;
/** @type {?} */
NzOptionLiComponent.prototype.nzMenuItemSelectedIcon;
/**
* @type {?}
* @private
*/
NzOptionLiComponent.prototype.elementRef;
/** @type {?} */
NzOptionLiComponent.prototype.nzSelectService;
/**
* @type {?}
* @private
*/
NzOptionLiComponent.prototype.cdr;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnotb3B0aW9uLWxpLmNvbXBvbmVudC5qcyIsInNvdXJjZVJvb3QiOiJuZzovL25nLXpvcnJvLWFudGQteWovIiwic291cmNlcyI6WyJzZWxlY3Qvbnotb3B0aW9uLWxpLmNvbXBvbmVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjo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