index.js 6.6 KB

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