index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. const genBaseStyle = token => {
  10. const {
  11. antCls,
  12. componentCls,
  13. iconCls,
  14. avatarBg,
  15. avatarColor,
  16. containerSize,
  17. containerSizeLG,
  18. containerSizeSM,
  19. textFontSize,
  20. textFontSizeLG,
  21. textFontSizeSM,
  22. iconFontSize,
  23. iconFontSizeLG,
  24. iconFontSizeSM,
  25. borderRadius,
  26. borderRadiusLG,
  27. borderRadiusSM,
  28. lineWidth,
  29. lineType
  30. } = token;
  31. // Avatar size style
  32. const avatarSizeStyle = (size, fontSize, iconFontSize, radius) => ({
  33. width: size,
  34. height: size,
  35. borderRadius: '50%',
  36. fontSize,
  37. [`&${componentCls}-square`]: {
  38. borderRadius: radius
  39. },
  40. [`&${componentCls}-icon`]: {
  41. fontSize: iconFontSize,
  42. [`> ${iconCls}`]: {
  43. margin: 0
  44. }
  45. }
  46. });
  47. return {
  48. [componentCls]: Object.assign(Object.assign(Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), {
  49. position: 'relative',
  50. display: 'inline-flex',
  51. justifyContent: 'center',
  52. alignItems: 'center',
  53. overflow: 'hidden',
  54. color: avatarColor,
  55. whiteSpace: 'nowrap',
  56. textAlign: 'center',
  57. verticalAlign: 'middle',
  58. background: avatarBg,
  59. border: `${(0, _cssinjs.unit)(lineWidth)} ${lineType} transparent`,
  60. '&-image': {
  61. background: 'transparent'
  62. },
  63. [`${antCls}-image-img`]: {
  64. display: 'block'
  65. }
  66. }), avatarSizeStyle(containerSize, textFontSize, iconFontSize, borderRadius)), {
  67. '&-lg': Object.assign({}, avatarSizeStyle(containerSizeLG, textFontSizeLG, iconFontSizeLG, borderRadiusLG)),
  68. '&-sm': Object.assign({}, avatarSizeStyle(containerSizeSM, textFontSizeSM, iconFontSizeSM, borderRadiusSM)),
  69. '> img': {
  70. display: 'block',
  71. width: '100%',
  72. height: '100%',
  73. objectFit: 'cover'
  74. }
  75. })
  76. };
  77. };
  78. const genGroupStyle = token => {
  79. const {
  80. componentCls,
  81. groupBorderColor,
  82. groupOverlapping,
  83. groupSpace
  84. } = token;
  85. return {
  86. [`${componentCls}-group`]: {
  87. display: 'inline-flex',
  88. [componentCls]: {
  89. borderColor: groupBorderColor
  90. },
  91. '> *:not(:first-child)': {
  92. marginInlineStart: groupOverlapping
  93. }
  94. },
  95. [`${componentCls}-group-popover`]: {
  96. [`${componentCls} + ${componentCls}`]: {
  97. marginInlineStart: groupSpace
  98. }
  99. }
  100. };
  101. };
  102. const prepareComponentToken = token => {
  103. const {
  104. controlHeight,
  105. controlHeightLG,
  106. controlHeightSM,
  107. fontSize,
  108. fontSizeLG,
  109. fontSizeXL,
  110. fontSizeHeading3,
  111. marginXS,
  112. marginXXS,
  113. colorBorderBg
  114. } = token;
  115. return {
  116. containerSize: controlHeight,
  117. containerSizeLG: controlHeightLG,
  118. containerSizeSM: controlHeightSM,
  119. textFontSize: fontSize,
  120. textFontSizeLG: fontSize,
  121. textFontSizeSM: fontSize,
  122. iconFontSize: Math.round((fontSizeLG + fontSizeXL) / 2),
  123. iconFontSizeLG: fontSizeHeading3,
  124. iconFontSizeSM: fontSize,
  125. groupSpace: marginXXS,
  126. groupOverlapping: -marginXS,
  127. groupBorderColor: colorBorderBg
  128. };
  129. };
  130. exports.prepareComponentToken = prepareComponentToken;
  131. var _default = exports.default = (0, _internal.genStyleHooks)('Avatar', token => {
  132. const {
  133. colorTextLightSolid,
  134. colorTextPlaceholder
  135. } = token;
  136. const avatarToken = (0, _internal.mergeToken)(token, {
  137. avatarBg: colorTextPlaceholder,
  138. avatarColor: colorTextLightSolid
  139. });
  140. return [genBaseStyle(avatarToken), genGroupStyle(avatarToken)];
  141. }, prepareComponentToken);