index.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { genComponentStyleHook, mergeToken } from '../../theme/internal';
  3. import { clearFix, resetComponent, textEllipsis } from '../../style';
  4. // ============================== Styles ==============================
  5. // ============================== Head ==============================
  6. const genCardHeadStyle = token => {
  7. const {
  8. antCls,
  9. componentCls,
  10. cardHeadHeight,
  11. cardPaddingBase,
  12. cardHeadTabsMarginBottom
  13. } = token;
  14. return _extends(_extends({
  15. display: 'flex',
  16. justifyContent: 'center',
  17. flexDirection: 'column',
  18. minHeight: cardHeadHeight,
  19. marginBottom: -1,
  20. padding: `0 ${cardPaddingBase}px`,
  21. color: token.colorTextHeading,
  22. fontWeight: token.fontWeightStrong,
  23. fontSize: token.fontSizeLG,
  24. background: 'transparent',
  25. borderBottom: `${token.lineWidth}px ${token.lineType} ${token.colorBorderSecondary}`,
  26. borderRadius: `${token.borderRadiusLG}px ${token.borderRadiusLG}px 0 0`
  27. }, clearFix()), {
  28. '&-wrapper': {
  29. width: '100%',
  30. display: 'flex',
  31. alignItems: 'center'
  32. },
  33. '&-title': _extends(_extends({
  34. display: 'inline-block',
  35. flex: 1
  36. }, textEllipsis), {
  37. [`
  38. > ${componentCls}-typography,
  39. > ${componentCls}-typography-edit-content
  40. `]: {
  41. insetInlineStart: 0,
  42. marginTop: 0,
  43. marginBottom: 0
  44. }
  45. }),
  46. [`${antCls}-tabs-top`]: {
  47. clear: 'both',
  48. marginBottom: cardHeadTabsMarginBottom,
  49. color: token.colorText,
  50. fontWeight: 'normal',
  51. fontSize: token.fontSize,
  52. '&-bar': {
  53. borderBottom: `${token.lineWidth}px ${token.lineType} ${token.colorBorderSecondary}`
  54. }
  55. }
  56. });
  57. };
  58. // ============================== Grid ==============================
  59. const genCardGridStyle = token => {
  60. const {
  61. cardPaddingBase,
  62. colorBorderSecondary,
  63. cardShadow,
  64. lineWidth
  65. } = token;
  66. return {
  67. width: '33.33%',
  68. padding: cardPaddingBase,
  69. border: 0,
  70. borderRadius: 0,
  71. boxShadow: `
  72. ${lineWidth}px 0 0 0 ${colorBorderSecondary},
  73. 0 ${lineWidth}px 0 0 ${colorBorderSecondary},
  74. ${lineWidth}px ${lineWidth}px 0 0 ${colorBorderSecondary},
  75. ${lineWidth}px 0 0 0 ${colorBorderSecondary} inset,
  76. 0 ${lineWidth}px 0 0 ${colorBorderSecondary} inset;
  77. `,
  78. transition: `all ${token.motionDurationMid}`,
  79. '&-hoverable:hover': {
  80. position: 'relative',
  81. zIndex: 1,
  82. boxShadow: cardShadow
  83. }
  84. };
  85. };
  86. // ============================== Actions ==============================
  87. const genCardActionsStyle = token => {
  88. const {
  89. componentCls,
  90. iconCls,
  91. cardActionsLiMargin,
  92. cardActionsIconSize,
  93. colorBorderSecondary
  94. } = token;
  95. return _extends(_extends({
  96. margin: 0,
  97. padding: 0,
  98. listStyle: 'none',
  99. background: token.colorBgContainer,
  100. borderTop: `${token.lineWidth}px ${token.lineType} ${colorBorderSecondary}`,
  101. display: 'flex',
  102. borderRadius: `0 0 ${token.borderRadiusLG}px ${token.borderRadiusLG}px `
  103. }, clearFix()), {
  104. '& > li': {
  105. margin: cardActionsLiMargin,
  106. color: token.colorTextDescription,
  107. textAlign: 'center',
  108. '> span': {
  109. position: 'relative',
  110. display: 'block',
  111. minWidth: token.cardActionsIconSize * 2,
  112. fontSize: token.fontSize,
  113. lineHeight: token.lineHeight,
  114. cursor: 'pointer',
  115. '&:hover': {
  116. color: token.colorPrimary,
  117. transition: `color ${token.motionDurationMid}`
  118. },
  119. [`a:not(${componentCls}-btn), > ${iconCls}`]: {
  120. display: 'inline-block',
  121. width: '100%',
  122. color: token.colorTextDescription,
  123. lineHeight: `${token.fontSize * token.lineHeight}px`,
  124. transition: `color ${token.motionDurationMid}`,
  125. '&:hover': {
  126. color: token.colorPrimary
  127. }
  128. },
  129. [`> ${iconCls}`]: {
  130. fontSize: cardActionsIconSize,
  131. lineHeight: `${cardActionsIconSize * token.lineHeight}px`
  132. }
  133. },
  134. '&:not(:last-child)': {
  135. borderInlineEnd: `${token.lineWidth}px ${token.lineType} ${colorBorderSecondary}`
  136. }
  137. }
  138. });
  139. };
  140. // ============================== Meta ==============================
  141. const genCardMetaStyle = token => _extends(_extends({
  142. margin: `-${token.marginXXS}px 0`,
  143. display: 'flex'
  144. }, clearFix()), {
  145. '&-avatar': {
  146. paddingInlineEnd: token.padding
  147. },
  148. '&-detail': {
  149. overflow: 'hidden',
  150. flex: 1,
  151. '> div:not(:last-child)': {
  152. marginBottom: token.marginXS
  153. }
  154. },
  155. '&-title': _extends({
  156. color: token.colorTextHeading,
  157. fontWeight: token.fontWeightStrong,
  158. fontSize: token.fontSizeLG
  159. }, textEllipsis),
  160. '&-description': {
  161. color: token.colorTextDescription
  162. }
  163. });
  164. // ============================== Inner ==============================
  165. const genCardTypeInnerStyle = token => {
  166. const {
  167. componentCls,
  168. cardPaddingBase,
  169. colorFillAlter
  170. } = token;
  171. return {
  172. [`${componentCls}-head`]: {
  173. padding: `0 ${cardPaddingBase}px`,
  174. background: colorFillAlter,
  175. '&-title': {
  176. fontSize: token.fontSize
  177. }
  178. },
  179. [`${componentCls}-body`]: {
  180. padding: `${token.padding}px ${cardPaddingBase}px`
  181. }
  182. };
  183. };
  184. // ============================== Loading ==============================
  185. const genCardLoadingStyle = token => {
  186. const {
  187. componentCls
  188. } = token;
  189. return {
  190. overflow: 'hidden',
  191. [`${componentCls}-body`]: {
  192. userSelect: 'none'
  193. }
  194. };
  195. };
  196. // ============================== Basic ==============================
  197. const genCardStyle = token => {
  198. const {
  199. componentCls,
  200. cardShadow,
  201. cardHeadPadding,
  202. colorBorderSecondary,
  203. boxShadow,
  204. cardPaddingBase
  205. } = token;
  206. return {
  207. [componentCls]: _extends(_extends({}, resetComponent(token)), {
  208. position: 'relative',
  209. background: token.colorBgContainer,
  210. borderRadius: token.borderRadiusLG,
  211. [`&:not(${componentCls}-bordered)`]: {
  212. boxShadow
  213. },
  214. [`${componentCls}-head`]: genCardHeadStyle(token),
  215. [`${componentCls}-extra`]: {
  216. // https://stackoverflow.com/a/22429853/3040605
  217. marginInlineStart: 'auto',
  218. color: '',
  219. fontWeight: 'normal',
  220. fontSize: token.fontSize
  221. },
  222. [`${componentCls}-body`]: _extends({
  223. padding: cardPaddingBase,
  224. borderRadius: ` 0 0 ${token.borderRadiusLG}px ${token.borderRadiusLG}px`
  225. }, clearFix()),
  226. [`${componentCls}-grid`]: genCardGridStyle(token),
  227. [`${componentCls}-cover`]: {
  228. '> *': {
  229. display: 'block',
  230. width: '100%'
  231. },
  232. img: {
  233. borderRadius: `${token.borderRadiusLG}px ${token.borderRadiusLG}px 0 0`
  234. }
  235. },
  236. [`${componentCls}-actions`]: genCardActionsStyle(token),
  237. [`${componentCls}-meta`]: genCardMetaStyle(token)
  238. }),
  239. [`${componentCls}-bordered`]: {
  240. border: `${token.lineWidth}px ${token.lineType} ${colorBorderSecondary}`,
  241. [`${componentCls}-cover`]: {
  242. marginTop: -1,
  243. marginInlineStart: -1,
  244. marginInlineEnd: -1
  245. }
  246. },
  247. [`${componentCls}-hoverable`]: {
  248. cursor: 'pointer',
  249. transition: `box-shadow ${token.motionDurationMid}, border-color ${token.motionDurationMid}`,
  250. '&:hover': {
  251. borderColor: 'transparent',
  252. boxShadow: cardShadow
  253. }
  254. },
  255. [`${componentCls}-contain-grid`]: {
  256. [`${componentCls}-body`]: {
  257. display: 'flex',
  258. flexWrap: 'wrap'
  259. },
  260. [`&:not(${componentCls}-loading) ${componentCls}-body`]: {
  261. marginBlockStart: -token.lineWidth,
  262. marginInlineStart: -token.lineWidth,
  263. padding: 0
  264. }
  265. },
  266. [`${componentCls}-contain-tabs`]: {
  267. [`> ${componentCls}-head`]: {
  268. [`${componentCls}-head-title, ${componentCls}-extra`]: {
  269. paddingTop: cardHeadPadding
  270. }
  271. }
  272. },
  273. [`${componentCls}-type-inner`]: genCardTypeInnerStyle(token),
  274. [`${componentCls}-loading`]: genCardLoadingStyle(token),
  275. [`${componentCls}-rtl`]: {
  276. direction: 'rtl'
  277. }
  278. };
  279. };
  280. // ============================== Size ==============================
  281. const genCardSizeStyle = token => {
  282. const {
  283. componentCls,
  284. cardPaddingSM,
  285. cardHeadHeightSM
  286. } = token;
  287. return {
  288. [`${componentCls}-small`]: {
  289. [`> ${componentCls}-head`]: {
  290. minHeight: cardHeadHeightSM,
  291. padding: `0 ${cardPaddingSM}px`,
  292. fontSize: token.fontSize,
  293. [`> ${componentCls}-head-wrapper`]: {
  294. [`> ${componentCls}-extra`]: {
  295. fontSize: token.fontSize
  296. }
  297. }
  298. },
  299. [`> ${componentCls}-body`]: {
  300. padding: cardPaddingSM
  301. }
  302. },
  303. [`${componentCls}-small${componentCls}-contain-tabs`]: {
  304. [`> ${componentCls}-head`]: {
  305. [`${componentCls}-head-title, ${componentCls}-extra`]: {
  306. minHeight: cardHeadHeightSM,
  307. paddingTop: 0,
  308. display: 'flex',
  309. alignItems: 'center'
  310. }
  311. }
  312. }
  313. };
  314. };
  315. // ============================== Export ==============================
  316. export default genComponentStyleHook('Card', token => {
  317. const cardToken = mergeToken(token, {
  318. cardShadow: token.boxShadowCard,
  319. cardHeadHeight: token.fontSizeLG * token.lineHeightLG + token.padding * 2,
  320. cardHeadHeightSM: token.fontSize * token.lineHeight + token.paddingXS * 2,
  321. cardHeadPadding: token.padding,
  322. cardPaddingBase: token.paddingLG,
  323. cardHeadTabsMarginBottom: -token.padding - token.lineWidth,
  324. cardActionsLiMargin: `${token.paddingSM}px 0`,
  325. cardActionsIconSize: token.fontSize,
  326. cardPaddingSM: 12 // Fixed padding.
  327. });
  328. return [
  329. // Style
  330. genCardStyle(cardToken),
  331. // Size
  332. genCardSizeStyle(cardToken)];
  333. });