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