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