UNPKG

ngx-bit

Version:

A flexible NG-ZORRO helper library

144 lines (136 loc) 6.15 kB
import { Component, ViewChild, Input, TemplateRef, NgModule } from '@angular/core'; import { BitService } from 'ngx-bit'; import { NzRadioModule } from 'ng-zorro-antd/radio'; import { FormsModule } from '@angular/forms'; import { CommonModule } from '@angular/common'; class BitErrorTipComponent { constructor() { this.hasError = {}; this.values = []; } ngOnChanges(changes) { if (changes.hasOwnProperty('hasError')) { this.values = []; const errors = changes.hasError.currentValue; for (const key in errors) { if (errors.hasOwnProperty(key)) { this.values.push({ key, error: errors[key] }); } } } } } BitErrorTipComponent.decorators = [ { type: Component, args: [{ selector: 'bit-error-tip', template: "<ng-template #ref let-control>\r\n <ng-container *ngFor=\"let value of values\">\r\n <ng-container *ngIf=\"control.hasError(value.key)\">\r\n {{value.error}}\r\n </ng-container>\r\n </ng-container>\r\n</ng-template>\r\n" },] } ]; BitErrorTipComponent.propDecorators = { ref: [{ type: ViewChild, args: ['ref', { static: true },] }], hasError: [{ type: Input }] }; class BitI18nSwitchComponent { constructor(bit) { this.bit = bit; } i18nChanged(value) { this.bit.i18nChanged.next(value); } } BitI18nSwitchComponent.decorators = [ { type: Component, args: [{ selector: 'bit-i18n-switch', template: "<ng-container *ngIf=\"bit.i18nContain.length > 1\">\n <nz-radio-group [(ngModel)]=\"bit.i18n\" (ngModelChange)=\"i18nChanged($event)\">\n <ng-container *ngFor=\"let item of bit.i18nSwitch\">\n <label nz-radio-button [nzValue]=\"item.i18n\">\n <span>\n <b>{{ item.name[bit.locale] }}</b>\n </span>\n </label>\n </ng-container>\n </nz-radio-group>\n</ng-container>\n" },] } ]; BitI18nSwitchComponent.ctorParameters = () => [ { type: BitService } ]; class BitI18nTooltipComponent { constructor(bit) { this.bit = bit; } } BitI18nTooltipComponent.decorators = [ { type: Component, args: [{ selector: 'bit-i18n-tooltip', template: "<ng-template #ref>\r\n <ng-container *ngIf=\"bit.i18nTooltip.hasOwnProperty(groupName) && bit.i18nTooltip[groupName].length !== 0;else not\">\r\n <ng-container *ngFor=\"let ID of bit.i18nTooltip[groupName];first as isFirst\">\r\n <ng-container *ngIf=\"!isFirst\">,</ng-container>\r\n <ng-container *ngIf=\"bit.l.hasOwnProperty(groupName + '_' + ID);else universal\">\r\n {{bit.l[groupName + '_' + ID]}}\r\n </ng-container>\r\n <ng-template #universal>\r\n <ng-container [ngSwitch]=\"ID\">\r\n <ng-container *ngSwitchCase=\"'zh_cn'\">\r\n {{bit.l['I18nZHCN']}}\r\n </ng-container>\r\n <ng-container *ngSwitchCase=\"'en_us'\">\r\n {{bit.l['I18nENUS']}}\r\n </ng-container>\r\n </ng-container>\r\n </ng-template>\r\n </ng-container>\r\n </ng-container>\r\n <ng-template #not>\r\n {{bit.l['I18nNoTip']}}\r\n </ng-template>\r\n</ng-template>\r\n" },] } ]; BitI18nTooltipComponent.ctorParameters = () => [ { type: BitService } ]; BitI18nTooltipComponent.propDecorators = { ref: [{ type: ViewChild, args: ['ref', { static: true },] }], groupName: [{ type: Input }] }; class BitPrintComponent { constructor() { this.values = []; this.varsMap = new Map(); } ngOnChanges(changes) { if (changes.hasOwnProperty('vars')) { if (changes.vars.currentValue) { this.varsMap = new Map(); changes.vars.currentValue.forEach((value, index) => { this.varsMap.set('$' + index, value); }); } } if (changes.hasOwnProperty('text')) { if (changes.text.currentValue) { const semi = changes.text.currentValue.replace(/\$[0-9]+/g, '**$&**'); this.values = semi.split('**').map(v => { return this.varsMap.has(v) ? this.varsMap.get(v) : v; }); } } } is(value) { return value instanceof TemplateRef; } } BitPrintComponent.decorators = [ { type: Component, args: [{ selector: 'bit-print', template: "<ng-template #ref>\r\n <ng-container *ngFor=\"let value of values\">\r\n <ng-container *ngIf=\"!is(value);else template\">\r\n {{value}}\r\n </ng-container>\r\n <ng-template #template>\r\n <ng-container *ngTemplateOutlet=\"value\"></ng-container>\r\n </ng-template>\r\n </ng-container>\r\n</ng-template>\r\n" },] } ]; BitPrintComponent.propDecorators = { ref: [{ type: ViewChild, args: ['ref', { static: true },] }], text: [{ type: Input }], vars: [{ type: Input }] }; class BitComponentModule { } BitComponentModule.decorators = [ { type: NgModule, args: [{ imports: [ FormsModule, CommonModule, NzRadioModule ], declarations: [ BitErrorTipComponent, BitI18nSwitchComponent, BitI18nTooltipComponent, BitPrintComponent ], exports: [ BitErrorTipComponent, BitI18nSwitchComponent, BitI18nTooltipComponent, BitPrintComponent ] },] } ]; /** * Generated bundle index. Do not edit. */ export { BitComponentModule, BitErrorTipComponent, BitI18nSwitchComponent, BitI18nTooltipComponent, BitPrintComponent }; //# sourceMappingURL=ngx-bit-component.js.map