index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.prepareComponentToken = exports.default = void 0;
  6. var _cssinjs = require("@ant-design/cssinjs");
  7. var _style = require("../../style");
  8. var _internal = require("../../theme/internal");
  9. // ============================== Styles ==============================
  10. // ============================== Head ==============================
  11. const genCardHeadStyle = token => {
  12. const {
  13. antCls,
  14. componentCls,
  15. headerHeight,
  16. headerPadding,
  17. tabsMarginBottom
  18. } = token;
  19. return Object.assign(Object.assign({
  20. display: 'flex',
  21. justifyContent: 'center',
  22. flexDirection: 'column',
  23. minHeight: headerHeight,
  24. marginBottom: -1,
  25. padding: `0 ${(0, _cssinjs.unit)(headerPadding)}`,
  26. color: token.colorTextHeading,
  27. fontWeight: token.fontWeightStrong,
  28. fontSize: token.headerFontSize,
  29. background: token.headerBg,
  30. borderBottom: `${(0, _cssinjs.unit)(token.lineWidth)} ${token.lineType} ${token.colorBorderSecondary}`,
  31. borderRadius: `${(0, _cssinjs.unit)(token.borderRadiusLG)} ${(0, _cssinjs.unit)(token.borderRadiusLG)} 0 0`
  32. }, (0, _style.clearFix)()), {
  33. '&-wrapper': {
  34. width: '100%',
  35. display: 'flex',
  36. alignItems: 'center'
  37. },
  38. '&-title': Object.assign(Object.assign({
  39. display: 'inline-block',
  40. flex: 1
  41. }, _style.textEllipsis), {
  42. [`
  43. > ${componentCls}-typography,
  44. > ${componentCls}-typography-edit-content
  45. `]: {
  46. insetInlineStart: 0,
  47. marginTop: 0,
  48. marginBottom: 0
  49. }
  50. }),
  51. [`${antCls}-tabs-top`]: {
  52. clear: 'both',
  53. marginBottom: tabsMarginBottom,
  54. color: token.colorText,
  55. fontWeight: 'normal',
  56. fontSize: token.fontSize,
  57. '&-bar': {
  58. borderBottom: `${(0, _cssinjs.unit)(token.lineWidth)} ${token.lineType} ${token.colorBorderSecondary}`
  59. }
  60. }
  61. });
  62. };
  63. // ============================== Grid ==============================
  64. const genCardGridStyle = token => {
  65. const {
  66. cardPaddingBase,
  67. colorBorderSecondary,
  68. cardShadow,
  69. lineWidth
  70. } = token;
  71. return {
  72. width: '33.33%',
  73. padding: cardPaddingBase,
  74. border: 0,
  75. borderRadius: 0,
  76. boxShadow: `
  77. ${(0, _cssinjs.unit)(lineWidth)} 0 0 0 ${colorBorderSecondary},
  78. 0 ${(0, _cssinjs.unit)(lineWidth)} 0 0 ${colorBorderSecondary},
  79. ${(0, _cssinjs.unit)(lineWidth)} ${(0, _cssinjs.unit)(lineWidth)} 0 0 ${colorBorderSecondary},
  80. ${(0, _cssinjs.unit)(lineWidth)} 0 0 0 ${colorBorderSecondary} inset,
  81. 0 ${(0, _cssinjs.unit)(lineWidth)} 0 0 ${colorBorderSecondary} inset;
  82. `,
  83. transition: `all ${token.motionDurationMid}`,
  84. '&-hoverable:hover': {
  85. position: 'relative',
  86. zIndex: 1,
  87. boxShadow: cardShadow
  88. }
  89. };
  90. };
  91. // ============================== Actions ==============================
  92. const genCardActionsStyle = token => {
  93. const {
  94. componentCls,
  95. iconCls,
  96. actionsLiMargin,
  97. cardActionsIconSize,
  98. colorBorderSecondary,
  99. actionsBg
  100. } = token;
  101. return Object.assign(Object.assign({
  102. margin: 0,
  103. padding: 0,
  104. listStyle: 'none',
  105. background: actionsBg,
  106. borderTop: `${(0, _cssinjs.unit)(token.lineWidth)} ${token.lineType} ${colorBorderSecondary}`,
  107. display: 'flex',
  108. borderRadius: `0 0 ${(0, _cssinjs.unit)(token.borderRadiusLG)} ${(0, _cssinjs.unit)(token.borderRadiusLG)}`
  109. }, (0, _style.clearFix)()), {
  110. '& > li': {
  111. margin: actionsLiMargin,
  112. color: token.colorTextDescription,
  113. textAlign: 'center',
  114. '> span': {
  115. position: 'relative',
  116. display: 'block',
  117. minWidth: token.calc(token.cardActionsIconSize).mul(2).equal(),
  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.colorIcon,
  129. lineHeight: (0, _cssinjs.unit)(token.fontHeight),
  130. transition: `color ${token.motionDurationMid}`,
  131. '&:hover': {
  132. color: token.colorPrimary
  133. }
  134. },
  135. [`> ${iconCls}`]: {
  136. fontSize: cardActionsIconSize,
  137. lineHeight: (0, _cssinjs.unit)(token.calc(cardActionsIconSize).mul(token.lineHeight).equal())
  138. }
  139. },
  140. '&:not(:last-child)': {
  141. borderInlineEnd: `${(0, _cssinjs.unit)(token.lineWidth)} ${token.lineType} ${colorBorderSecondary}`
  142. }
  143. }
  144. });
  145. };
  146. // ============================== Meta ==============================
  147. const genCardMetaStyle = token => Object.assign(Object.assign({
  148. margin: `${(0, _cssinjs.unit)(token.calc(token.marginXXS).mul(-1).equal())} 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': Object.assign({
  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. colorFillAlter,
  175. headerPadding,
  176. bodyPadding
  177. } = token;
  178. return {
  179. [`${componentCls}-head`]: {
  180. padding: `0 ${(0, _cssinjs.unit)(headerPadding)}`,
  181. background: colorFillAlter,
  182. '&-title': {
  183. fontSize: token.fontSize
  184. }
  185. },
  186. [`${componentCls}-body`]: {
  187. padding: `${(0, _cssinjs.unit)(token.padding)} ${(0, _cssinjs.unit)(bodyPadding)}`
  188. }
  189. };
  190. };
  191. // ============================== Loading ==============================
  192. const genCardLoadingStyle = token => {
  193. const {
  194. componentCls
  195. } = token;
  196. return {
  197. overflow: 'hidden',
  198. [`${componentCls}-body`]: {
  199. userSelect: 'none'
  200. }
  201. };
  202. };
  203. // ============================== Basic ==============================
  204. const genCardStyle = token => {
  205. const {
  206. componentCls,
  207. cardShadow,
  208. cardHeadPadding,
  209. colorBorderSecondary,
  210. boxShadowTertiary,
  211. bodyPadding,
  212. extraColor
  213. } = token;
  214. return {
  215. [componentCls]: Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), {
  216. position: 'relative',
  217. background: token.colorBgContainer,
  218. borderRadius: token.borderRadiusLG,
  219. [`&:not(${componentCls}-bordered)`]: {
  220. boxShadow: boxShadowTertiary
  221. },
  222. [`${componentCls}-head`]: genCardHeadStyle(token),
  223. [`${componentCls}-extra`]: {
  224. // https://stackoverflow.com/a/22429853/3040605
  225. marginInlineStart: 'auto',
  226. color: extraColor,
  227. fontWeight: 'normal',
  228. fontSize: token.fontSize
  229. },
  230. [`${componentCls}-body`]: Object.assign({
  231. padding: bodyPadding,
  232. borderRadius: `0 0 ${(0, _cssinjs.unit)(token.borderRadiusLG)} ${(0, _cssinjs.unit)(token.borderRadiusLG)}`
  233. }, (0, _style.clearFix)()),
  234. [`${componentCls}-grid`]: genCardGridStyle(token),
  235. [`${componentCls}-cover`]: {
  236. '> *': {
  237. display: 'block',
  238. width: '100%',
  239. borderRadius: `${(0, _cssinjs.unit)(token.borderRadiusLG)} ${(0, _cssinjs.unit)(token.borderRadiusLG)} 0 0`
  240. }
  241. },
  242. [`${componentCls}-actions`]: genCardActionsStyle(token),
  243. [`${componentCls}-meta`]: genCardMetaStyle(token)
  244. }),
  245. [`${componentCls}-bordered`]: {
  246. border: `${(0, _cssinjs.unit)(token.lineWidth)} ${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. borderRadius: `${(0, _cssinjs.unit)(token.borderRadiusLG)} ${(0, _cssinjs.unit)(token.borderRadiusLG)} 0 0 `,
  263. [`${componentCls}-body`]: {
  264. display: 'flex',
  265. flexWrap: 'wrap'
  266. },
  267. [`&:not(${componentCls}-loading) ${componentCls}-body`]: {
  268. marginBlockStart: token.calc(token.lineWidth).mul(-1).equal(),
  269. marginInlineStart: token.calc(token.lineWidth).mul(-1).equal(),
  270. padding: 0
  271. }
  272. },
  273. [`${componentCls}-contain-tabs`]: {
  274. [`> div${componentCls}-head`]: {
  275. minHeight: 0,
  276. [`${componentCls}-head-title, ${componentCls}-extra`]: {
  277. paddingTop: cardHeadPadding
  278. }
  279. }
  280. },
  281. [`${componentCls}-type-inner`]: genCardTypeInnerStyle(token),
  282. [`${componentCls}-loading`]: genCardLoadingStyle(token),
  283. [`${componentCls}-rtl`]: {
  284. direction: 'rtl'
  285. }
  286. };
  287. };
  288. // ============================== Size ==============================
  289. const genCardSizeStyle = token => {
  290. const {
  291. componentCls,
  292. bodyPaddingSM,
  293. headerPaddingSM,
  294. headerHeightSM,
  295. headerFontSizeSM
  296. } = token;
  297. return {
  298. [`${componentCls}-small`]: {
  299. [`> ${componentCls}-head`]: {
  300. minHeight: headerHeightSM,
  301. padding: `0 ${(0, _cssinjs.unit)(headerPaddingSM)}`,
  302. fontSize: headerFontSizeSM,
  303. [`> ${componentCls}-head-wrapper`]: {
  304. [`> ${componentCls}-extra`]: {
  305. fontSize: token.fontSize
  306. }
  307. }
  308. },
  309. [`> ${componentCls}-body`]: {
  310. padding: bodyPaddingSM
  311. }
  312. },
  313. [`${componentCls}-small${componentCls}-contain-tabs`]: {
  314. [`> ${componentCls}-head`]: {
  315. [`${componentCls}-head-title, ${componentCls}-extra`]: {
  316. paddingTop: 0,
  317. display: 'flex',
  318. alignItems: 'center'
  319. }
  320. }
  321. }
  322. };
  323. };
  324. const prepareComponentToken = token => {
  325. var _a, _b;
  326. return {
  327. headerBg: 'transparent',
  328. headerFontSize: token.fontSizeLG,
  329. headerFontSizeSM: token.fontSize,
  330. headerHeight: token.fontSizeLG * token.lineHeightLG + token.padding * 2,
  331. headerHeightSM: token.fontSize * token.lineHeight + token.paddingXS * 2,
  332. actionsBg: token.colorBgContainer,
  333. actionsLiMargin: `${token.paddingSM}px 0`,
  334. tabsMarginBottom: -token.padding - token.lineWidth,
  335. extraColor: token.colorText,
  336. bodyPaddingSM: 12,
  337. // Fixed padding.
  338. headerPaddingSM: 12,
  339. bodyPadding: (_a = token.bodyPadding) !== null && _a !== void 0 ? _a : token.paddingLG,
  340. headerPadding: (_b = token.headerPadding) !== null && _b !== void 0 ? _b : token.paddingLG
  341. };
  342. };
  343. // ============================== Export ==============================
  344. exports.prepareComponentToken = prepareComponentToken;
  345. var _default = exports.default = (0, _internal.genStyleHooks)('Card', token => {
  346. const cardToken = (0, _internal.mergeToken)(token, {
  347. cardShadow: token.boxShadowCard,
  348. cardHeadPadding: token.padding,
  349. cardPaddingBase: token.paddingLG,
  350. cardActionsIconSize: token.fontSize
  351. });
  352. return [
  353. // Style
  354. genCardStyle(cardToken),
  355. // Size
  356. genCardSizeStyle(cardToken)];
  357. }, prepareComponentToken);