Skip to content

Commit

Permalink
fix(docs-app): adjusting how docs pulls active theme (#2109)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <[email protected]>
  • Loading branch information
owilliams320 and github-actions authored Feb 27, 2024
1 parent 4827c56 commit e4de3ce
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion apps/docs-app/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<td-layout #layout [class]="activeTheme" [dir]="dir">
<td-layout #layout [dir]="dir">
<td-navigation-drawer
sidenavTitle="Covalent"
logo="teradata"
Expand Down
7 changes: 0 additions & 7 deletions apps/docs-app/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,4 @@ export class DocsAppComponent {
// set direction
this.dir = getDirection();
}

get activeTheme(): string {
return localStorage.getItem('theme') ?? '';
}
theme(theme: string): void {
localStorage.setItem('theme', theme);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<button
mat-menu-item
*ngIf="activeTheme === 'theme-dark'"
(click)="theme('default-theme')"
(click)="theme('theme-light')"
>
<mat-icon>brightness_high</mat-icon>
<span>Light Mode</span>
Expand Down
18 changes: 16 additions & 2 deletions apps/docs-app/src/app/components/toolbar/toolbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ export class ToolbarComponent implements OnInit {
private _dir: Dir,
@Inject(DOCUMENT) private _document: any
) {
const localTheme = localStorage.getItem('theme');

this._dir.dir = this.dir;

// Set active theme from user dark theme preference if not set locally
this.activeTheme =
localTheme ??
(window.matchMedia &&
window.matchMedia('(prefers-color-scheme: dark)').matches
? 'theme-dark'
: 'theme-light');
}

async ngOnInit(): Promise<void> {
Expand All @@ -53,8 +63,12 @@ export class ToolbarComponent implements OnInit {
get activeTheme(): string | null {
return localStorage.getItem('theme');
}
set activeTheme(theme: string) {
localStorage.setItem('theme', theme);
set activeTheme(activeTheme: string) {
document.querySelector('body')?.classList.remove('theme-dark');
document.querySelector('body')?.classList.remove('theme-light');

localStorage.setItem('theme', activeTheme);
document.querySelector('body')?.classList.add(activeTheme);
}

theme(theme: string): void {
Expand Down

0 comments on commit e4de3ce

Please sign in to comment.