Skip to content
Merged
Show file tree
Hide file tree
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 Sep 2, 2021
5a5f6f9
feat: TT-332 dark mode implementation
JosueOb Sep 3, 2021
b017fbd
style: TT-332 color palette
JosueOb Sep 6, 2021
2d648d7
test: TT-332 unit test on the dark mode component
JosueOb Sep 6, 2021
1e23038
fix: TT-216 add tabIndex attribute to materialDatePicker and to Date …
bytesantiago Sep 7, 2021
13fd98a
chore(release): 1.50.5 [skip ci]nn
semantic-release-bot Sep 7, 2021
c63a8a0
refactor: TT-332 application of Azure toggle function to display dark…
JosueOb Sep 8, 2021
8e1ec7e
style: TT-332 TW prefix added to the color palette
JosueOb Sep 8, 2021
181bc76
refactor: TT-332 changes in sidebar and dark mode components
JosueOb Sep 8, 2021
704ba0e
fix: TT-334 keep the sidebar item selected when the page is refreshed…
JosueOb Sep 9, 2021
0125ac6
chore(release): 1.50.6 [skip ci]nn
semantic-release-bot Sep 9, 2021
5ecda54
refactor: TT-332 changes to the button to change the page theme
JosueOb Sep 10, 2021
f6fd309
test: TT-332 unit test to check if the user has the dark-mode feature…
JosueOb Sep 11, 2021
ff1ded3
style: TT-332 include Tailwind in global style file
JosueOb Sep 2, 2021
419ff2b
feat: TT-332 dark mode implementation
JosueOb Sep 3, 2021
c4ac6f7
style: TT-332 color palette
JosueOb Sep 6, 2021
57f96d7
test: TT-332 unit test on the dark mode component
JosueOb Sep 6, 2021
1507382
refactor: TT-332 application of Azure toggle function to display dark…
JosueOb Sep 8, 2021
18997af
style: TT-332 TW prefix added to the color palette
JosueOb Sep 8, 2021
1ed1c33
refactor: TT-332 changes in sidebar and dark mode components
JosueOb Sep 8, 2021
b99fa46
refactor: TT-332 changes to the button to change the page theme
JosueOb Sep 10, 2021
1e2e392
test: TT-332 unit test to check if the user has the dark-mode feature…
JosueOb Sep 11, 2021
b8705dd
refactor: TT-332 changes in the unit test description of the dark mod…
JosueOb Sep 13, 2021
95d1ed3
refactor: TT-332 changes in the unit test description of the dark mod…
JosueOb Sep 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: TT-332 changes to the button to change the page theme
  • Loading branch information
JosueOb committed Sep 13, 2021
commit b99fa466d1283569847768b3f750b38415c8869a
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
<button
class="w-10 h-6 rounded-full bg-grayTW-lightest flex items-center transition duration-300 focus:outline-none shadow"
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
#themeToggle
class="w-7 h-7 relative rounded-full transition duration-500 transform bg-warningTW -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>
<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>
Empty file.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed} from '@angular/core/testing';
import { DarkModeComponent } from './dark-mode.component';

describe('DarkModeComponent', () => {
let component: DarkModeComponent;
let fixture: ComponentFixture<DarkModeComponent>;
let html: HTMLElement;

beforeEach(async () => {
await TestBed.configureTestingModule({
Expand All @@ -14,6 +15,7 @@ describe('DarkModeComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(DarkModeComponent);
component = fixture.componentInstance;
html = document.documentElement;
fixture.detectChanges();
});

Expand Down Expand Up @@ -57,24 +59,21 @@ describe('DarkModeComponent', () => {
component.theme = 'dark';
component.addOrRemoveDarkMode();
fixture.detectChanges();
const htmlContainsDarkClass = document.documentElement.classList.contains('dark');
expect(htmlContainsDarkClass).toBe(true);
expect(html.classList.contains('dark')).toBe(true);
});

it('should be changed to dark mode if the mode toggle is selected', () => {
component.isFeatureToggleDarkModeActive = true;
fixture.detectChanges();
component.themeToggle.nativeElement.click();
it('should not have dark class in the html tag when theme is light', () => {
component.addOrRemoveDarkMode();
fixture.detectChanges();
expect(component.theme).toEqual('dark');
expect(localStorage.getItem('theme')).toEqual('dark');
expect(component.theme).toEqual('light');
expect(html.classList.contains('dark')).toBe(false);
});

it('call switchThemeToggleStyles() when ngAfterViewInit is called and isFeatureToggleDarkModeActive is true', () => {
component.isFeatureToggleDarkModeActive = true;
fixture.detectChanges();
component.ngAfterViewInit();
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.themeToggle.nativeElement.classList.contains('bg-warningTW')).toBe(true);
expect(component.theme).toEqual('dark');
expect(localStorage.getItem('theme')).toEqual('dark');
expect(html.classList.contains('dark')).toBe(true);
});
});
34 changes: 7 additions & 27 deletions src/app/modules/shared/components/dark-mode/dark-mode.component.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,29 @@
import { AfterViewInit, ElementRef, ViewChild, Component, OnInit } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { CookieService } from 'ngx-cookie-service';
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',
styleUrls: ['./dark-mode.component.scss'],
})
export class DarkModeComponent implements OnInit, AfterViewInit {
export class DarkModeComponent implements OnInit {
public theme = 'light';
public isFeatureToggleDarkModeActive: boolean;

@ViewChild('themeToggle') themeToggle: ElementRef;

constructor(
private cookiesService: CookieService,
private featureToggleGeneralService: FeatureToggleGeneralService
) {}

ngOnInit(): void {
ngOnInit() {
this.featureToggleGeneralService.getActivated().subscribe(() => {
this.isFeatureToggleDarkModeActive = this.cookiesService.get(FeatureToggle.DARK_MODE) === 'true';
if (this.isFeatureToggleDarkModeActive) {
this.checkThemeInLocalStorage();
this.addOrRemoveDarkMode();
}
});
if (this.isFeatureToggleDarkModeActive) {
this.checkThemeInLocalStorage();
this.addOrRemoveDarkMode();
}
}

ngAfterViewInit(): void {
if (this.isFeatureToggleDarkModeActive) {
this.switchThemeToggleStyles();
}
}

getLocalStorageTheme(): string {
Expand Down Expand Up @@ -70,17 +61,6 @@ export class DarkModeComponent implements OnInit, AfterViewInit {
changeToDarkOrLightTheme(): void {
this.theme = this.setTheme();
this.setLocalStorageTheme(this.theme);
this.switchThemeToggleStyles();
this.addOrRemoveDarkMode();
}

switchThemeToggleStyles(): void {
if (this.isDarkTheme()) {
this.themeToggle.nativeElement.classList.remove('bg-warningTW', '-translate-x-1');
this.themeToggle.nativeElement.classList.add('bg-grayTW-lighter', 'translate-x-1/2');
} else {
this.themeToggle.nativeElement.classList.remove('bg-grayTW-lighter', 'translate-x-1/2');
this.themeToggle.nativeElement.classList.add('bg-warningTW', '-translate-x-1');
}
}
}
2 changes: 1 addition & 1 deletion src/assets/icons/sun.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.