index.js 12 KB

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