-
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 9 commits
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
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
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,10 @@ | ||
<button | ||
type="button" | ||
class="p-2 transition duration-150 ease-in-out bg-whiteTW rounded-md hover:bg-grayTW-lightest dark:bg-grayTW-dark dark:hover:bg-grayTW-darker dark:hover:bg-gray-700 hover:text-gray-700 focus:outline-none focus:bg-grayTW-lightest dark:focus:bg-grayTW-darker" | ||
(click)="changeToDarkOrLightTheme()" | ||
*ngIf="isFeatureToggleDarkModeActive" | ||
> | ||
<div *ngIf="isDarkTheme(); then sunIcon; else moonIcon"></div> | ||
<ng-template #moonIcon><img class="w-5 h-5" src="assets/icons/moon.svg" alt="moon icon" /></ng-template> | ||
<ng-template #sunIcon><img class="w-5 h-5" src="assets/icons/sun.svg" alt="sun icon" /></ng-template> | ||
</button> |
96 changes: 96 additions & 0 deletions
96
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,96 @@ | ||
import { ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing'; | ||
import { of } from 'rxjs'; | ||
import { delay } from 'rxjs/operators'; | ||
import { FeatureToggleGeneralService } from '../../feature-toggles/feature-toggle-general/feature-toggle-general.service'; | ||
import { FeatureToggleModel } from '../../feature-toggles/feature-toggle.model'; | ||
import { FeatureFilterModel } from '../../feature-toggles/filters/feature-filter.model'; | ||
import { DarkModeComponent } from './dark-mode.component'; | ||
|
||
describe('DarkModeComponent', () => { | ||
let component: DarkModeComponent; | ||
let fixture: ComponentFixture<DarkModeComponent>; | ||
let html: HTMLElement; | ||
let featureToggleGeneralService: FeatureToggleGeneralService; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [DarkModeComponent], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(DarkModeComponent); | ||
component = fixture.componentInstance; | ||
html = document.documentElement; | ||
featureToggleGeneralService = TestBed.inject(FeatureToggleGeneralService); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
afterEach(() => { | ||
localStorage.removeItem('theme'); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should be light the default theme', () => { | ||
expect(component.theme).toEqual('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).toEqual('dark'); | ||
}); | ||
|
||
it('should be light theme if it does not exist in local storage', () => { | ||
component.checkThemeInLocalStorage(); | ||
expect(component.theme).toEqual('light'); | ||
}); | ||
|
||
it('should be light theme if only the theme property exists in local storage and not its value', () => { | ||
localStorage.setItem('theme', ''); | ||
component.checkThemeInLocalStorage(); | ||
expect(component.theme).toEqual('light'); | ||
}); | ||
|
||
it('should switch to dark theme if the theme property is light and vice versa', () => { | ||
component.theme = component.setTheme(); | ||
expect(component.theme).toEqual('dark'); | ||
component.theme = component.setTheme(); | ||
expect(component.theme).toEqual('light'); | ||
}); | ||
|
||
it('should add the dark class in the html tag to apply dark mode', () => { | ||
component.theme = 'dark'; | ||
component.addOrRemoveDarkMode(); | ||
fixture.detectChanges(); | ||
expect(html.classList.contains('dark')).toBe(true); | ||
}); | ||
|
||
it('should not have dark class in the html tag when theme is light', () => { | ||
component.addOrRemoveDarkMode(); | ||
fixture.detectChanges(); | ||
expect(component.theme).toEqual('light'); | ||
expect(html.classList.contains('dark')).toBe(false); | ||
}); | ||
|
||
it('should change the value of the theme property, save it in the local storage and add the dark class to the HTML tag to change the theme', () => { | ||
component.changeToDarkOrLightTheme(); | ||
fixture.detectChanges(); | ||
expect(component.theme).toEqual('dark'); | ||
expect(localStorage.getItem('theme')).toEqual('dark'); | ||
expect(html.classList.contains('dark')).toBe(true); | ||
}); | ||
|
||
it('should be true the isFeatureToggleDarkModeActive property when the user has the dark-mode feature toggle enabled', fakeAsync(() => { | ||
const filters : FeatureFilterModel[] = []; | ||
const featureToggle: FeatureToggleModel = {name: 'dark-mode', enabled: true, filters}; | ||
spyOn(featureToggleGeneralService, 'getActivated').and.returnValue(of([featureToggle]).pipe(delay(1))); | ||
component.ngOnInit(); | ||
tick(1); | ||
expect(component.isFeatureToggleDarkModeActive).toBeTruthy(); | ||
})); | ||
|
||
}); |
65 changes: 65 additions & 0 deletions
65
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,65 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { FeatureToggle } from 'src/environments/enum'; | ||
import { FeatureToggleGeneralService } from '../../feature-toggles/feature-toggle-general/feature-toggle-general.service'; | ||
|
||
@Component({ | ||
selector: 'app-dark-mode', | ||
templateUrl: './dark-mode.component.html', | ||
}) | ||
export class DarkModeComponent implements OnInit { | ||
public theme = 'light'; | ||
public isFeatureToggleDarkModeActive: boolean; | ||
|
||
constructor( | ||
private featureToggleGeneralService: FeatureToggleGeneralService | ||
) {} | ||
|
||
ngOnInit() { | ||
this.featureToggleGeneralService.getActivated().subscribe((featuresToggles) => { | ||
const darkModeToggle = featuresToggles.find( (item) => item.name === FeatureToggle.DARK_MODE); | ||
this.isFeatureToggleDarkModeActive = darkModeToggle.enabled; | ||
if (this.isFeatureToggleDarkModeActive) { | ||
this.checkThemeInLocalStorage(); | ||
this.addOrRemoveDarkMode(); | ||
} | ||
}); | ||
} | ||
|
||
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; | ||
} | ||
|
||
setTheme(): string { | ||
return this.isDarkTheme() ? 'light' : 'dark'; | ||
} | ||
|
||
addOrRemoveDarkMode(): void { | ||
if (this.isDarkTheme()) { | ||
document.documentElement.classList.add('dark'); | ||
} else { | ||
document.documentElement.classList.remove('dark'); | ||
} | ||
} | ||
|
||
changeToDarkOrLightTheme(): void { | ||
this.theme = this.setTheme(); | ||
this.setLocalStorageTheme(this.theme); | ||
this.addOrRemoveDarkMode(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export enum FeatureToggle { | ||
SWITCH_GROUP = 'switch-group', | ||
TIME_TRACKER_CALENDAR = 'time-tracker-calendar' | ||
SWITCH_GROUP = 'switch-group', | ||
TIME_TRACKER_CALENDAR = 'time-tracker-calendar', | ||
DARK_MODE = 'dark-mode', | ||
} |
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
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.
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 {