2022-09-19 22:17:26 +08:00
|
|
|
import { TinyColor } from '@ctrl/tinycolor';
|
2022-07-28 20:33:10 +08:00
|
|
|
import { genCollapseMotion, initSlideMotion, initZoomMotion } from '../../style/motion';
|
2022-06-27 14:25:59 +08:00
|
|
|
import type { FullToken, GenerateStyle, UseComponentStyleResult } from '../../theme';
|
2022-07-11 15:35:58 +08:00
|
|
|
import { genComponentStyleHook, mergeToken } from '../../theme';
|
2022-05-23 10:58:30 +08:00
|
|
|
import getHorizontalStyle from './horizontal';
|
|
|
|
import getRTLStyle from './rtl';
|
|
|
|
import getThemeStyle from './theme';
|
|
|
|
import getVerticalStyle from './vertical';
|
2022-07-11 15:35:58 +08:00
|
|
|
import { clearFix, resetComponent, resetIcon } from '../../style';
|
2017-06-30 21:07:01 +08:00
|
|
|
|
2022-04-20 15:31:04 +08:00
|
|
|
/** Component only token. Which will handle additional calculation of alias token */
|
2022-05-23 10:58:30 +08:00
|
|
|
export interface ComponentToken {
|
|
|
|
dropdownWidth: number;
|
|
|
|
zIndexPopup: number;
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
// Group
|
2022-07-28 20:33:10 +08:00
|
|
|
colorGroupTitle: string;
|
|
|
|
|
|
|
|
// radius
|
|
|
|
radiusItem: number;
|
2022-10-18 17:04:06 +08:00
|
|
|
radiusSubMenuItem: number;
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
// Item Text
|
|
|
|
// > Default
|
2022-07-28 20:33:10 +08:00
|
|
|
colorItemText: string;
|
|
|
|
colorItemTextHover: string;
|
2022-10-18 17:04:06 +08:00
|
|
|
colorItemTextHoverHorizontal: string;
|
2022-07-28 20:33:10 +08:00
|
|
|
colorItemTextSelected: string;
|
2022-10-18 17:04:06 +08:00
|
|
|
colorItemTextSelectedHorizontal: string;
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
// > Disabled
|
2022-07-28 20:33:10 +08:00
|
|
|
colorItemTextDisabled: string;
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
// > Danger
|
2022-07-28 20:33:10 +08:00
|
|
|
colorDangerItemText: string;
|
|
|
|
colorDangerItemTextHover: string;
|
|
|
|
colorDangerItemTextSelected: string;
|
2022-09-19 22:17:26 +08:00
|
|
|
colorDangerItemBgActive: string;
|
|
|
|
colorDangerItemBgSelected: string;
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
// Item Bg
|
2022-07-28 20:33:10 +08:00
|
|
|
colorItemBg: string;
|
2022-10-18 17:04:06 +08:00
|
|
|
colorItemBgHover: string;
|
2022-07-28 20:33:10 +08:00
|
|
|
colorSubItemBg: string;
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
// > Default
|
2022-07-28 20:33:10 +08:00
|
|
|
colorItemBgActive: string;
|
|
|
|
colorItemBgSelected: string;
|
|
|
|
colorItemBgSelectedHorizontal: string;
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
// Ink Bar
|
2022-07-28 20:33:10 +08:00
|
|
|
colorActiveBarWidth: number;
|
|
|
|
colorActiveBarHeight: number;
|
|
|
|
colorActiveBarBorderSize: number;
|
2022-10-18 17:04:06 +08:00
|
|
|
|
|
|
|
itemMarginInline: number;
|
2022-07-28 20:33:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface MenuToken extends FullToken<'Menu'> {
|
|
|
|
menuItemHeight: number;
|
|
|
|
menuHorizontalHeight: number;
|
|
|
|
menuItemPaddingInline: number;
|
2022-08-01 11:19:32 +08:00
|
|
|
menuItemMarginInline: number;
|
2022-07-28 20:33:10 +08:00
|
|
|
menuArrowSize: number;
|
|
|
|
menuArrowOffset: string;
|
|
|
|
menuPanelMaskInset: number;
|
2022-05-23 10:58:30 +08:00
|
|
|
}
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
// =============================== Base ===============================
|
|
|
|
const getBaseStyle: GenerateStyle<MenuToken> = token => {
|
2022-04-20 15:31:04 +08:00
|
|
|
const {
|
|
|
|
antCls,
|
2022-05-23 10:58:30 +08:00
|
|
|
componentCls,
|
|
|
|
fontSize,
|
2022-04-20 15:31:04 +08:00
|
|
|
motionDurationSlow,
|
2022-05-23 10:58:30 +08:00
|
|
|
motionDurationMid,
|
2022-04-20 15:31:04 +08:00
|
|
|
motionEaseInOut,
|
2022-05-23 10:58:30 +08:00
|
|
|
motionEaseOut,
|
2022-04-20 15:31:04 +08:00
|
|
|
lineHeight,
|
|
|
|
paddingXS,
|
2022-05-23 10:58:30 +08:00
|
|
|
padding,
|
2022-07-21 17:00:42 +08:00
|
|
|
colorSplit,
|
2022-05-23 10:58:30 +08:00
|
|
|
lineWidth,
|
|
|
|
iconCls,
|
|
|
|
zIndexPopup,
|
|
|
|
radiusBase,
|
2022-10-18 17:04:06 +08:00
|
|
|
radiusLG,
|
|
|
|
radiusSubMenuItem,
|
2022-05-23 10:58:30 +08:00
|
|
|
menuArrowSize,
|
|
|
|
controlHeightSM,
|
|
|
|
menuArrowOffset,
|
|
|
|
lineType,
|
|
|
|
menuPanelMaskInset,
|
2022-04-20 15:31:04 +08:00
|
|
|
} = token;
|
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
return [
|
|
|
|
// Misc
|
|
|
|
{
|
|
|
|
'': {
|
2022-04-20 15:31:04 +08:00
|
|
|
[`${componentCls}`]: {
|
|
|
|
...clearFix(),
|
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
// Hidden
|
|
|
|
[`&-hidden`]: {
|
|
|
|
display: 'none',
|
|
|
|
},
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
},
|
2022-05-23 10:58:30 +08:00
|
|
|
[`${componentCls}-submenu-hidden`]: {
|
|
|
|
display: 'none',
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
2022-05-23 10:58:30 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
[componentCls]: {
|
|
|
|
...resetComponent(token),
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
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,
|
2022-04-20 15:31:04 +08:00
|
|
|
padding: 0,
|
2022-05-23 10:58:30 +08:00
|
|
|
listStyle: 'none',
|
|
|
|
},
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
// Overflow ellipsis
|
|
|
|
[`&-overflow`]: {
|
|
|
|
display: 'flex',
|
2022-04-20 15:31:04 +08:00
|
|
|
|
|
|
|
[`${componentCls}-item`]: {
|
2022-05-23 10:58:30 +08:00
|
|
|
flex: 'none',
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
},
|
2022-10-18 17:04:06 +08:00
|
|
|
[`${componentCls}-item, ${componentCls}-submenu`]: {
|
2022-07-28 20:33:10 +08:00
|
|
|
borderRadius: token.radiusItem,
|
|
|
|
},
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
[`${componentCls}-item-group-title`]: {
|
|
|
|
padding: `${paddingXS}px ${padding}px`,
|
2022-04-20 15:31:04 +08:00
|
|
|
fontSize,
|
2022-05-23 10:58:30 +08:00
|
|
|
lineHeight,
|
|
|
|
transition: `all ${motionDurationSlow}`,
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
[`&-horizontal ${componentCls}-submenu`]: {
|
|
|
|
transition: [
|
|
|
|
`border-color ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
`background ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
].join(','),
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
[`${componentCls}-submenu, ${componentCls}-submenu-inline`]: {
|
|
|
|
transition: [
|
|
|
|
`border-color ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
`background ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
`padding ${motionDurationMid} ${motionEaseInOut}`,
|
|
|
|
].join(','),
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
[`${componentCls}-submenu ${componentCls}-sub`]: {
|
|
|
|
cursor: 'initial',
|
|
|
|
transition: [
|
|
|
|
`background ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
`padding ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
],
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
[`${componentCls}-title-content`]: {
|
|
|
|
transition: `color ${motionDurationSlow}`,
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
[`${componentCls}-item a`]: {
|
|
|
|
'&::before': {
|
|
|
|
position: 'absolute',
|
|
|
|
inset: 0,
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
content: '""',
|
|
|
|
},
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
// Removed a Badge related style seems it's safe
|
|
|
|
// https://github.com/ant-design/ant-design/issues/19809
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
// >>>>> Divider
|
|
|
|
[`${componentCls}-item-divider`]: {
|
|
|
|
overflow: 'hidden',
|
|
|
|
lineHeight: 0,
|
2022-07-21 17:00:42 +08:00
|
|
|
borderColor: colorSplit,
|
2022-05-23 10:58:30 +08:00
|
|
|
borderStyle: lineType,
|
|
|
|
borderTopWidth: lineWidth,
|
|
|
|
marginBlock: lineWidth,
|
|
|
|
padding: 0,
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
'&-dashed': {
|
|
|
|
borderStyle: 'dashed',
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
// >>>>> Item
|
|
|
|
[`${componentCls}-item, ${componentCls}-submenu-title`]: {
|
|
|
|
position: 'relative',
|
|
|
|
display: 'block',
|
|
|
|
margin: 0,
|
|
|
|
// paddingInline: menuItemPaddingInline,
|
2022-04-20 15:31:04 +08:00
|
|
|
whiteSpace: 'nowrap',
|
2022-05-23 10:58:30 +08:00
|
|
|
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(','),
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
'+ span': {
|
|
|
|
marginInlineStart: controlHeightSM - fontSize,
|
|
|
|
opacity: 1,
|
|
|
|
transition: [
|
|
|
|
`opacity ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
`margin ${motionDurationSlow}`,
|
|
|
|
`color ${motionDurationSlow}`,
|
|
|
|
].join(','),
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
[`${componentCls}-item-icon`]: {
|
|
|
|
...resetIcon(),
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
[`&.${componentCls}-item-only-child`]: {
|
|
|
|
[`> ${iconCls}, > ${componentCls}-item-icon`]: {
|
|
|
|
marginInlineEnd: 0,
|
|
|
|
},
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
},
|
2022-05-23 10:58:30 +08:00
|
|
|
|
|
|
|
// Disabled state sets text to gray and nukes hover/tab effects
|
|
|
|
[`${componentCls}-item-disabled, ${componentCls}-submenu-disabled`]: {
|
|
|
|
background: 'none !important',
|
|
|
|
cursor: 'not-allowed',
|
|
|
|
|
2022-04-20 15:31:04 +08:00
|
|
|
'&::after': {
|
2022-05-23 10:58:30 +08:00
|
|
|
borderColor: 'transparent !important',
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
2022-05-23 10:58:30 +08:00
|
|
|
|
|
|
|
a: {
|
|
|
|
color: 'inherit !important',
|
|
|
|
pointerEvents: 'none',
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
[`> ${componentCls}-submenu-title`]: {
|
|
|
|
color: 'inherit !important',
|
|
|
|
cursor: 'not-allowed',
|
|
|
|
},
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
[`${componentCls}-item-group`]: {
|
|
|
|
[`${componentCls}-item-group-list`]: {
|
|
|
|
margin: 0,
|
|
|
|
padding: 0,
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
[`${componentCls}-item, ${componentCls}-submenu-title`]: {
|
|
|
|
paddingInline: `${fontSize * 2}px ${padding}px`,
|
|
|
|
},
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
// ======================= Sub Menu =======================
|
|
|
|
'&-submenu': {
|
|
|
|
'&-popup': {
|
|
|
|
position: 'absolute',
|
|
|
|
zIndex: zIndexPopup,
|
|
|
|
background: 'transparent',
|
2022-10-18 17:04:06 +08:00
|
|
|
borderRadius: radiusLG,
|
2022-05-23 10:58:30 +08:00
|
|
|
boxShadow: 'none',
|
|
|
|
transformOrigin: '0 0',
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
// https://github.com/ant-design/ant-design/issues/13955
|
|
|
|
'&::before': {
|
|
|
|
position: 'absolute',
|
|
|
|
inset: `${menuPanelMaskInset}px 0 0`,
|
|
|
|
zIndex: -1,
|
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
|
|
|
opacity: 0,
|
|
|
|
content: '""',
|
|
|
|
},
|
|
|
|
},
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
// https://github.com/ant-design/ant-design/issues/13955
|
|
|
|
'&-placement-rightTop::before': {
|
|
|
|
top: 0,
|
|
|
|
insetInlineStart: menuPanelMaskInset,
|
|
|
|
},
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
[`> ${componentCls}`]: {
|
2022-10-18 17:04:06 +08:00
|
|
|
borderRadius: radiusLG,
|
|
|
|
|
|
|
|
[`> ${componentCls}-item`]: {
|
|
|
|
borderRadius: radiusSubMenuItem,
|
|
|
|
},
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
[`${componentCls}-submenu-title::after`]: {
|
|
|
|
transition: `transform ${motionDurationSlow} ${motionEaseInOut}`,
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
[`${componentCls}-submenu`]: {
|
|
|
|
[`&-expand-icon, &-arrow`]: {
|
|
|
|
position: 'absolute',
|
|
|
|
top: '50%',
|
|
|
|
insetInlineEnd: token.margin,
|
|
|
|
width: menuArrowSize,
|
|
|
|
color: 'currentcolor',
|
|
|
|
transform: 'translateY(-50%)',
|
|
|
|
transition: `transform ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
},
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
'&-arrow': {
|
|
|
|
// →
|
|
|
|
'&::before, &::after': {
|
|
|
|
position: 'absolute',
|
|
|
|
width: menuArrowSize * 0.6,
|
|
|
|
height: menuArrowSize * 0.15,
|
|
|
|
backgroundColor: 'currentcolor',
|
|
|
|
borderRadius: radiusBase,
|
|
|
|
transition: [
|
|
|
|
`background ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
`transform ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
`top ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
`color ${motionDurationSlow} ${motionEaseInOut}`,
|
|
|
|
].join(','),
|
|
|
|
content: '""',
|
|
|
|
},
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
'&::before': {
|
|
|
|
transform: `rotate(45deg) translateY(-${menuArrowOffset})`,
|
|
|
|
},
|
2022-04-20 15:31:04 +08:00
|
|
|
|
|
|
|
'&::after': {
|
2022-05-23 10:58:30 +08:00
|
|
|
transform: `rotate(-45deg) translateY(${menuArrowOffset})`,
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
[`&-inline-collapsed ${componentCls}-submenu-arrow,
|
|
|
|
&-inline ${componentCls}-submenu-arrow`]: {
|
|
|
|
// ↓
|
2022-04-20 15:31:04 +08:00
|
|
|
'&::before': {
|
2022-05-23 10:58:30 +08:00
|
|
|
transform: `rotate(-45deg) translateX(${menuArrowOffset})`,
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
'&::after': {
|
2022-05-23 10:58:30 +08:00
|
|
|
transform: `rotate(45deg) translateX(-${menuArrowOffset})`,
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
[`${componentCls}-submenu-open${componentCls}-submenu-inline > ${componentCls}-submenu-title > ${componentCls}-submenu-arrow`]:
|
|
|
|
{
|
|
|
|
// ↑
|
|
|
|
transform: `translateY(-${menuArrowSize * 0.2}px)`,
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
'&::after': {
|
|
|
|
transform: `rotate(-45deg) translateX(-${menuArrowOffset})`,
|
|
|
|
},
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
'&::before': {
|
|
|
|
transform: `rotate(45deg) translateX(${menuArrowOffset})`,
|
|
|
|
},
|
|
|
|
},
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// Integration with header element so menu items have the same height
|
2022-05-23 10:58:30 +08:00
|
|
|
{
|
|
|
|
[`${antCls}-layout-header`]: {
|
|
|
|
[componentCls]: {
|
|
|
|
lineHeight: 'inherit',
|
|
|
|
},
|
2022-04-20 15:31:04 +08:00
|
|
|
},
|
|
|
|
},
|
2022-05-23 10:58:30 +08:00
|
|
|
];
|
2022-04-20 15:31:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// ============================== Export ==============================
|
2022-04-25 10:54:00 +08:00
|
|
|
export default (prefixCls: string, injectStyle: boolean): UseComponentStyleResult => {
|
2022-05-23 10:58:30 +08:00
|
|
|
const useOriginHook = genComponentStyleHook(
|
|
|
|
'Menu',
|
2022-09-19 22:17:26 +08:00
|
|
|
(token, { overrideComponentToken }) => {
|
2022-05-23 10:58:30 +08:00
|
|
|
// Dropdown will handle menu style self. We do not need to handle this.
|
|
|
|
if (injectStyle === false) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2022-09-19 22:17:26 +08:00
|
|
|
const { colorPrimary, colorError, colorErrorHover, colorTextLightSolid, colorTextSecondary } =
|
|
|
|
token;
|
|
|
|
|
2022-07-28 20:33:10 +08:00
|
|
|
const { controlHeightLG, fontSize } = token;
|
2022-05-23 10:58:30 +08:00
|
|
|
|
|
|
|
const menuArrowSize = (fontSize / 7) * 5;
|
|
|
|
|
|
|
|
// Menu Token
|
|
|
|
const menuToken = mergeToken<MenuToken>(token, {
|
|
|
|
menuItemHeight: controlHeightLG,
|
2022-08-01 11:19:32 +08:00
|
|
|
menuItemPaddingInline: token.margin,
|
|
|
|
menuItemMarginInline: token.marginXXS,
|
2022-05-23 10:58:30 +08:00
|
|
|
menuArrowSize,
|
|
|
|
menuHorizontalHeight: controlHeightLG * 1.15,
|
|
|
|
menuArrowOffset: `${menuArrowSize * 0.25}px`,
|
|
|
|
menuPanelMaskInset: -7, // Still a hardcode here since it's offset by rc-align
|
|
|
|
});
|
|
|
|
|
2022-09-19 22:17:26 +08:00
|
|
|
const menuDarkToken = mergeToken<MenuToken>(
|
|
|
|
menuToken,
|
|
|
|
{
|
|
|
|
colorItemText: new TinyColor(colorTextLightSolid).setAlpha(0.65).toRgbString(),
|
|
|
|
colorItemTextHover: colorTextLightSolid,
|
|
|
|
colorGroupTitle: colorTextSecondary,
|
|
|
|
colorItemTextSelected: colorTextLightSolid,
|
|
|
|
colorItemBg: '#001529',
|
|
|
|
colorSubItemBg: '#000c17',
|
|
|
|
colorItemBgActive: 'transparent',
|
|
|
|
colorItemBgSelected: colorPrimary,
|
|
|
|
colorActiveBarWidth: 0,
|
|
|
|
colorActiveBarHeight: 0,
|
|
|
|
colorActiveBarBorderSize: 0,
|
|
|
|
|
|
|
|
// Disabled
|
|
|
|
colorItemTextDisabled: new TinyColor(colorTextLightSolid).setAlpha(0.25).toRgbString(),
|
|
|
|
|
|
|
|
// Danger
|
|
|
|
colorDangerItemText: colorError,
|
|
|
|
colorDangerItemTextHover: colorErrorHover,
|
|
|
|
colorDangerItemTextSelected: colorTextLightSolid,
|
|
|
|
colorDangerItemBgActive: colorError,
|
|
|
|
colorDangerItemBgSelected: colorError,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
...overrideComponentToken,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2022-05-23 10:58:30 +08:00
|
|
|
return [
|
|
|
|
// Basic
|
|
|
|
getBaseStyle(menuToken),
|
|
|
|
|
|
|
|
// Horizontal
|
2022-07-28 20:33:10 +08:00
|
|
|
getHorizontalStyle(menuToken), // Hard code for some light style
|
2022-05-23 10:58:30 +08:00
|
|
|
|
|
|
|
// Vertical
|
2022-07-28 20:33:10 +08:00
|
|
|
getVerticalStyle(menuToken), // Hard code for some light style
|
2022-05-23 10:58:30 +08:00
|
|
|
|
|
|
|
// Theme
|
2022-09-19 22:17:26 +08:00
|
|
|
getThemeStyle(menuToken, 'light'),
|
|
|
|
getThemeStyle(menuDarkToken, 'dark'),
|
2022-05-23 10:58:30 +08:00
|
|
|
|
|
|
|
// RTL
|
|
|
|
getRTLStyle(menuToken),
|
2022-07-19 22:53:38 +08:00
|
|
|
|
|
|
|
// Motion
|
|
|
|
genCollapseMotion(menuToken),
|
2022-07-28 20:33:10 +08:00
|
|
|
|
|
|
|
initSlideMotion(menuToken, 'slide-up'),
|
|
|
|
initSlideMotion(menuToken, 'slide-down'),
|
|
|
|
initZoomMotion(menuToken, 'zoom-big'),
|
2022-05-23 10:58:30 +08:00
|
|
|
];
|
|
|
|
},
|
2022-07-28 20:33:10 +08:00
|
|
|
token => {
|
|
|
|
const {
|
|
|
|
colorPrimary,
|
|
|
|
colorError,
|
|
|
|
colorTextDisabled,
|
|
|
|
colorErrorBg,
|
|
|
|
colorText,
|
2022-08-04 16:16:50 +08:00
|
|
|
colorTextDescription,
|
2022-07-28 20:33:10 +08:00
|
|
|
colorBgContainer,
|
|
|
|
colorFillAlter,
|
2022-10-18 17:04:06 +08:00
|
|
|
colorFillContent,
|
2022-07-28 20:33:10 +08:00
|
|
|
lineWidth,
|
|
|
|
lineWidthBold,
|
2022-10-18 17:04:06 +08:00
|
|
|
controlItemBgActiveHover,
|
|
|
|
colorBgTextHover,
|
2022-07-28 20:33:10 +08:00
|
|
|
} = token;
|
|
|
|
|
|
|
|
return {
|
|
|
|
dropdownWidth: 160,
|
|
|
|
zIndexPopup: token.zIndexPopupBase + 50,
|
2022-10-18 17:04:06 +08:00
|
|
|
radiusItem: token.radiusLG,
|
|
|
|
radiusSubMenuItem: token.radiusSM,
|
2022-07-28 20:33:10 +08:00
|
|
|
colorItemText: colorText,
|
2022-10-18 17:04:06 +08:00
|
|
|
colorItemTextHover: colorText,
|
|
|
|
colorItemTextHoverHorizontal: colorPrimary,
|
2022-08-04 16:16:50 +08:00
|
|
|
colorGroupTitle: colorTextDescription,
|
2022-10-18 17:04:06 +08:00
|
|
|
colorItemTextSelected: colorText,
|
|
|
|
colorItemTextSelectedHorizontal: colorPrimary,
|
2022-07-28 20:33:10 +08:00
|
|
|
colorItemBg: colorBgContainer,
|
2022-10-18 17:04:06 +08:00
|
|
|
colorItemBgHover: colorBgTextHover,
|
|
|
|
colorItemBgActive: colorFillContent,
|
2022-07-28 20:33:10 +08:00
|
|
|
colorSubItemBg: colorFillAlter,
|
2022-10-18 17:04:06 +08:00
|
|
|
colorItemBgSelected: controlItemBgActiveHover,
|
2022-07-28 20:33:10 +08:00
|
|
|
colorItemBgSelectedHorizontal: 'transparent',
|
2022-10-18 17:04:06 +08:00
|
|
|
colorActiveBarWidth: 0,
|
2022-07-28 20:33:10 +08:00
|
|
|
colorActiveBarHeight: lineWidthBold,
|
|
|
|
colorActiveBarBorderSize: lineWidth,
|
|
|
|
|
|
|
|
// Disabled
|
|
|
|
colorItemTextDisabled: colorTextDisabled,
|
|
|
|
|
|
|
|
// Danger
|
|
|
|
colorDangerItemText: colorError,
|
|
|
|
colorDangerItemTextHover: colorError,
|
|
|
|
colorDangerItemTextSelected: colorError,
|
|
|
|
colorDangerItemBgActive: colorErrorBg,
|
|
|
|
colorDangerItemBgSelected: colorErrorBg,
|
2022-10-18 17:04:06 +08:00
|
|
|
|
|
|
|
itemMarginInline: token.marginXXS,
|
2022-07-28 20:33:10 +08:00
|
|
|
};
|
|
|
|
},
|
2022-05-23 10:58:30 +08:00
|
|
|
);
|
2022-04-20 15:31:04 +08:00
|
|
|
|
2022-04-25 10:54:00 +08:00
|
|
|
return useOriginHook(prefixCls);
|
|
|
|
};
|