fix: the brand color setting does not take effect (#4405)

This commit is contained in:
Vben
2024-09-14 21:35:12 +08:00
committed by GitHub
parent 38fe6426a2
commit c3d0102cda
14 changed files with 39 additions and 37 deletions

View File

@@ -86,21 +86,22 @@ function updateMainColorVariables(preference: Preferences) {
{ alias: 'destructive', color: colorDestructive, name: 'red' },
]);
if (colorPrimary) {
const mainColor = colorVariables['--primary-500'];
mainColor &&
document.documentElement.style.setProperty('--primary', mainColor);
}
// 要设置的 CSS 变量映射
const colorMappings = {
'--green-500': '--success',
'--primary-500': '--primary',
'--red-500': '--destructive',
'--yellow-500': '--warning',
};
// 统一处理颜色变量的更新
Object.entries(colorMappings).forEach(([sourceVar, targetVar]) => {
const colorValue = colorVariables[sourceVar];
if (colorValue) {
document.documentElement.style.setProperty(targetVar, colorValue);
}
});
if (colorVariables['--green-500']) {
colorVariables['--success'] = colorVariables['--green-500'];
}
if (colorVariables['--yellow-500']) {
colorVariables['--warning'] = colorVariables['--yellow-500'];
}
if (colorVariables['--red-500']) {
colorVariables['--destructive'] = colorVariables['--red-500'];
}
executeUpdateCSSVariables(colorVariables);
}