index.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { Keyframes } from '../../_util/cssinjs';
  3. import { genComponentStyleHook, mergeToken } from '../../theme/internal';
  4. import { resetComponent } from '../../style';
  5. const antProgressActive = new Keyframes('antProgressActive', {
  6. '0%': {
  7. transform: 'translateX(-100%) scaleX(0)',
  8. opacity: 0.1
  9. },
  10. '20%': {
  11. transform: 'translateX(-100%) scaleX(0)',
  12. opacity: 0.5
  13. },
  14. to: {
  15. transform: 'translateX(0) scaleX(1)',
  16. opacity: 0
  17. }
  18. });
  19. const genBaseStyle = token => {
  20. const {
  21. componentCls: progressCls,
  22. iconCls: iconPrefixCls
  23. } = token;
  24. return {
  25. [progressCls]: _extends(_extends({}, resetComponent(token)), {
  26. display: 'inline-block',
  27. '&-rtl': {
  28. direction: 'rtl'
  29. },
  30. '&-line': {
  31. position: 'relative',
  32. width: '100%',
  33. fontSize: token.fontSize,
  34. marginInlineEnd: token.marginXS,
  35. marginBottom: token.marginXS
  36. },
  37. [`${progressCls}-outer`]: {
  38. display: 'inline-block',
  39. width: '100%'
  40. },
  41. [`&${progressCls}-show-info`]: {
  42. [`${progressCls}-outer`]: {
  43. marginInlineEnd: `calc(-2em - ${token.marginXS}px)`,
  44. paddingInlineEnd: `calc(2em + ${token.paddingXS}px)`
  45. }
  46. },
  47. [`${progressCls}-inner`]: {
  48. position: 'relative',
  49. display: 'inline-block',
  50. width: '100%',
  51. overflow: 'hidden',
  52. verticalAlign: 'middle',
  53. backgroundColor: token.progressRemainingColor,
  54. borderRadius: token.progressLineRadius
  55. },
  56. [`${progressCls}-inner:not(${progressCls}-circle-gradient)`]: {
  57. [`${progressCls}-circle-path`]: {
  58. stroke: token.colorInfo
  59. }
  60. },
  61. [`${progressCls}-success-bg, ${progressCls}-bg`]: {
  62. position: 'relative',
  63. backgroundColor: token.colorInfo,
  64. borderRadius: token.progressLineRadius,
  65. transition: `all ${token.motionDurationSlow} ${token.motionEaseInOutCirc}`
  66. },
  67. [`${progressCls}-success-bg`]: {
  68. position: 'absolute',
  69. insetBlockStart: 0,
  70. insetInlineStart: 0,
  71. backgroundColor: token.colorSuccess
  72. },
  73. [`${progressCls}-text`]: {
  74. display: 'inline-block',
  75. width: '2em',
  76. marginInlineStart: token.marginXS,
  77. color: token.progressInfoTextColor,
  78. lineHeight: 1,
  79. whiteSpace: 'nowrap',
  80. textAlign: 'start',
  81. verticalAlign: 'middle',
  82. wordBreak: 'normal',
  83. [iconPrefixCls]: {
  84. fontSize: token.fontSize
  85. }
  86. },
  87. [`&${progressCls}-status-active`]: {
  88. [`${progressCls}-bg::before`]: {
  89. position: 'absolute',
  90. inset: 0,
  91. backgroundColor: token.colorBgContainer,
  92. borderRadius: token.progressLineRadius,
  93. opacity: 0,
  94. animationName: antProgressActive,
  95. animationDuration: token.progressActiveMotionDuration,
  96. animationTimingFunction: token.motionEaseOutQuint,
  97. animationIterationCount: 'infinite',
  98. content: '""'
  99. }
  100. },
  101. [`&${progressCls}-status-exception`]: {
  102. [`${progressCls}-bg`]: {
  103. backgroundColor: token.colorError
  104. },
  105. [`${progressCls}-text`]: {
  106. color: token.colorError
  107. }
  108. },
  109. [`&${progressCls}-status-exception ${progressCls}-inner:not(${progressCls}-circle-gradient)`]: {
  110. [`${progressCls}-circle-path`]: {
  111. stroke: token.colorError
  112. }
  113. },
  114. [`&${progressCls}-status-success`]: {
  115. [`${progressCls}-bg`]: {
  116. backgroundColor: token.colorSuccess
  117. },
  118. [`${progressCls}-text`]: {
  119. color: token.colorSuccess
  120. }
  121. },
  122. [`&${progressCls}-status-success ${progressCls}-inner:not(${progressCls}-circle-gradient)`]: {
  123. [`${progressCls}-circle-path`]: {
  124. stroke: token.colorSuccess
  125. }
  126. }
  127. })
  128. };
  129. };
  130. const genCircleStyle = token => {
  131. const {
  132. componentCls: progressCls,
  133. iconCls: iconPrefixCls
  134. } = token;
  135. return {
  136. [progressCls]: {
  137. [`${progressCls}-circle-trail`]: {
  138. stroke: token.progressRemainingColor
  139. },
  140. [`&${progressCls}-circle ${progressCls}-inner`]: {
  141. position: 'relative',
  142. lineHeight: 1,
  143. backgroundColor: 'transparent'
  144. },
  145. [`&${progressCls}-circle ${progressCls}-text`]: {
  146. position: 'absolute',
  147. insetBlockStart: '50%',
  148. insetInlineStart: 0,
  149. width: '100%',
  150. margin: 0,
  151. padding: 0,
  152. color: token.colorText,
  153. lineHeight: 1,
  154. whiteSpace: 'normal',
  155. textAlign: 'center',
  156. transform: 'translateY(-50%)',
  157. [iconPrefixCls]: {
  158. fontSize: `${token.fontSize / token.fontSizeSM}em`
  159. }
  160. },
  161. [`${progressCls}-circle&-status-exception`]: {
  162. [`${progressCls}-text`]: {
  163. color: token.colorError
  164. }
  165. },
  166. [`${progressCls}-circle&-status-success`]: {
  167. [`${progressCls}-text`]: {
  168. color: token.colorSuccess
  169. }
  170. }
  171. },
  172. [`${progressCls}-inline-circle`]: {
  173. lineHeight: 1,
  174. [`${progressCls}-inner`]: {
  175. verticalAlign: 'bottom'
  176. }
  177. }
  178. };
  179. };
  180. const genStepStyle = token => {
  181. const {
  182. componentCls: progressCls
  183. } = token;
  184. return {
  185. [progressCls]: {
  186. [`${progressCls}-steps`]: {
  187. display: 'inline-block',
  188. '&-outer': {
  189. display: 'flex',
  190. flexDirection: 'row',
  191. alignItems: 'center'
  192. },
  193. '&-item': {
  194. flexShrink: 0,
  195. minWidth: token.progressStepMinWidth,
  196. marginInlineEnd: token.progressStepMarginInlineEnd,
  197. backgroundColor: token.progressRemainingColor,
  198. transition: `all ${token.motionDurationSlow}`,
  199. '&-active': {
  200. backgroundColor: token.colorInfo
  201. }
  202. }
  203. }
  204. }
  205. };
  206. };
  207. const genSmallLine = token => {
  208. const {
  209. componentCls: progressCls,
  210. iconCls: iconPrefixCls
  211. } = token;
  212. return {
  213. [progressCls]: {
  214. [`${progressCls}-small&-line, ${progressCls}-small&-line ${progressCls}-text ${iconPrefixCls}`]: {
  215. fontSize: token.fontSizeSM
  216. }
  217. }
  218. };
  219. };
  220. export default genComponentStyleHook('Progress', token => {
  221. const progressStepMarginInlineEnd = token.marginXXS / 2;
  222. const progressToken = mergeToken(token, {
  223. progressLineRadius: 100,
  224. progressInfoTextColor: token.colorText,
  225. progressDefaultColor: token.colorInfo,
  226. progressRemainingColor: token.colorFillSecondary,
  227. progressStepMarginInlineEnd,
  228. progressStepMinWidth: progressStepMarginInlineEnd,
  229. progressActiveMotionDuration: '2.4s'
  230. });
  231. return [genBaseStyle(progressToken), genCircleStyle(progressToken), genStepStyle(progressToken), genSmallLine(progressToken)];
  232. });