index.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.prepareComponentToken = exports.default = exports.Percent = exports.LineStrokeColorVar = void 0;
  6. var _cssinjs = require("@ant-design/cssinjs");
  7. var _style = require("../../style");
  8. var _internal = require("../../theme/internal");
  9. const LineStrokeColorVar = exports.LineStrokeColorVar = '--progress-line-stroke-color';
  10. const Percent = exports.Percent = '--progress-percent';
  11. const genAntProgressActive = isRtl => {
  12. const direction = isRtl ? '100%' : '-100%';
  13. return new _cssinjs.Keyframes(`antProgress${isRtl ? 'RTL' : 'LTR'}Active`, {
  14. '0%': {
  15. transform: `translateX(${direction}) scaleX(0)`,
  16. opacity: 0.1
  17. },
  18. '20%': {
  19. transform: `translateX(${direction}) scaleX(0)`,
  20. opacity: 0.5
  21. },
  22. to: {
  23. transform: 'translateX(0) scaleX(1)',
  24. opacity: 0
  25. }
  26. });
  27. };
  28. const genBaseStyle = token => {
  29. const {
  30. componentCls: progressCls,
  31. iconCls: iconPrefixCls
  32. } = token;
  33. return {
  34. [progressCls]: Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), {
  35. display: 'inline-block',
  36. '&-rtl': {
  37. direction: 'rtl'
  38. },
  39. '&-line': {
  40. position: 'relative',
  41. width: '100%',
  42. fontSize: token.fontSize
  43. },
  44. [`${progressCls}-outer`]: {
  45. display: 'inline-flex',
  46. alignItems: 'center',
  47. width: '100%'
  48. },
  49. [`${progressCls}-inner`]: {
  50. position: 'relative',
  51. display: 'inline-block',
  52. width: '100%',
  53. flex: 1,
  54. overflow: 'hidden',
  55. verticalAlign: 'middle',
  56. backgroundColor: token.remainingColor,
  57. borderRadius: token.lineBorderRadius
  58. },
  59. [`${progressCls}-inner:not(${progressCls}-circle-gradient)`]: {
  60. [`${progressCls}-circle-path`]: {
  61. stroke: token.defaultColor
  62. }
  63. },
  64. [`${progressCls}-success-bg, ${progressCls}-bg`]: {
  65. position: 'relative',
  66. background: token.defaultColor,
  67. borderRadius: token.lineBorderRadius,
  68. transition: `all ${token.motionDurationSlow} ${token.motionEaseInOutCirc}`
  69. },
  70. [`${progressCls}-layout-bottom`]: {
  71. display: 'flex',
  72. flexDirection: 'column',
  73. alignItems: 'center',
  74. justifyContent: 'center',
  75. [`${progressCls}-text`]: {
  76. width: 'max-content',
  77. marginInlineStart: 0,
  78. marginTop: token.marginXXS
  79. }
  80. },
  81. [`${progressCls}-bg`]: {
  82. overflow: 'hidden',
  83. '&::after': {
  84. content: '""',
  85. background: {
  86. _multi_value_: true,
  87. value: ['inherit', `var(${LineStrokeColorVar})`]
  88. },
  89. height: '100%',
  90. width: `calc(1 / var(${Percent}) * 100%)`,
  91. display: 'block'
  92. },
  93. [`&${progressCls}-bg-inner`]: {
  94. minWidth: 'max-content',
  95. '&::after': {
  96. content: 'none'
  97. },
  98. [`${progressCls}-text-inner`]: {
  99. color: token.colorWhite,
  100. [`&${progressCls}-text-bright`]: {
  101. color: 'rgba(0, 0, 0, 0.45)'
  102. }
  103. }
  104. }
  105. },
  106. [`${progressCls}-success-bg`]: {
  107. position: 'absolute',
  108. insetBlockStart: 0,
  109. insetInlineStart: 0,
  110. backgroundColor: token.colorSuccess
  111. },
  112. [`${progressCls}-text`]: {
  113. display: 'inline-block',
  114. marginInlineStart: token.marginXS,
  115. color: token.colorText,
  116. lineHeight: 1,
  117. width: '2em',
  118. whiteSpace: 'nowrap',
  119. textAlign: 'start',
  120. verticalAlign: 'middle',
  121. wordBreak: 'normal',
  122. [iconPrefixCls]: {
  123. fontSize: token.fontSize
  124. },
  125. [`&${progressCls}-text-outer`]: {
  126. width: 'max-content'
  127. },
  128. [`&${progressCls}-text-outer${progressCls}-text-start`]: {
  129. width: 'max-content',
  130. marginInlineStart: 0,
  131. marginInlineEnd: token.marginXS
  132. }
  133. },
  134. [`${progressCls}-text-inner`]: {
  135. display: 'flex',
  136. justifyContent: 'center',
  137. alignItems: 'center',
  138. width: '100%',
  139. height: '100%',
  140. marginInlineStart: 0,
  141. padding: `0 ${(0, _cssinjs.unit)(token.paddingXXS)}`,
  142. [`&${progressCls}-text-start`]: {
  143. justifyContent: 'start'
  144. },
  145. [`&${progressCls}-text-end`]: {
  146. justifyContent: 'end'
  147. }
  148. },
  149. [`&${progressCls}-status-active`]: {
  150. [`${progressCls}-bg::before`]: {
  151. position: 'absolute',
  152. inset: 0,
  153. backgroundColor: token.colorBgContainer,
  154. borderRadius: token.lineBorderRadius,
  155. opacity: 0,
  156. animationName: genAntProgressActive(),
  157. animationDuration: token.progressActiveMotionDuration,
  158. animationTimingFunction: token.motionEaseOutQuint,
  159. animationIterationCount: 'infinite',
  160. content: '""'
  161. }
  162. },
  163. [`&${progressCls}-rtl${progressCls}-status-active`]: {
  164. [`${progressCls}-bg::before`]: {
  165. animationName: genAntProgressActive(true)
  166. }
  167. },
  168. [`&${progressCls}-status-exception`]: {
  169. [`${progressCls}-bg`]: {
  170. backgroundColor: token.colorError
  171. },
  172. [`${progressCls}-text`]: {
  173. color: token.colorError
  174. }
  175. },
  176. [`&${progressCls}-status-exception ${progressCls}-inner:not(${progressCls}-circle-gradient)`]: {
  177. [`${progressCls}-circle-path`]: {
  178. stroke: token.colorError
  179. }
  180. },
  181. [`&${progressCls}-status-success`]: {
  182. [`${progressCls}-bg`]: {
  183. backgroundColor: token.colorSuccess
  184. },
  185. [`${progressCls}-text`]: {
  186. color: token.colorSuccess
  187. }
  188. },
  189. [`&${progressCls}-status-success ${progressCls}-inner:not(${progressCls}-circle-gradient)`]: {
  190. [`${progressCls}-circle-path`]: {
  191. stroke: token.colorSuccess
  192. }
  193. }
  194. })
  195. };
  196. };
  197. const genCircleStyle = token => {
  198. const {
  199. componentCls: progressCls,
  200. iconCls: iconPrefixCls
  201. } = token;
  202. return {
  203. [progressCls]: {
  204. [`${progressCls}-circle-trail`]: {
  205. stroke: token.remainingColor
  206. },
  207. [`&${progressCls}-circle ${progressCls}-inner`]: {
  208. position: 'relative',
  209. lineHeight: 1,
  210. backgroundColor: 'transparent'
  211. },
  212. [`&${progressCls}-circle ${progressCls}-text`]: {
  213. position: 'absolute',
  214. insetBlockStart: '50%',
  215. insetInlineStart: 0,
  216. width: '100%',
  217. margin: 0,
  218. padding: 0,
  219. color: token.circleTextColor,
  220. fontSize: token.circleTextFontSize,
  221. lineHeight: 1,
  222. whiteSpace: 'normal',
  223. textAlign: 'center',
  224. transform: 'translateY(-50%)',
  225. [iconPrefixCls]: {
  226. fontSize: token.circleIconFontSize
  227. }
  228. },
  229. [`${progressCls}-circle&-status-exception`]: {
  230. [`${progressCls}-text`]: {
  231. color: token.colorError
  232. }
  233. },
  234. [`${progressCls}-circle&-status-success`]: {
  235. [`${progressCls}-text`]: {
  236. color: token.colorSuccess
  237. }
  238. }
  239. },
  240. [`${progressCls}-inline-circle`]: {
  241. lineHeight: 1,
  242. [`${progressCls}-inner`]: {
  243. verticalAlign: 'bottom'
  244. }
  245. }
  246. };
  247. };
  248. const genStepStyle = token => {
  249. const {
  250. componentCls: progressCls
  251. } = token;
  252. return {
  253. [progressCls]: {
  254. [`${progressCls}-steps`]: {
  255. display: 'inline-block',
  256. '&-outer': {
  257. display: 'flex',
  258. flexDirection: 'row',
  259. alignItems: 'center'
  260. },
  261. '&-item': {
  262. flexShrink: 0,
  263. minWidth: token.progressStepMinWidth,
  264. marginInlineEnd: token.progressStepMarginInlineEnd,
  265. backgroundColor: token.remainingColor,
  266. transition: `all ${token.motionDurationSlow}`,
  267. '&-active': {
  268. backgroundColor: token.defaultColor
  269. }
  270. }
  271. }
  272. }
  273. };
  274. };
  275. const genSmallLine = token => {
  276. const {
  277. componentCls: progressCls,
  278. iconCls: iconPrefixCls
  279. } = token;
  280. return {
  281. [progressCls]: {
  282. [`${progressCls}-small&-line, ${progressCls}-small&-line ${progressCls}-text ${iconPrefixCls}`]: {
  283. fontSize: token.fontSizeSM
  284. }
  285. }
  286. };
  287. };
  288. const prepareComponentToken = token => ({
  289. circleTextColor: token.colorText,
  290. defaultColor: token.colorInfo,
  291. remainingColor: token.colorFillSecondary,
  292. lineBorderRadius: 100,
  293. // magic for capsule shape, should be a very large number
  294. circleTextFontSize: '1em',
  295. circleIconFontSize: `${token.fontSize / token.fontSizeSM}em`
  296. });
  297. exports.prepareComponentToken = prepareComponentToken;
  298. var _default = exports.default = (0, _internal.genStyleHooks)('Progress', token => {
  299. const progressStepMarginInlineEnd = token.calc(token.marginXXS).div(2).equal();
  300. const progressToken = (0, _internal.mergeToken)(token, {
  301. progressStepMarginInlineEnd,
  302. progressStepMinWidth: progressStepMarginInlineEnd,
  303. progressActiveMotionDuration: '2.4s'
  304. });
  305. return [genBaseStyle(progressToken), genCircleStyle(progressToken), genStepStyle(progressToken), genSmallLine(progressToken)];
  306. }, prepareComponentToken);