|
|
|
import { TinyColor } from '@ctrl/tinycolor';
|
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
|
|
|
import { genCollapseMotion, initSlideMotion, initZoomMotion } from '../../style/motion';
|
|
|
|
import type { FullToken, GenerateStyle, UseComponentStyleResult } from '../../theme/internal';
|
|
|
|
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
|
|
|
|
import getHorizontalStyle from './horizontal';
|
|
|
|
import getRTLStyle from './rtl';
|
|
|
|
import getThemeStyle from './theme';
|
|
|
|
import getVerticalStyle from './vertical';
|
|
|
|
import { clearFix, resetComponent, resetIcon } from '../../style';
|
|
|
|
|
|
|
|
/** Component only token. Which will handle additional calculation of alias token */
|
|
|
|
export interface ComponentToken {
|
|
|
|
dropdownWidth: number;
|
|
|
|
zIndexPopup: number;
|
|
|
|
|
|
|
|
// Group
|
|
|
|
colorGroupTitle: string;
|
|
|
|
|
|
|
|
// radius
|
|
|
|
radiusItem: number;
|
|
|
|
radiusSubMenuItem: number;
|
|
|
|
|
|
|
|
// Item Text
|
|
|
|
// > Default
|
|
|
|
colorItemText: string;
|
|
|
|
colorItemTextHover: string;
|
|
|
|
colorItemTextHoverHorizontal: string;
|
|
|
|
colorItemTextSelected: string;
|
|
|
|
colorItemTextSelectedHorizontal: string;
|
|
|
|
|
|
|
|
// > Disabled
|
|
|
|
colorItemTextDisabled: string;
|
|
|
|
|
|
|
|
// > Danger
|
|
|
|
colorDangerItemText: string;
|
|
|
|
colorDangerItemTextHover: string;
|
|
|
|
colorDangerItemTextSelected: string;
|
|
|
|
colorDangerItemBgActive: string;
|
|
|
|
colorDangerItemBgSelected: string;
|
|
|
|
|
|
|
|
// Item Bg
|
|
|
|
colorItemBg: string;
|
|
|
|
colorItemBgHover: string;
|
|
|
|
colorSubItemBg: string;
|
|
|
|
|
|
|
|
// > Default
|
|
|
|
colorItemBgActive: string;
|
|
|
|
colorItemBgSelected: string;
|
|
|
|
colorItemBgSelectedHorizontal: string;
|
|
|
|
|
|
|
|
// Ink Bar
|
|
|
|
colorActiveBarWidth: number;
|
|
|
|
colorActiveBarHeight: number;
|
|
|
|
colorActiveBarBorderSize: number;
|
|
|
|
|
|
|
|
itemMarginInline: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface MenuToken extends FullToken<'Menu'> {
|
|
|
|
menuItemHeight: number;
|
|
|
|
menuHorizontalHeight: number;
|
|
|
|
menuItemPaddingInline: number;
|
|
|
|
menuArrowSize: number;
|
|
|
|
menuArrowOffset: string;
|
|
|
|
menuPanelMaskInset: number;
|
|
|
|
menuSubMenuBg: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const genMenuItemStyle = (token: MenuToken): CSSObject => {
|
|
|
|
const {
|
|
|
|
componentCls,
|
|
|
|
fontSize,
|
|
|
|
motionDurationSlow,
|
|
|
|
motionDurationMid,
|
|
|
|
motionEaseInOut,
|
|
|
|
motionEaseOut,
|
|
|
|
iconCls,
|
|
|
|
controlHeightSM,
|
|
|
|
} = token;
|
|
|
|
|
|
|
|
return {
|
|
|
|
// >>>>> Item
|
|
|
|
[`${componentCls}-item, ${componentCls}-submenu-title`]: {
|
|
|
|
position: 'relative',
|
|
|
|
display: 'block',
|
|
|
|
margin: 0,
|
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
cursor: 'pointer',
|
|
|
|
transition: [
|
|
|
|
`border-color ${motionDurationSlow}`,
|
|
|
|
`background ${motionDurationSlow}`,
|
|
|
|
`padding ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
].join(','),
|
|
|
|
|
|
|
|
[`${componentCls}-item-icon, ${iconCls}`]: {
|
|
|
|
minWidth: fontSize,
|
|
|
|
fontSize,
|
|
|
|
transition: [
|
|
|
|
`font-size ${motionDurationMid} ${motionEaseOut}`,
|
|
|
|
`margin ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
`color ${motionDurationSlow}`,
|
|
|
|
].join(','),
|
|
|
|
|
|
|
|
'+ span': {
|
|
|
|
marginInlineStart: controlHeightSM - fontSize,
|
|
|
|
opacity: 1,
|
|
|
|
transition: [
|
|
|
|
`opacity ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
`margin ${motionDurationSlow}`,
|
|
|
|
`color ${motionDurationSlow}`,
|
|
|
|
].join(','),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-item-icon`]: {
|
|
|
|
...resetIcon(),
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&${componentCls}-item-only-child`]: {
|
|
|
|
[`> ${iconCls}, > ${componentCls}-item-icon`]: {
|
|
|
|
marginInlineEnd: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// Disabled state sets text to gray and nukes hover/tab effects
|
|
|
|
[`${componentCls}-item-disabled, ${componentCls}-submenu-disabled`]: {
|
|
|
|
background: 'none !important',
|
|
|
|
cursor: 'not-allowed',
|
|
|
|
|
|
|
|
'&::after': {
|
|
|
|
borderColor: 'transparent !important',
|
|
|
|
},
|
|
|
|
|
|
|
|
a: {
|
|
|
|
color: 'inherit !important',
|
|
|
|
},
|
|
|
|
|
|
|
|
[`> ${componentCls}-submenu-title`]: {
|
|
|
|
color: 'inherit !important',
|
|
|
|
cursor: 'not-allowed',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const genSubMenuArrowStyle = (token: MenuToken): CSSObject => {
|
|
|
|
const {
|
|
|
|
componentCls,
|
|
|
|
motionDurationSlow,
|
|
|
|
motionEaseInOut,
|
|
|
|
borderRadius,
|
|
|
|
menuArrowSize,
|
|
|
|
menuArrowOffset,
|
|
|
|
} = token;
|
|
|
|
|
|
|
|
return {
|
|
|
|
[`${componentCls}-submenu`]: {
|
|
|
|
[`&-expand-icon, &-arrow`]: {
|
|
|
|
position: 'absolute',
|
|
|
|
top: '50%',
|
|
|
|
insetInlineEnd: token.margin,
|
|
|
|
width: menuArrowSize,
|
|
|
|
color: 'currentcolor',
|
|
|
|
transform: 'translateY(-50%)',
|
|
|
|
transition: `transform ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-arrow': {
|
|
|
|
// →
|
|
|
|
'&::before, &::after': {
|
|
|
|
position: 'absolute',
|
|
|
|
width: menuArrowSize * 0.6,
|
|
|
|
height: menuArrowSize * 0.15,
|
|
|
|
backgroundColor: 'currentcolor',
|
|
|
|
borderRadius,
|
|
|
|
transition: [
|
|
|
|
`background ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
`transform ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
`top ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
`color ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
].join(','),
|
|
|
|
content: '""',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&::before': {
|
|
|
|
transform: `rotate(45deg) translateY(-${menuArrowOffset})`,
|
|
|
|
},
|
|
|
|
|
|
|
|
'&::after': {
|
|
|
|
transform: `rotate(-45deg) translateY(${menuArrowOffset})`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// =============================== Base ===============================
|
|
|
|
const getBaseStyle: GenerateStyle<MenuToken> = (token) => {
|
|
|
|
const {
|
|
|
|
antCls,
|
|
|
|
componentCls,
|
|
|
|
fontSize,
|
|
|
|
motionDurationSlow,
|
|
|
|
motionDurationMid,
|
|
|
|
motionEaseInOut,
|
|
|
|
lineHeight,
|
|
|
|
paddingXS,
|
|
|
|
padding,
|
|
|
|
colorSplit,
|
|
|
|
lineWidth,
|
|
|
|
zIndexPopup,
|
|
|
|
borderRadiusLG,
|
|
|
|
radiusSubMenuItem,
|
|
|
|
menuArrowSize,
|
|
|
|
menuArrowOffset,
|
|
|
|
lineType,
|
|
|
|
menuPanelMaskInset,
|
|
|
|
} = token;
|
|
|
|
|
|
|
|
return [
|
|
|
|
// Misc
|
|
|
|
{
|
|
|
|
'': {
|
|
|
|
[`${componentCls}`]: {
|
|
|
|
...clearFix(),
|
|
|
|
|
|
|
|
// Hidden
|
|
|
|
[`&-hidden`]: {
|
|
|
|
display: 'none',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[`${componentCls}-submenu-hidden`]: {
|
|
|
|
display: 'none',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[componentCls]: {
|
|
|
|
...resetComponent(token),
|
|
|
|
...clearFix(),
|
|
|
|
|
|
|
|
marginBottom: 0,
|
|
|
|
paddingInlineStart: 0, // Override default ul/ol
|
|
|
|
fontSize,
|
|
|
|
lineHeight: 0, // Fix display inline-block gap
|
|
|
|
listStyle: 'none',
|
|
|
|
outline: 'none',
|
|
|
|
transition: [
|
|
|
|
`background ${motionDurationSlow}`,
|
|
|
|
// Magic cubic here but smooth transition
|
|
|
|
`width ${motionDurationSlow} cubic-bezier(0.2, 0, 0, 1) 0s`,
|
|
|
|
].join(','),
|
|
|
|
|
|
|
|
[`ul, ol`]: {
|
|
|
|
margin: 0,
|
|
|
|
padding: 0,
|
|
|
|
listStyle: 'none',
|
|
|
|
},
|
|
|
|
|
|
|
|
// Overflow ellipsis
|
|
|
|
[`&-overflow`]: {
|
|
|
|
display: 'flex',
|
|
|
|
|
|
|
|
[`${componentCls}-item`]: {
|
|
|
|
flex: 'none',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[`${componentCls}-item, ${componentCls}-submenu, ${componentCls}-submenu-title`]: {
|
|
|
|
borderRadius: token.radiusItem,
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-item-group-title`]: {
|
|
|
|
padding: `${paddingXS}px ${padding}px`,
|
|
|
|
fontSize,
|
|
|
|
lineHeight,
|
|
|
|
transition: `all ${motionDurationSlow}`,
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&-horizontal ${componentCls}-submenu`]: {
|
|
|
|
transition: [
|
|
|
|
`border-color ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
`background ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
].join(','),
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-submenu, ${componentCls}-submenu-inline`]: {
|
|
|
|
transition: [
|
|
|
|
`border-color ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
`background ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
`padding ${motionDurationMid} ${motionEaseInOut}`,
|
|
|
|
].join(','),
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-submenu ${componentCls}-sub`]: {
|
|
|
|
cursor: 'initial',
|
|
|
|
transition: [
|
|
|
|
`background ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
`padding ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|