index.js 3.6 KB

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