vertical.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import { unit } from '@ant-design/cssinjs';
  2. import { textEllipsis } from '../../style';
  3. const getVerticalInlineStyle = token => {
  4. const {
  5. componentCls,
  6. itemHeight,
  7. itemMarginInline,
  8. padding,
  9. menuArrowSize,
  10. marginXS,
  11. itemMarginBlock,
  12. itemWidth,
  13. itemPaddingInline
  14. } = token;
  15. const paddingWithArrow = token.calc(menuArrowSize).add(padding).add(marginXS).equal();
  16. return {
  17. [`${componentCls}-item`]: {
  18. position: 'relative',
  19. overflow: 'hidden'
  20. },
  21. [`${componentCls}-item, ${componentCls}-submenu-title`]: {
  22. height: itemHeight,
  23. lineHeight: unit(itemHeight),
  24. paddingInline: itemPaddingInline,
  25. overflow: 'hidden',
  26. textOverflow: 'ellipsis',
  27. marginInline: itemMarginInline,
  28. marginBlock: itemMarginBlock,
  29. width: itemWidth
  30. },
  31. [`> ${componentCls}-item,
  32. > ${componentCls}-submenu > ${componentCls}-submenu-title`]: {
  33. height: itemHeight,
  34. lineHeight: unit(itemHeight)
  35. },
  36. [`${componentCls}-item-group-list ${componentCls}-submenu-title,
  37. ${componentCls}-submenu-title`]: {
  38. paddingInlineEnd: paddingWithArrow
  39. }
  40. };
  41. };
  42. const getVerticalStyle = token => {
  43. const {
  44. componentCls,
  45. iconCls,
  46. itemHeight,
  47. colorTextLightSolid,
  48. dropdownWidth,
  49. controlHeightLG,
  50. motionEaseOut,
  51. paddingXL,
  52. itemMarginInline,
  53. fontSizeLG,
  54. motionDurationFast,
  55. motionDurationSlow,
  56. paddingXS,
  57. boxShadowSecondary,
  58. collapsedWidth,
  59. collapsedIconSize
  60. } = token;
  61. const inlineItemStyle = {
  62. height: itemHeight,
  63. lineHeight: unit(itemHeight),
  64. listStylePosition: 'inside',
  65. listStyleType: 'disc'
  66. };
  67. return [{
  68. [componentCls]: {
  69. '&-inline, &-vertical': Object.assign({
  70. [`&${componentCls}-root`]: {
  71. boxShadow: 'none'
  72. }
  73. }, getVerticalInlineStyle(token))
  74. },
  75. [`${componentCls}-submenu-popup`]: {
  76. [`${componentCls}-vertical`]: Object.assign(Object.assign({}, getVerticalInlineStyle(token)), {
  77. boxShadow: boxShadowSecondary
  78. })
  79. }
  80. },
  81. // Vertical only
  82. {
  83. [`${componentCls}-submenu-popup ${componentCls}-vertical${componentCls}-sub`]: {
  84. minWidth: dropdownWidth,
  85. maxHeight: `calc(100vh - ${unit(token.calc(controlHeightLG).mul(2.5).equal())})`,
  86. padding: '0',
  87. overflow: 'hidden',
  88. borderInlineEnd: 0,
  89. // https://github.com/ant-design/ant-design/issues/22244
  90. // https://github.com/ant-design/ant-design/issues/26812
  91. "&:not([class*='-active'])": {
  92. overflowX: 'hidden',
  93. overflowY: 'auto'
  94. }
  95. }
  96. },
  97. // Inline Only
  98. {
  99. [`${componentCls}-inline`]: {
  100. width: '100%',
  101. // Motion enhance for first level
  102. [`&${componentCls}-root`]: {
  103. [`${componentCls}-item, ${componentCls}-submenu-title`]: {
  104. display: 'flex',
  105. alignItems: 'center',
  106. transition: [`border-color ${motionDurationSlow}`, `background ${motionDurationSlow}`, `padding ${motionDurationFast} ${motionEaseOut}`].join(','),
  107. [`> ${componentCls}-title-content`]: {
  108. flex: 'auto',
  109. minWidth: 0,
  110. overflow: 'hidden',
  111. textOverflow: 'ellipsis'
  112. },
  113. '> *': {
  114. flex: 'none'
  115. }
  116. }
  117. },
  118. // >>>>> Sub
  119. [`${componentCls}-sub${componentCls}-inline`]: {
  120. padding: 0,
  121. border: 0,
  122. borderRadius: 0,
  123. boxShadow: 'none',
  124. [`& > ${componentCls}-submenu > ${componentCls}-submenu-title`]: inlineItemStyle,
  125. [`& ${componentCls}-item-group-title`]: {
  126. paddingInlineStart: paddingXL
  127. }
  128. },
  129. // >>>>> Item
  130. [`${componentCls}-item`]: inlineItemStyle
  131. }
  132. },
  133. // Inline Collapse Only
  134. {
  135. [`${componentCls}-inline-collapsed`]: {
  136. width: collapsedWidth,
  137. [`&${componentCls}-root`]: {
  138. [`${componentCls}-item, ${componentCls}-submenu ${componentCls}-submenu-title`]: {
  139. [`> ${componentCls}-inline-collapsed-noicon`]: {
  140. fontSize: fontSizeLG,
  141. textAlign: 'center'
  142. }
  143. }
  144. },
  145. [`> ${componentCls}-item,
  146. > ${componentCls}-item-group > ${componentCls}-item-group-list > ${componentCls}-item,
  147. > ${componentCls}-item-group > ${componentCls}-item-group-list > ${componentCls}-submenu > ${componentCls}-submenu-title,
  148. > ${componentCls}-submenu > ${componentCls}-submenu-title`]: {
  149. insetInlineStart: 0,
  150. paddingInline: `calc(50% - ${unit(token.calc(collapsedIconSize).div(2).equal())} - ${unit(itemMarginInline)})`,
  151. textOverflow: 'clip',
  152. [`
  153. ${componentCls}-submenu-arrow,
  154. ${componentCls}-submenu-expand-icon
  155. `]: {
  156. opacity: 0
  157. },
  158. [`${componentCls}-item-icon, ${iconCls}`]: {
  159. margin: 0,
  160. fontSize: collapsedIconSize,
  161. lineHeight: unit(itemHeight),
  162. '+ span': {
  163. display: 'inline-block',
  164. opacity: 0
  165. }
  166. }
  167. },
  168. [`${componentCls}-item-icon, ${iconCls}`]: {
  169. display: 'inline-block'
  170. },
  171. '&-tooltip': {
  172. pointerEvents: 'none',
  173. [`${componentCls}-item-icon, ${iconCls}`]: {
  174. display: 'none'
  175. },
  176. 'a, a:hover': {
  177. color: colorTextLightSolid
  178. }
  179. },
  180. [`${componentCls}-item-group-title`]: Object.assign(Object.assign({}, textEllipsis), {
  181. paddingInline: paddingXS
  182. })
  183. }
  184. }];
  185. };
  186. export default getVerticalStyle;