UNPKG

@ng-flexy/form-bootstrap

Version:

Flexy components and tools to build Angular 8+ applications

159 lines (158 loc) 13.2 kB
import { Component, Input, ViewChild } from '@angular/core'; import { isRequired as checkIfRequired } from '@ng-flexy/form'; import * as i0 from "@angular/core"; import * as i1 from "@angular/common"; import * as i2 from "ngx-bootstrap/tooltip"; import * as i3 from "./field-info.component"; import * as i4 from "@ngx-translate/core"; const _c0 = ["fieldContainerRef"]; function FlexyFieldComponent_label_2_i_1_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelement(0, "i"); } if (rf & 2) { const ctx_r4 = i0.ɵɵnextContext(2); i0.ɵɵclassMap(ctx_r4.labelIcon); } } function FlexyFieldComponent_label_2_span_4_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelementStart(0, "span", 8); i0.ɵɵpipe(1, "translate"); i0.ɵɵtext(2, "("); i0.ɵɵelementStart(3, "b"); i0.ɵɵtext(4, "*"); i0.ɵɵelementEnd(); i0.ɵɵtext(5, ")"); i0.ɵɵelementEnd(); } if (rf & 2) { i0.ɵɵproperty("tooltip", i0.ɵɵpipeBind1(1, 1, "FLEXY_FORM_FIELD_IS_REQUIRED")); } } const _c1 = function (a0) { return { "not-empty": a0 }; }; function FlexyFieldComponent_label_2_Template(rf, ctx) { if (rf & 1) { const _r7 = i0.ɵɵgetCurrentView(); i0.ɵɵelementStart(0, "label", 6); i0.ɵɵlistener("click", function FlexyFieldComponent_label_2_Template_label_click_0_listener($event) { i0.ɵɵrestoreView(_r7); const ctx_r6 = i0.ɵɵnextContext(); ctx_r6.focusControl(); return $event.stopPropagation(); }); i0.ɵɵtemplate(1, FlexyFieldComponent_label_2_i_1_Template, 1, 2, "i", 7); i0.ɵɵtext(2); i0.ɵɵpipe(3, "translate"); i0.ɵɵtemplate(4, FlexyFieldComponent_label_2_span_4_Template, 6, 3, "span", 3); i0.ɵɵelementEnd(); } if (rf & 2) { const ctx_r1 = i0.ɵɵnextContext(); i0.ɵɵproperty("ngClass", i0.ɵɵpureFunction1(8, _c1, ctx_r1.control.value || ctx_r1.control.value === 0)); i0.ɵɵattribute("data-rel-name", ctx_r1.name); i0.ɵɵadvance(1); i0.ɵɵproperty("ngIf", ctx_r1.labelIcon); i0.ɵɵadvance(1); i0.ɵɵtextInterpolate2(" ", i0.ɵɵpipeBind1(3, 6, ctx_r1.label), "", ctx_r1.label[ctx_r1.label.length - 1] !== ":" ? ":" : "", " "); i0.ɵɵadvance(2); i0.ɵɵproperty("ngIf", ctx_r1.isRequired); } } function FlexyFieldComponent_label_3_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelementStart(0, "label", 8); i0.ɵɵpipe(1, "translate"); i0.ɵɵtext(2, "("); i0.ɵɵelementStart(3, "b"); i0.ɵɵtext(4, "*"); i0.ɵɵelementEnd(); i0.ɵɵtext(5, ")"); i0.ɵɵelementEnd(); } if (rf & 2) { i0.ɵɵproperty("tooltip", i0.ɵɵpipeBind1(1, 1, "FLEXY_FORM_FIELD_IS_REQUIRED")); } } function FlexyFieldComponent_flexy_form_field_info_6_Template(rf, ctx) { if (rf & 1) { i0.ɵɵelement(0, "flexy-form-field-info", 9); } if (rf & 2) { const ctx_r3 = i0.ɵɵnextContext(); i0.ɵɵproperty("control", ctx_r3.control)("description", ctx_r3.description); } } const _c2 = function (a0, a1, a2) { return { "has-error": a0, "has-success": a1, "is-required": a2 }; }; const _c3 = ["*"]; export class FlexyFieldComponent { constructor() { } ngOnInit() { if (this.control) { this.isRequired = checkIfRequired(this.control); } } focusControl() { if (this.control && this.fieldContainerRef && this.fieldContainerRef.nativeElement) { let inputs = this.fieldContainerRef.nativeElement.getElementsByTagName('input'); if (!inputs[0]) { inputs = this.fieldContainerRef.nativeElement.getElementsByTagName('textarea'); } if (inputs[0]) { inputs[0].focus(); } } } } FlexyFieldComponent.ɵfac = function FlexyFieldComponent_Factory(t) { return new (t || FlexyFieldComponent)(); }; FlexyFieldComponent.ɵcmp = i0.ɵɵdefineComponent({ type: FlexyFieldComponent, selectors: [["flexy-form-field"]], viewQuery: function FlexyFieldComponent_Query(rf, ctx) { if (rf & 1) { i0.ɵɵviewQuery(_c0, true); } if (rf & 2) { var _t; i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.fieldContainerRef = _t.first); } }, inputs: { control: "control", name: "name", label: "label", labelIcon: "labelIcon", description: "description" }, ngContentSelectors: _c3, decls: 7, vars: 8, consts: [[1, "flexy-field", 3, "ngClass"], ["fieldContainerRef", ""], ["class", "flexy-field-label", 3, "ngClass", "click", 4, "ngIf"], ["class", "isRequired", 3, "tooltip", 4, "ngIf"], [1, "flexy-field-control"], [3, "control", "description", 4, "ngIf"], [1, "flexy-field-label", 3, "ngClass", "click"], [3, "class", 4, "ngIf"], [1, "isRequired", 3, "tooltip"], [3, "control", "description"]], template: function FlexyFieldComponent_Template(rf, ctx) { if (rf & 1) { i0.ɵɵprojectionDef(); i0.ɵɵelementStart(0, "div", 0, 1); i0.ɵɵtemplate(2, FlexyFieldComponent_label_2_Template, 5, 10, "label", 2); i0.ɵɵtemplate(3, FlexyFieldComponent_label_3_Template, 6, 3, "label", 3); i0.ɵɵelementStart(4, "div", 4); i0.ɵɵprojection(5); i0.ɵɵtemplate(6, FlexyFieldComponent_flexy_form_field_info_6_Template, 1, 2, "flexy-form-field-info", 5); i0.ɵɵelementEnd(); i0.ɵɵelementEnd(); } if (rf & 2) { i0.ɵɵproperty("ngClass", i0.ɵɵpureFunction3(4, _c2, (ctx.control == null ? null : ctx.control.dirty) && !ctx.control.pending && !ctx.control.valid, (ctx.control == null ? null : ctx.control.dirty) && !(!ctx.control.pending && !ctx.control.valid), ctx.isRequired)); i0.ɵɵadvance(2); i0.ɵɵproperty("ngIf", ctx.label); i0.ɵɵadvance(1); i0.ɵɵproperty("ngIf", !ctx.label && ctx.isRequired); i0.ɵɵadvance(3); i0.ɵɵproperty("ngIf", ctx.control); } }, directives: [i1.NgClass, i1.NgIf, i2.TooltipDirective, i3.FlexyFieldControlInfoComponent], pipes: [i4.TranslatePipe], encapsulation: 2 }); /*@__PURE__*/ (function () { i0.ɵsetClassMetadata(FlexyFieldComponent, [{ type: Component, args: [{ selector: 'flexy-form-field', template: ` <div class="flexy-field" [ngClass]="{ 'has-error': control?.dirty && !control.pending && !control.valid, 'has-success': control?.dirty && !(!control.pending && !control.valid), 'is-required': isRequired }" #fieldContainerRef > <label *ngIf="label" class="flexy-field-label" [ngClass]="{ 'not-empty': control.value || control.value === 0 }" (click)="focusControl(); $event.stopPropagation()" [attr.data-rel-name]="name" > <i *ngIf="labelIcon" [class]="labelIcon"></i> {{ label | translate }}{{ label[label.length - 1] !== ':' ? ':' : '' }} <span *ngIf="isRequired" class="isRequired" [tooltip]="'FLEXY_FORM_FIELD_IS_REQUIRED' | translate">(<b>*</b>)</span> </label> <label *ngIf="!label && isRequired" class="isRequired" [tooltip]="'FLEXY_FORM_FIELD_IS_REQUIRED' | translate">(<b>*</b>)</label> <div class="flexy-field-control"> <ng-content></ng-content> <flexy-form-field-info *ngIf="control" [control]="control" [description]="description"></flexy-form-field-info> </div> </div> ` }] }], function () { return []; }, { control: [{ type: Input }], name: [{ type: Input }], label: [{ type: Input }], labelIcon: [{ type: Input }], description: [{ type: Input }], fieldContainerRef: [{ type: ViewChild, args: ['fieldContainerRef'] }] }); })(); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmllbGQuY29tcG9uZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vcHJvamVjdHMvZm9ybS1ib290c3RyYXAvc3JjL2xpYi9jb21wb25lbnRzL2ZpZWxkLmNvbXBvbmVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsU0FBUyxFQUFFLEtBQUssRUFBVSxTQUFTLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFFcEUsT0FBTyxFQUFFLFVBQVUsSUFBSSxlQUFlLEVBQUUsTUFBT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