index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.prepareToken = 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 antStatusProcessing = new _cssinjs.Keyframes('antStatusProcessing', {
  10. '0%': {
  11. transform: 'scale(0.8)',
  12. opacity: 0.5
  13. },
  14. '100%': {
  15. transform: 'scale(2.4)',
  16. opacity: 0
  17. }
  18. });
  19. const antZoomBadgeIn = new _cssinjs.Keyframes('antZoomBadgeIn', {
  20. '0%': {
  21. transform: 'scale(0) translate(50%, -50%)',
  22. opacity: 0
  23. },
  24. '100%': {
  25. transform: 'scale(1) translate(50%, -50%)'
  26. }
  27. });
  28. const antZoomBadgeOut = new _cssinjs.Keyframes('antZoomBadgeOut', {
  29. '0%': {
  30. transform: 'scale(1) translate(50%, -50%)'
  31. },
  32. '100%': {
  33. transform: 'scale(0) translate(50%, -50%)',
  34. opacity: 0
  35. }
  36. });
  37. const antNoWrapperZoomBadgeIn = new _cssinjs.Keyframes('antNoWrapperZoomBadgeIn', {
  38. '0%': {
  39. transform: 'scale(0)',
  40. opacity: 0
  41. },
  42. '100%': {
  43. transform: 'scale(1)'
  44. }
  45. });
  46. const antNoWrapperZoomBadgeOut = new _cssinjs.Keyframes('antNoWrapperZoomBadgeOut', {
  47. '0%': {
  48. transform: 'scale(1)'
  49. },
  50. '100%': {
  51. transform: 'scale(0)',
  52. opacity: 0
  53. }
  54. });
  55. const antBadgeLoadingCircle = new _cssinjs.Keyframes('antBadgeLoadingCircle', {
  56. '0%': {
  57. transformOrigin: '50%'
  58. },
  59. '100%': {
  60. transform: 'translate(50%, -50%) rotate(360deg)',
  61. transformOrigin: '50%'
  62. }
  63. });
  64. const genSharedBadgeStyle = token => {
  65. const {
  66. componentCls,
  67. iconCls,
  68. antCls,
  69. badgeShadowSize,
  70. textFontSize,
  71. textFontSizeSM,
  72. statusSize,
  73. dotSize,
  74. textFontWeight,
  75. indicatorHeight,
  76. indicatorHeightSM,
  77. marginXS,
  78. calc
  79. } = token;
  80. const numberPrefixCls = `${antCls}-scroll-number`;
  81. const colorPreset = (0, _internal.genPresetColor)(token, (colorKey, {
  82. darkColor
  83. }) => ({
  84. [`&${componentCls} ${componentCls}-color-${colorKey}`]: {
  85. background: darkColor,
  86. [`&:not(${componentCls}-count)`]: {
  87. color: darkColor
  88. },
  89. 'a:hover &': {
  90. background: darkColor
  91. }
  92. }
  93. }));
  94. return {
  95. [componentCls]: Object.assign(Object.assign(Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), {
  96. position: 'relative',
  97. display: 'inline-block',
  98. width: 'fit-content',
  99. lineHeight: 1,
  100. [`${componentCls}-count`]: {
  101. display: 'inline-flex',
  102. justifyContent: 'center',
  103. zIndex: token.indicatorZIndex,
  104. minWidth: indicatorHeight,
  105. height: indicatorHeight,
  106. color: token.badgeTextColor,
  107. fontWeight: textFontWeight,
  108. fontSize: textFontSize,
  109. lineHeight: (0, _cssinjs.unit)(indicatorHeight),
  110. whiteSpace: 'nowrap',
  111. textAlign: 'center',
  112. background: token.badgeColor,
  113. borderRadius: calc(indicatorHeight).div(2).equal(),
  114. boxShadow: `0 0 0 ${(0, _cssinjs.unit)(badgeShadowSize)} ${token.badgeShadowColor}`,
  115. transition: `background ${token.motionDurationMid}`,
  116. a: {
  117. color: token.badgeTextColor
  118. },
  119. 'a:hover': {
  120. color: token.badgeTextColor
  121. },
  122. 'a:hover &': {
  123. background: token.badgeColorHover
  124. }
  125. },
  126. [`${componentCls}-count-sm`]: {
  127. minWidth: indicatorHeightSM,
  128. height: indicatorHeightSM,
  129. fontSize: textFontSizeSM,
  130. lineHeight: (0, _cssinjs.unit)(indicatorHeightSM),
  131. borderRadius: calc(indicatorHeightSM).div(2).equal()
  132. },
  133. [`${componentCls}-multiple-words`]: {
  134. padding: `0 ${(0, _cssinjs.unit)(token.paddingXS)}`,
  135. bdi: {
  136. unicodeBidi: 'plaintext'
  137. }
  138. },
  139. [`${componentCls}-dot`]: {
  140. zIndex: token.indicatorZIndex,
  141. width: dotSize,
  142. minWidth: dotSize,
  143. height: dotSize,
  144. background: token.badgeColor,
  145. borderRadius: '100%',
  146. boxShadow: `0 0 0 ${(0, _cssinjs.unit)(badgeShadowSize)} ${token.badgeShadowColor}`
  147. },
  148. [`${componentCls}-count, ${componentCls}-dot, ${numberPrefixCls}-custom-component`]: {
  149. position: 'absolute',
  150. top: 0,
  151. insetInlineEnd: 0,
  152. transform: 'translate(50%, -50%)',
  153. transformOrigin: '100% 0%',
  154. [`&${iconCls}-spin`]: {
  155. animationName: antBadgeLoadingCircle,
  156. animationDuration: '1s',
  157. animationIterationCount: 'infinite',
  158. animationTimingFunction: 'linear'
  159. }
  160. },
  161. [`&${componentCls}-status`]: {
  162. lineHeight: 'inherit',
  163. verticalAlign: 'baseline',
  164. [`${componentCls}-status-dot`]: {
  165. position: 'relative',
  166. top: -1,
  167. // Magic number, but seems better experience
  168. display: 'inline-block',
  169. width: statusSize,
  170. height: statusSize,
  171. verticalAlign: 'middle',
  172. borderRadius: '50%'
  173. },
  174. [`${componentCls}-status-success`]: {
  175. backgroundColor: token.colorSuccess
  176. },
  177. [`${componentCls}-status-processing`]: {
  178. overflow: 'visible',
  179. color: token.colorInfo,
  180. backgroundColor: token.colorInfo,
  181. borderColor: 'currentcolor',
  182. '&::after': {
  183. position: 'absolute',
  184. top: 0,
  185. insetInlineStart: 0,
  186. width: '100%',
  187. height: '100%',
  188. borderWidth: badgeShadowSize,
  189. borderStyle: 'solid',
  190. borderColor: 'inherit',
  191. borderRadius: '50%',
  192. animationName: antStatusProcessing,
  193. animationDuration: token.badgeProcessingDuration,
  194. animationIterationCount: 'infinite',
  195. animationTimingFunction: 'ease-in-out',
  196. content: '""'
  197. }
  198. },
  199. [`${componentCls}-status-default`]: {
  200. backgroundColor: token.colorTextPlaceholder
  201. },
  202. [`${componentCls}-status-error`]: {
  203. backgroundColor: token.colorError
  204. },
  205. [`${componentCls}-status-warning`]: {
  206. backgroundColor: token.colorWarning
  207. },
  208. [`${componentCls}-status-text`]: {
  209. marginInlineStart: marginXS,
  210. color: token.colorText,
  211. fontSize: token.fontSize
  212. }
  213. }
  214. }), colorPreset), {
  215. [`${componentCls}-zoom-appear, ${componentCls}-zoom-enter`]: {
  216. animationName: antZoomBadgeIn,
  217. animationDuration: token.motionDurationSlow,
  218. animationTimingFunction: token.motionEaseOutBack,
  219. animationFillMode: 'both'
  220. },
  221. [`${componentCls}-zoom-leave`]: {
  222. animationName: antZoomBadgeOut,
  223. animationDuration: token.motionDurationSlow,
  224. animationTimingFunction: token.motionEaseOutBack,
  225. animationFillMode: 'both'
  226. },
  227. [`&${componentCls}-not-a-wrapper`]: {
  228. [`${componentCls}-zoom-appear, ${componentCls}-zoom-enter`]: {
  229. animationName: antNoWrapperZoomBadgeIn,
  230. animationDuration: token.motionDurationSlow,
  231. animationTimingFunction: token.motionEaseOutBack
  232. },
  233. [`${componentCls}-zoom-leave`]: {
  234. animationName: antNoWrapperZoomBadgeOut,
  235. animationDuration: token.motionDurationSlow,
  236. animationTimingFunction: token.motionEaseOutBack
  237. },
  238. [`&:not(${componentCls}-status)`]: {
  239. verticalAlign: 'middle'
  240. },
  241. [`${numberPrefixCls}-custom-component, ${componentCls}-count`]: {
  242. transform: 'none'
  243. },
  244. [`${numberPrefixCls}-custom-component, ${numberPrefixCls}`]: {
  245. position: 'relative',
  246. top: 'auto',
  247. display: 'block',
  248. transformOrigin: '50% 50%'
  249. }
  250. },
  251. [numberPrefixCls]: {
  252. overflow: 'hidden',
  253. transition: `all ${token.motionDurationMid} ${token.motionEaseOutBack}`,
  254. [`${numberPrefixCls}-only`]: {
  255. position: 'relative',
  256. display: 'inline-block',
  257. height: indicatorHeight,
  258. transition: `all ${token.motionDurationSlow} ${token.motionEaseOutBack}`,
  259. WebkitTransformStyle: 'preserve-3d',
  260. WebkitBackfaceVisibility: 'hidden',
  261. [`> p${numberPrefixCls}-only-unit`]: {
  262. height: indicatorHeight,
  263. margin: 0,
  264. WebkitTransformStyle: 'preserve-3d',
  265. WebkitBackfaceVisibility: 'hidden'
  266. }
  267. },
  268. [`${numberPrefixCls}-symbol`]: {
  269. verticalAlign: 'top'
  270. }
  271. },
  272. // ====================== RTL =======================
  273. '&-rtl': {
  274. direction: 'rtl',
  275. [`${componentCls}-count, ${componentCls}-dot, ${numberPrefixCls}-custom-component`]: {
  276. transform: 'translate(-50%, -50%)'
  277. }
  278. }
  279. })
  280. };
  281. };
  282. // ============================== Export ==============================
  283. const prepareToken = token => {
  284. const {
  285. fontHeight,
  286. lineWidth,
  287. marginXS,
  288. colorBorderBg
  289. } = token;
  290. const badgeFontHeight = fontHeight;
  291. const badgeShadowSize = lineWidth;
  292. const badgeTextColor = token.colorTextLightSolid;
  293. const badgeColor = token.colorError;
  294. const badgeColorHover = token.colorErrorHover;
  295. const badgeToken = (0, _internal.mergeToken)(token, {
  296. badgeFontHeight,
  297. badgeShadowSize,
  298. badgeTextColor,
  299. badgeColor,
  300. badgeColorHover,
  301. badgeShadowColor: colorBorderBg,
  302. badgeProcessingDuration: '1.2s',
  303. badgeRibbonOffset: marginXS,
  304. // Follow token just by Design. Not related with token
  305. badgeRibbonCornerTransform: 'scaleY(0.75)',
  306. badgeRibbonCornerFilter: `brightness(75%)`
  307. });
  308. return badgeToken;
  309. };
  310. exports.prepareToken = prepareToken;
  311. const prepareComponentToken = token => {
  312. const {
  313. fontSize,
  314. lineHeight,
  315. fontSizeSM,
  316. lineWidth
  317. } = token;
  318. return {
  319. indicatorZIndex: 'auto',
  320. indicatorHeight: Math.round(fontSize * lineHeight) - 2 * lineWidth,
  321. indicatorHeightSM: fontSize,
  322. dotSize: fontSizeSM / 2,
  323. textFontSize: fontSizeSM,
  324. textFontSizeSM: fontSizeSM,
  325. textFontWeight: 'normal',
  326. statusSize: fontSizeSM / 2
  327. };
  328. };
  329. exports.prepareComponentToken = prepareComponentToken;
  330. var _default = exports.default = (0, _internal.genStyleHooks)('Badge', token => {
  331. const badgeToken = prepareToken(token);
  332. return genSharedBadgeStyle(badgeToken);
  333. }, prepareComponentToken);