index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = void 0;
  7. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  8. var _tinycolor = require("@ctrl/tinycolor");
  9. var _motion = require("../../style/motion");
  10. var _internal = require("../../theme/internal");
  11. var _horizontal = _interopRequireDefault(require("./horizontal"));
  12. var _rtl = _interopRequireDefault(require("./rtl"));
  13. var _theme = _interopRequireDefault(require("./theme"));
  14. var _vertical = _interopRequireDefault(require("./vertical"));
  15. var _style = require("../../style");
  16. require("vue");
  17. const genMenuItemStyle = token => {
  18. const {
  19. componentCls,
  20. fontSize,
  21. motionDurationSlow,
  22. motionDurationMid,
  23. motionEaseInOut,
  24. motionEaseOut,
  25. iconCls,
  26. controlHeightSM
  27. } = token;
  28. return {
  29. // >>>>> Item
  30. [`${componentCls}-item, ${componentCls}-submenu-title`]: {
  31. position: 'relative',
  32. display: 'block',
  33. margin: 0,
  34. whiteSpace: 'nowrap',
  35. cursor: 'pointer',
  36. transition: [`border-color ${motionDurationSlow}`, `background ${motionDurationSlow}`, `padding ${motionDurationSlow} ${motionEaseInOut}`].join(','),
  37. [`${componentCls}-item-icon, ${iconCls}`]: {
  38. minWidth: fontSize,
  39. fontSize,
  40. transition: [`font-size ${motionDurationMid} ${motionEaseOut}`, `margin ${motionDurationSlow} ${motionEaseInOut}`, `color ${motionDurationSlow}`].join(','),
  41. '+ span': {
  42. marginInlineStart: controlHeightSM - fontSize,
  43. opacity: 1,
  44. transition: [`opacity ${motionDurationSlow} ${motionEaseInOut}`, `margin ${motionDurationSlow}`, `color ${motionDurationSlow}`].join(',')
  45. }
  46. },
  47. [`${componentCls}-item-icon`]: (0, _extends2.default)({}, (0, _style.resetIcon)()),
  48. [`&${componentCls}-item-only-child`]: {
  49. [`> ${iconCls}, > ${componentCls}-item-icon`]: {
  50. marginInlineEnd: 0
  51. }
  52. }
  53. },
  54. // Disabled state sets text to gray and nukes hover/tab effects
  55. [`${componentCls}-item-disabled, ${componentCls}-submenu-disabled`]: {
  56. background: 'none !important',
  57. cursor: 'not-allowed',
  58. '&::after': {
  59. borderColor: 'transparent !important'
  60. },
  61. a: {
  62. color: 'inherit !important'
  63. },
  64. [`> ${componentCls}-submenu-title`]: {
  65. color: 'inherit !important',
  66. cursor: 'not-allowed'
  67. }
  68. }
  69. };
  70. };
  71. const genSubMenuArrowStyle = token => {
  72. const {
  73. componentCls,
  74. motionDurationSlow,
  75. motionEaseInOut,
  76. borderRadius,
  77. menuArrowSize,
  78. menuArrowOffset
  79. } = token;
  80. return {
  81. [`${componentCls}-submenu`]: {
  82. [`&-expand-icon, &-arrow`]: {
  83. position: 'absolute',
  84. top: '50%',
  85. insetInlineEnd: token.margin,
  86. width: menuArrowSize,
  87. color: 'currentcolor',
  88. transform: 'translateY(-50%)',
  89. transition: `transform ${motionDurationSlow} ${motionEaseInOut}, opacity ${motionDurationSlow}`
  90. },
  91. '&-arrow': {
  92. // →
  93. '&::before, &::after': {
  94. position: 'absolute',
  95. width: menuArrowSize * 0.6,
  96. height: menuArrowSize * 0.15,
  97. backgroundColor: 'currentcolor',
  98. borderRadius,
  99. transition: [`background ${motionDurationSlow} ${motionEaseInOut}`, `transform ${motionDurationSlow} ${motionEaseInOut}`, `top ${motionDurationSlow} ${motionEaseInOut}`, `color ${motionDurationSlow} ${motionEaseInOut}`].join(','),
  100. content: '""'
  101. },
  102. '&::before': {
  103. transform: `rotate(45deg) translateY(-${menuArrowOffset})`
  104. },
  105. '&::after': {
  106. transform: `rotate(-45deg) translateY(${menuArrowOffset})`
  107. }
  108. }
  109. }
  110. };
  111. };
  112. // =============================== Base ===============================
  113. const getBaseStyle = token => {
  114. const {
  115. antCls,
  116. componentCls,
  117. fontSize,
  118. motionDurationSlow,
  119. motionDurationMid,
  120. motionEaseInOut,
  121. lineHeight,
  122. paddingXS,
  123. padding,
  124. colorSplit,
  125. lineWidth,
  126. zIndexPopup,
  127. borderRadiusLG,
  128. radiusSubMenuItem,
  129. menuArrowSize,
  130. menuArrowOffset,
  131. lineType,
  132. menuPanelMaskInset
  133. } = token;
  134. return [
  135. // Misc
  136. {
  137. '': {
  138. [`${componentCls}`]: (0, _extends2.default)((0, _extends2.default)({}, (0, _style.clearFix)()), {
  139. // Hidden
  140. [`&-hidden`]: {
  141. display: 'none'
  142. }
  143. })
  144. },
  145. [`${componentCls}-submenu-hidden`]: {
  146. display: 'none'
  147. }
  148. }, {
  149. [componentCls]: (0, _extends2.default)((0, _extends2.default)((0, _extends2.default)((0, _extends2.default)((0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({}, (0, _style.resetComponent)(token)), (0, _style.clearFix)()), {
  150. marginBottom: 0,
  151. paddingInlineStart: 0,
  152. // Override default ul/ol
  153. fontSize,
  154. lineHeight: 0,
  155. listStyle: 'none',
  156. outline: 'none',
  157. transition: `width ${motionDurationSlow} cubic-bezier(0.2, 0, 0, 1) 0s`,
  158. [`ul, ol`]: {
  159. margin: 0,
  160. padding: 0,
  161. listStyle: 'none'
  162. },
  163. // Overflow ellipsis
  164. [`&-overflow`]: {
  165. display: 'flex',
  166. [`${componentCls}-item`]: {
  167. flex: 'none'
  168. }
  169. },
  170. [`${componentCls}-item, ${componentCls}-submenu, ${componentCls}-submenu-title`]: {
  171. borderRadius: token.radiusItem
  172. },
  173. [`${componentCls}-item-group-title`]: {
  174. padding: `${paddingXS}px ${padding}px`,
  175. fontSize,
  176. lineHeight,
  177. transition: `all ${motionDurationSlow}`
  178. },
  179. [`&-horizontal ${componentCls}-submenu`]: {
  180. transition: [`border-color ${motionDurationSlow} ${motionEaseInOut}`, `background ${motionDurationSlow} ${motionEaseInOut}`].join(',')
  181. },
  182. [`${componentCls}-submenu, ${componentCls}-submenu-inline`]: {
  183. transition: [`border-color ${motionDurationSlow} ${motionEaseInOut}`, `background ${motionDurationSlow} ${motionEaseInOut}`, `padding ${motionDurationMid} ${motionEaseInOut}`].join(',')
  184. },
  185. [`${componentCls}-submenu ${componentCls}-sub`]: {
  186. cursor: 'initial',
  187. transition: [`background ${motionDurationSlow} ${motionEaseInOut}`, `padding ${motionDurationSlow} ${motionEaseInOut}`].join(',')
  188. },
  189. [`${componentCls}-title-content`]: {
  190. transition: `color ${motionDurationSlow}`
  191. },
  192. [`${componentCls}-item a`]: {
  193. '&::before': {
  194. position: 'absolute',
  195. inset: 0,
  196. backgroundColor: 'transparent',
  197. content: '""'
  198. }
  199. },
  200. // Removed a Badge related style seems it's safe
  201. // https://github.com/ant-design/ant-design/issues/19809
  202. // >>>>> Divider
  203. [`${componentCls}-item-divider`]: {
  204. overflow: 'hidden',
  205. lineHeight: 0,
  206. borderColor: colorSplit,
  207. borderStyle: lineType,
  208. borderWidth: 0,
  209. borderTopWidth: lineWidth,
  210. marginBlock: lineWidth,
  211. padding: 0,
  212. '&-dashed': {
  213. borderStyle: 'dashed'
  214. }
  215. }
  216. }), genMenuItemStyle(token)), {
  217. [`${componentCls}-item-group`]: {
  218. [`${componentCls}-item-group-list`]: {
  219. margin: 0,
  220. padding: 0,
  221. [`${componentCls}-item, ${componentCls}-submenu-title`]: {
  222. paddingInline: `${fontSize * 2}px ${padding}px`
  223. }
  224. }
  225. },
  226. // ======================= Sub Menu =======================
  227. '&-submenu': {
  228. '&-popup': {
  229. position: 'absolute',
  230. zIndex: zIndexPopup,
  231. background: 'transparent',
  232. borderRadius: borderRadiusLG,
  233. boxShadow: 'none',
  234. transformOrigin: '0 0',
  235. // https://github.com/ant-design/ant-design/issues/13955
  236. '&::before': {
  237. position: 'absolute',
  238. inset: `${menuPanelMaskInset}px 0 0`,
  239. zIndex: -1,
  240. width: '100%',
  241. height: '100%',
  242. opacity: 0,
  243. content: '""'
  244. }
  245. },
  246. // https://github.com/ant-design/ant-design/issues/13955
  247. '&-placement-rightTop::before': {
  248. top: 0,
  249. insetInlineStart: menuPanelMaskInset
  250. },
  251. [`> ${componentCls}`]: (0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({
  252. borderRadius: borderRadiusLG
  253. }, genMenuItemStyle(token)), genSubMenuArrowStyle(token)), {
  254. [`${componentCls}-item, ${componentCls}-submenu > ${componentCls}-submenu-title`]: {
  255. borderRadius: radiusSubMenuItem
  256. },
  257. [`${componentCls}-submenu-title::after`]: {
  258. transition: `transform ${motionDurationSlow} ${motionEaseInOut}`
  259. }
  260. })
  261. }
  262. }), genSubMenuArrowStyle(token)), {
  263. [`&-inline-collapsed ${componentCls}-submenu-arrow,
  264. &-inline ${componentCls}-submenu-arrow`]: {
  265. // ↓
  266. '&::before': {
  267. transform: `rotate(-45deg) translateX(${menuArrowOffset})`
  268. },
  269. '&::after': {
  270. transform: `rotate(45deg) translateX(-${menuArrowOffset})`
  271. }
  272. },
  273. [`${componentCls}-submenu-open${componentCls}-submenu-inline > ${componentCls}-submenu-title > ${componentCls}-submenu-arrow`]: {
  274. // ↑
  275. transform: `translateY(-${menuArrowSize * 0.2}px)`,
  276. '&::after': {
  277. transform: `rotate(-45deg) translateX(-${menuArrowOffset})`
  278. },
  279. '&::before': {
  280. transform: `rotate(45deg) translateX(${menuArrowOffset})`
  281. }
  282. }
  283. })
  284. },
  285. // Integration with header element so menu items have the same height
  286. {
  287. [`${antCls}-layout-header`]: {
  288. [componentCls]: {
  289. lineHeight: 'inherit'
  290. }
  291. }
  292. }];
  293. };
  294. // ============================== Export ==============================
  295. var _default = (prefixCls, injectStyle) => {
  296. const useOriginHook = (0, _internal.genComponentStyleHook)('Menu', (token, _ref) => {
  297. let {
  298. overrideComponentToken
  299. } = _ref;
  300. // Dropdown will handle menu style self. We do not need to handle this.
  301. if ((injectStyle === null || injectStyle === void 0 ? void 0 : injectStyle.value) === false) {
  302. return [];
  303. }
  304. const {
  305. colorBgElevated,
  306. colorPrimary,
  307. colorError,
  308. colorErrorHover,
  309. colorTextLightSolid
  310. } = token;
  311. const {
  312. controlHeightLG,
  313. fontSize
  314. } = token;
  315. const menuArrowSize = fontSize / 7 * 5;
  316. // Menu Token
  317. const menuToken = (0, _internal.mergeToken)(token, {
  318. menuItemHeight: controlHeightLG,
  319. menuItemPaddingInline: token.margin,
  320. menuArrowSize,
  321. menuHorizontalHeight: controlHeightLG * 1.15,
  322. menuArrowOffset: `${menuArrowSize * 0.25}px`,
  323. menuPanelMaskInset: -7,
  324. menuSubMenuBg: colorBgElevated
  325. });
  326. const colorTextDark = new _tinycolor.TinyColor(colorTextLightSolid).setAlpha(0.65).toRgbString();
  327. const menuDarkToken = (0, _internal.mergeToken)(menuToken, {
  328. colorItemText: colorTextDark,
  329. colorItemTextHover: colorTextLightSolid,
  330. colorGroupTitle: colorTextDark,
  331. colorItemTextSelected: colorTextLightSolid,
  332. colorItemBg: '#001529',
  333. colorSubItemBg: '#000c17',
  334. colorItemBgActive: 'transparent',
  335. colorItemBgSelected: colorPrimary,
  336. colorActiveBarWidth: 0,
  337. colorActiveBarHeight: 0,
  338. colorActiveBarBorderSize: 0,
  339. // Disabled
  340. colorItemTextDisabled: new _tinycolor.TinyColor(colorTextLightSolid).setAlpha(0.25).toRgbString(),
  341. // Danger
  342. colorDangerItemText: colorError,
  343. colorDangerItemTextHover: colorErrorHover,
  344. colorDangerItemTextSelected: colorTextLightSolid,
  345. colorDangerItemBgActive: colorError,
  346. colorDangerItemBgSelected: colorError,
  347. menuSubMenuBg: '#001529',
  348. // Horizontal
  349. colorItemTextSelectedHorizontal: colorTextLightSolid,
  350. colorItemBgSelectedHorizontal: colorPrimary
  351. }, (0, _extends2.default)({}, overrideComponentToken));
  352. return [
  353. // Basic
  354. getBaseStyle(menuToken),
  355. // Horizontal
  356. (0, _horizontal.default)(menuToken),
  357. // Vertical
  358. (0, _vertical.default)(menuToken),
  359. // Theme
  360. (0, _theme.default)(menuToken, 'light'), (0, _theme.default)(menuDarkToken, 'dark'),
  361. // RTL
  362. (0, _rtl.default)(menuToken),
  363. // Motion
  364. (0, _motion.genCollapseMotion)(menuToken), (0, _motion.initSlideMotion)(menuToken, 'slide-up'), (0, _motion.initSlideMotion)(menuToken, 'slide-down'), (0, _motion.initZoomMotion)(menuToken, 'zoom-big')];
  365. }, token => {
  366. const {
  367. colorPrimary,
  368. colorError,
  369. colorTextDisabled,
  370. colorErrorBg,
  371. colorText,
  372. colorTextDescription,
  373. colorBgContainer,
  374. colorFillAlter,
  375. colorFillContent,
  376. lineWidth,
  377. lineWidthBold,
  378. controlItemBgActive,
  379. colorBgTextHover
  380. } = token;
  381. return {
  382. dropdownWidth: 160,
  383. zIndexPopup: token.zIndexPopupBase + 50,
  384. radiusItem: token.borderRadiusLG,
  385. radiusSubMenuItem: token.borderRadiusSM,
  386. colorItemText: colorText,
  387. colorItemTextHover: colorText,
  388. colorItemTextHoverHorizontal: colorPrimary,
  389. colorGroupTitle: colorTextDescription,
  390. colorItemTextSelected: colorPrimary,
  391. colorItemTextSelectedHorizontal: colorPrimary,
  392. colorItemBg: colorBgContainer,
  393. colorItemBgHover: colorBgTextHover,
  394. colorItemBgActive: colorFillContent,
  395. colorSubItemBg: colorFillAlter,
  396. colorItemBgSelected: controlItemBgActive,
  397. colorItemBgSelectedHorizontal: 'transparent',
  398. colorActiveBarWidth: 0,
  399. colorActiveBarHeight: lineWidthBold,
  400. colorActiveBarBorderSize: lineWidth,
  401. // Disabled
  402. colorItemTextDisabled: colorTextDisabled,
  403. // Danger
  404. colorDangerItemText: colorError,
  405. colorDangerItemTextHover: colorError,
  406. colorDangerItemTextSelected: colorError,
  407. colorDangerItemBgActive: colorErrorBg,
  408. colorDangerItemBgSelected: colorErrorBg,
  409. itemMarginInline: token.marginXXS
  410. };
  411. });
  412. return useOriginHook(prefixCls);
  413. };
  414. exports.default = _default;