Skip to content

Commit e778775

Browse files
authored
Merge pull request #1 from Anlanther/test
refactor: added dark theme and overrides
2 parents fb96504 + 596638c commit e778775

File tree

12 files changed

+178
-76
lines changed

12 files changed

+178
-76
lines changed

src/app/components/workspace-selector/workspace-selector.component.html

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@
66
<button
77
mat-flat-button
88
(click)="toggleTheme()"
9-
class="actions button-accent"
9+
class="actions"
10+
[class.button-accent-light]="!(isDarkTheme$ | async)"
11+
[class.button-accent-dark]="isDarkTheme$ | async"
1012
>
11-
Accent Button
13+
<mat-icon>
14+
{{ (isDarkTheme$ | async) ? "light_mode" : "dark_mode" }}
15+
</mat-icon>
16+
{{ (isDarkTheme$ | async) ? "Light Theme" : "Dark Theme" }}
1217
</button>
1318
</div>
1419

15-
<mat-tab-group class="table-tabs">
20+
<mat-tab-group
21+
[class.table-tabs-light]="!(isDarkTheme$ | async)"
22+
[class.table-tabs-dark]="isDarkTheme$ | async"
23+
class="table-tabs"
24+
>
1625
<mat-tab label="First"><app-discovery-table></app-discovery-table></mat-tab>
1726
<mat-tab label="Second">
1827
<app-discovery-table></app-discovery-table>

src/app/components/workspace-selector/workspace-selector.component.scss

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,38 @@
22
@use "../../styles/vars" as vars;
33
@use "../../styles/mixins" as mixins;
44

5-
.button-accent {
5+
@mixin button($theme: "light") {
6+
$tertiary-color: if(
7+
$theme == "light",
8+
vars.$tertiary-color-light,
9+
vars.$tertiary-color-dark
10+
);
11+
612
@include mat.button-overrides(
713
(
8-
filled-container-color: vars.$tertiary-color-light,
9-
filled-label-text-color: black,
14+
filled-container-color: $tertiary-color,
15+
filled-label-text-color: vars.$text-color-black,
1016
filled-container-height: 36px,
1117
)
1218
);
1319
}
1420

15-
.table-tabs {
21+
.button-accent-light {
22+
@include button("light");
23+
}
24+
25+
.button-accent-dark {
26+
@include button("dark");
27+
}
28+
29+
.table-tabs-light {
1630
background-color: vars.$neutral-color-variant-light;
17-
@include mixins.single-color-tabs;
31+
@include mixins.single-color-tabs("light");
32+
}
33+
34+
.table-tabs-dark {
35+
background-color: vars.$neutral-color-variant-dark;
36+
@include mixins.single-color-tabs("dark");
1837
}
1938

2039
.discovery {

src/app/components/workspace-selector/workspace-selector.component.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { AsyncPipe } from '@angular/common';
12
import { Component } from '@angular/core';
23
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
34
import { MaterialModule } from '../../modules/material.module';
5+
import { ThemeService } from '../../services/theme.service';
46
import { DiscoveryTableComponent } from './discovery-table/discovery-table.component';
57

68
@Component({
@@ -10,12 +12,20 @@ import { DiscoveryTableComponent } from './discovery-table/discovery-table.compo
1012
DiscoveryTableComponent,
1113
ReactiveFormsModule,
1214
FormsModule,
15+
AsyncPipe,
1316
],
1417
templateUrl: './workspace-selector.component.html',
1518
styleUrl: './workspace-selector.component.scss',
1619
})
1720
export class WorkspaceSelectorComponent {
1821
form = new FormControl('');
22+
isDarkTheme$;
1923

20-
toggleTheme() {}
24+
constructor(private themeService: ThemeService) {
25+
this.isDarkTheme$ = this.themeService.isDarkTheme$;
26+
}
27+
28+
toggleTheme() {
29+
this.themeService.toggleTheme();
30+
}
2131
}

src/app/services/style-manager.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/app/services/theme.service.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Injectable } from '@angular/core';
2+
import { BehaviorSubject } from 'rxjs';
3+
4+
@Injectable({
5+
providedIn: 'root',
6+
})
7+
export class ThemeService {
8+
private darkThemeSubject = new BehaviorSubject<boolean>(false);
9+
isDarkTheme$ = this.darkThemeSubject.asObservable();
10+
11+
toggleTheme() {
12+
const isDarkTheme = !this.darkThemeSubject.value;
13+
this.darkThemeSubject.next(isDarkTheme);
14+
if (isDarkTheme) {
15+
document.documentElement.classList.add('dark-theme');
16+
} else {
17+
document.documentElement.classList.remove('dark-theme');
18+
}
19+
}
20+
21+
getCurrentTheme(): boolean {
22+
return this.darkThemeSubject.value;
23+
}
24+
}

src/app/styles/_mixins.scss

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,59 @@
11
@use "@angular/material" as mat;
22
@use "./vars" as vars;
33

4-
@mixin single-color-tabs {
4+
@mixin single-color-tabs($theme: "light") {
5+
$neutral-color: if(
6+
$theme == "light",
7+
vars.$neutral-color-light,
8+
vars.$neutral-color-dark
9+
);
10+
$neutral-variant: if(
11+
$theme == "light",
12+
vars.$neutral-color-variant-light,
13+
vars.$neutral-color-variant-dark
14+
);
15+
516
@include mat.tabs-overrides(
617
(
7-
divider-height: 0,
18+
background-color: $neutral-variant,
819
active-indicator-height: 100vh,
9-
active-indicator-color: vars.$neutral-color-light,
10-
active-focus-indicator-color: vars.$neutral-color-light,
11-
active-hover-indicator-color: vars.$neutral-color-light,
20+
active-indicator-color: $neutral-color,
21+
active-focus-indicator-color: $neutral-color,
22+
active-hover-indicator-color: $neutral-color,
23+
divider-height: 0,
24+
)
25+
);
26+
}
27+
28+
@mixin component-overrides($theme: "light") {
29+
$neutral-color: if(
30+
$theme == "light",
31+
vars.$neutral-color-light,
32+
vars.$neutral-color-dark
33+
);
34+
$neutral-variant: if(
35+
$theme == "light",
36+
vars.$neutral-color-variant-light,
37+
vars.$neutral-color-variant-dark
38+
);
39+
40+
@include mat.button-overrides(
41+
(
42+
filled-container-shape: vars.$border-radius,
43+
)
44+
);
45+
46+
@include mat.table-overrides(
47+
(
48+
background-color: $neutral-color,
49+
row-item-outline-width: 0,
50+
)
51+
);
52+
53+
@include mat.form-field-overrides(
54+
(
55+
filled-container-shape: vars.$border-radius,
56+
outlined-outline-color: $neutral-variant,
1257
)
1358
);
1459
}

src/app/styles/_vars.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ $neutral-color-dark: #747c89;
1212
$neutral-color-variant-dark: #414956;
1313
$error-color-dark: #d23729;
1414

15+
$text-color-black: black;
16+
$text-color-white: white;
17+
1518
$border-radius: 2px;

src/app/views/main/main.component.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
focusOnNavigation
44
mat-stretch-tabs="false"
55
[tabPanel]="panel"
6-
class="tabs"
6+
[class.tabs-light]="!(isDarkTheme$ | async)"
7+
[class.tabs-dark]="isDarkTheme$ | async"
78
>
89
@for (workspace of workspaces; track workspace) {
910
<a
@@ -12,7 +13,8 @@
1213
routerLinkActive
1314
#rla="routerLinkActive"
1415
[active]="rla.isActive"
15-
[class.isInactive]="!rla.isActive"
16+
[class.inactive-light]="!rla.isActive && !(isDarkTheme$ | async)"
17+
[class.inactive-dark]="!rla.isActive && (isDarkTheme$ | async)"
1618
>
1719
{{ workspace }}
1820
</a>

src/app/views/main/main.component.scss

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,34 @@
22
@use "../../styles/vars" as vars;
33
@use "../../styles/mixins" as mixins;
44

5-
.isInactive {
6-
background-color: var(--mat-sys-surface-variant);
5+
@mixin main-table($theme: "light") {
6+
$neutral-variant: if(
7+
$theme == "light",
8+
vars.$neutral-color-variant-light,
9+
vars.$neutral-color-variant-dark
10+
);
11+
12+
background-color: $neutral-variant;
13+
}
14+
15+
.inactive-light {
16+
@include main-table("light");
17+
border-radius: vars.$border-radius;
18+
}
19+
20+
.inactive-dark {
21+
@include main-table("dark");
722
border-radius: vars.$border-radius;
823
}
924

10-
.tabs {
25+
.tabs-light {
26+
margin: 5px 0;
27+
@include mixins.single-color-tabs("light");
28+
}
29+
30+
.tabs-dark {
1131
margin: 5px 0;
12-
@include mixins.single-color-tabs;
32+
@include mixins.single-color-tabs("dark");
1333
}
1434

1535
.gap {

0 commit comments

Comments
 (0)