Fixed type issues

This commit is contained in:
Mert Sincan
2025-01-07 13:24:19 +00:00
parent fd44b5d430
commit fba7700eff
2 changed files with 31 additions and 11 deletions

View File

@@ -2,8 +2,8 @@ import { provideHttpClient, withFetch } from '@angular/common/http';
import { ApplicationConfig } from '@angular/core'; import { ApplicationConfig } from '@angular/core';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async'; import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { provideRouter, withEnabledBlockingInitialNavigation, withInMemoryScrolling } from '@angular/router'; import { provideRouter, withEnabledBlockingInitialNavigation, withInMemoryScrolling } from '@angular/router';
import { providePrimeNG } from 'primeng/config';
import Aura from '@primeng/themes/aura'; import Aura from '@primeng/themes/aura';
import { providePrimeNG } from 'primeng/config';
import { appRoutes } from './app.routes'; import { appRoutes } from './app.routes';
export const appConfig: ApplicationConfig = { export const appConfig: ApplicationConfig = {

View File

@@ -15,7 +15,27 @@ const presets = {
Material, Material,
Lara, Lara,
Nora Nora
}; } as const;
declare type KeyOfType<T> = keyof T extends infer U ? U : never;
declare type SurfacesType = {
name?: string;
palette?: {
0?: string;
50?: string;
100?: string;
200?: string;
300?: string;
400?: string;
500?: string;
600?: string;
700?: string;
800?: string;
900?: string;
950?: string;
}
}
@Component({ @Component({
selector: 'app-configurator', selector: 'app-configurator',
@@ -34,7 +54,7 @@ const presets = {
[ngClass]="{ 'outline-primary': primaryColor.name === selectedPrimaryColor() }" [ngClass]="{ 'outline-primary': primaryColor.name === selectedPrimaryColor() }"
class="border-none w-5 h-5 rounded-full p-0 cursor-pointer outline-none outline-offset-1" class="border-none w-5 h-5 rounded-full p-0 cursor-pointer outline-none outline-offset-1"
[style]="{ [style]="{
'background-color': primaryColor.name === 'noir' ? 'var(--text-color)' : primaryColor?.palette['500'] 'background-color': primaryColor?.name === 'noir' ? 'var(--text-color)' : primaryColor?.palette?.['500']
}" }"
></button> ></button>
} }
@@ -51,7 +71,7 @@ const presets = {
[ngClass]="{ 'outline-primary': selectedSurfaceColor() ? selectedSurfaceColor() === surface.name : layoutService.layoutConfig().darkTheme ? surface.name === 'zinc' : surface.name === 'slate' }" [ngClass]="{ 'outline-primary': selectedSurfaceColor() ? selectedSurfaceColor() === surface.name : layoutService.layoutConfig().darkTheme ? surface.name === 'zinc' : surface.name === 'slate' }"
class="border-none w-5 h-5 rounded-full p-0 cursor-pointer outline-none outline-offset-1" class="border-none w-5 h-5 rounded-full p-0 cursor-pointer outline-none outline-offset-1"
[style]="{ [style]="{
'background-color': surface.name === 'noir' ? 'var(--text-color)' : surface?.palette['500'] 'background-color': surface?.name === 'noir' ? 'var(--text-color)' : surface?.palette?.['500']
}" }"
></button> ></button>
} }
@@ -93,7 +113,7 @@ export class AppConfigurator {
} }
} }
surfaces = [ surfaces: SurfacesType[] = [
{ {
name: 'slate', name: 'slate',
palette: { palette: {
@@ -242,15 +262,15 @@ export class AppConfigurator {
menuMode = computed(() => this.layoutService.layoutConfig().menuMode); menuMode = computed(() => this.layoutService.layoutConfig().menuMode);
primaryColors = computed(() => { primaryColors = computed<SurfacesType[]>(() => {
const presetPalette = presets[this.layoutService.layoutConfig().preset].primitive; const presetPalette = presets[this.layoutService.layoutConfig().preset as KeyOfType<typeof presets>].primitive;
const colors = ['emerald', 'green', 'lime', 'orange', 'amber', 'yellow', 'teal', 'cyan', 'sky', 'blue', 'indigo', 'violet', 'purple', 'fuchsia', 'pink', 'rose']; const colors = ['emerald', 'green', 'lime', 'orange', 'amber', 'yellow', 'teal', 'cyan', 'sky', 'blue', 'indigo', 'violet', 'purple', 'fuchsia', 'pink', 'rose'];
const palettes = [{ name: 'noir', palette: {} }]; const palettes: SurfacesType[] = [{ name: 'noir', palette: {} }];
colors.forEach((color) => { colors.forEach((color) => {
palettes.push({ palettes.push({
name: color, name: color,
palette: presetPalette[color] palette: presetPalette?.[color as KeyOfType<typeof presetPalette>] as SurfacesType['palette']
}); });
}); });
@@ -258,7 +278,7 @@ export class AppConfigurator {
}); });
getPresetExt() { getPresetExt() {
const color = this.primaryColors().find((c) => c.name === this.selectedPrimaryColor()); const color: SurfacesType = this.primaryColors().find((c) => c.name === this.selectedPrimaryColor()) || {};
if (color.name === 'noir') { if (color.name === 'noir') {
return { return {
@@ -444,7 +464,7 @@ export class AppConfigurator {
onPresetChange(event: any) { onPresetChange(event: any) {
this.layoutService.layoutConfig.update((state) => ({ ...state, preset: event })); this.layoutService.layoutConfig.update((state) => ({ ...state, preset: event }));
const preset = presets[event]; const preset = presets[event as KeyOfType<typeof presets>];
const surfacePalette = this.surfaces.find((s) => s.name === this.selectedSurfaceColor())?.palette; const surfacePalette = this.surfaces.find((s) => s.name === this.selectedSurfaceColor())?.palette;
if (this.layoutService.layoutConfig().preset === 'Material') { if (this.layoutService.layoutConfig().preset === 'Material') {
document.body.classList.add('material'); document.body.classList.add('material');