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 = {
|
||||
colorPrimary: '#0091FF',
|
||||
colorPrimaryDisabledDark: '#0e3a5b',
|
||||
colorPrimaryDisabledLight: '#e6f8ff',
|
||||
colorSuccess: '#30D158',
|
||||
colorWarning: '#FF9230',
|
||||
colorError: '#FF4245',
|
||||
@ -38,6 +40,8 @@ export const ThemeProvider = ({ children }) => {
|
||||
return savedCompact ? JSON.parse(savedCompact) : false
|
||||
})
|
||||
|
||||
const [primaryColorOverride, setPrimaryColorOverride] = useState(null)
|
||||
|
||||
// System theme detection
|
||||
useEffect(() => {
|
||||
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
|
||||
@ -124,7 +128,16 @@ export const ThemeProvider = ({ children }) => {
|
||||
// Set CSS custom properties for theme colors
|
||||
useEffect(() => {
|
||||
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-warning', COLORS.colorWarning)
|
||||
root.style.setProperty('--color-error', COLORS.colorError)
|
||||
@ -139,12 +152,20 @@ export const ThemeProvider = ({ children }) => {
|
||||
'--layout-header-bg',
|
||||
isDarkMode ? '#141414' : '#ffffff'
|
||||
)
|
||||
}, [isDarkMode])
|
||||
root.style.setProperty(
|
||||
'--layout-modal-bg',
|
||||
isDarkMode ? '#1f1f1f' : '#ffffff'
|
||||
)
|
||||
}, [isDarkMode, primaryColorOverride])
|
||||
|
||||
const themeConfig = {
|
||||
algorithm: getThemeAlgorithm(),
|
||||
token: {
|
||||
...COLORS,
|
||||
colorPrimary:
|
||||
primaryColorOverride == null
|
||||
? COLORS.colorPrimary
|
||||
: primaryColorOverride,
|
||||
borderRadius: '12px'
|
||||
},
|
||||
components: {
|
||||
@ -166,6 +187,7 @@ export const ThemeProvider = ({ children }) => {
|
||||
setThemeMode,
|
||||
setDensityMode,
|
||||
getColors,
|
||||
setPrimaryColorOverride,
|
||||
themeConfig
|
||||
}}
|
||||
>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user