mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 21:33:27 +00:00
* [PM-14426] Add hideIcon input to simple dialog component * [PM-14426] Introduce dark-image-source.directive.ts * [PM-14426] Tweaks to the Vault Carousel component - Create a Carousel NgModule so that the carousel component and carousel slide component are exported - Update barrel files - Adjust min height calculation logic to wait for ;hidden slides to finish rendering before calculating height * [PM-14426] Introduce at risk password getting started carousel component and images * [PM-14426] Refactor at-risk-password-page.service.ts to use the same state definition for banner and carousel dismissal * [PM-14426] Open the getting started carousel on page load * [PM-14426] Add tests * [PM-14426] Use booleanAttribute * [PM-14426] Fix failing type checking
63 lines
2.0 KiB
TypeScript
63 lines
2.0 KiB
TypeScript
import {
|
|
DestroyRef,
|
|
Directive,
|
|
ElementRef,
|
|
HostBinding,
|
|
inject,
|
|
input,
|
|
OnInit,
|
|
} from "@angular/core";
|
|
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
|
import { combineLatest, Observable } from "rxjs";
|
|
|
|
import { SYSTEM_THEME_OBSERVABLE } from "@bitwarden/angular/services/injection-tokens";
|
|
import { Theme } from "@bitwarden/common/platform/enums";
|
|
import { ThemeStateService } from "@bitwarden/common/platform/theming/theme-state.service";
|
|
|
|
/**
|
|
* Directive that will switch the image source based on the currently applied theme.
|
|
*
|
|
* @example
|
|
* ```html
|
|
* <img src="light-image.png" appDarkImgSrc="dark-image.png" />
|
|
* ```
|
|
*/
|
|
@Directive({
|
|
selector: "[appDarkImgSrc]",
|
|
standalone: true,
|
|
})
|
|
export class DarkImageSourceDirective implements OnInit {
|
|
private themeService = inject(ThemeStateService);
|
|
private systemTheme$: Observable<Theme> = inject(SYSTEM_THEME_OBSERVABLE);
|
|
private el = inject(ElementRef<HTMLElement>);
|
|
private destroyRef = inject(DestroyRef);
|
|
|
|
/**
|
|
* The image source to use when the light theme is applied. Automatically assigned the value
|
|
* of the `<img>` src attribute.
|
|
*/
|
|
protected lightImgSrc: string | undefined;
|
|
|
|
/**
|
|
* The image source to use when the dark theme is applied.
|
|
*/
|
|
darkImgSrc = input.required<string>({ alias: "appDarkImgSrc" });
|
|
|
|
@HostBinding("attr.src") src: string | undefined;
|
|
|
|
ngOnInit() {
|
|
// Set the light image source from the element's current src attribute
|
|
this.lightImgSrc = this.el.nativeElement.getAttribute("src");
|
|
|
|
// Update the image source based on the active theme
|
|
combineLatest([this.themeService.selectedTheme$, this.systemTheme$])
|
|
.pipe(takeUntilDestroyed(this.destroyRef))
|
|
.subscribe(([theme, systemTheme]) => {
|
|
const appliedTheme = theme === "system" ? systemTheme : theme;
|
|
const isDark =
|
|
appliedTheme === "dark" || appliedTheme === "nord" || appliedTheme === "solarizedDark";
|
|
this.src = isDark ? this.darkImgSrc() : this.lightImgSrc;
|
|
});
|
|
}
|
|
}
|