index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
  4. Object.defineProperty(exports, "__esModule", {
  5. value: true
  6. });
  7. exports.prepareComponentToken = exports.default = void 0;
  8. var _cssinjs = require("@ant-design/cssinjs");
  9. var _style = require("../../style");
  10. var _motion = require("../../style/motion");
  11. var _placementArrow = _interopRequireWildcard(require("../../style/placementArrow"));
  12. var _roundedArrow = require("../../style/roundedArrow");
  13. var _internal = require("../../theme/internal");
  14. var _status = _interopRequireDefault(require("./status"));
  15. // =============================== Base ===============================
  16. const genBaseStyle = token => {
  17. const {
  18. componentCls,
  19. menuCls,
  20. zIndexPopup,
  21. dropdownArrowDistance,
  22. sizePopupArrow,
  23. antCls,
  24. iconCls,
  25. motionDurationMid,
  26. paddingBlock,
  27. fontSize,
  28. dropdownEdgeChildPadding,
  29. colorTextDisabled,
  30. fontSizeIcon,
  31. controlPaddingHorizontal,
  32. colorBgElevated
  33. } = token;
  34. return [{
  35. [componentCls]: {
  36. position: 'absolute',
  37. top: -9999,
  38. left: {
  39. _skip_check_: true,
  40. value: -9999
  41. },
  42. zIndex: zIndexPopup,
  43. display: 'block',
  44. // A placeholder out of dropdown visible range to avoid close when user moving
  45. '&::before': {
  46. position: 'absolute',
  47. insetBlock: token.calc(sizePopupArrow).div(2).sub(dropdownArrowDistance).equal(),
  48. // insetInlineStart: -7, // FIXME: Seems not work for hidden element
  49. zIndex: -9999,
  50. opacity: 0.0001,
  51. content: '""'
  52. },
  53. // Makes vertical dropdowns have a scrollbar once they become taller than the viewport.
  54. '&-menu-vertical': {
  55. maxHeight: '100vh',
  56. overflowY: 'auto'
  57. },
  58. [`&-trigger${antCls}-btn`]: {
  59. [`& > ${iconCls}-down, & > ${antCls}-btn-icon > ${iconCls}-down`]: {
  60. fontSize: fontSizeIcon
  61. }
  62. },
  63. [`${componentCls}-wrap`]: {
  64. position: 'relative',
  65. [`${antCls}-btn > ${iconCls}-down`]: {
  66. fontSize: fontSizeIcon
  67. },
  68. [`${iconCls}-down::before`]: {
  69. transition: `transform ${motionDurationMid}`
  70. }
  71. },
  72. [`${componentCls}-wrap-open`]: {
  73. [`${iconCls}-down::before`]: {
  74. transform: `rotate(180deg)`
  75. }
  76. },
  77. [`
  78. &-hidden,
  79. &-menu-hidden,
  80. &-menu-submenu-hidden
  81. `]: {
  82. display: 'none'
  83. },
  84. // =============================================================
  85. // == Motion ==
  86. // =============================================================
  87. // When position is not enough for dropdown, the placement will revert.
  88. // We will handle this with revert motion name.
  89. [`&${antCls}-slide-down-enter${antCls}-slide-down-enter-active${componentCls}-placement-bottomLeft,
  90. &${antCls}-slide-down-appear${antCls}-slide-down-appear-active${componentCls}-placement-bottomLeft,
  91. &${antCls}-slide-down-enter${antCls}-slide-down-enter-active${componentCls}-placement-bottom,
  92. &${antCls}-slide-down-appear${antCls}-slide-down-appear-active${componentCls}-placement-bottom,
  93. &${antCls}-slide-down-enter${antCls}-slide-down-enter-active${componentCls}-placement-bottomRight,
  94. &${antCls}-slide-down-appear${antCls}-slide-down-appear-active${componentCls}-placement-bottomRight`]: {
  95. animationName: _motion.slideUpIn
  96. },
  97. [`&${antCls}-slide-up-enter${antCls}-slide-up-enter-active${componentCls}-placement-topLeft,
  98. &${antCls}-slide-up-appear${antCls}-slide-up-appear-active${componentCls}-placement-topLeft,
  99. &${antCls}-slide-up-enter${antCls}-slide-up-enter-active${componentCls}-placement-top,
  100. &${antCls}-slide-up-appear${antCls}-slide-up-appear-active${componentCls}-placement-top,
  101. &${antCls}-slide-up-enter${antCls}-slide-up-enter-active${componentCls}-placement-topRight,
  102. &${antCls}-slide-up-appear${antCls}-slide-up-appear-active${componentCls}-placement-topRight`]: {
  103. animationName: _motion.slideDownIn
  104. },
  105. [`&${antCls}-slide-down-leave${antCls}-slide-down-leave-active${componentCls}-placement-bottomLeft,
  106. &${antCls}-slide-down-leave${antCls}-slide-down-leave-active${componentCls}-placement-bottom,
  107. &${antCls}-slide-down-leave${antCls}-slide-down-leave-active${componentCls}-placement-bottomRight`]: {
  108. animationName: _motion.slideUpOut
  109. },
  110. [`&${antCls}-slide-up-leave${antCls}-slide-up-leave-active${componentCls}-placement-topLeft,
  111. &${antCls}-slide-up-leave${antCls}-slide-up-leave-active${componentCls}-placement-top,
  112. &${antCls}-slide-up-leave${antCls}-slide-up-leave-active${componentCls}-placement-topRight`]: {
  113. animationName: _motion.slideDownOut
  114. }
  115. }
  116. },
  117. // =============================================================
  118. // == Arrow style ==
  119. // =============================================================
  120. (0, _placementArrow.default)(token, colorBgElevated, {
  121. arrowPlacement: {
  122. top: true,
  123. bottom: true
  124. }
  125. }), {
  126. // =============================================================
  127. // == Menu ==
  128. // =============================================================
  129. [`${componentCls} ${menuCls}`]: {
  130. position: 'relative',
  131. margin: 0
  132. },
  133. [`${menuCls}-submenu-popup`]: {
  134. position: 'absolute',
  135. zIndex: zIndexPopup,
  136. background: 'transparent',
  137. boxShadow: 'none',
  138. transformOrigin: '0 0',
  139. 'ul, li': {
  140. listStyle: 'none',
  141. margin: 0
  142. }
  143. },
  144. [`${componentCls}, ${componentCls}-menu-submenu`]: Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), {
  145. [menuCls]: Object.assign(Object.assign({
  146. padding: dropdownEdgeChildPadding,
  147. listStyleType: 'none',
  148. backgroundColor: colorBgElevated,
  149. backgroundClip: 'padding-box',
  150. borderRadius: token.borderRadiusLG,
  151. outline: 'none',
  152. boxShadow: token.boxShadowSecondary
  153. }, (0, _style.genFocusStyle)(token)), {
  154. '&:empty': {
  155. padding: 0,
  156. boxShadow: 'none'
  157. },
  158. [`${menuCls}-item-group-title`]: {
  159. padding: `${(0, _cssinjs.unit)(paddingBlock)} ${(0, _cssinjs.unit)(controlPaddingHorizontal)}`,
  160. color: token.colorTextDescription,
  161. transition: `all ${motionDurationMid}`
  162. },
  163. // ======================= Item Content =======================
  164. [`${menuCls}-item`]: {
  165. position: 'relative',
  166. display: 'flex',
  167. alignItems: 'center'
  168. },
  169. [`${menuCls}-item-icon`]: {
  170. minWidth: fontSize,
  171. marginInlineEnd: token.marginXS,
  172. fontSize: token.fontSizeSM
  173. },
  174. [`${menuCls}-title-content`]: {
  175. flex: 'auto',
  176. '&-with-extra': {
  177. display: 'inline-flex',
  178. alignItems: 'center',
  179. width: '100%'
  180. },
  181. '> a': {
  182. color: 'inherit',
  183. transition: `all ${motionDurationMid}`,
  184. '&:hover': {
  185. color: 'inherit'
  186. },
  187. '&::after': {
  188. position: 'absolute',
  189. inset: 0,
  190. content: '""'
  191. }
  192. },
  193. [`${menuCls}-item-extra`]: {
  194. paddingInlineStart: token.padding,
  195. marginInlineStart: 'auto',
  196. fontSize: token.fontSizeSM,
  197. color: token.colorTextDescription
  198. }
  199. },
  200. // =========================== Item ===========================
  201. [`${menuCls}-item, ${menuCls}-submenu-title`]: Object.assign(Object.assign({
  202. display: 'flex',
  203. margin: 0,
  204. padding: `${(0, _cssinjs.unit)(paddingBlock)} ${(0, _cssinjs.unit)(controlPaddingHorizontal)}`,
  205. color: token.colorText,
  206. fontWeight: 'normal',
  207. fontSize,
  208. lineHeight: token.lineHeight,
  209. cursor: 'pointer',
  210. transition: `all ${motionDurationMid}`,
  211. borderRadius: token.borderRadiusSM,
  212. '&:hover, &-active': {
  213. backgroundColor: token.controlItemBgHover
  214. }
  215. }, (0, _style.genFocusStyle)(token)), {
  216. '&-selected': {
  217. color: token.colorPrimary,
  218. backgroundColor: token.controlItemBgActive,
  219. '&:hover, &-active': {
  220. backgroundColor: token.controlItemBgActiveHover
  221. }
  222. },
  223. '&-disabled': {
  224. color: colorTextDisabled,
  225. cursor: 'not-allowed',
  226. '&:hover': {
  227. color: colorTextDisabled,
  228. backgroundColor: colorBgElevated,
  229. cursor: 'not-allowed'
  230. },
  231. a: {
  232. pointerEvents: 'none'
  233. }
  234. },
  235. '&-divider': {
  236. height: 1,
  237. // By design
  238. margin: `${(0, _cssinjs.unit)(token.marginXXS)} 0`,
  239. overflow: 'hidden',
  240. lineHeight: 0,
  241. backgroundColor: token.colorSplit
  242. },
  243. [`${componentCls}-menu-submenu-expand-icon`]: {
  244. position: 'absolute',
  245. insetInlineEnd: token.paddingXS,
  246. [`${componentCls}-menu-submenu-arrow-icon`]: {
  247. marginInlineEnd: '0 !important',
  248. color: token.colorIcon,
  249. fontSize: fontSizeIcon,
  250. fontStyle: 'normal'
  251. }
  252. }
  253. }),
  254. [`${menuCls}-item-group-list`]: {
  255. margin: `0 ${(0, _cssinjs.unit)(token.marginXS)}`,
  256. padding: 0,
  257. listStyle: 'none'
  258. },
  259. [`${menuCls}-submenu-title`]: {
  260. paddingInlineEnd: token.calc(controlPaddingHorizontal).add(token.fontSizeSM).equal()
  261. },
  262. [`${menuCls}-submenu-vertical`]: {
  263. position: 'relative'
  264. },
  265. [`${menuCls}-submenu${menuCls}-submenu-disabled ${componentCls}-menu-submenu-title`]: {
  266. [`&, ${componentCls}-menu-submenu-arrow-icon`]: {
  267. color: colorTextDisabled,
  268. backgroundColor: colorBgElevated,
  269. cursor: 'not-allowed'
  270. }
  271. },
  272. // https://github.com/ant-design/ant-design/issues/19264
  273. [`${menuCls}-submenu-selected ${componentCls}-menu-submenu-title`]: {
  274. color: token.colorPrimary
  275. }
  276. })
  277. })
  278. },
  279. // Follow code may reuse in other components
  280. [(0, _motion.initSlideMotion)(token, 'slide-up'), (0, _motion.initSlideMotion)(token, 'slide-down'), (0, _motion.initMoveMotion)(token, 'move-up'), (0, _motion.initMoveMotion)(token, 'move-down'), (0, _motion.initZoomMotion)(token, 'zoom-big')]];
  281. };
  282. // ============================== Export ==============================
  283. const prepareComponentToken = token => Object.assign(Object.assign({
  284. zIndexPopup: token.zIndexPopupBase + 50,
  285. paddingBlock: (token.controlHeight - token.fontSize * token.lineHeight) / 2
  286. }, (0, _placementArrow.getArrowOffsetToken)({
  287. contentRadius: token.borderRadiusLG,
  288. limitVerticalRadius: true
  289. })), (0, _roundedArrow.getArrowToken)(token));
  290. exports.prepareComponentToken = prepareComponentToken;
  291. var _default = exports.default = (0, _internal.genStyleHooks)('Dropdown', token => {
  292. const {
  293. marginXXS,
  294. sizePopupArrow,
  295. paddingXXS,
  296. componentCls
  297. } = token;
  298. const dropdownToken = (0, _internal.mergeToken)(token, {
  299. menuCls: `${componentCls}-menu`,
  300. dropdownArrowDistance: token.calc(sizePopupArrow).div(2).add(marginXXS).equal(),
  301. dropdownEdgeChildPadding: paddingXXS
  302. });
  303. return [genBaseStyle(dropdownToken), (0, _status.default)(dropdownToken)];
  304. }, prepareComponentToken, {
  305. resetStyle: false
  306. });