-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
9 changed files
with
106 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import { ElementRef, Renderer2 } from '@angular/core'; | ||
import { NesIconDirective } from './icon.directive'; | ||
|
||
describe('IconDirective', () => { | ||
it('should create an instance', () => { | ||
const directive = new NesIconDirective(); | ||
const mockElementRef = {} as ElementRef<HTMLElement>; | ||
const mockRenderer2 = {} as Renderer2; | ||
const directive = new NesIconDirective(mockElementRef, mockRenderer2); | ||
expect(directive).toBeTruthy(); | ||
}); | ||
}); |
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,2 @@ | ||
export * from './pixel-art.directive'; | ||
export * from './pixel-art.module'; |
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,11 @@ | ||
import { ElementRef, Renderer2 } from '@angular/core'; | ||
import { NesPixelArtDirective } from './pixel-art.directive'; | ||
|
||
describe('PixelArtDirective', () => { | ||
it('should create an instance', () => { | ||
const mockElementRef = {} as ElementRef<HTMLElement>; | ||
const mockRenderer2 = {} as Renderer2; | ||
const directive = new NesPixelArtDirective(mockElementRef, mockRenderer2); | ||
expect(directive).toBeTruthy(); | ||
}); | ||
}); |
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,48 @@ | ||
import { Directive, ElementRef, Input, OnChanges, Renderer2, SimpleChanges } from '@angular/core'; | ||
|
||
export type NesPixelArt | ||
= 'nes-logo' | ||
| 'nes-jp-logo' | ||
| 'snes-logo' | ||
| 'snes-jp-logo' | ||
| 'nes-octocat' | ||
| 'nes-octocat-animate' | ||
| 'nes-smartphone' | ||
| 'nes-phone'; | ||
|
||
const PIXELART_CLASSLIST_MAP = new Map<NesPixelArt, string[]>([ | ||
['nes-octocat-animate', ['nes-octocat', 'animate']], | ||
]); | ||
|
||
@Directive({ | ||
selector: '[nes-pixel-art]', | ||
}) | ||
export class NesPixelArtDirective implements OnChanges { | ||
@Input('pixel-art') pixelArt?: NesPixelArt; | ||
|
||
constructor( | ||
private readonly _elementRef: ElementRef<HTMLElement>, | ||
private readonly _renderer: Renderer2, | ||
) { } | ||
|
||
ngOnChanges(change: SimpleChanges): void { | ||
this._handlePixelArtChange(change); | ||
} | ||
|
||
private _handlePixelArtChange({ pixelArt }: SimpleChanges): void { | ||
if (pixelArt == null || pixelArt.currentValue === pixelArt.previousValue) { | ||
return; | ||
} | ||
|
||
const previousClassList = PIXELART_CLASSLIST_MAP.get(pixelArt.previousValue) || [pixelArt.previousValue]; | ||
const currentClassList = PIXELART_CLASSLIST_MAP.get(pixelArt.currentValue) || [pixelArt.currentValue]; | ||
|
||
previousClassList.forEach( | ||
(cssClass) => this._renderer.removeClass(this._elementRef.nativeElement, cssClass), | ||
); | ||
|
||
currentClassList.forEach( | ||
(cssClass) => this._renderer.addClass(this._elementRef.nativeElement, cssClass), | ||
); | ||
} | ||
} |
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 { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
import { NesPixelArtDirective } from './pixel-art.directive'; | ||
|
||
const SHARED_DECLARATIONS = [ | ||
NesPixelArtDirective, | ||
]; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
...SHARED_DECLARATIONS, | ||
], | ||
imports: [ | ||
CommonModule, | ||
], | ||
exports: [ | ||
...SHARED_DECLARATIONS, | ||
], | ||
}) | ||
export class NesPixelArtModule { } |