index.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { genComponentStyleHook, mergeToken } from '../../theme/internal';
  3. import { resetComponent } from '../../style';
  4. const genBorderedStyle = token => {
  5. const {
  6. listBorderedCls,
  7. componentCls,
  8. paddingLG,
  9. margin,
  10. padding,
  11. listItemPaddingSM,
  12. marginLG,
  13. borderRadiusLG
  14. } = token;
  15. return {
  16. [`${listBorderedCls}`]: {
  17. border: `${token.lineWidth}px ${token.lineType} ${token.colorBorder}`,
  18. borderRadius: borderRadiusLG,
  19. [`${componentCls}-header,${componentCls}-footer,${componentCls}-item`]: {
  20. paddingInline: paddingLG
  21. },
  22. [`${componentCls}-pagination`]: {
  23. margin: `${margin}px ${marginLG}px`
  24. }
  25. },
  26. [`${listBorderedCls}${componentCls}-sm`]: {
  27. [`${componentCls}-item,${componentCls}-header,${componentCls}-footer`]: {
  28. padding: listItemPaddingSM
  29. }
  30. },
  31. [`${listBorderedCls}${componentCls}-lg`]: {
  32. [`${componentCls}-item,${componentCls}-header,${componentCls}-footer`]: {
  33. padding: `${padding}px ${paddingLG}px`
  34. }
  35. }
  36. };
  37. };
  38. const genResponsiveStyle = token => {
  39. const {
  40. componentCls,
  41. screenSM,
  42. screenMD,
  43. marginLG,
  44. marginSM,
  45. margin
  46. } = token;
  47. return {
  48. [`@media screen and (max-width:${screenMD})`]: {
  49. [`${componentCls}`]: {
  50. [`${componentCls}-item`]: {
  51. [`${componentCls}-item-action`]: {
  52. marginInlineStart: marginLG
  53. }
  54. }
  55. },
  56. [`${componentCls}-vertical`]: {
  57. [`${componentCls}-item`]: {
  58. [`${componentCls}-item-extra`]: {
  59. marginInlineStart: marginLG
  60. }
  61. }
  62. }
  63. },
  64. [`@media screen and (max-width: ${screenSM})`]: {
  65. [`${componentCls}`]: {
  66. [`${componentCls}-item`]: {
  67. flexWrap: 'wrap',
  68. [`${componentCls}-action`]: {
  69. marginInlineStart: marginSM
  70. }
  71. }
  72. },
  73. [`${componentCls}-vertical`]: {
  74. [`${componentCls}-item`]: {
  75. flexWrap: 'wrap-reverse',
  76. [`${componentCls}-item-main`]: {
  77. minWidth: token.contentWidth
  78. },
  79. [`${componentCls}-item-extra`]: {
  80. margin: `auto auto ${margin}px`
  81. }
  82. }
  83. }
  84. }
  85. };
  86. };
  87. // =============================== Base ===============================
  88. const genBaseStyle = token => {
  89. const {
  90. componentCls,
  91. antCls,
  92. controlHeight,
  93. minHeight,
  94. paddingSM,
  95. marginLG,
  96. padding,
  97. listItemPadding,
  98. colorPrimary,
  99. listItemPaddingSM,
  100. listItemPaddingLG,
  101. paddingXS,
  102. margin,
  103. colorText,
  104. colorTextDescription,
  105. motionDurationSlow,
  106. lineWidth
  107. } = token;
  108. return {
  109. [`${componentCls}`]: _extends(_extends({}, resetComponent(token)), {
  110. position: 'relative',
  111. '*': {
  112. outline: 'none'
  113. },
  114. [`${componentCls}-header, ${componentCls}-footer`]: {
  115. background: 'transparent',
  116. paddingBlock: paddingSM
  117. },
  118. [`${componentCls}-pagination`]: {
  119. marginBlockStart: marginLG,
  120. textAlign: 'end',
  121. // https://github.com/ant-design/ant-design/issues/20037
  122. [`${antCls}-pagination-options`]: {
  123. textAlign: 'start'
  124. }
  125. },
  126. [`${componentCls}-spin`]: {
  127. minHeight,
  128. textAlign: 'center'
  129. },
  130. [`${componentCls}-items`]: {
  131. margin: 0,
  132. padding: 0,
  133. listStyle: 'none'
  134. },
  135. [`${componentCls}-item`]: {
  136. display: 'flex',
  137. alignItems: 'center',
  138. justifyContent: 'space-between',
  139. padding: listItemPadding,
  140. color: colorText,
  141. [`${componentCls}-item-meta`]: {
  142. display: 'flex',
  143. flex: 1,
  144. alignItems: 'flex-start',
  145. maxWidth: '100%',
  146. [`${componentCls}-item-meta-avatar`]: {
  147. marginInlineEnd: padding
  148. },
  149. [`${componentCls}-item-meta-content`]: {
  150. flex: '1 0',
  151. width: 0,
  152. color: colorText
  153. },
  154. [`${componentCls}-item-meta-title`]: {
  155. marginBottom: token.marginXXS,
  156. color: colorText,
  157. fontSize: token.fontSize,
  158. lineHeight: token.lineHeight,
  159. '> a': {
  160. color: colorText,
  161. transition: `all ${motionDurationSlow}`,
  162. [`&:hover`]: {
  163. color: colorPrimary
  164. }
  165. }
  166. },
  167. [`${componentCls}-item-meta-description`]: {
  168. color: colorTextDescription,
  169. fontSize: token.fontSize,
  170. lineHeight: token.lineHeight
  171. }
  172. },
  173. [`${componentCls}-item-action`]: {
  174. flex: '0 0 auto',
  175. marginInlineStart: token.marginXXL,
  176. padding: 0,
  177. fontSize: 0,
  178. listStyle: 'none',
  179. [`& > li`]: {
  180. position: 'relative',
  181. display: 'inline-block',
  182. padding: `0 ${paddingXS}px`,
  183. color: colorTextDescription,
  184. fontSize: token.fontSize,
  185. lineHeight: token.lineHeight,
  186. textAlign: 'center',
  187. [`&:first-child`]: {
  188. paddingInlineStart: 0
  189. }
  190. },
  191. [`${componentCls}-item-action-split`]: {
  192. position: 'absolute',
  193. insetBlockStart: '50%',
  194. insetInlineEnd: 0,
  195. width: lineWidth,
  196. height: Math.ceil(token.fontSize * token.lineHeight) - token.marginXXS * 2,
  197. transform: 'translateY(-50%)',
  198. backgroundColor: token.colorSplit
  199. }
  200. }
  201. },
  202. [`${componentCls}-empty`]: {
  203. padding: `${padding}px 0`,
  204. color: colorTextDescription,
  205. fontSize: token.fontSizeSM,
  206. textAlign: 'center'
  207. },
  208. [`${componentCls}-empty-text`]: {
  209. padding,
  210. color: token.colorTextDisabled,
  211. fontSize: token.fontSize,
  212. textAlign: 'center'
  213. },
  214. // ============================ without flex ============================
  215. [`${componentCls}-item-no-flex`]: {
  216. display: 'block'
  217. }
  218. }),
  219. [`${componentCls}-grid ${antCls}-col > ${componentCls}-item`]: {
  220. display: 'block',
  221. maxWidth: '100%',
  222. marginBlockEnd: margin,
  223. paddingBlock: 0,
  224. borderBlockEnd: 'none'
  225. },
  226. [`${componentCls}-vertical ${componentCls}-item`]: {
  227. alignItems: 'initial',
  228. [`${componentCls}-item-main`]: {
  229. display: 'block',
  230. flex: 1
  231. },
  232. [`${componentCls}-item-extra`]: {
  233. marginInlineStart: marginLG
  234. },
  235. [`${componentCls}-item-meta`]: {
  236. marginBlockEnd: padding,
  237. [`${componentCls}-item-meta-title`]: {
  238. marginBlockEnd: paddingSM,
  239. color: colorText,
  240. fontSize: token.fontSizeLG,
  241. lineHeight: token.lineHeightLG
  242. }
  243. },
  244. [`${componentCls}-item-action`]: {
  245. marginBlockStart: padding,
  246. marginInlineStart: 'auto',
  247. '> li': {
  248. padding: `0 ${padding}px`,
  249. [`&:first-child`]: {
  250. paddingInlineStart: 0
  251. }
  252. }
  253. }
  254. },
  255. [`${componentCls}-split ${componentCls}-item`]: {
  256. borderBlockEnd: `${token.lineWidth}px ${token.lineType} ${token.colorSplit}`,
  257. [`&:last-child`]: {
  258. borderBlockEnd: 'none'
  259. }
  260. },
  261. [`${componentCls}-split ${componentCls}-header`]: {
  262. borderBlockEnd: `${token.lineWidth}px ${token.lineType} ${token.colorSplit}`
  263. },
  264. [`${componentCls}-split${componentCls}-empty ${componentCls}-footer`]: {
  265. borderTop: `${token.lineWidth}px ${token.lineType} ${token.colorSplit}`
  266. },
  267. [`${componentCls}-loading ${componentCls}-spin-nested-loading`]: {
  268. minHeight: controlHeight
  269. },
  270. [`${componentCls}-split${componentCls}-something-after-last-item ${antCls}-spin-container > ${componentCls}-items > ${componentCls}-item:last-child`]: {
  271. borderBlockEnd: `${token.lineWidth}px ${token.lineType} ${token.colorSplit}`
  272. },
  273. [`${componentCls}-lg ${componentCls}-item`]: {
  274. padding: listItemPaddingLG
  275. },
  276. [`${componentCls}-sm ${componentCls}-item`]: {
  277. padding: listItemPaddingSM
  278. },
  279. // Horizontal
  280. [`${componentCls}:not(${componentCls}-vertical)`]: {
  281. [`${componentCls}-item-no-flex`]: {
  282. [`${componentCls}-item-action`]: {
  283. float: 'right'
  284. }
  285. }
  286. }
  287. };
  288. };
  289. // ============================== Export ==============================
  290. export default genComponentStyleHook('List', token => {
  291. const listToken = mergeToken(token, {
  292. listBorderedCls: `${token.componentCls}-bordered`,
  293. minHeight: token.controlHeightLG,
  294. listItemPadding: `${token.paddingContentVertical}px ${token.paddingContentHorizontalLG}px`,
  295. listItemPaddingSM: `${token.paddingContentVerticalSM}px ${token.paddingContentHorizontal}px`,
  296. listItemPaddingLG: `${token.paddingContentVerticalLG}px ${token.paddingContentHorizontalLG}px`
  297. });
  298. return [genBaseStyle(listToken), genBorderedStyle(listToken), genResponsiveStyle(listToken)];
  299. }, {
  300. contentWidth: 220
  301. });