File size: 31,489 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 |
import type { CSSProperties } from 'react';
import type { CSSObject } from '@ant-design/cssinjs';
import { unit } from '@ant-design/cssinjs';
import { FastColor } from '@ant-design/fast-color';
import type { CssUtil } from 'antd-style';
import { clearFix, resetComponent, resetIcon } from '../../style';
import { genCollapseMotion, initSlideMotion, initZoomMotion } from '../../style/motion';
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
import { genStyleHooks, mergeToken } from '../../theme/internal';
import getHorizontalStyle from './horizontal';
import getRTLStyle from './rtl';
import getThemeStyle from './theme';
import getVerticalStyle from './vertical';
/** Component only token. Which will handle additional calculation of alias token */
export interface ComponentToken {
/**
* @desc 弹出菜单的宽度
* @descEN Width of popup menu
*/
dropdownWidth: number | string;
/**
* @desc 弹出菜单的 z-index
* @descEN z-index of popup menu
*/
zIndexPopup: number;
// Group
/** @deprecated Use `groupTitleColor` instead */
colorGroupTitle: string;
/**
* @desc 分组标题文字颜色
* @descEN Color of group title text
*/
groupTitleColor: string;
/**
* @desc 分组标题文字高度
* @descEN line-height of group title
*/
groupTitleLineHeight: string | number;
/**
* @desc 分组标题文字大小
* @descEN font-size of group title
*/
groupTitleFontSize: number;
// radius
/** @deprecated Use `itemBorderRadius` instead */
radiusItem: number;
/**
* @desc 菜单项的圆角
* @descEN Radius of menu item
*/
itemBorderRadius: number;
/** @deprecated Use `subMenuItemBorderRadius` instead */
radiusSubMenuItem: number;
/**
* @desc 子菜单项的圆角
* @descEN Radius of sub-menu item
*/
subMenuItemBorderRadius: number;
// Item Text
// > Default
/** @deprecated Use `itemColor` instead */
colorItemText: string;
/**
* @desc 菜单项文字颜色
* @descEN Color of menu item text
*/
itemColor: string;
/** @deprecated Use `itemHoverColor` instead */
colorItemTextHover: string;
/**
* @desc 菜单项文字悬浮颜色
* @descEN Hover color of menu item text
*/
itemHoverColor: string;
/** @deprecated Use `horizontalItemHoverColor` instead */
colorItemTextHoverHorizontal: string;
/**
* @desc 水平菜单项文字悬浮颜色
* @descEN Hover color of horizontal menu item text
*/
horizontalItemHoverColor: string;
/** @deprecated Use `itemSelectedColor` instead */
colorItemTextSelected: string;
/**
* @desc 菜单项文字选中颜色
* @descEN Color of selected menu item text
*/
itemSelectedColor: string;
/**
* @desc 子菜单内有选中项时,子菜单标题色
* @descEN Color of submenu title when submenu has selected item
*/
subMenuItemSelectedColor: string;
/** @deprecated Use `horizontalItemSelectedColor` instead */
colorItemTextSelectedHorizontal: string;
/**
* @desc 水平菜单项文字选中颜色
* @descEN Color of selected horizontal menu item text
*/
horizontalItemSelectedColor: string;
// > Disabled
/** @deprecated Use `itemDisabledColor` instead */
colorItemTextDisabled: string;
/**
* @desc 菜单项文字禁用颜色
* @descEN Color of disabled menu item text
*/
itemDisabledColor: string;
// > Danger
/** @deprecated Use `dangerItemColor` instead */
colorDangerItemText: string;
/**
* @desc 危险菜单项文字颜色
* @descEN Color of danger menu item text
*/
dangerItemColor: string;
/** @deprecated Use `dangerItemHoverColor` instead */
colorDangerItemTextHover: string;
/**
* @desc 危险菜单项文字悬浮颜色
* @descEN Hover color of danger menu item text
*/
dangerItemHoverColor: string;
/** @deprecated Use `dangerItemSelectedColor` instead */
colorDangerItemTextSelected: string;
/**
* @desc 危险菜单项文字选中颜色
* @descEN Color of selected danger menu item text
*/
dangerItemSelectedColor: string;
/** @deprecated Use `dangerItemActiveBg` instead */
colorDangerItemBgActive: string;
/**
* @desc 危险菜单项激活态背景色
* @descEN Background color of danger menu item when active
*/
dangerItemActiveBg: string;
/** @deprecated Use `dangerItemSelectedBg` instead */
colorDangerItemBgSelected: string;
/**
* @desc 危险菜单项选中背景色
* @descEN Background color of selected danger menu item
*/
dangerItemSelectedBg: string;
// Item Bg
/** @deprecated Use `itemBg` instead */
colorItemBg: string;
/**
* @desc 菜单项背景色
*/
itemBg: string;
/** @deprecated Use `itemHoverBg` instead */
colorItemBgHover: string;
/**
* @desc 菜单项悬浮态背景色
* @descEN Background color of menu item when hover
*/
itemHoverBg: string;
/** @deprecated Use `subMenuItemBg` instead */
colorSubItemBg: string;
/**
* @desc 子菜单项背景色
* @descEN Background color of sub-menu item
*/
subMenuItemBg: string;
// > Default
/** @deprecated Use `itemActiveBg` instead */
colorItemBgActive: string;
/**
* @desc 菜单项激活态背景色
* @descEN Background color of menu item when active
*/
itemActiveBg: string;
/** @deprecated Use `itemSelectedBg` instead */
colorItemBgSelected: string;
/**
* @desc 菜单项选中态背景色
* @descEN Background color of menu item when selected
*/
itemSelectedBg: string;
/** @deprecated Use `horizontalItemSelectedBg` instead */
colorItemBgSelectedHorizontal: string;
/**
* @desc 水平菜单项选中态背景色
* @descEN Background color of horizontal menu item when selected
*/
horizontalItemSelectedBg: string;
// Ink Bar
/** @deprecated Use `activeBarWidth` instead */
colorActiveBarWidth: number | string;
/**
* @desc 菜单项指示条宽度
* @descEN Width of menu item active bar
*/
activeBarWidth: number | string;
/** @deprecated Use `activeBarHeight` instead */
colorActiveBarHeight: number;
/**
* @desc 菜单项指示条高度
* @descEN Height of menu item active bar
*/
activeBarHeight: number;
/** @deprecated Use `activeBarBorderWidth` instead */
colorActiveBarBorderSize: number;
/**
* @desc 菜单项指示条边框宽度
* @descEN Border width of menu item active bar
*/
activeBarBorderWidth: number | string;
/**
* @desc 菜单项横向外间距
* @descEN Horizontal margin of menu item
*/
itemMarginInline: number;
/**
* @desc 横向菜单项横悬浮态背景色
* @descEN Background color of horizontal menu item when hover
*/
horizontalItemHoverBg: string;
/**
* @desc 横向菜单项圆角
* @descEN Border radius of horizontal menu item
*/
horizontalItemBorderRadius: number;
/**
* @desc 菜单项高度
* @descEN Height of menu item
*/
itemHeight: number | string;
/**
* @desc 收起后的宽度
* @descEN Width when collapsed
*/
collapsedWidth: number | string;
/**
* @desc 弹出框背景色
* @descEN Background color of popup
*/
popupBg: string;
/**
* @desc 菜单项纵向外间距
* @descEN margin-block of menu item
*/
itemMarginBlock: CSSProperties['marginBlock'];
/**
* @desc 菜单项横向内间距
* @descEN padding-inline of menu item
*/
itemPaddingInline: CSSProperties['paddingInline'];
/**
* @desc 横向菜单行高
* @descEN LineHeight of horizontal menu item
*/
horizontalLineHeight: CSSProperties['lineHeight'];
/**
* @desc 图标与文字间距
* @descEN Spacing between icon and text
*/
iconMarginInlineEnd: CSSProperties['marginInlineEnd'];
/**
* @desc 图标尺寸
* @descEN Size of icon
*/
iconSize: number;
/**
* @desc 收起时图标尺寸
* @descEN Size of icon when collapsed
*/
collapsedIconSize: number;
// Dark
/**
* @desc 暗色模式下的浮层菜单的背景颜色
* @descEN The background color of the overlay menu in dark mode.
*/
darkPopupBg: string;
/**
* @desc 暗色模式下的菜单项文字颜色
* @descEN Color of menu item text in dark mode
*/
darkItemColor: string;
/**
* @desc 暗色模式下的危险菜单项文字颜色
* @descEN Color of danger menu item text in dark mode
*/
darkDangerItemColor: string;
/**
* @desc 暗色模式下的菜单项背景
* @descEN Background of menu item in dark mode
*/
darkItemBg: string;
/**
* @desc 暗色模式下的子菜单项背景
* @descEN Background of submenu item in dark mode
*/
darkSubMenuItemBg: string;
/**
* @desc 暗色模式下的菜单项选中颜色
* @descEN Color of selected menu item in dark mode
*/
darkItemSelectedColor: string;
/**
* @desc 暗色模式下的菜单项选中背景
* @descEN Background of active menu item in dark mode
*/
darkItemSelectedBg: string;
/**
* @desc 暗色模式下的菜单项悬浮背景
* @descEN Background of hovered menu item in dark mode
*/
darkItemHoverBg: string;
/**
* @desc 暗色模式下的分组标题文字颜色
* @descEN Color of group title text in dark mode
*/
darkGroupTitleColor: string;
/**
* @desc 暗色模式下的菜单项悬浮颜色
* @descEN Color of hovered menu item in dark mode
*/
darkItemHoverColor: string;
/**
* @desc 暗色模式下的菜单项禁用颜色
* @descEN Color of disabled menu item in dark mode
*/
darkItemDisabledColor: string;
/**
* @desc 暗色模式下的危险菜单项选中背景
* @descEN Background of active danger menu item in dark mode
*/
darkDangerItemSelectedBg: string;
/**
* @desc 暗色模式下的危险菜单项悬浮文字背景
* @descEN Background of hovered danger menu item in dark mode
*/
darkDangerItemHoverColor: string;
/**
* @desc 暗色模式下的危险菜单项选中文字颜色
* @descEN Color of selected danger menu item in dark mode
*/
darkDangerItemSelectedColor: string;
/**
* @desc 暗色模式下的危险菜单项激活态背景
* @descEN Background of active danger menu item in dark mode
*/
darkDangerItemActiveBg: string;
/** @internal */
itemWidth: number | string;
}
/**
* @desc Menu 组件的 Token
* @descEN Token for Menu component
*/
export interface MenuToken extends FullToken<'Menu'> {
/**
* @desc 水平菜单高度
* @descEN Height of horizontal menu
*/
menuHorizontalHeight: number | string;
/**
* @desc 菜单箭头尺寸
* @descEN Size of menu arrow
*/
menuArrowSize: number | string;
/**
* @desc 菜单箭头偏移量
* @descEN Offset of menu arrow
*/
menuArrowOffset: number | string;
/**
* @desc 子菜单背景色
* @descEN Background color of sub-menu
*/
menuSubMenuBg: string;
/**
* @desc 暗色模式下的浮层菜单背景色
* @descEN Background color of popup menu in dark mode
*/
darkPopupBg: string;
}
const genMenuItemStyle = (token: MenuToken): CSSObject => {
const {
componentCls,
motionDurationSlow,
motionDurationMid,
motionEaseInOut,
motionEaseOut,
iconCls,
iconSize,
iconMarginInlineEnd,
} = 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 calc(${motionDurationSlow} + 0.1s) ${motionEaseInOut}`,
].join(','),
[`${componentCls}-item-icon, ${iconCls}`]: {
minWidth: iconSize,
fontSize: iconSize,
transition: [
`font-size ${motionDurationMid} ${motionEaseOut}`,
`margin ${motionDurationSlow} ${motionEaseInOut}`,
`color ${motionDurationSlow}`,
].join(','),
'+ span': {
marginInlineStart: iconMarginInlineEnd,
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',
cursor: 'not-allowed',
pointerEvents: 'none',
},
[`> ${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}, opacity ${motionDurationSlow}`,
},
'&-arrow': {
// →
'&::before, &::after': {
position: 'absolute',
width: token.calc(menuArrowSize).mul(0.6).equal(),
height: token.calc(menuArrowSize).mul(0.15).equal(),
backgroundColor: 'currentcolor',
borderRadius,
transition: [
`background ${motionDurationSlow} ${motionEaseInOut}`,
`transform ${motionDurationSlow} ${motionEaseInOut}`,
`top ${motionDurationSlow} ${motionEaseInOut}`,
`color ${motionDurationSlow} ${motionEaseInOut}`,
].join(','),
content: '""',
},
'&::before': {
transform: `rotate(45deg) translateY(${unit(
token.calc(menuArrowOffset).mul(-1).equal(),
)})`,
},
'&::after': {
transform: `rotate(-45deg) translateY(${unit(menuArrowOffset)})`,
},
},
},
};
};
// =============================== Base ===============================
const getBaseStyle: GenerateStyle<MenuToken> = (token) => {
const {
antCls,
componentCls,
fontSize,
motionDurationSlow,
motionDurationMid,
motionEaseInOut,
paddingXS,
padding,
colorSplit,
lineWidth,
zIndexPopup,
borderRadiusLG,
subMenuItemBorderRadius,
menuArrowSize,
menuArrowOffset,
lineType,
groupTitleLineHeight,
groupTitleFontSize,
} = 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',
// Magic cubic here but smooth transition
transition: `width ${motionDurationSlow} cubic-bezier(0.2, 0, 0, 1) 0s`,
'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.itemBorderRadius,
},
[`${componentCls}-item-group-title`]: {
padding: `${unit(paddingXS)} ${unit(padding)}`,
fontSize: groupTitleFontSize,
lineHeight: groupTitleLineHeight,
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}`,
].join(','),
},
[`${componentCls}-title-content`]: {
transition: `color ${motionDurationSlow}`,
'&-with-extra': {
display: 'inline-flex',
alignItems: 'center',
width: '100%',
},
// https://github.com/ant-design/ant-design/issues/41143
[`> ${antCls}-typography-ellipsis-single-line`]: {
display: 'inline',
verticalAlign: 'unset',
},
[`${componentCls}-item-extra`]: {
marginInlineStart: 'auto',
paddingInlineStart: token.padding,
},
},
[`${componentCls}-item a`]: {
'&::before': {
position: 'absolute',
inset: 0,
backgroundColor: 'transparent',
content: '""',
},
},
// Removed a Badge related style seems it's safe
// https://github.com/ant-design/ant-design/issues/19809
// >>>>> Divider
[`${componentCls}-item-divider`]: {
overflow: 'hidden',
lineHeight: 0,
borderColor: colorSplit,
borderStyle: lineType,
borderWidth: 0,
borderTopWidth: lineWidth,
marginBlock: lineWidth,
padding: 0,
'&-dashed': {
borderStyle: 'dashed',
},
},
// Item
...genMenuItemStyle(token),
[`${componentCls}-item-group`]: {
[`${componentCls}-item-group-list`]: {
margin: 0,
padding: 0,
[`${componentCls}-item, ${componentCls}-submenu-title`]: {
paddingInline: `${unit(token.calc(fontSize).mul(2).equal())} ${unit(padding)}`,
},
},
},
// ======================= Sub Menu =======================
'&-submenu': {
'&-popup': {
position: 'absolute',
zIndex: zIndexPopup,
borderRadius: borderRadiusLG,
boxShadow: 'none',
transformOrigin: '0 0',
[`&${componentCls}-submenu`]: {
background: 'transparent',
},
// https://github.com/ant-design/ant-design/issues/13955
'&::before': {
position: 'absolute',
inset: 0,
zIndex: -1,
width: '100%',
height: '100%',
opacity: 0,
content: '""',
},
[`> ${componentCls}`]: {
borderRadius: borderRadiusLG,
...genMenuItemStyle(token),
...genSubMenuArrowStyle(token),
[`${componentCls}-item, ${componentCls}-submenu > ${componentCls}-submenu-title`]: {
borderRadius: subMenuItemBorderRadius,
},
[`${componentCls}-submenu-title::after`]: {
transition: `transform ${motionDurationSlow} ${motionEaseInOut}`,
},
},
},
[`
&-placement-leftTop,
&-placement-bottomRight,
`]: {
transformOrigin: '100% 0',
},
[`
&-placement-leftBottom,
&-placement-topRight,
`]: {
transformOrigin: '100% 100%',
},
[`
&-placement-rightBottom,
&-placement-topLeft,
`]: {
transformOrigin: '0 100%',
},
[`
&-placement-bottomLeft,
&-placement-rightTop,
`]: {
transformOrigin: '0 0',
},
[`
&-placement-leftTop,
&-placement-leftBottom
`]: {
paddingInlineEnd: token.paddingXS,
},
[`
&-placement-rightTop,
&-placement-rightBottom
`]: {
paddingInlineStart: token.paddingXS,
},
[`
&-placement-topRight,
&-placement-topLeft
`]: {
paddingBottom: token.paddingXS,
},
[`
&-placement-bottomRight,
&-placement-bottomLeft
`]: {
paddingTop: token.paddingXS,
},
},
...genSubMenuArrowStyle(token),
[`&-inline-collapsed ${componentCls}-submenu-arrow,
&-inline ${componentCls}-submenu-arrow`]: {
// ↓
'&::before': {
transform: `rotate(-45deg) translateX(${unit(menuArrowOffset)})`,
},
'&::after': {
transform: `rotate(45deg) translateX(${unit(
token.calc(menuArrowOffset).mul(-1).equal(),
)})`,
},
},
[`${componentCls}-submenu-open${componentCls}-submenu-inline > ${componentCls}-submenu-title > ${componentCls}-submenu-arrow`]:
{
// ↑
transform: `translateY(${unit(token.calc(menuArrowSize).mul(0.2).mul(-1).equal())})`,
'&::after': {
transform: `rotate(-45deg) translateX(${unit(
token.calc(menuArrowOffset).mul(-1).equal(),
)})`,
},
'&::before': {
transform: `rotate(45deg) translateX(${unit(menuArrowOffset)})`,
},
},
},
},
// Integration with header element so menu items have the same height
{
[`${antCls}-layout-header`]: {
[componentCls]: {
lineHeight: 'inherit',
},
},
},
];
};
export const prepareComponentToken: GetDefaultToken<'Menu'> = (token) => {
const {
colorPrimary,
colorError,
colorTextDisabled,
colorErrorBg,
colorText,
colorTextDescription,
colorBgContainer,
colorFillAlter,
colorFillContent,
lineWidth,
lineWidthBold,
controlItemBgActive,
colorBgTextHover,
controlHeightLG,
lineHeight,
colorBgElevated,
marginXXS,
padding,
fontSize,
controlHeightSM,
fontSizeLG,
colorTextLightSolid,
colorErrorHover,
} = token;
const activeBarWidth = token.activeBarWidth ?? 0;
const activeBarBorderWidth = token.activeBarBorderWidth ?? lineWidth;
const itemMarginInline = token.itemMarginInline ?? token.marginXXS;
const colorTextDark = new FastColor(colorTextLightSolid).setA(0.65).toRgbString();
return {
dropdownWidth: 160,
zIndexPopup: token.zIndexPopupBase + 50,
radiusItem: token.borderRadiusLG,
itemBorderRadius: token.borderRadiusLG,
radiusSubMenuItem: token.borderRadiusSM,
subMenuItemBorderRadius: token.borderRadiusSM,
colorItemText: colorText,
itemColor: colorText,
colorItemTextHover: colorText,
itemHoverColor: colorText,
colorItemTextHoverHorizontal: colorPrimary,
horizontalItemHoverColor: colorPrimary,
colorGroupTitle: colorTextDescription,
groupTitleColor: colorTextDescription,
colorItemTextSelected: colorPrimary,
itemSelectedColor: colorPrimary,
subMenuItemSelectedColor: colorPrimary,
colorItemTextSelectedHorizontal: colorPrimary,
horizontalItemSelectedColor: colorPrimary,
colorItemBg: colorBgContainer,
itemBg: colorBgContainer,
colorItemBgHover: colorBgTextHover,
itemHoverBg: colorBgTextHover,
colorItemBgActive: colorFillContent,
itemActiveBg: controlItemBgActive,
colorSubItemBg: colorFillAlter,
subMenuItemBg: colorFillAlter,
colorItemBgSelected: controlItemBgActive,
itemSelectedBg: controlItemBgActive,
colorItemBgSelectedHorizontal: 'transparent',
horizontalItemSelectedBg: 'transparent',
colorActiveBarWidth: 0,
activeBarWidth,
colorActiveBarHeight: lineWidthBold,
activeBarHeight: lineWidthBold,
colorActiveBarBorderSize: lineWidth,
activeBarBorderWidth,
// Disabled
colorItemTextDisabled: colorTextDisabled,
itemDisabledColor: colorTextDisabled,
// Danger
colorDangerItemText: colorError,
dangerItemColor: colorError,
colorDangerItemTextHover: colorError,
dangerItemHoverColor: colorError,
colorDangerItemTextSelected: colorError,
dangerItemSelectedColor: colorError,
colorDangerItemBgActive: colorErrorBg,
dangerItemActiveBg: colorErrorBg,
colorDangerItemBgSelected: colorErrorBg,
dangerItemSelectedBg: colorErrorBg,
itemMarginInline,
horizontalItemBorderRadius: 0,
horizontalItemHoverBg: 'transparent',
itemHeight: controlHeightLG,
groupTitleLineHeight: lineHeight,
collapsedWidth: controlHeightLG * 2,
popupBg: colorBgElevated,
itemMarginBlock: marginXXS,
itemPaddingInline: padding,
horizontalLineHeight: `${controlHeightLG * 1.15}px`,
iconSize: fontSize,
iconMarginInlineEnd: controlHeightSM - fontSize,
collapsedIconSize: fontSizeLG,
groupTitleFontSize: fontSize,
// Disabled
darkItemDisabledColor: new FastColor(colorTextLightSolid).setA(0.25).toRgbString(),
// Dark
darkItemColor: colorTextDark,
darkDangerItemColor: colorError,
darkItemBg: '#001529',
darkPopupBg: '#001529',
darkSubMenuItemBg: '#000c17',
darkItemSelectedColor: colorTextLightSolid,
darkItemSelectedBg: colorPrimary,
darkDangerItemSelectedBg: colorError,
darkItemHoverBg: 'transparent',
darkGroupTitleColor: colorTextDark,
darkItemHoverColor: colorTextLightSolid,
darkDangerItemHoverColor: colorErrorHover,
darkDangerItemSelectedColor: colorTextLightSolid,
darkDangerItemActiveBg: colorError,
// internal
itemWidth: activeBarWidth
? `calc(100% + ${activeBarBorderWidth}px)`
: `calc(100% - ${itemMarginInline * 2}px)`,
};
};
// ============================== Export ==============================
export default (prefixCls: string, rootCls: string = prefixCls, injectStyle = true) => {
const useStyle = genStyleHooks(
'Menu',
(token) => {
const {
colorBgElevated,
controlHeightLG,
fontSize,
darkItemColor,
darkDangerItemColor,
darkItemBg,
darkSubMenuItemBg,
darkItemSelectedColor,
darkItemSelectedBg,
darkDangerItemSelectedBg,
darkItemHoverBg,
darkGroupTitleColor,
darkItemHoverColor,
darkItemDisabledColor,
darkDangerItemHoverColor,
darkDangerItemSelectedColor,
darkDangerItemActiveBg,
popupBg,
darkPopupBg,
} = token;
const menuArrowSize = token.calc(fontSize).div(7).mul(5).equal();
// Menu Token
const menuToken = mergeToken<MenuToken & CssUtil>(token, {
menuArrowSize,
menuHorizontalHeight: token.calc(controlHeightLG).mul(1.15).equal(),
menuArrowOffset: token.calc(menuArrowSize).mul(0.25).equal(),
menuSubMenuBg: colorBgElevated,
calc: token.calc,
popupBg,
});
const menuDarkToken = mergeToken<MenuToken>(menuToken, {
itemColor: darkItemColor,
itemHoverColor: darkItemHoverColor,
groupTitleColor: darkGroupTitleColor,
itemSelectedColor: darkItemSelectedColor,
subMenuItemSelectedColor: darkItemSelectedColor,
itemBg: darkItemBg,
popupBg: darkPopupBg,
subMenuItemBg: darkSubMenuItemBg,
itemActiveBg: 'transparent',
itemSelectedBg: darkItemSelectedBg,
activeBarHeight: 0,
activeBarBorderWidth: 0,
itemHoverBg: darkItemHoverBg,
// Disabled
itemDisabledColor: darkItemDisabledColor,
// Danger
dangerItemColor: darkDangerItemColor,
dangerItemHoverColor: darkDangerItemHoverColor,
dangerItemSelectedColor: darkDangerItemSelectedColor,
dangerItemActiveBg: darkDangerItemActiveBg,
dangerItemSelectedBg: darkDangerItemSelectedBg,
menuSubMenuBg: darkSubMenuItemBg,
// Horizontal
horizontalItemSelectedColor: darkItemSelectedColor,
horizontalItemSelectedBg: darkItemSelectedBg,
});
return [
// Basic
getBaseStyle(menuToken),
// Horizontal
getHorizontalStyle(menuToken), // Hard code for some light style
// Vertical
getVerticalStyle(menuToken), // Hard code for some light style
// Theme
getThemeStyle(menuToken, 'light'),
getThemeStyle(menuDarkToken, 'dark'),
// RTL
getRTLStyle(menuToken),
// Motion
genCollapseMotion(menuToken),
initSlideMotion(menuToken, 'slide-up'),
initSlideMotion(menuToken, 'slide-down'),
initZoomMotion(menuToken, 'zoom-big'),
];
},
prepareComponentToken,
{
deprecatedTokens: [
['colorGroupTitle', 'groupTitleColor'],
['radiusItem', 'itemBorderRadius'],
['radiusSubMenuItem', 'subMenuItemBorderRadius'],
['colorItemText', 'itemColor'],
['colorItemTextHover', 'itemHoverColor'],
['colorItemTextHoverHorizontal', 'horizontalItemHoverColor'],
['colorItemTextSelected', 'itemSelectedColor'],
['colorItemTextSelectedHorizontal', 'horizontalItemSelectedColor'],
['colorItemTextDisabled', 'itemDisabledColor'],
['colorDangerItemText', 'dangerItemColor'],
['colorDangerItemTextHover', 'dangerItemHoverColor'],
['colorDangerItemTextSelected', 'dangerItemSelectedColor'],
['colorDangerItemBgActive', 'dangerItemActiveBg'],
['colorDangerItemBgSelected', 'dangerItemSelectedBg'],
['colorItemBg', 'itemBg'],
['colorItemBgHover', 'itemHoverBg'],
['colorSubItemBg', 'subMenuItemBg'],
['colorItemBgActive', 'itemActiveBg'],
['colorItemBgSelectedHorizontal', 'horizontalItemSelectedBg'],
['colorActiveBarWidth', 'activeBarWidth'],
['colorActiveBarHeight', 'activeBarHeight'],
['colorActiveBarBorderSize', 'activeBarBorderWidth'],
['colorItemBgSelected', 'itemSelectedBg'],
],
// Dropdown will handle menu style self. We do not need to handle this.
injectStyle,
unitless: {
groupTitleLineHeight: true,
},
},
);
return useStyle(prefixCls, rootCls);
};
|