dropdown.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 _motion = require("../../style/motion");
  9. var _style = require("../../style");
  10. const genItemStyle = token => {
  11. const {
  12. controlPaddingHorizontal
  13. } = token;
  14. return {
  15. position: 'relative',
  16. display: 'block',
  17. minHeight: token.controlHeight,
  18. padding: `${(token.controlHeight - token.fontSize * token.lineHeight) / 2}px ${controlPaddingHorizontal}px`,
  19. color: token.colorText,
  20. fontWeight: 'normal',
  21. fontSize: token.fontSize,
  22. lineHeight: token.lineHeight,
  23. boxSizing: 'border-box'
  24. };
  25. };
  26. const genSingleStyle = token => {
  27. const {
  28. antCls,
  29. componentCls
  30. } = token;
  31. const selectItemCls = `${componentCls}-item`;
  32. return [{
  33. [`${componentCls}-dropdown`]: (0, _extends2.default)((0, _extends2.default)({}, (0, _style.resetComponent)(token)), {
  34. position: 'absolute',
  35. top: -9999,
  36. zIndex: token.zIndexPopup,
  37. boxSizing: 'border-box',
  38. padding: token.paddingXXS,
  39. overflow: 'hidden',
  40. fontSize: token.fontSize,
  41. // Fix select render lag of long text in chrome
  42. // https://github.com/ant-design/ant-design/issues/11456
  43. // https://github.com/ant-design/ant-design/issues/11843
  44. fontVariant: 'initial',
  45. backgroundColor: token.colorBgElevated,
  46. borderRadius: token.borderRadiusLG,
  47. outline: 'none',
  48. boxShadow: token.boxShadowSecondary,
  49. [`
  50. &${antCls}-slide-up-enter${antCls}-slide-up-enter-active${componentCls}-dropdown-placement-bottomLeft,
  51. &${antCls}-slide-up-appear${antCls}-slide-up-appear-active${componentCls}-dropdown-placement-bottomLeft
  52. `]: {
  53. animationName: _motion.slideUpIn
  54. },
  55. [`
  56. &${antCls}-slide-up-enter${antCls}-slide-up-enter-active${componentCls}-dropdown-placement-topLeft,
  57. &${antCls}-slide-up-appear${antCls}-slide-up-appear-active${componentCls}-dropdown-placement-topLeft
  58. `]: {
  59. animationName: _motion.slideDownIn
  60. },
  61. [`&${antCls}-slide-up-leave${antCls}-slide-up-leave-active${componentCls}-dropdown-placement-bottomLeft`]: {
  62. animationName: _motion.slideUpOut
  63. },
  64. [`&${antCls}-slide-up-leave${antCls}-slide-up-leave-active${componentCls}-dropdown-placement-topLeft`]: {
  65. animationName: _motion.slideDownOut
  66. },
  67. '&-hidden': {
  68. display: 'none'
  69. },
  70. '&-empty': {
  71. color: token.colorTextDisabled
  72. },
  73. // ========================= Options =========================
  74. [`${selectItemCls}-empty`]: (0, _extends2.default)((0, _extends2.default)({}, genItemStyle(token)), {
  75. color: token.colorTextDisabled
  76. }),
  77. [`${selectItemCls}`]: (0, _extends2.default)((0, _extends2.default)({}, genItemStyle(token)), {
  78. cursor: 'pointer',
  79. transition: `background ${token.motionDurationSlow} ease`,
  80. borderRadius: token.borderRadiusSM,
  81. // =========== Group ============
  82. '&-group': {
  83. color: token.colorTextDescription,
  84. fontSize: token.fontSizeSM,
  85. cursor: 'default'
  86. },
  87. // =========== Option ===========
  88. '&-option': {
  89. display: 'flex',
  90. '&-content': (0, _extends2.default)({
  91. flex: 'auto'
  92. }, _style.textEllipsis),
  93. '&-state': {
  94. flex: 'none'
  95. },
  96. [`&-active:not(${selectItemCls}-option-disabled)`]: {
  97. backgroundColor: token.controlItemBgHover
  98. },
  99. [`&-selected:not(${selectItemCls}-option-disabled)`]: {
  100. color: token.colorText,
  101. fontWeight: token.fontWeightStrong,
  102. backgroundColor: token.controlItemBgActive,
  103. [`${selectItemCls}-option-state`]: {
  104. color: token.colorPrimary
  105. }
  106. },
  107. '&-disabled': {
  108. [`&${selectItemCls}-option-selected`]: {
  109. backgroundColor: token.colorBgContainerDisabled
  110. },
  111. color: token.colorTextDisabled,
  112. cursor: 'not-allowed'
  113. },
  114. '&-grouped': {
  115. paddingInlineStart: token.controlPaddingHorizontal * 2
  116. }
  117. }
  118. }),
  119. // =========================== RTL ===========================
  120. '&-rtl': {
  121. direction: 'rtl'
  122. }
  123. })
  124. },
  125. // Follow code may reuse in other components
  126. (0, _motion.initSlideMotion)(token, 'slide-up'), (0, _motion.initSlideMotion)(token, 'slide-down'), (0, _motion.initMoveMotion)(token, 'move-up'), (0, _motion.initMoveMotion)(token, 'move-down')];
  127. };
  128. var _default = exports.default = genSingleStyle;