dropdown.js 4.4 KB

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