feat: add menu font size variable and update related components
- Introduced a new CSS variable `--menu-font-size` calculated from the base font size. - Updated `PreferenceManager` to trigger CSS variable updates when `fontSize` is modified. - Adjusted `updateCSSVariables` to set the new `--menu-font-size` based on the theme's font size. - Ensured that the menu components utilize the updated font size with `!important` to maintain styling consistency.
This commit is contained in:
@@ -93,6 +93,7 @@
|
|||||||
|
|
||||||
/* 基本文字大小 */
|
/* 基本文字大小 */
|
||||||
--font-size-base: 16px;
|
--font-size-base: 16px;
|
||||||
|
--menu-font-size: calc(var(--font-size-base) * 0.875);
|
||||||
|
|
||||||
/* =============component & UI============= */
|
/* =============component & UI============= */
|
||||||
|
|
||||||
|
|||||||
@@ -141,7 +141,10 @@ class PreferenceManager {
|
|||||||
private handleUpdates(updates: DeepPartial<Preferences>) {
|
private handleUpdates(updates: DeepPartial<Preferences>) {
|
||||||
const themeUpdates = updates.theme || {};
|
const themeUpdates = updates.theme || {};
|
||||||
const appUpdates = updates.app || {};
|
const appUpdates = updates.app || {};
|
||||||
if (themeUpdates && Object.keys(themeUpdates).length > 0) {
|
if (
|
||||||
|
(themeUpdates && Object.keys(themeUpdates).length > 0) ||
|
||||||
|
Reflect.has(themeUpdates, 'fontSize')
|
||||||
|
) {
|
||||||
updateCSSVariables(this.state);
|
updateCSSVariables(this.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,9 +69,14 @@ function updateCSSVariables(preferences: Preferences) {
|
|||||||
|
|
||||||
// 更新字体大小
|
// 更新字体大小
|
||||||
if (Reflect.has(theme, 'fontSize')) {
|
if (Reflect.has(theme, 'fontSize')) {
|
||||||
|
const fontSize = theme.fontSize;
|
||||||
document.documentElement.style.setProperty(
|
document.documentElement.style.setProperty(
|
||||||
'--font-size-base',
|
'--font-size-base',
|
||||||
`${theme.fontSize}px`,
|
`${fontSize}px`,
|
||||||
|
);
|
||||||
|
document.documentElement.style.setProperty(
|
||||||
|
'--menu-font-size',
|
||||||
|
`calc(${fontSize}px * 0.875)`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -388,7 +388,7 @@ $namespace: vben;
|
|||||||
padding: var(--menu-item-padding-y) var(--menu-item-padding-x);
|
padding: var(--menu-item-padding-y) var(--menu-item-padding-x);
|
||||||
margin: 0 var(--menu-item-margin-x) var(--menu-item-margin-y)
|
margin: 0 var(--menu-item-margin-x) var(--menu-item-margin-y)
|
||||||
var(--menu-item-margin-x);
|
var(--menu-item-margin-x);
|
||||||
font-size: var(--menu-font-size);
|
font-size: var(--menu-font-size) !important;
|
||||||
color: var(--menu-item-color);
|
color: var(--menu-item-color);
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
@@ -433,6 +433,7 @@ $namespace: vben;
|
|||||||
max-width: var(--menu-title-width);
|
max-width: var(--menu-title-width);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
|
font-size: var(--menu-font-size) !important;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
@@ -458,7 +459,6 @@ $namespace: vben;
|
|||||||
--menu-item-collapse-margin-x: 0px;
|
--menu-item-collapse-margin-x: 0px;
|
||||||
--menu-item-radius: 0px;
|
--menu-item-radius: 0px;
|
||||||
--menu-item-indent: 16px;
|
--menu-item-indent: 16px;
|
||||||
--menu-font-size: calc(var(--font-size-base, 16px) * 0.875);
|
|
||||||
|
|
||||||
&.is-dark {
|
&.is-dark {
|
||||||
--menu-background-color: hsl(var(--menu));
|
--menu-background-color: hsl(var(--menu));
|
||||||
@@ -785,7 +785,7 @@ $namespace: vben;
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
padding: 0 var(--menu-item-padding-x);
|
padding: 0 var(--menu-item-padding-x);
|
||||||
font-size: var(--menu-font-size);
|
font-size: var(--menu-font-size) !important;
|
||||||
line-height: var(--menu-item-height);
|
line-height: var(--menu-item-height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -812,9 +812,14 @@ $namespace: vben;
|
|||||||
|
|
||||||
.#{$namespace}-sub-menu-content {
|
.#{$namespace}-sub-menu-content {
|
||||||
height: var(--menu-item-height);
|
height: var(--menu-item-height);
|
||||||
|
font-size: var(--menu-font-size) !important;
|
||||||
|
|
||||||
@include menu-item;
|
@include menu-item;
|
||||||
|
|
||||||
|
* {
|
||||||
|
font-size: inherit !important;
|
||||||
|
}
|
||||||
|
|
||||||
&__icon-arrow {
|
&__icon-arrow {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
|
|||||||
Reference in New Issue
Block a user