-
Notifications
You must be signed in to change notification settings - Fork 27.5k
feat(docs-infra): add an angry Angie theme-toggle easter egg #69736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
erkamyaman
wants to merge
1
commit into
angular:main
Choose a base branch
from
erkamyaman:angie-theme-toggle-easter-egg
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+397
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
10 changes: 10 additions & 0 deletions
10
adev/src/app/core/layout/angry-angie/angry-angie.component.html
This file contains hidden or 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,10 @@ | ||
| @if (angie.show()) { | ||
| <div | ||
| class="adev-angry-angie" | ||
| animate.enter="adev-angry-angie--entering" | ||
| animate.leave="adev-angry-angie--leaving" | ||
| aria-hidden="true" | ||
| > | ||
| <img src="assets/images/angie/angry.svg" alt="" /> | ||
| </div> | ||
| } |
66 changes: 66 additions & 0 deletions
66
adev/src/app/core/layout/angry-angie/angry-angie.component.scss
This file contains hidden or 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,66 @@ | ||
| .adev-angry-angie { | ||
| position: fixed; | ||
| inset: 0; | ||
| z-index: var(--z-index-easter-egg); | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| pointer-events: none; | ||
|
|
||
| img { | ||
| display: block; | ||
| width: min(340px, 60vw); | ||
| height: auto; | ||
| animation: adev-angry-angie-shake 0.8s ease-in-out 0.35s 3; | ||
| } | ||
| } | ||
|
|
||
| .adev-angry-angie--entering { | ||
| animation: adev-angry-angie-in 0.35s ease-out; | ||
| } | ||
|
|
||
| .adev-angry-angie--leaving { | ||
| animation: adev-angry-angie-out 0.3s ease-in forwards; | ||
| } | ||
|
|
||
| @keyframes adev-angry-angie-in { | ||
| from { | ||
| opacity: 0; | ||
| transform: scale(0.5); | ||
| } | ||
| to { | ||
| opacity: 1; | ||
| transform: scale(1); | ||
| } | ||
| } | ||
|
|
||
| @keyframes adev-angry-angie-out { | ||
| from { | ||
| opacity: 1; | ||
| transform: scale(1); | ||
| } | ||
| to { | ||
| opacity: 0; | ||
| transform: scale(0.5); | ||
| } | ||
| } | ||
|
|
||
| @keyframes adev-angry-angie-shake { | ||
| from, | ||
| to { | ||
| transform: translate3d(0, 0, 0); | ||
| } | ||
| 10%, | ||
| 30%, | ||
| 50%, | ||
| 70%, | ||
| 90% { | ||
| transform: translate3d(-8px, 0, 0); | ||
| } | ||
| 20%, | ||
| 40%, | ||
| 60%, | ||
| 80% { | ||
| transform: translate3d(8px, 0, 0); | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
adev/src/app/core/layout/angry-angie/angry-angie.component.spec.ts
This file contains hidden or 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,43 @@ | ||
| /*! | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import {signal} from '@angular/core'; | ||
| import {ComponentFixture, TestBed} from '@angular/core/testing'; | ||
| import {By} from '@angular/platform-browser'; | ||
|
|
||
| import {AngryAngie} from '../../services/angry-angie.service'; | ||
| import {AngryAngieComponent} from './angry-angie.component'; | ||
|
|
||
| describe('AngryAngieComponent', () => { | ||
| const fakeAngie = {show: signal(false)}; | ||
| let fixture: ComponentFixture<AngryAngieComponent>; | ||
|
|
||
| beforeEach(async () => { | ||
| fakeAngie.show.set(false); | ||
| TestBed.configureTestingModule({ | ||
| imports: [AngryAngieComponent], | ||
| providers: [{provide: AngryAngie, useValue: fakeAngie}], | ||
| }); | ||
| fixture = TestBed.createComponent(AngryAngieComponent); | ||
| await fixture.whenStable(); | ||
| }); | ||
|
|
||
| const overlay = () => fixture.debugElement.query(By.css('.adev-angry-angie')); | ||
|
|
||
| it('renders nothing while the easter egg is hidden', () => { | ||
| expect(overlay()).toBeNull(); | ||
| }); | ||
|
|
||
| it('renders the overlay while the easter egg is showing', async () => { | ||
| fakeAngie.show.set(true); | ||
| await fixture.whenStable(); | ||
|
|
||
| expect(overlay()).not.toBeNull(); | ||
| expect(overlay().query(By.css('img'))).not.toBeNull(); | ||
| }); | ||
| }); |
20 changes: 20 additions & 0 deletions
20
adev/src/app/core/layout/angry-angie/angry-angie.component.ts
This file contains hidden or 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 @@ | ||
| /*! | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import {Component, inject} from '@angular/core'; | ||
|
|
||
| import {AngryAngie} from '../../services/angry-angie.service'; | ||
|
|
||
| @Component({ | ||
| selector: 'adev-angry-angie', | ||
| templateUrl: './angry-angie.component.html', | ||
| styleUrl: './angry-angie.component.scss', | ||
| }) | ||
| export class AngryAngieComponent { | ||
| protected readonly angie = inject(AngryAngie); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,124 @@ | ||
| /*! | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import {DOCUMENT} from '@angular/common'; | ||
| import {TestBed} from '@angular/core/testing'; | ||
| import {NavigationState} from '@angular/docs'; | ||
|
|
||
| import {AngryAngie} from './angry-angie.service'; | ||
|
|
||
| describe('AngryAngie', () => { | ||
| // Timings mirror the service's internal constants. | ||
| const TAP_WINDOW_MS = 2000; | ||
| const VISIBLE_MS = 6000; | ||
| const STROBE_MS = 400; | ||
|
|
||
| let service: AngryAngie; | ||
| let root: DOMTokenList; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({providers: [AngryAngie]}); | ||
| service = TestBed.inject(AngryAngie); | ||
| root = TestBed.inject(DOCUMENT).documentElement.classList; | ||
| root.remove('docs-dark-mode', 'docs-light-mode'); | ||
| jasmine.clock().install(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jasmine.clock().uninstall(); | ||
| root.remove('docs-dark-mode', 'docs-light-mode'); | ||
| }); | ||
|
|
||
| const tap = (times: number) => { | ||
| for (let i = 0; i < times; i++) { | ||
| service.registerTap(); | ||
| } | ||
| }; | ||
| const mockReducedMotion = (reduce: boolean) => { | ||
| const realMatchMedia = window.matchMedia.bind(window); | ||
| spyOn(window, 'matchMedia').and.callFake((query: string) => | ||
| query.includes('prefers-reduced-motion') | ||
| ? ({matches: reduce} as MediaQueryList) | ||
| : realMatchMedia(query), | ||
| ); | ||
| }; | ||
|
|
||
| it('should not trigger before the tap threshold', () => { | ||
| tap(9); | ||
| expect(service.show()).toBe(false); | ||
| }); | ||
|
|
||
| it('should trigger once the tap threshold is reached', () => { | ||
| tap(10); | ||
| expect(service.show()).toBe(true); | ||
| }); | ||
|
|
||
| it('should reset the count when taps are spaced beyond the window', () => { | ||
| tap(9); | ||
| jasmine.clock().tick(TAP_WINDOW_MS + 1); // window elapses, count resets to 0 | ||
|
|
||
| tap(9); | ||
| expect(service.show()).toBe(false); // 9 taps in the new window is still below threshold | ||
|
|
||
| tap(1); | ||
| expect(service.show()).toBe(true); // the 10th within the window fires it | ||
| }); | ||
|
|
||
| it('should hide after the visible duration', () => { | ||
| mockReducedMotion(false); | ||
| tap(10); | ||
| expect(service.show()).toBe(true); | ||
|
|
||
| jasmine.clock().tick(VISIBLE_MS); | ||
| expect(service.show()).toBe(false); | ||
| }); | ||
|
|
||
| it('should ignore further taps while it is on screen', () => { | ||
| mockReducedMotion(false); | ||
| tap(10); | ||
| expect(service.show()).toBe(true); | ||
|
|
||
| tap(10); // ignored while showing, so it stays shown rather than re-arming | ||
| expect(service.show()).toBe(true); | ||
| }); | ||
|
|
||
| it('should close the mobile nav when it fires', () => { | ||
| mockReducedMotion(false); | ||
| const navigationState = TestBed.inject(NavigationState); | ||
| navigationState.setMobileNavigationListVisibility(true); | ||
|
|
||
| tap(10); | ||
|
|
||
| expect(navigationState.isMobileNavVisible()).toBe(false); | ||
| }); | ||
|
|
||
| it('should strobe the theme while on screen and restore it afterward', () => { | ||
| mockReducedMotion(false); | ||
| root.add('docs-light-mode'); // starting theme | ||
|
|
||
| tap(10); | ||
| jasmine.clock().tick(STROBE_MS); | ||
| expect(root.contains('docs-dark-mode')).toBe(true); // flipped while on screen | ||
|
|
||
| jasmine.clock().tick(VISIBLE_MS); | ||
| expect(root.contains('docs-light-mode')).toBe(true); // restored to the starting theme | ||
| expect(root.contains('docs-dark-mode')).toBe(false); | ||
| }); | ||
|
|
||
| it('should not strobe the theme when the user prefers reduced motion', () => { | ||
| mockReducedMotion(true); | ||
| root.add('docs-dark-mode'); // starting theme | ||
|
|
||
| tap(10); | ||
| expect(service.show()).toBe(true); // she still shows | ||
|
|
||
| jasmine.clock().tick(VISIBLE_MS); | ||
| expect(root.contains('docs-dark-mode')).toBe(true); // theme untouched, no strobe | ||
| expect(root.contains('docs-light-mode')).toBe(false); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.