index.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.prepareComponentToken = exports.genBaseStyle = exports.default = void 0;
  6. var _cssinjs = require("@ant-design/cssinjs");
  7. var _style = require("../../style");
  8. var _motion = require("../../style/motion");
  9. var _internal = require("../../theme/internal");
  10. const genBaseStyle = token => {
  11. const {
  12. componentCls,
  13. contentBg,
  14. padding,
  15. headerBg,
  16. headerPadding,
  17. collapseHeaderPaddingSM,
  18. collapseHeaderPaddingLG,
  19. collapsePanelBorderRadius,
  20. lineWidth,
  21. lineType,
  22. colorBorder,
  23. colorText,
  24. colorTextHeading,
  25. colorTextDisabled,
  26. fontSizeLG,
  27. lineHeight,
  28. lineHeightLG,
  29. marginSM,
  30. paddingSM,
  31. paddingLG,
  32. paddingXS,
  33. motionDurationSlow,
  34. fontSizeIcon,
  35. contentPadding,
  36. fontHeight,
  37. fontHeightLG
  38. } = token;
  39. const borderBase = `${(0, _cssinjs.unit)(lineWidth)} ${lineType} ${colorBorder}`;
  40. return {
  41. [componentCls]: Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), {
  42. backgroundColor: headerBg,
  43. border: borderBase,
  44. borderRadius: collapsePanelBorderRadius,
  45. '&-rtl': {
  46. direction: 'rtl'
  47. },
  48. [`& > ${componentCls}-item`]: {
  49. borderBottom: borderBase,
  50. '&:first-child': {
  51. [`
  52. &,
  53. & > ${componentCls}-header`]: {
  54. borderRadius: `${(0, _cssinjs.unit)(collapsePanelBorderRadius)} ${(0, _cssinjs.unit)(collapsePanelBorderRadius)} 0 0`
  55. }
  56. },
  57. '&:last-child': {
  58. [`
  59. &,
  60. & > ${componentCls}-header`]: {
  61. borderRadius: `0 0 ${(0, _cssinjs.unit)(collapsePanelBorderRadius)} ${(0, _cssinjs.unit)(collapsePanelBorderRadius)}`
  62. }
  63. },
  64. [`> ${componentCls}-header`]: Object.assign(Object.assign({
  65. position: 'relative',
  66. display: 'flex',
  67. flexWrap: 'nowrap',
  68. alignItems: 'flex-start',
  69. padding: headerPadding,
  70. color: colorTextHeading,
  71. lineHeight,
  72. cursor: 'pointer',
  73. transition: `all ${motionDurationSlow}, visibility 0s`
  74. }, (0, _style.genFocusStyle)(token)), {
  75. [`> ${componentCls}-header-text`]: {
  76. flex: 'auto'
  77. },
  78. // >>>>> Arrow
  79. [`${componentCls}-expand-icon`]: {
  80. height: fontHeight,
  81. display: 'flex',
  82. alignItems: 'center',
  83. paddingInlineEnd: marginSM
  84. },
  85. [`${componentCls}-arrow`]: Object.assign(Object.assign({}, (0, _style.resetIcon)()), {
  86. fontSize: fontSizeIcon,
  87. // when `transform: rotate()` is applied to icon's root element
  88. transition: `transform ${motionDurationSlow}`,
  89. // when `transform: rotate()` is applied to icon's child element
  90. svg: {
  91. transition: `transform ${motionDurationSlow}`
  92. }
  93. }),
  94. // >>>>> Text
  95. [`${componentCls}-header-text`]: {
  96. marginInlineEnd: 'auto'
  97. }
  98. }),
  99. [`${componentCls}-collapsible-header`]: {
  100. cursor: 'default',
  101. [`${componentCls}-header-text`]: {
  102. flex: 'none',
  103. cursor: 'pointer'
  104. },
  105. [`${componentCls}-expand-icon`]: {
  106. cursor: 'pointer'
  107. }
  108. },
  109. [`${componentCls}-collapsible-icon`]: {
  110. cursor: 'unset',
  111. [`${componentCls}-expand-icon`]: {
  112. cursor: 'pointer'
  113. }
  114. }
  115. },
  116. [`${componentCls}-content`]: {
  117. color: colorText,
  118. backgroundColor: contentBg,
  119. borderTop: borderBase,
  120. [`& > ${componentCls}-content-box`]: {
  121. padding: contentPadding
  122. },
  123. '&-hidden': {
  124. display: 'none'
  125. }
  126. },
  127. '&-small': {
  128. [`> ${componentCls}-item`]: {
  129. [`> ${componentCls}-header`]: {
  130. padding: collapseHeaderPaddingSM,
  131. paddingInlineStart: paddingXS,
  132. [`> ${componentCls}-expand-icon`]: {
  133. // Arrow offset
  134. marginInlineStart: token.calc(paddingSM).sub(paddingXS).equal()
  135. }
  136. },
  137. [`> ${componentCls}-content > ${componentCls}-content-box`]: {
  138. padding: paddingSM
  139. }
  140. }
  141. },
  142. '&-large': {
  143. [`> ${componentCls}-item`]: {
  144. fontSize: fontSizeLG,
  145. lineHeight: lineHeightLG,
  146. [`> ${componentCls}-header`]: {
  147. padding: collapseHeaderPaddingLG,
  148. paddingInlineStart: padding,
  149. [`> ${componentCls}-expand-icon`]: {
  150. height: fontHeightLG,
  151. // Arrow offset
  152. marginInlineStart: token.calc(paddingLG).sub(padding).equal()
  153. }
  154. },
  155. [`> ${componentCls}-content > ${componentCls}-content-box`]: {
  156. padding: paddingLG
  157. }
  158. }
  159. },
  160. [`${componentCls}-item:last-child`]: {
  161. borderBottom: 0,
  162. [`> ${componentCls}-content`]: {
  163. borderRadius: `0 0 ${(0, _cssinjs.unit)(collapsePanelBorderRadius)} ${(0, _cssinjs.unit)(collapsePanelBorderRadius)}`
  164. }
  165. },
  166. [`& ${componentCls}-item-disabled > ${componentCls}-header`]: {
  167. [`
  168. &,
  169. & > .arrow
  170. `]: {
  171. color: colorTextDisabled,
  172. cursor: 'not-allowed'
  173. }
  174. },
  175. // ========================== Icon Position ==========================
  176. [`&${componentCls}-icon-position-end`]: {
  177. [`& > ${componentCls}-item`]: {
  178. [`> ${componentCls}-header`]: {
  179. [`${componentCls}-expand-icon`]: {
  180. order: 1,
  181. paddingInlineEnd: 0,
  182. paddingInlineStart: marginSM
  183. }
  184. }
  185. }
  186. }
  187. })
  188. };
  189. };
  190. exports.genBaseStyle = genBaseStyle;
  191. const genArrowStyle = token => {
  192. const {
  193. componentCls
  194. } = token;
  195. const fixedSelector = `> ${componentCls}-item > ${componentCls}-header ${componentCls}-arrow`;
  196. return {
  197. [`${componentCls}-rtl`]: {
  198. [fixedSelector]: {
  199. transform: `rotate(180deg)`
  200. }
  201. }
  202. };
  203. };
  204. const genBorderlessStyle = token => {
  205. const {
  206. componentCls,
  207. headerBg,
  208. borderlessContentPadding,
  209. borderlessContentBg,
  210. colorBorder
  211. } = token;
  212. return {
  213. [`${componentCls}-borderless`]: {
  214. backgroundColor: headerBg,
  215. border: 0,
  216. [`> ${componentCls}-item`]: {
  217. borderBottom: `1px solid ${colorBorder}`
  218. },
  219. [`
  220. > ${componentCls}-item:last-child,
  221. > ${componentCls}-item:last-child ${componentCls}-header
  222. `]: {
  223. borderRadius: 0
  224. },
  225. [`> ${componentCls}-item:last-child`]: {
  226. borderBottom: 0
  227. },
  228. [`> ${componentCls}-item > ${componentCls}-content`]: {
  229. backgroundColor: borderlessContentBg,
  230. borderTop: 0
  231. },
  232. [`> ${componentCls}-item > ${componentCls}-content > ${componentCls}-content-box`]: {
  233. padding: borderlessContentPadding
  234. }
  235. }
  236. };
  237. };
  238. const genGhostStyle = token => {
  239. const {
  240. componentCls,
  241. paddingSM
  242. } = token;
  243. return {
  244. [`${componentCls}-ghost`]: {
  245. backgroundColor: 'transparent',
  246. border: 0,
  247. [`> ${componentCls}-item`]: {
  248. borderBottom: 0,
  249. [`> ${componentCls}-content`]: {
  250. backgroundColor: 'transparent',
  251. border: 0,
  252. [`> ${componentCls}-content-box`]: {
  253. paddingBlock: paddingSM
  254. }
  255. }
  256. }
  257. }
  258. };
  259. };
  260. const prepareComponentToken = token => ({
  261. headerPadding: `${token.paddingSM}px ${token.padding}px`,
  262. headerBg: token.colorFillAlter,
  263. contentPadding: `${token.padding}px 16px`,
  264. // Fixed Value
  265. contentBg: token.colorBgContainer,
  266. borderlessContentPadding: `${token.paddingXXS}px 16px ${token.padding}px`,
  267. borderlessContentBg: 'transparent'
  268. });
  269. exports.prepareComponentToken = prepareComponentToken;
  270. var _default = exports.default = (0, _internal.genStyleHooks)('Collapse', token => {
  271. const collapseToken = (0, _internal.mergeToken)(token, {
  272. collapseHeaderPaddingSM: `${(0, _cssinjs.unit)(token.paddingXS)} ${(0, _cssinjs.unit)(token.paddingSM)}`,
  273. collapseHeaderPaddingLG: `${(0, _cssinjs.unit)(token.padding)} ${(0, _cssinjs.unit)(token.paddingLG)}`,
  274. collapsePanelBorderRadius: token.borderRadiusLG
  275. });
  276. return [genBaseStyle(collapseToken), genBorderlessStyle(collapseToken), genGhostStyle(collapseToken), genArrowStyle(collapseToken), (0, _motion.genCollapseMotion)(collapseToken)];
  277. }, prepareComponentToken);