index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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 _placementArrow = require("../../style/placementArrow");
  9. var _motion = require("../../style/motion");
  10. var _internal = require("../../theme/internal");
  11. var _button = _interopRequireDefault(require("./button"));
  12. var _status = _interopRequireDefault(require("./status"));
  13. var _style = require("../../style");
  14. // =============================== Base ===============================
  15. const genBaseStyle = token => {
  16. const {
  17. componentCls,
  18. menuCls,
  19. zIndexPopup,
  20. dropdownArrowDistance,
  21. dropdownArrowOffset,
  22. sizePopupArrow,
  23. antCls,
  24. iconCls,
  25. motionDurationMid,
  26. dropdownPaddingVertical,
  27. fontSize,
  28. dropdownEdgeChildPadding,
  29. colorTextDisabled,
  30. fontSizeIcon,
  31. controlPaddingHorizontal,
  32. colorBgElevated,
  33. boxShadowPopoverArrow
  34. } = token;
  35. return [{
  36. [componentCls]: (0, _extends2.default)((0, _extends2.default)({}, (0, _style.resetComponent)(token)), {
  37. position: 'absolute',
  38. top: -9999,
  39. left: {
  40. _skip_check_: true,
  41. value: -9999
  42. },
  43. zIndex: zIndexPopup,
  44. display: 'block',
  45. // A placeholder out of dropdown visible range to avoid close when user moving
  46. '&::before': {
  47. position: 'absolute',
  48. insetBlock: -dropdownArrowDistance + sizePopupArrow / 2,
  49. // insetInlineStart: -7, // FIXME: Seems not work for hidden element
  50. zIndex: -9999,
  51. opacity: 0.0001,
  52. content: '""'
  53. },
  54. [`${componentCls}-wrap`]: {
  55. position: 'relative',
  56. [`${antCls}-btn > ${iconCls}-down`]: {
  57. fontSize: fontSizeIcon
  58. },
  59. [`${iconCls}-down::before`]: {
  60. transition: `transform ${motionDurationMid}`
  61. }
  62. },
  63. [`${componentCls}-wrap-open`]: {
  64. [`${iconCls}-down::before`]: {
  65. transform: `rotate(180deg)`
  66. }
  67. },
  68. [`
  69. &-hidden,
  70. &-menu-hidden,
  71. &-menu-submenu-hidden
  72. `]: {
  73. display: 'none'
  74. },
  75. // =============================================================
  76. // == Arrow ==
  77. // =============================================================
  78. // Offset the popover to account for the dropdown arrow
  79. [`
  80. &-show-arrow${componentCls}-placement-topLeft,
  81. &-show-arrow${componentCls}-placement-top,
  82. &-show-arrow${componentCls}-placement-topRight
  83. `]: {
  84. paddingBottom: dropdownArrowDistance
  85. },
  86. [`
  87. &-show-arrow${componentCls}-placement-bottomLeft,
  88. &-show-arrow${componentCls}-placement-bottom,
  89. &-show-arrow${componentCls}-placement-bottomRight
  90. `]: {
  91. paddingTop: dropdownArrowDistance
  92. },
  93. // Note: .popover-arrow is outer, .popover-arrow:after is inner
  94. [`${componentCls}-arrow`]: (0, _extends2.default)({
  95. position: 'absolute',
  96. zIndex: 1,
  97. display: 'block'
  98. }, (0, _style.roundedArrow)(sizePopupArrow, token.borderRadiusXS, token.borderRadiusOuter, colorBgElevated, boxShadowPopoverArrow)),
  99. [`
  100. &-placement-top > ${componentCls}-arrow,
  101. &-placement-topLeft > ${componentCls}-arrow,
  102. &-placement-topRight > ${componentCls}-arrow
  103. `]: {
  104. bottom: dropdownArrowDistance,
  105. transform: 'translateY(100%) rotate(180deg)'
  106. },
  107. [`&-placement-top > ${componentCls}-arrow`]: {
  108. left: {
  109. _skip_check_: true,
  110. value: '50%'
  111. },
  112. transform: 'translateX(-50%) translateY(100%) rotate(180deg)'
  113. },
  114. [`&-placement-topLeft > ${componentCls}-arrow`]: {
  115. left: {
  116. _skip_check_: true,
  117. value: dropdownArrowOffset
  118. }
  119. },
  120. [`&-placement-topRight > ${componentCls}-arrow`]: {
  121. right: {
  122. _skip_check_: true,
  123. value: dropdownArrowOffset
  124. }
  125. },
  126. [`
  127. &-placement-bottom > ${componentCls}-arrow,
  128. &-placement-bottomLeft > ${componentCls}-arrow,
  129. &-placement-bottomRight > ${componentCls}-arrow
  130. `]: {
  131. top: dropdownArrowDistance,
  132. transform: `translateY(-100%)`
  133. },
  134. [`&-placement-bottom > ${componentCls}-arrow`]: {
  135. left: {
  136. _skip_check_: true,
  137. value: '50%'
  138. },
  139. transform: `translateY(-100%) translateX(-50%)`
  140. },
  141. [`&-placement-bottomLeft > ${componentCls}-arrow`]: {
  142. left: {
  143. _skip_check_: true,
  144. value: dropdownArrowOffset
  145. }
  146. },
  147. [`&-placement-bottomRight > ${componentCls}-arrow`]: {
  148. right: {
  149. _skip_check_: true,
  150. value: dropdownArrowOffset
  151. }
  152. },
  153. // =============================================================
  154. // == Motion ==
  155. // =============================================================
  156. // When position is not enough for dropdown, the placement will revert.
  157. // We will handle this with revert motion name.
  158. [`&${antCls}-slide-down-enter${antCls}-slide-down-enter-active${componentCls}-placement-bottomLeft,
  159. &${antCls}-slide-down-appear${antCls}-slide-down-appear-active${componentCls}-placement-bottomLeft,
  160. &${antCls}-slide-down-enter${antCls}-slide-down-enter-active${componentCls}-placement-bottom,
  161. &${antCls}-slide-down-appear${antCls}-slide-down-appear-active${componentCls}-placement-bottom,
  162. &${antCls}-slide-down-enter${antCls}-slide-down-enter-active${componentCls}-placement-bottomRight,
  163. &${antCls}-slide-down-appear${antCls}-slide-down-appear-active${componentCls}-placement-bottomRight`]: {
  164. animationName: _motion.slideUpIn
  165. },
  166. [`&${antCls}-slide-up-enter${antCls}-slide-up-enter-active${componentCls}-placement-topLeft,
  167. &${antCls}-slide-up-appear${antCls}-slide-up-appear-active${componentCls}-placement-topLeft,
  168. &${antCls}-slide-up-enter${antCls}-slide-up-enter-active${componentCls}-placement-top,
  169. &${antCls}-slide-up-appear${antCls}-slide-up-appear-active${componentCls}-placement-top,
  170. &${antCls}-slide-up-enter${antCls}-slide-up-enter-active${componentCls}-placement-topRight,
  171. &${antCls}-slide-up-appear${antCls}-slide-up-appear-active${componentCls}-placement-topRight`]: {
  172. animationName: _motion.slideDownIn
  173. },
  174. [`&${antCls}-slide-down-leave${antCls}-slide-down-leave-active${componentCls}-placement-bottomLeft,
  175. &${antCls}-slide-down-leave${antCls}-slide-down-leave-active${componentCls}-placement-bottom,
  176. &${antCls}-slide-down-leave${antCls}-slide-down-leave-active${componentCls}-placement-bottomRight`]: {
  177. animationName: _motion.slideUpOut
  178. },
  179. [`&${antCls}-slide-up-leave${antCls}-slide-up-leave-active${componentCls}-placement-topLeft,
  180. &${antCls}-slide-up-leave${antCls}-slide-up-leave-active${componentCls}-placement-top,
  181. &${antCls}-slide-up-leave${antCls}-slide-up-leave-active${componentCls}-placement-topRight`]: {
  182. animationName: _motion.slideDownOut
  183. }
  184. })
  185. }, {
  186. // =============================================================
  187. // == Menu ==
  188. // =============================================================
  189. [`${componentCls} ${menuCls}`]: {
  190. position: 'relative',
  191. margin: 0
  192. },
  193. [`${menuCls}-submenu-popup`]: {
  194. position: 'absolute',
  195. zIndex: zIndexPopup,
  196. background: 'transparent',
  197. boxShadow: 'none',
  198. transformOrigin: '0 0',
  199. 'ul,li': {
  200. listStyle: 'none'
  201. },
  202. ul: {
  203. marginInline: '0.3em'
  204. }
  205. },
  206. [`${componentCls}, ${componentCls}-menu-submenu`]: {
  207. [menuCls]: (0, _extends2.default)((0, _extends2.default)({
  208. padding: dropdownEdgeChildPadding,
  209. listStyleType: 'none',
  210. backgroundColor: colorBgElevated,
  211. backgroundClip: 'padding-box',
  212. borderRadius: token.borderRadiusLG,
  213. outline: 'none',
  214. boxShadow: token.boxShadowSecondary
  215. }, (0, _style.genFocusStyle)(token)), {
  216. [`${menuCls}-item-group-title`]: {
  217. padding: `${dropdownPaddingVertical}px ${controlPaddingHorizontal}px`,
  218. color: token.colorTextDescription,
  219. transition: `all ${motionDurationMid}`
  220. },
  221. // ======================= Item Content =======================
  222. [`${menuCls}-item`]: {
  223. position: 'relative',
  224. display: 'flex',
  225. alignItems: 'center',
  226. borderRadius: token.borderRadiusSM
  227. },
  228. [`${menuCls}-item-icon`]: {
  229. minWidth: fontSize,
  230. marginInlineEnd: token.marginXS,
  231. fontSize: token.fontSizeSM
  232. },
  233. [`${menuCls}-title-content`]: {
  234. flex: 'auto',
  235. '> a': {
  236. color: 'inherit',
  237. transition: `all ${motionDurationMid}`,
  238. '&:hover': {
  239. color: 'inherit'
  240. },
  241. '&::after': {
  242. position: 'absolute',
  243. inset: 0,
  244. content: '""'
  245. }
  246. }
  247. },
  248. // =========================== Item ===========================
  249. [`${menuCls}-item, ${menuCls}-submenu-title`]: (0, _extends2.default)((0, _extends2.default)({
  250. clear: 'both',
  251. margin: 0,
  252. padding: `${dropdownPaddingVertical}px ${controlPaddingHorizontal}px`,
  253. color: token.colorText,
  254. fontWeight: 'normal',
  255. fontSize,
  256. lineHeight: token.lineHeight,
  257. cursor: 'pointer',
  258. transition: `all ${motionDurationMid}`,
  259. [`&:hover, &-active`]: {
  260. backgroundColor: token.controlItemBgHover
  261. }
  262. }, (0, _style.genFocusStyle)(token)), {
  263. '&-selected': {
  264. color: token.colorPrimary,
  265. backgroundColor: token.controlItemBgActive,
  266. '&:hover, &-active': {
  267. backgroundColor: token.controlItemBgActiveHover
  268. }
  269. },
  270. '&-disabled': {
  271. color: colorTextDisabled,
  272. cursor: 'not-allowed',
  273. '&:hover': {
  274. color: colorTextDisabled,
  275. backgroundColor: colorBgElevated,
  276. cursor: 'not-allowed'
  277. },
  278. a: {
  279. pointerEvents: 'none'
  280. }
  281. },
  282. '&-divider': {
  283. height: 1,
  284. margin: `${token.marginXXS}px 0`,
  285. overflow: 'hidden',
  286. lineHeight: 0,
  287. backgroundColor: token.colorSplit
  288. },
  289. [`${componentCls}-menu-submenu-expand-icon`]: {
  290. position: 'absolute',
  291. insetInlineEnd: token.paddingXS,
  292. [`${componentCls}-menu-submenu-arrow-icon`]: {
  293. marginInlineEnd: '0 !important',
  294. color: token.colorTextDescription,
  295. fontSize: fontSizeIcon,
  296. fontStyle: 'normal'
  297. }
  298. }
  299. }),
  300. [`${menuCls}-item-group-list`]: {
  301. margin: `0 ${token.marginXS}px`,
  302. padding: 0,
  303. listStyle: 'none'
  304. },
  305. [`${menuCls}-submenu-title`]: {
  306. paddingInlineEnd: controlPaddingHorizontal + token.fontSizeSM
  307. },
  308. [`${menuCls}-submenu-vertical`]: {
  309. position: 'relative'
  310. },
  311. [`${menuCls}-submenu${menuCls}-submenu-disabled ${componentCls}-menu-submenu-title`]: {
  312. [`&, ${componentCls}-menu-submenu-arrow-icon`]: {
  313. color: colorTextDisabled,
  314. backgroundColor: colorBgElevated,
  315. cursor: 'not-allowed'
  316. }
  317. },
  318. // https://github.com/ant-design/ant-design/issues/19264
  319. [`${menuCls}-submenu-selected ${componentCls}-menu-submenu-title`]: {
  320. color: token.colorPrimary
  321. }
  322. })
  323. }
  324. },
  325. // Follow code may reuse in other components
  326. [(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')]];
  327. };
  328. // ============================== Export ==============================
  329. var _default = exports.default = (0, _internal.genComponentStyleHook)('Dropdown', (token, _ref) => {
  330. let {
  331. rootPrefixCls
  332. } = _ref;
  333. const {
  334. marginXXS,
  335. sizePopupArrow,
  336. controlHeight,
  337. fontSize,
  338. lineHeight,
  339. paddingXXS,
  340. componentCls,
  341. borderRadiusOuter,
  342. borderRadiusLG
  343. } = token;
  344. const dropdownPaddingVertical = (controlHeight - fontSize * lineHeight) / 2;
  345. const {
  346. dropdownArrowOffset
  347. } = (0, _placementArrow.getArrowOffset)({
  348. sizePopupArrow,
  349. contentRadius: borderRadiusLG,
  350. borderRadiusOuter
  351. });
  352. const dropdownToken = (0, _internal.mergeToken)(token, {
  353. menuCls: `${componentCls}-menu`,
  354. rootPrefixCls,
  355. dropdownArrowDistance: sizePopupArrow / 2 + marginXXS,
  356. dropdownArrowOffset,
  357. dropdownPaddingVertical,
  358. dropdownEdgeChildPadding: paddingXXS
  359. });
  360. return [genBaseStyle(dropdownToken), (0, _button.default)(dropdownToken), (0, _status.default)(dropdownToken)];
  361. }, token => ({
  362. zIndexPopup: token.zIndexPopupBase + 50
  363. }));