index.js 10 KB

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