UNPKG

@nbxx/nb-input

Version:
51 lines 1.79 kB
import { Directive, ElementRef, Input, Renderer2 } from "@angular/core"; export class NbStyleDirective { constructor(el, renderer) { this.el = el; this.renderer = renderer; this._css = []; this._styles = {}; } set css(val) { this._css = val ? ((typeof val == 'object' && typeof val.length == 'number') ? val : (typeof val == 'string' ? val.split(' ') : [])) : []; if (this.el && this.el.nativeElement && this.renderer) { this._css.filter(c => !!c && c.trim().length > 0).forEach(c => this.renderer.addClass(this.el.nativeElement, c)); } } set invalid(val) { if (this.el && this.el.nativeElement && this.renderer) { if (val) { this._css.forEach(() => this.renderer.addClass(this.el.nativeElement, 'invalid')); } else { this._css.forEach(() => this.renderer.removeClass(this.el.nativeElement, 'invalid')); } } } set styles(val) { this._styles = val ? val : {}; if (this.el && this.el.nativeElement && this.renderer && this._css) { Object.keys(this._styles).forEach(p => { this.renderer.setStyle(this.el.nativeElement, p, this._styles[p]); }); } } } NbStyleDirective.decorators = [ { type: Directive, args: [{ selector: '[nbStyle]' },] }, ]; /** @nocollapse */ NbStyleDirective.ctorParameters = () => [ { type: ElementRef }, { type: Renderer2 } ]; NbStyleDirective.propDecorators = { css: [{ type: Input }], invalid: [{ type: Input }], styles: [{ type: Input }] }; export class NbStyle { } //# sourceMappingURL=nb-style.directive.js.map