-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from pawcoding/feat/confetti
Confetti 🎉 🎊
- Loading branch information
Showing
12 changed files
with
118 additions
and
249 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,23 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { ConfettiService } from './confetti.service'; | ||
import { PaletteService, PaletteServiceMock } from './palette.service'; | ||
|
||
describe('ConfettiService', () => { | ||
let service: ConfettiService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{ | ||
provide: PaletteService, | ||
useClass: PaletteServiceMock | ||
} | ||
] | ||
}); | ||
service = TestBed.inject(ConfettiService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).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,38 @@ | ||
import { computed, inject, Injectable } from '@angular/core'; | ||
import confetti from 'canvas-confetti'; | ||
import { PaletteService } from './palette.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class ConfettiService { | ||
readonly #paletteService = inject(PaletteService); | ||
|
||
/** | ||
* Hex colors of the current palette | ||
*/ | ||
readonly #colors = computed<Array<string> | undefined>(() => { | ||
// Check if palette is present | ||
const palette = this.#paletteService.palette(); | ||
if (!palette || !palette.colors) { | ||
return undefined; | ||
} | ||
|
||
// Get all hex codes of all shades in palette | ||
return palette.colors.flatMap((color) => color.shades.map((shade) => shade.hex)); | ||
}); | ||
|
||
/** | ||
* Shoot confetti in the colors of the current palette | ||
*/ | ||
public confetti(configs: Array<Omit<confetti.Options, 'colors' | 'zIndex'>>): void { | ||
// Trigger all given confetti configs | ||
for (const config of configs) { | ||
confetti({ ...config, colors: this.#colors(), zIndex: 1001 }); | ||
} | ||
} | ||
} | ||
|
||
export class ConfettiServiceMock { | ||
public confetti(_configs: Array<Omit<confetti.Options, 'colors' | 'zIndex'>>): void {} | ||
} |
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
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