-
Notifications
You must be signed in to change notification settings - Fork 1
feat: TT-332 Dark mode #746
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
63dcbc7
style: TT-332 include Tailwind in global style file
JosueOb 5a5f6f9
feat: TT-332 dark mode implementation
JosueOb b017fbd
style: TT-332 color palette
JosueOb 2d648d7
test: TT-332 unit test on the dark mode component
JosueOb 1e23038
fix: TT-216 add tabIndex attribute to materialDatePicker and to Date …
bytesantiago 13fd98a
chore(release): 1.50.5 [skip ci]nn
semantic-release-bot c63a8a0
refactor: TT-332 application of Azure toggle function to display dark…
JosueOb 8e1ec7e
style: TT-332 TW prefix added to the color palette
JosueOb 181bc76
refactor: TT-332 changes in sidebar and dark mode components
JosueOb 704ba0e
fix: TT-334 keep the sidebar item selected when the page is refreshed…
JosueOb 0125ac6
chore(release): 1.50.6 [skip ci]nn
semantic-release-bot 5ecda54
refactor: TT-332 changes to the button to change the page theme
JosueOb f6fd309
test: TT-332 unit test to check if the user has the dark-mode feature…
JosueOb ff1ded3
style: TT-332 include Tailwind in global style file
JosueOb 419ff2b
feat: TT-332 dark mode implementation
JosueOb c4ac6f7
style: TT-332 color palette
JosueOb 57f96d7
test: TT-332 unit test on the dark mode component
JosueOb 1507382
refactor: TT-332 application of Azure toggle function to display dark…
JosueOb 18997af
style: TT-332 TW prefix added to the color palette
JosueOb 1ed1c33
refactor: TT-332 changes in sidebar and dark mode components
JosueOb b99fa46
refactor: TT-332 changes to the button to change the page theme
JosueOb 1e2e392
test: TT-332 unit test to check if the user has the dark-mode feature…
JosueOb b8705dd
refactor: TT-332 changes in the unit test description of the dark mod…
JosueOb 95d1ed3
refactor: TT-332 changes in the unit test description of the dark mod…
JosueOb 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
feat: TT-332 dark mode implementation
- Loading branch information
commit 419ff2be301e49030c013aec7ca9f2b691b02563
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
16 changes: 16 additions & 0 deletions
16
src/app/modules/shared/components/dark-mode/dark-mode.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,16 @@ | ||
<button | ||
class="w-10 h-6 rounded-full bg-white flex items-center transition duration-300 focus:outline-none shadow" | ||
(click)="changeToDarkOrLightTheme()" | ||
> | ||
<div | ||
#themeToggle | ||
class="w-7 h-7 relative rounded-full transition duration-500 transform bg-yellow-300 -translate-x-1 p-1" | ||
> | ||
<ng-container *ngIf="isDarkTheme(); else elseToggle"> | ||
<img src="assets/icons/moon.svg" alt="moon icon" /> | ||
</ng-container> | ||
<ng-template #elseToggle> | ||
<img src="assets/icons/sun.svg" alt="sun icon" /> | ||
</ng-template> | ||
</div> | ||
</button> |
Empty file.
50 changes: 50 additions & 0 deletions
50
src/app/modules/shared/components/dark-mode/dark-mode.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,50 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { DarkModeComponent } from './dark-mode.component'; | ||
|
||
describe('DarkModeComponent', () => { | ||
let component: DarkModeComponent; | ||
let fixture: ComponentFixture<DarkModeComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [DarkModeComponent], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(DarkModeComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
afterEach(() => { | ||
localStorage.removeItem('theme'); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should be clear the default theme', () => { | ||
expect(component.theme).toBe('light'); | ||
}); | ||
|
||
it('should change the value of the theme property if it exists in the local storage', () => { | ||
localStorage.setItem('theme', 'dark'); | ||
component.checkThemeInLocalStorage(); | ||
expect(component.theme).toBe('dark'); | ||
}); | ||
|
||
it('should be light theme if it does not exist in local storage', () => { | ||
component.checkThemeInLocalStorage(); | ||
expect(component.theme).toBe('light'); | ||
}); | ||
|
||
it('should be changed to dark mode if the mode toggle is selected', () => { | ||
component.themeToggle.nativeElement.click(); | ||
fixture.detectChanges(); | ||
expect(component.theme).toBe('dark'); | ||
expect(localStorage.getItem('theme')).toBe('dark'); | ||
}); | ||
}); |
73 changes: 73 additions & 0 deletions
73
src/app/modules/shared/components/dark-mode/dark-mode.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,73 @@ | ||
import { AfterViewInit, ElementRef, ViewChild, Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-dark-mode', | ||
templateUrl: './dark-mode.component.html', | ||
styleUrls: ['./dark-mode.component.scss'], | ||
}) | ||
export class DarkModeComponent implements AfterViewInit { | ||
public theme = 'light'; | ||
|
||
@ViewChild('themeToggle') themeToggle: ElementRef; | ||
|
||
constructor() { | ||
this.checkThemeInLocalStorage(); | ||
this.addOrRemoveDarkMode(); | ||
} | ||
|
||
ngAfterViewInit(): void { | ||
this.switchThemeToggleStyles(this.theme); | ||
} | ||
|
||
getLocalStorageTheme(): string { | ||
return localStorage.getItem('theme') || 'light'; | ||
} | ||
|
||
setLocalStorageTheme(theme: string): void { | ||
localStorage.setItem('theme', theme); | ||
} | ||
|
||
checkThemeInLocalStorage(): void { | ||
if ('theme' in localStorage) { | ||
this.theme = this.getLocalStorageTheme(); | ||
} else { | ||
this.setLocalStorageTheme(this.theme); | ||
} | ||
} | ||
|
||
isDarkTheme(): boolean { | ||
return this.theme === 'dark' ? true : false; | ||
} | ||
|
||
addOrRemoveDarkMode(): void { | ||
if (this.isDarkTheme()) { | ||
document.documentElement.classList.add('dark'); | ||
} else { | ||
document.documentElement.classList.remove('dark'); | ||
} | ||
} | ||
|
||
changeToDarkOrLightTheme(): void { | ||
if (this.isDarkTheme()) { | ||
this.theme = 'light'; | ||
} else { | ||
this.theme = 'dark'; | ||
} | ||
this.setLocalStorageTheme(this.theme); | ||
this.switchThemeToggleStyles(this.theme); | ||
this.addOrRemoveDarkMode(); | ||
} | ||
|
||
switchThemeToggleStyles(theme: string): void { | ||
switch (theme) { | ||
case 'dark': | ||
this.themeToggle.nativeElement.classList.remove('bg-yellow-300', '-translate-x-1'); | ||
this.themeToggle.nativeElement.classList.add('bg-gray-300', 'translate-x-1/2'); | ||
break; | ||
case 'light': | ||
this.themeToggle.nativeElement.classList.remove('bg-gray-300', 'translate-x-1/2'); | ||
this.themeToggle.nativeElement.classList.add('bg-yellow-300', '-translate-x-1'); | ||
break; | ||
} | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a space after .dark-mode-toggle
.dark-mode-toggle {