Skip to content

Commit 0410908

Browse files
shu-harisongsichen
andauthored
feat: Menu support CSS Var (#8323)
Co-authored-by: songsichen <[email protected]>
1 parent c9443e0 commit 0410908

File tree

8 files changed

+850
-284
lines changed

8 files changed

+850
-284
lines changed

components/menu/src/Menu.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import type { ItemType } from './hooks/useItems';
4343
import useItems from './hooks/useItems';
4444
import useStyle from '../style';
4545
import { useInjectOverride } from './OverrideContext';
46+
import useCSSVarCls from '../../config-provider/hooks/useCssVarCls';
4647

4748
export const menuProps = () => ({
4849
id: String,
@@ -106,8 +107,10 @@ export default defineComponent({
106107
const prefixCls = computed(() => {
107108
return getPrefixCls('menu', props.prefixCls || override?.prefixCls?.value);
108109
});
109-
const [wrapSSR, hashId] = useStyle(
110+
const rootCls = useCSSVarCls(prefixCls);
111+
const [wrapSSR, hashId, cssVarCls] = useStyle(
110112
prefixCls,
113+
rootCls,
111114
computed(() => {
112115
return !override;
113116
}),
@@ -336,6 +339,8 @@ export default defineComponent({
336339
[`${prefixCls.value}-inline-collapsed`]: mergedInlineCollapsed.value,
337340
[`${prefixCls.value}-rtl`]: isRtl.value,
338341
[`${prefixCls.value}-${props.theme}`]: true,
342+
[rootCls.value]: true,
343+
[cssVarCls.value]: true,
339344
};
340345
});
341346
const rootPrefixCls = computed(() => getPrefixCls());
@@ -411,6 +416,7 @@ export default defineComponent({
411416
);
412417
useProvideMenu({
413418
prefixCls,
419+
cssVarCls: computed(() => `${rootCls.value} ${cssVarCls.value}`),
414420
activeKeys,
415421
openKeys: mergedOpenKeys,
416422
selectedKeys: mergedSelectedKeys,

components/menu/src/SubMenu.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export default defineComponent({
103103

104104
const {
105105
prefixCls,
106+
cssVarCls,
106107
activeKeys,
107108
disabled: contextDisabled,
108109
changeActiveKeys,
@@ -210,6 +211,7 @@ export default defineComponent({
210211

211212
const popupClassName = computed(() =>
212213
classNames(
214+
cssVarCls.value,
213215
prefixCls.value,
214216
`${prefixCls.value}-${props.theme || theme.value}`,
215217
props.popupClassName,

components/menu/src/hooks/useMenuContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface MenuContextProps {
2323
registerMenuInfo: (key: string, info: StoreMenuInfo) => void;
2424
unRegisterMenuInfo: (key: string) => void;
2525
prefixCls: ComputedRef<string>;
26+
cssVarCls: ComputedRef<string>;
2627
openKeys: Ref<Key[]>;
2728
selectedKeys: Ref<Key[]>;
2829

components/menu/style/horizontal.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1+
import { unit } from '../../_util/cssinjs';
12
import type { MenuToken } from '.';
23
import type { GenerateStyle } from '../../theme/internal';
34

45
const getHorizontalStyle: GenerateStyle<MenuToken> = token => {
56
const {
67
componentCls,
78
motionDurationSlow,
8-
menuHorizontalHeight,
9+
horizontalLineHeight,
910
colorSplit,
1011
lineWidth,
1112
lineType,
12-
menuItemPaddingInline,
13+
itemPaddingInline,
1314
} = token;
1415

1516
return {
1617
[`${componentCls}-horizontal`]: {
17-
lineHeight: `${menuHorizontalHeight}px`,
18+
lineHeight: horizontalLineHeight,
1819
border: 0,
19-
borderBottom: `${lineWidth}px ${lineType} ${colorSplit}`,
20+
borderBottom: `${unit(lineWidth)} ${lineType} ${colorSplit}`,
2021
boxShadow: 'none',
2122

2223
'&::after': {
@@ -31,7 +32,7 @@ const getHorizontalStyle: GenerateStyle<MenuToken> = token => {
3132
position: 'relative',
3233
display: 'inline-block',
3334
verticalAlign: 'bottom',
34-
paddingInline: menuItemPaddingInline,
35+
paddingInline: itemPaddingInline,
3536
},
3637

3738
[`> ${componentCls}-item:hover,

0 commit comments

Comments
 (0)