mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-19 09:54:18 +02:00
add type assertion for primaryShade
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import type { MantineThemeOverride } from '@mantine/core';
|
||||||
|
|
||||||
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';
|
||||||
|
|
||||||
@@ -52,8 +54,15 @@ export const useAppTheme = (overrideTheme?: AppTheme) => {
|
|||||||
const themeInlineStylesRef = useRef<HTMLStyleElement | null>(null);
|
const themeInlineStylesRef = useRef<HTMLStyleElement | null>(null);
|
||||||
const getCurrentTheme = () => window.matchMedia('(prefers-color-scheme: dark)').matches;
|
const getCurrentTheme = () => window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||||
const [isDarkTheme, setIsDarkTheme] = useState(getCurrentTheme());
|
const [isDarkTheme, setIsDarkTheme] = useState(getCurrentTheme());
|
||||||
const { followSystemTheme, primaryShade, theme, themeDark, themeLight, useThemeAccentColor, useThemePrimaryShade } =
|
const {
|
||||||
useThemeSettings();
|
followSystemTheme,
|
||||||
|
primaryShade,
|
||||||
|
theme,
|
||||||
|
themeDark,
|
||||||
|
themeLight,
|
||||||
|
useThemeAccentColor,
|
||||||
|
useThemePrimaryShade,
|
||||||
|
} = useThemeSettings();
|
||||||
|
|
||||||
const mqListener = (e: any) => {
|
const mqListener = (e: any) => {
|
||||||
setIsDarkTheme(e.matches);
|
setIsDarkTheme(e.matches);
|
||||||
@@ -144,10 +153,10 @@ export const useAppTheme = (overrideTheme?: AppTheme) => {
|
|||||||
? themeProperties.colors?.primary || themeProperties.colors?.['state-info'] || accent
|
? themeProperties.colors?.primary || themeProperties.colors?.['state-info'] || accent
|
||||||
: accent;
|
: accent;
|
||||||
|
|
||||||
// Use theme's primary shade if useThemePrimaryShade is enabled, otherwise use slider value
|
// Use theme's primary shade if useThemePrimaryShade is enabled, otherwise use slider value (0-9)
|
||||||
const effectivePrimaryShade = useThemePrimaryShade
|
const effectivePrimaryShade: MantineThemeOverride['primaryShade'] = useThemePrimaryShade
|
||||||
? themeProperties.mantineOverride?.primaryShade
|
? themeProperties.mantineOverride?.primaryShade
|
||||||
: { dark: primaryShade, light: primaryShade };
|
: ({ dark: primaryShade, light: primaryShade } as MantineThemeOverride['primaryShade']);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...themeProperties,
|
...themeProperties,
|
||||||
@@ -250,8 +259,15 @@ export const useAppThemeColors = () => {
|
|||||||
const accent = useAccent();
|
const accent = useAccent();
|
||||||
const getCurrentTheme = () => window.matchMedia('(prefers-color-scheme: dark)').matches;
|
const getCurrentTheme = () => window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||||
const [isDarkTheme] = useState(getCurrentTheme());
|
const [isDarkTheme] = useState(getCurrentTheme());
|
||||||
const { followSystemTheme, primaryShade, theme, themeDark, themeLight, useThemeAccentColor, useThemePrimaryShade } =
|
const {
|
||||||
useThemeSettings();
|
followSystemTheme,
|
||||||
|
primaryShade,
|
||||||
|
theme,
|
||||||
|
themeDark,
|
||||||
|
themeLight,
|
||||||
|
useThemeAccentColor,
|
||||||
|
useThemePrimaryShade,
|
||||||
|
} = useThemeSettings();
|
||||||
|
|
||||||
const getSelectedTheme = () => {
|
const getSelectedTheme = () => {
|
||||||
if (followSystemTheme) {
|
if (followSystemTheme) {
|
||||||
@@ -271,10 +287,10 @@ export const useAppThemeColors = () => {
|
|||||||
? themeProperties.colors?.primary || themeProperties.colors?.['state-info'] || accent
|
? themeProperties.colors?.primary || themeProperties.colors?.['state-info'] || accent
|
||||||
: accent;
|
: accent;
|
||||||
|
|
||||||
// Use theme's primary shade if useThemePrimaryShade is enabled, otherwise use slider value
|
// Use theme's primary shade if useThemePrimaryShade is enabled, otherwise use slider value (0-9)
|
||||||
const effectivePrimaryShade = useThemePrimaryShade
|
const effectivePrimaryShade: MantineThemeOverride['primaryShade'] = useThemePrimaryShade
|
||||||
? themeProperties.mantineOverride?.primaryShade
|
? themeProperties.mantineOverride?.primaryShade
|
||||||
: { dark: primaryShade, light: primaryShade };
|
: ({ dark: primaryShade, light: primaryShade } as MantineThemeOverride['primaryShade']);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...themeProperties,
|
...themeProperties,
|
||||||
|
|||||||
Reference in New Issue
Block a user