Add primary color override and disabled color properties in ThemeContext. Update CSS custom properties for primary and disabled colors based on theme mode and user-defined overrides, enhancing theme customization capabilities.
This commit is contained in:
parent
ca0128d986
commit
37d6ba9148
@ -12,6 +12,8 @@ const ThemeContext = createContext()
|
|||||||
|
|
||||||
const COLORS = {
|
const COLORS = {
|
||||||
colorPrimary: '#0091FF',
|
colorPrimary: '#0091FF',
|
||||||
|
colorPrimaryDisabledDark: '#0e3a5b',
|
||||||
|
colorPrimaryDisabledLight: '#e6f8ff',
|
||||||
colorSuccess: '#30D158',
|
colorSuccess: '#30D158',
|
||||||
colorWarning: '#FF9230',
|
colorWarning: '#FF9230',
|
||||||
colorError: '#FF4245',
|
colorError: '#FF4245',
|
||||||
@ -38,6 +40,8 @@ export const ThemeProvider = ({ children }) => {
|
|||||||
return savedCompact ? JSON.parse(savedCompact) : false
|
return savedCompact ? JSON.parse(savedCompact) : false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const [primaryColorOverride, setPrimaryColorOverride] = useState(null)
|
||||||
|
|
||||||
// System theme detection
|
// System theme detection
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
|
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
|
||||||
@ -124,7 +128,16 @@ export const ThemeProvider = ({ children }) => {
|
|||||||
// Set CSS custom properties for theme colors
|
// Set CSS custom properties for theme colors
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const root = document.documentElement
|
const root = document.documentElement
|
||||||
root.style.setProperty('--color-primary', COLORS.colorPrimary)
|
root.style.setProperty(
|
||||||
|
'--color-primary',
|
||||||
|
primaryColorOverride == null ? COLORS.colorPrimary : primaryColorOverride
|
||||||
|
)
|
||||||
|
root.style.setProperty(
|
||||||
|
'--color-primary-disabled',
|
||||||
|
isDarkMode
|
||||||
|
? COLORS.colorPrimaryDisabledDark
|
||||||
|
: COLORS.colorPrimaryDisabledLight
|
||||||
|
)
|
||||||
root.style.setProperty('--color-success', COLORS.colorSuccess)
|
root.style.setProperty('--color-success', COLORS.colorSuccess)
|
||||||
root.style.setProperty('--color-warning', COLORS.colorWarning)
|
root.style.setProperty('--color-warning', COLORS.colorWarning)
|
||||||
root.style.setProperty('--color-error', COLORS.colorError)
|
root.style.setProperty('--color-error', COLORS.colorError)
|
||||||
@ -139,12 +152,20 @@ export const ThemeProvider = ({ children }) => {
|
|||||||
'--layout-header-bg',
|
'--layout-header-bg',
|
||||||
isDarkMode ? '#141414' : '#ffffff'
|
isDarkMode ? '#141414' : '#ffffff'
|
||||||
)
|
)
|
||||||
}, [isDarkMode])
|
root.style.setProperty(
|
||||||
|
'--layout-modal-bg',
|
||||||
|
isDarkMode ? '#1f1f1f' : '#ffffff'
|
||||||
|
)
|
||||||
|
}, [isDarkMode, primaryColorOverride])
|
||||||
|
|
||||||
const themeConfig = {
|
const themeConfig = {
|
||||||
algorithm: getThemeAlgorithm(),
|
algorithm: getThemeAlgorithm(),
|
||||||
token: {
|
token: {
|
||||||
...COLORS,
|
...COLORS,
|
||||||
|
colorPrimary:
|
||||||
|
primaryColorOverride == null
|
||||||
|
? COLORS.colorPrimary
|
||||||
|
: primaryColorOverride,
|
||||||
borderRadius: '12px'
|
borderRadius: '12px'
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
@ -166,6 +187,7 @@ export const ThemeProvider = ({ children }) => {
|
|||||||
setThemeMode,
|
setThemeMode,
|
||||||
setDensityMode,
|
setDensityMode,
|
||||||
getColors,
|
getColors,
|
||||||
|
setPrimaryColorOverride,
|
||||||
themeConfig
|
themeConfig
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user