ant-design/components/menu/style/theme.ts
ice 6a62d9e7ea
fix(menu): menu-title-content style (#51425)
* fix(dropdown): dropdown menu title content style

* chore: update rc-mentions to version 2.17.0 and rc-tabs to version 15.4.0

* test: add extra style debug

* test: snap

* test: snap

* Refactor menu demo: remove extra-style-debug component and rename extra-style-debug files to extra-style

* Refactor menu demo: remove extra-style-debug component and rename extra-style-debug files to extra-style

* Refactor dropdown and menu styles: Add width to extra-style elements

* test: snap

* fix: Add Space component to menu demo

The Space component was missing from the import statement in the menu demo file. This caused a compilation error. The fix adds the Space component to the import statement, resolving the issue.

Refactor the menu demo to use Space component for vertical spacing between menus. This improves the visual layout and readability of the menus.

Fixes #51492

* test: snap

* refactor: Update dropdown and menu title content class names

---------

Co-authored-by: afc163 <afc163@gmail.com>
2024-11-07 20:00:06 +08:00

276 lines
7.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { unit } from '@ant-design/cssinjs';
import type { CSSInterpolation } from '@ant-design/cssinjs';
import type { MenuToken } from '.';
import { genFocusOutline } from '../../style';
const accessibilityFocus = (token: MenuToken) => ({
...genFocusOutline(token),
});
const getThemeStyle = (token: MenuToken, themeSuffix: string): CSSInterpolation => {
const {
componentCls,
itemColor,
itemSelectedColor,
groupTitleColor,
itemBg,
subMenuItemBg,
itemSelectedBg,
activeBarHeight,
activeBarWidth,
activeBarBorderWidth,
motionDurationSlow,
motionEaseInOut,
motionEaseOut,
itemPaddingInline,
motionDurationMid,
itemHoverColor,
lineType,
colorSplit,
// Disabled
itemDisabledColor,
// Danger
dangerItemColor,
dangerItemHoverColor,
dangerItemSelectedColor,
dangerItemActiveBg,
dangerItemSelectedBg,
// Bg
popupBg,
itemHoverBg,
itemActiveBg,
menuSubMenuBg,
// Horizontal
horizontalItemSelectedColor,
horizontalItemSelectedBg,
horizontalItemBorderRadius,
horizontalItemHoverBg,
} = token;
return {
[`${componentCls}-${themeSuffix}, ${componentCls}-${themeSuffix} > ${componentCls}`]: {
color: itemColor,
background: itemBg,
[`&${componentCls}-root:focus-visible`]: {
...accessibilityFocus(token),
},
// ======================== Item ========================
[`${componentCls}-item`]: {
'&-group-title, &-extra': {
color: groupTitleColor,
},
},
[`${componentCls}-submenu-selected`]: {
[`> ${componentCls}-submenu-title`]: {
color: itemSelectedColor,
},
},
[`${componentCls}-item, ${componentCls}-submenu-title`]: {
color: itemColor,
[`&:not(${componentCls}-item-disabled):focus-visible`]: {
...accessibilityFocus(token),
},
},
// Disabled
[`${componentCls}-item-disabled, ${componentCls}-submenu-disabled`]: {
color: `${itemDisabledColor} !important`,
},
// Hover
[`${componentCls}-item:not(${componentCls}-item-selected):not(${componentCls}-submenu-selected)`]:
{
[`&:hover, > ${componentCls}-submenu-title:hover`]: {
color: itemHoverColor,
},
},
[`&:not(${componentCls}-horizontal)`]: {
[`${componentCls}-item:not(${componentCls}-item-selected)`]: {
'&:hover': {
backgroundColor: itemHoverBg,
},
'&:active': {
backgroundColor: itemActiveBg,
},
},
[`${componentCls}-submenu-title`]: {
'&:hover': {
backgroundColor: itemHoverBg,
},
'&:active': {
backgroundColor: itemActiveBg,
},
},
},
// Danger - only Item has
[`${componentCls}-item-danger`]: {
color: dangerItemColor,
[`&${componentCls}-item:hover`]: {
[`&:not(${componentCls}-item-selected):not(${componentCls}-submenu-selected)`]: {
color: dangerItemHoverColor,
},
},
[`&${componentCls}-item:active`]: {
background: dangerItemActiveBg,
},
},
[`${componentCls}-item a`]: {
'&, &:hover': {
color: 'inherit',
},
},
[`${componentCls}-item-selected`]: {
color: itemSelectedColor,
// Danger
[`&${componentCls}-item-danger`]: {
color: dangerItemSelectedColor,
},
'a, a:hover': {
color: 'inherit',
},
},
[`& ${componentCls}-item-selected`]: {
backgroundColor: itemSelectedBg,
// Danger
[`&${componentCls}-item-danger`]: {
backgroundColor: dangerItemSelectedBg,
},
},
[`&${componentCls}-submenu > ${componentCls}`]: {
backgroundColor: menuSubMenuBg,
},
// ===== 设置浮层的颜色 =======
// dark 模式会被popupBg 会被rest 为 darkPopupBg
[`&${componentCls}-popup > ${componentCls}`]: {
backgroundColor: popupBg,
},
[`&${componentCls}-submenu-popup > ${componentCls}`]: {
backgroundColor: popupBg,
},
// ===== 设置浮层的颜色 end =======
// ====================== Horizontal ======================
[`&${componentCls}-horizontal`]: {
...(themeSuffix === 'dark'
? {
borderBottom: 0,
}
: {}),
[`> ${componentCls}-item, > ${componentCls}-submenu`]: {
top: activeBarBorderWidth,
marginTop: token.calc(activeBarBorderWidth).mul(-1).equal(),
marginBottom: 0,
borderRadius: horizontalItemBorderRadius,
'&::after': {
position: 'absolute',
insetInline: itemPaddingInline,
bottom: 0,
borderBottom: `${unit(activeBarHeight)} solid transparent`,
transition: `border-color ${motionDurationSlow} ${motionEaseInOut}`,
content: '""',
},
'&:hover, &-active, &-open': {
background: horizontalItemHoverBg,
'&::after': {
borderBottomWidth: activeBarHeight,
borderBottomColor: horizontalItemSelectedColor,
},
},
'&-selected': {
color: horizontalItemSelectedColor,
backgroundColor: horizontalItemSelectedBg,
'&:hover': {
backgroundColor: horizontalItemSelectedBg,
},
'&::after': {
borderBottomWidth: activeBarHeight,
borderBottomColor: horizontalItemSelectedColor,
},
},
},
},
// ================== Inline & Vertical ===================
//
[`&${componentCls}-root`]: {
[`&${componentCls}-inline, &${componentCls}-vertical`]: {
borderInlineEnd: `${unit(activeBarBorderWidth)} ${lineType} ${colorSplit}`,
},
},
// ======================== Inline ========================
[`&${componentCls}-inline`]: {
// Sub
[`${componentCls}-sub${componentCls}-inline`]: {
background: subMenuItemBg,
},
[`${componentCls}-item`]: {
position: 'relative',
'&::after': {
position: 'absolute',
insetBlock: 0,
insetInlineEnd: 0,
borderInlineEnd: `${unit(activeBarWidth)} solid ${itemSelectedColor}`,
transform: 'scaleY(0.0001)',
opacity: 0,
transition: [
`transform ${motionDurationMid} ${motionEaseOut}`,
`opacity ${motionDurationMid} ${motionEaseOut}`,
].join(','),
content: '""',
},
// Danger
[`&${componentCls}-item-danger`]: {
'&::after': {
borderInlineEndColor: dangerItemSelectedColor,
},
},
},
[`${componentCls}-selected, ${componentCls}-item-selected`]: {
'&::after': {
transform: 'scaleY(1)',
opacity: 1,
transition: [
`transform ${motionDurationMid} ${motionEaseInOut}`,
`opacity ${motionDurationMid} ${motionEaseInOut}`,
].join(','),
},
},
},
},
};
};
export default getThemeStyle;