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
feat: TT-332 dark mode implementation
  • Loading branch information
JosueOb committed Sep 13, 2021
commit 419ff2be301e49030c013aec7ca9f2b691b02563
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import { TechnologyReportComponent } from './modules/technology-report/pages/tec
import { CalendarComponent } from './modules/time-entries/components/calendar/calendar.component';
import { DropdownComponent } from './modules/shared/components/dropdown/dropdown.component';
import { NgSelectModule } from '@ng-select/ng-select';
import { DarkModeComponent } from './modules/shared/components/dark-mode/dark-mode.component';

const maskConfig: Partial<IConfig> = {
validation: false,
Expand Down Expand Up @@ -140,6 +141,7 @@ const maskConfig: Partial<IConfig> = {
TechnologyReportTableComponent,
CalendarComponent,
DropdownComponent,
DarkModeComponent,
],
imports: [
NgxMaskModule.forRoot(maskConfig),
Expand Down
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.
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 src/app/modules/shared/components/dark-mode/dark-mode.component.ts
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;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="d-flex" id="wrapper">
<div class="bg-light border-right" id="sidebar-wrapper">
<div class="d-flex dark:bg-gray" id="wrapper">
<div class="border-right dark:bg-grey-dark" id="sidebar-wrapper">
<div class="sidebar-heading" style="text-align: center">
<img src="assets/img/ioet.png" width="90" height="auto" style="padding-top: 2rem; padding-bottom: 2rem;" alt="logo" />
</div>
Expand All @@ -8,7 +8,7 @@
*ngFor="let item of itemsSidebar"
[routerLink]="item.route"
routerLinkActive=""
class="list-group-item list-group-item-action bg-light"
class="list-group-item list-group-item-action dark:bg-grey-dark dark:text-white"
[ngClass]="{active: item.active}"
>
<i class="{{ item.icon }}"></i> {{ item.text }}
Expand All @@ -20,6 +20,9 @@
<button class="btn btn-primary" id="menu-toggle">
Toggle Menu
</button>
<div class="dark-mode-toggle">
<app-dark-mode></app-dark-mode>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ body {
font-weight: bold;
text-decoration: underline;
border-color: $primary;
background-color: transparent;
}

.full-height {
Expand All @@ -62,3 +63,9 @@ body {
height: -o-calc(100vh - 12vh);
height: calc(100vh - 12vh);
}

.dark-mode-toggle{
Copy link
Collaborator

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 {

position: absolute;
left: 50%;
transform: translateX(-50%);
}
8 changes: 8 additions & 0 deletions src/assets/icons/moon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions 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.
2 changes: 1 addition & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
'./src/**/*.{html,ts}',
]
},
darkMode: false,
darkMode: 'class',
theme: {
extend: {
screens: {
Expand Down