ng2-ui-kit
Version:
Angular2 UI Kit
36 lines (29 loc) • 863 B
text/typescript
import { Component, Input, OnInit, ElementRef } from '@angular/core';
export class ButtonComponent implements OnInit {
size: string = '';
type: string = '';
active: boolean = false;
private el;
private class;
constructor(elementRef: ElementRef) {
this.el = elementRef.nativeElement;
}
toggle() {
this.active = !this.active;
}
ngOnInit() {
this.class = `ui-kit-button ${this.size} ${this.type}`;
let body = document.querySelector('body');
body.addEventListener('click', e => {
if (!this.active || !e.target) { return; };
if (this.el !== e.target && !this.el.contains((<any>e.target))) {
this.active = false;
}
}, false);
}
}