UNPKG

elaw-common

Version:

Angular common directives library with clickable, click-outside and auto-focus directives

108 lines (101 loc) 5.05 kB
import * as i0 from '@angular/core'; import { Directive, Input, HostListener, EventEmitter, Output } from '@angular/core'; class ClickableDirective { constructor(elementRef, renderer) { this.elementRef = elementRef; this.renderer = renderer; this.isActive = true; } mouseover() { if (this.isActive) { this.renderer.setStyle(this.elementRef.nativeElement, 'opacity', '0.8'); this.renderer.setStyle(this.elementRef.nativeElement, 'transform', 'scale(1.03)'); this.renderer.setStyle(this.elementRef.nativeElement, 'cursor', 'pointer'); } else { this.renderer.setStyle(this.elementRef.nativeElement, 'cursor', 'default'); } } mouseleave() { if (this.isActive) { this.renderer.setStyle(this.elementRef.nativeElement, 'opacity', '1'); this.renderer.setStyle(this.elementRef.nativeElement, 'transform', 'scale(1)'); } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ClickableDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.3.12", type: ClickableDirective, isStandalone: true, selector: "[appClickable]", inputs: { isActive: "isActive" }, host: { listeners: { "mouseenter": "mouseover()", "mouseleave": "mouseleave()" } }, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ClickableDirective, decorators: [{ type: Directive, args: [{ selector: '[appClickable]', standalone: true }] }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.Renderer2 }], propDecorators: { isActive: [{ type: Input }], mouseover: [{ type: HostListener, args: ['mouseenter'] }], mouseleave: [{ type: HostListener, args: ['mouseleave'] }] } }); class ClickOutsideDirective { constructor(elementRef) { this.elementRef = elementRef; this.clickOutside = new EventEmitter(); this.wasInside = false; } onMouseDown(target) { this.wasInside = this.elementRef.nativeElement.contains(target); } onClick(target) { if (!this.wasInside && !this.elementRef.nativeElement.contains(target)) { this.clickOutside.emit(); } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ClickOutsideDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.3.12", type: ClickOutsideDirective, isStandalone: true, selector: "[appClickOutside]", outputs: { clickOutside: "clickOutside" }, host: { listeners: { "document:mousedown": "onMouseDown($event.target)", "document:click": "onClick($event.target)" } }, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: ClickOutsideDirective, decorators: [{ type: Directive, args: [{ selector: '[appClickOutside]', standalone: true }] }], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { clickOutside: [{ type: Output }], onMouseDown: [{ type: HostListener, args: ['document:mousedown', ['$event.target']] }], onClick: [{ type: HostListener, args: ['document:click', ['$event.target']] }] } }); class AutoFocusDirective { constructor(el) { this.el = el; } ngAfterViewInit() { setTimeout(() => { this.el.nativeElement.focus(); }); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: AutoFocusDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.3.12", type: AutoFocusDirective, isStandalone: true, selector: "[appAutoFocus]", ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: AutoFocusDirective, decorators: [{ type: Directive, args: [{ selector: '[appAutoFocus]', standalone: true }] }], ctorParameters: () => [{ type: i0.ElementRef }] }); /* * Public API Surface of common */ /** * Generated bundle index. Do not edit. */ export { AutoFocusDirective, ClickOutsideDirective, ClickableDirective }; //# sourceMappingURL=elaw-common.mjs.map