37 lines
863 B
TypeScript
Raw Normal View History

/* tslint:disable:member-ordering */
// #docplaster
// #docregion
// #docregion imports
import { Directive, ElementRef, HostListener, Input } from '@angular/core';
// #enddocregion imports
@Directive({
2016-06-13 00:41:33 +02:00
selector: '[myHighlight]'
})
export class HighlightDirective {
constructor(private el: ElementRef) { }
2016-03-26 12:18:13 -04:00
// #docregion defaultColor
@Input() defaultColor: string;
// #enddocregion defaultColor
2016-03-26 12:18:13 -04:00
// #docregion color
@Input('myHighlight') highlightColor: string;
// #enddocregion color
// #docregion mouse-enter
2016-06-13 00:41:33 +02:00
@HostListener('mouseenter') onMouseEnter() {
this.highlight(this.highlightColor || this.defaultColor || 'red');
2016-06-13 00:41:33 +02:00
}
// #enddocregion mouse-enter
2016-06-13 00:41:33 +02:00
@HostListener('mouseleave') onMouseLeave() {
this.highlight(null);
}
private highlight(color: string) {
this.el.nativeElement.style.backgroundColor = color;
}
}