-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c32898
commit ba04b2d
Showing
7 changed files
with
81 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Directive, ElementRef, HostListener, Input, OnInit } from '@angular/core'; | ||
|
||
@Directive({ | ||
selector: '[appBorder]', | ||
standalone: true, | ||
}) | ||
export class BorderDirective implements OnInit { | ||
@Input() color: string = 'red'; | ||
|
||
constructor(private el: ElementRef) {} | ||
|
||
ngOnInit() { | ||
this.border(''); | ||
} | ||
|
||
@HostListener('mouseenter') onMouseEnter() { | ||
this.border(this.color); | ||
} | ||
|
||
@HostListener('mouseleave') onMouseLeave() { | ||
this.border(''); | ||
} | ||
|
||
private border(color: string) { | ||
this.el.nativeElement.style.border = `2px solid ${color || 'transparent'}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/app/shared/directives/highlight-and-border.directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Directive } from '@angular/core'; | ||
import { BorderDirective } from './border.directive'; | ||
import { HighlightDirective } from './highlight.directive'; | ||
|
||
@Directive({ | ||
selector: '[appHighlightAndBorder]', | ||
hostDirectives: [ | ||
{ | ||
directive: HighlightDirective, | ||
inputs: ['color'], | ||
}, | ||
{ | ||
directive: BorderDirective, | ||
inputs: ['color'], | ||
outputs: ['tat', 'tit'], | ||
}, | ||
], | ||
standalone: true, | ||
}) | ||
export class HighlightAndBorderDirective {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Directive, ElementRef, HostListener, Input } from '@angular/core'; | ||
|
||
@Directive({ | ||
selector: '[appHighlight]', | ||
standalone: true, | ||
}) | ||
export class HighlightDirective { | ||
@Input() color = 'yellow'; | ||
|
||
constructor(private el: ElementRef) {} | ||
|
||
@HostListener('mouseenter') onMouseEnter() { | ||
this.highlight(this.color); | ||
} | ||
|
||
@HostListener('mouseleave') onMouseLeave() { | ||
this.highlight(''); | ||
} | ||
|
||
private highlight(color: string) { | ||
this.el.nativeElement.style.backgroundColor = color; | ||
} | ||
} |