index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { genComponentStyleHook, mergeToken } from '../../theme/internal';
  3. import { resetComponent } from '../../style';
  4. const genBaseStyle = token => {
  5. const {
  6. antCls,
  7. componentCls,
  8. iconCls,
  9. avatarBg,
  10. avatarColor,
  11. containerSize,
  12. containerSizeLG,
  13. containerSizeSM,
  14. textFontSize,
  15. textFontSizeLG,
  16. textFontSizeSM,
  17. borderRadius,
  18. borderRadiusLG,
  19. borderRadiusSM,
  20. lineWidth,
  21. lineType
  22. } = token;
  23. // Avatar size style
  24. const avatarSizeStyle = (size, fontSize, radius) => ({
  25. width: size,
  26. height: size,
  27. lineHeight: `${size - lineWidth * 2}px`,
  28. borderRadius: '50%',
  29. [`&${componentCls}-square`]: {
  30. borderRadius: radius
  31. },
  32. [`${componentCls}-string`]: {
  33. position: 'absolute',
  34. left: {
  35. _skip_check_: true,
  36. value: '50%'
  37. },
  38. transformOrigin: '0 center'
  39. },
  40. [`&${componentCls}-icon`]: {
  41. fontSize,
  42. [`> ${iconCls}`]: {
  43. margin: 0
  44. }
  45. }
  46. });
  47. return {
  48. [componentCls]: _extends(_extends(_extends(_extends({}, resetComponent(token)), {
  49. position: 'relative',
  50. display: 'inline-block',
  51. overflow: 'hidden',
  52. color: avatarColor,
  53. whiteSpace: 'nowrap',
  54. textAlign: 'center',
  55. verticalAlign: 'middle',
  56. background: avatarBg,
  57. border: `${lineWidth}px ${lineType} transparent`,
  58. [`&-image`]: {
  59. background: 'transparent'
  60. },
  61. [`${antCls}-image-img`]: {
  62. display: 'block'
  63. }
  64. }), avatarSizeStyle(containerSize, textFontSize, borderRadius)), {
  65. [`&-lg`]: _extends({}, avatarSizeStyle(containerSizeLG, textFontSizeLG, borderRadiusLG)),
  66. [`&-sm`]: _extends({}, avatarSizeStyle(containerSizeSM, textFontSizeSM, borderRadiusSM)),
  67. '> img': {
  68. display: 'block',
  69. width: '100%',
  70. height: '100%',
  71. objectFit: 'cover'
  72. }
  73. })
  74. };
  75. };
  76. const genGroupStyle = token => {
  77. const {
  78. componentCls,
  79. groupBorderColor,
  80. groupOverlapping,
  81. groupSpace
  82. } = token;
  83. return {
  84. [`${componentCls}-group`]: {
  85. display: 'inline-flex',
  86. [`${componentCls}`]: {
  87. borderColor: groupBorderColor
  88. },
  89. [`> *:not(:first-child)`]: {
  90. marginInlineStart: groupOverlapping
  91. }
  92. },
  93. [`${componentCls}-group-popover`]: {
  94. [`${componentCls} + ${componentCls}`]: {
  95. marginInlineStart: groupSpace
  96. }
  97. }
  98. };
  99. };
  100. export default genComponentStyleHook('Avatar', token => {
  101. const {
  102. colorTextLightSolid,
  103. colorTextPlaceholder
  104. } = token;
  105. const avatarToken = mergeToken(token, {
  106. avatarBg: colorTextPlaceholder,
  107. avatarColor: colorTextLightSolid
  108. });
  109. return [genBaseStyle(avatarToken), genGroupStyle(avatarToken)];
  110. }, token => {
  111. const {
  112. controlHeight,
  113. controlHeightLG,
  114. controlHeightSM,
  115. fontSize,
  116. fontSizeLG,
  117. fontSizeXL,
  118. fontSizeHeading3,
  119. marginXS,
  120. marginXXS,
  121. colorBorderBg
  122. } = token;
  123. return {
  124. containerSize: controlHeight,
  125. containerSizeLG: controlHeightLG,
  126. containerSizeSM: controlHeightSM,
  127. textFontSize: Math.round((fontSizeLG + fontSizeXL) / 2),
  128. textFontSizeLG: fontSizeHeading3,
  129. textFontSizeSM: fontSize,
  130. groupSpace: marginXXS,
  131. groupOverlapping: -marginXS,
  132. groupBorderColor: colorBorderBg
  133. };
  134. });