fix primary color css variable to use new shade value

This commit is contained in:
jeffvli
2026-03-04 21:26:44 -08:00
parent 41f1f376bc
commit 43c5cf4275
+25 -2
View File
@@ -1,5 +1,6 @@
import type { MantineThemeOverride } from '@mantine/core'; import type { MantineThemeOverride } from '@mantine/core';
import { generateColors } from '@mantine/colors-generator';
import { useMantineColorScheme } from '@mantine/core'; import { useMantineColorScheme } from '@mantine/core';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
@@ -177,8 +178,30 @@ export const useAppTheme = (overrideTheme?: AppTheme) => {
const primaryColor = useThemeAccentColor const primaryColor = useThemeAccentColor
? themeProperties.colors?.primary || themeProperties.colors?.['state-info'] || accent ? themeProperties.colors?.primary || themeProperties.colors?.['state-info'] || accent
: accent; : accent;
root.style.setProperty('--theme-colors-primary', primaryColor); const effectivePrimaryShade: MantineThemeOverride['primaryShade'] = useThemePrimaryShade
}, [accent, selectedTheme, useThemeAccentColor]); ? themeProperties.mantineOverride?.primaryShade
: ({ dark: primaryShade, light: primaryShade } as MantineThemeOverride['primaryShade']);
const mode = themeProperties.mode ?? (isDarkTheme ? 'dark' : 'light');
const shadeIndex = Math.min(
9,
Math.max(
0,
typeof effectivePrimaryShade === 'object'
? (effectivePrimaryShade?.[mode] ?? 6)
: (effectivePrimaryShade ?? 6),
),
);
const primaryScale = generateColors(primaryColor);
const primaryAtShade = primaryScale[shadeIndex];
root.style.setProperty('--theme-colors-primary', primaryAtShade);
}, [
accent,
isDarkTheme,
primaryShade,
selectedTheme,
useThemeAccentColor,
useThemePrimaryShade,
]);
useEffect(() => { useEffect(() => {
const root = document.documentElement; const root = document.documentElement;