index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { genCollapseMotion } from '../../style/motion';
  3. import { genComponentStyleHook, mergeToken } from '../../theme/internal';
  4. import { resetComponent, resetIcon } from '../../style';
  5. export const genBaseStyle = token => {
  6. const {
  7. componentCls,
  8. collapseContentBg,
  9. padding,
  10. collapseContentPaddingHorizontal,
  11. collapseHeaderBg,
  12. collapseHeaderPadding,
  13. collapsePanelBorderRadius,
  14. lineWidth,
  15. lineType,
  16. colorBorder,
  17. colorText,
  18. colorTextHeading,
  19. colorTextDisabled,
  20. fontSize,
  21. lineHeight,
  22. marginSM,
  23. paddingSM,
  24. motionDurationSlow,
  25. fontSizeIcon
  26. } = token;
  27. const borderBase = `${lineWidth}px ${lineType} ${colorBorder}`;
  28. return {
  29. [componentCls]: _extends(_extends({}, resetComponent(token)), {
  30. backgroundColor: collapseHeaderBg,
  31. border: borderBase,
  32. borderBottom: 0,
  33. borderRadius: `${collapsePanelBorderRadius}px`,
  34. [`&-rtl`]: {
  35. direction: 'rtl'
  36. },
  37. [`& > ${componentCls}-item`]: {
  38. borderBottom: borderBase,
  39. [`&:last-child`]: {
  40. [`
  41. &,
  42. & > ${componentCls}-header`]: {
  43. borderRadius: `0 0 ${collapsePanelBorderRadius}px ${collapsePanelBorderRadius}px`
  44. }
  45. },
  46. [`> ${componentCls}-header`]: {
  47. position: 'relative',
  48. display: 'flex',
  49. flexWrap: 'nowrap',
  50. alignItems: 'flex-start',
  51. padding: collapseHeaderPadding,
  52. color: colorTextHeading,
  53. lineHeight,
  54. cursor: 'pointer',
  55. transition: `all ${motionDurationSlow}, visibility 0s`,
  56. [`> ${componentCls}-header-text`]: {
  57. flex: 'auto'
  58. },
  59. '&:focus': {
  60. outline: 'none'
  61. },
  62. // >>>>> Arrow
  63. [`${componentCls}-expand-icon`]: {
  64. height: fontSize * lineHeight,
  65. display: 'flex',
  66. alignItems: 'center',
  67. paddingInlineEnd: marginSM
  68. },
  69. [`${componentCls}-arrow`]: _extends(_extends({}, resetIcon()), {
  70. fontSize: fontSizeIcon,
  71. svg: {
  72. transition: `transform ${motionDurationSlow}`
  73. }
  74. }),
  75. // >>>>> Text
  76. [`${componentCls}-header-text`]: {
  77. marginInlineEnd: 'auto'
  78. }
  79. },
  80. [`${componentCls}-header-collapsible-only`]: {
  81. cursor: 'default',
  82. [`${componentCls}-header-text`]: {
  83. flex: 'none',
  84. cursor: 'pointer'
  85. },
  86. [`${componentCls}-expand-icon`]: {
  87. cursor: 'pointer'
  88. }
  89. },
  90. [`${componentCls}-icon-collapsible-only`]: {
  91. cursor: 'default',
  92. [`${componentCls}-expand-icon`]: {
  93. cursor: 'pointer'
  94. }
  95. },
  96. [`&${componentCls}-no-arrow`]: {
  97. [`> ${componentCls}-header`]: {
  98. paddingInlineStart: paddingSM
  99. }
  100. }
  101. },
  102. [`${componentCls}-content`]: {
  103. color: colorText,
  104. backgroundColor: collapseContentBg,
  105. borderTop: borderBase,
  106. [`& > ${componentCls}-content-box`]: {
  107. padding: `${padding}px ${collapseContentPaddingHorizontal}px`
  108. },
  109. [`&-hidden`]: {
  110. display: 'none'
  111. }
  112. },
  113. [`${componentCls}-item:last-child`]: {
  114. [`> ${componentCls}-content`]: {
  115. borderRadius: `0 0 ${collapsePanelBorderRadius}px ${collapsePanelBorderRadius}px`
  116. }
  117. },
  118. [`& ${componentCls}-item-disabled > ${componentCls}-header`]: {
  119. [`
  120. &,
  121. & > .arrow
  122. `]: {
  123. color: colorTextDisabled,
  124. cursor: 'not-allowed'
  125. }
  126. },
  127. // ========================== Icon Position ==========================
  128. [`&${componentCls}-icon-position-end`]: {
  129. [`& > ${componentCls}-item`]: {
  130. [`> ${componentCls}-header`]: {
  131. [`${componentCls}-expand-icon`]: {
  132. order: 1,
  133. paddingInlineEnd: 0,
  134. paddingInlineStart: marginSM
  135. }
  136. }
  137. }
  138. }
  139. })
  140. };
  141. };
  142. const genArrowStyle = token => {
  143. const {
  144. componentCls
  145. } = token;
  146. const fixedSelector = `> ${componentCls}-item > ${componentCls}-header ${componentCls}-arrow svg`;
  147. return {
  148. [`${componentCls}-rtl`]: {
  149. [fixedSelector]: {
  150. transform: `rotate(180deg)`
  151. }
  152. }
  153. };
  154. };
  155. const genBorderlessStyle = token => {
  156. const {
  157. componentCls,
  158. collapseHeaderBg,
  159. paddingXXS,
  160. colorBorder
  161. } = token;
  162. return {
  163. [`${componentCls}-borderless`]: {
  164. backgroundColor: collapseHeaderBg,
  165. border: 0,
  166. [`> ${componentCls}-item`]: {
  167. borderBottom: `1px solid ${colorBorder}`
  168. },
  169. [`
  170. > ${componentCls}-item:last-child,
  171. > ${componentCls}-item:last-child ${componentCls}-header
  172. `]: {
  173. borderRadius: 0
  174. },
  175. [`> ${componentCls}-item:last-child`]: {
  176. borderBottom: 0
  177. },
  178. [`> ${componentCls}-item > ${componentCls}-content`]: {
  179. backgroundColor: 'transparent',
  180. borderTop: 0
  181. },
  182. [`> ${componentCls}-item > ${componentCls}-content > ${componentCls}-content-box`]: {
  183. paddingTop: paddingXXS
  184. }
  185. }
  186. };
  187. };
  188. const genGhostStyle = token => {
  189. const {
  190. componentCls,
  191. paddingSM
  192. } = token;
  193. return {
  194. [`${componentCls}-ghost`]: {
  195. backgroundColor: 'transparent',
  196. border: 0,
  197. [`> ${componentCls}-item`]: {
  198. borderBottom: 0,
  199. [`> ${componentCls}-content`]: {
  200. backgroundColor: 'transparent',
  201. border: 0,
  202. [`> ${componentCls}-content-box`]: {
  203. paddingBlock: paddingSM
  204. }
  205. }
  206. }
  207. }
  208. };
  209. };
  210. export default genComponentStyleHook('Collapse', token => {
  211. const collapseToken = mergeToken(token, {
  212. collapseContentBg: token.colorBgContainer,
  213. collapseHeaderBg: token.colorFillAlter,
  214. collapseHeaderPadding: `${token.paddingSM}px ${token.padding}px`,
  215. collapsePanelBorderRadius: token.borderRadiusLG,
  216. collapseContentPaddingHorizontal: 16 // Fixed value
  217. });
  218. return [genBaseStyle(collapseToken), genBorderlessStyle(collapseToken), genGhostStyle(collapseToken), genArrowStyle(collapseToken), genCollapseMotion(collapseToken)];
  219. });