-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(workbench-client-testing-app): consolidate theme activation
- Loading branch information
1 parent
056bcde
commit 7e26d55
Showing
4 changed files
with
46 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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 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
36 changes: 36 additions & 0 deletions
36
apps/workbench-client-testing-app/src/app/theme/workbench-theme-switcher.service.ts
This file contains 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,36 @@ | ||
import {EnvironmentProviders, inject, Injectable, makeEnvironmentProviders} from '@angular/core'; | ||
import {DOCUMENT} from '@angular/common'; | ||
import {WorkbenchTheme, WorkbenchThemeMonitor} from '@scion/workbench-client'; | ||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop'; | ||
import {WORKBENCH_POST_CONNECT} from '../workbench-client/workbench-client.provider'; | ||
|
||
/** | ||
* Switches the theme when changed in the workbench. | ||
*/ | ||
@Injectable(/* DO NOT PROVIDE via 'providedIn' metadata as associated with the {@link WORKBENCH_POST_CONNECT} DI token. */) | ||
class WorkbenchThemeSwitcher { | ||
|
||
constructor(workbenchThemeMonitor: WorkbenchThemeMonitor) { | ||
const documentRoot = inject<Document>(DOCUMENT).documentElement; | ||
|
||
workbenchThemeMonitor.theme$ | ||
.pipe(takeUntilDestroyed()) | ||
.subscribe((theme: WorkbenchTheme | null) => { | ||
if (theme) { | ||
documentRoot.setAttribute('sci-theme', theme.name); | ||
} | ||
else { | ||
documentRoot.removeAttribute('sci-theme'); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Registers a set of DI providers to set up workbench theme. | ||
*/ | ||
export function provideWorkbenchTheme(): EnvironmentProviders { | ||
return makeEnvironmentProviders([ | ||
{provide: WORKBENCH_POST_CONNECT, useClass: WorkbenchThemeSwitcher, multi: true}, | ||
]); | ||
} |
This file contains 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