mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-19 11:45:12 +00:00
feat: rehauled console (#3525)
* new console * move npm ci to angular build * rel path for assets * local grpc copy * login policy, rm clear views, features rel path * lock Co-authored-by: Livio Amstutz <[email protected]>
This commit is contained in:
co-authored by
Livio Amstutz
parent
00f7dbe875
commit
08ae39ae19
@@ -1,23 +1,35 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, Subject } from 'rxjs';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
|
||||
declare const tinycolor: any;
|
||||
|
||||
export interface Color {
|
||||
name: string;
|
||||
hex: string;
|
||||
darkContrast: boolean;
|
||||
rgb: string;
|
||||
contrastColor: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ThemeService {
|
||||
private _darkTheme: Subject<boolean> = new Subject<boolean>();
|
||||
private _darkTheme: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(true);
|
||||
public isDarkTheme: Observable<boolean> = this._darkTheme.asObservable();
|
||||
|
||||
private primaryColorPalette: Color[] = [];
|
||||
private warnColorPalette: Color[] = [];
|
||||
private backgroundColorPalette: Color[] = [];
|
||||
|
||||
constructor() {
|
||||
const theme = localStorage.getItem('theme');
|
||||
if (theme) {
|
||||
if (theme === 'light-theme') {
|
||||
this.setDarkTheme(false);
|
||||
} else {
|
||||
this.setDarkTheme(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setDarkTheme(isDarkTheme: boolean): void {
|
||||
this._darkTheme.next(isDarkTheme);
|
||||
}
|
||||
@@ -25,10 +37,7 @@ export class ThemeService {
|
||||
public updateTheme(colors: Color[], type: string, theme: string): void {
|
||||
colors.forEach((color) => {
|
||||
document.documentElement.style.setProperty(`--theme-${theme}-${type}-${color.name}`, color.hex);
|
||||
document.documentElement.style.setProperty(
|
||||
`--theme-${theme}-${type}-contrast-${color.name}`,
|
||||
color.darkContrast ? 'hsla(0, 0%, 0%, 0.87)' : '#ffffff',
|
||||
);
|
||||
document.documentElement.style.setProperty(`--theme-${theme}-${type}-contrast-${color.name}`, color.contrastColor);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -77,7 +86,8 @@ export class ThemeService {
|
||||
return {
|
||||
name: name,
|
||||
hex: c.toHexString(),
|
||||
darkContrast: c.isLight(),
|
||||
rgb: c.toRgbString(),
|
||||
contrastColor: this.getContrast(c.toHexString()),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -90,4 +100,14 @@ export class ThemeService {
|
||||
const color = tinycolor(hex);
|
||||
return color.isDark();
|
||||
}
|
||||
|
||||
public getContrast(color: string): string {
|
||||
const onBlack = tinycolor.readability('#000', color);
|
||||
const onWhite = tinycolor.readability('#fff', color);
|
||||
if (onBlack > onWhite) {
|
||||
return 'hsla(0, 0%, 0%, 0.87)';
|
||||
} else {
|
||||
return '#ffffff';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user