index.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. import { Keyframes } from '@ant-design/cssinjs';
  2. import { resetComponent } from '../../style';
  3. import { genStyleHooks, mergeToken } from '../../theme/internal';
  4. const antSpinMove = new Keyframes('antSpinMove', {
  5. to: {
  6. opacity: 1
  7. }
  8. });
  9. const antRotate = new Keyframes('antRotate', {
  10. to: {
  11. transform: 'rotate(405deg)'
  12. }
  13. });
  14. const genSpinStyle = token => {
  15. const {
  16. componentCls,
  17. calc
  18. } = token;
  19. return {
  20. [componentCls]: Object.assign(Object.assign({}, resetComponent(token)), {
  21. position: 'absolute',
  22. display: 'none',
  23. color: token.colorPrimary,
  24. fontSize: 0,
  25. textAlign: 'center',
  26. verticalAlign: 'middle',
  27. opacity: 0,
  28. transition: `transform ${token.motionDurationSlow} ${token.motionEaseInOutCirc}`,
  29. '&-spinning': {
  30. position: 'relative',
  31. display: 'inline-block',
  32. opacity: 1
  33. },
  34. [`${componentCls}-text`]: {
  35. fontSize: token.fontSize,
  36. paddingTop: calc(calc(token.dotSize).sub(token.fontSize)).div(2).add(2).equal()
  37. },
  38. '&-fullscreen': {
  39. position: 'fixed',
  40. width: '100vw',
  41. height: '100vh',
  42. backgroundColor: token.colorBgMask,
  43. zIndex: token.zIndexPopupBase,
  44. inset: 0,
  45. display: 'flex',
  46. alignItems: 'center',
  47. flexDirection: 'column',
  48. justifyContent: 'center',
  49. opacity: 0,
  50. visibility: 'hidden',
  51. transition: `all ${token.motionDurationMid}`,
  52. '&-show': {
  53. opacity: 1,
  54. visibility: 'visible'
  55. },
  56. [componentCls]: {
  57. [`${componentCls}-dot-holder`]: {
  58. color: token.colorWhite
  59. },
  60. [`${componentCls}-text`]: {
  61. color: token.colorTextLightSolid
  62. }
  63. }
  64. },
  65. '&-nested-loading': {
  66. position: 'relative',
  67. [`> div > ${componentCls}`]: {
  68. position: 'absolute',
  69. top: 0,
  70. insetInlineStart: 0,
  71. zIndex: 4,
  72. display: 'block',
  73. width: '100%',
  74. height: '100%',
  75. maxHeight: token.contentHeight,
  76. [`${componentCls}-dot`]: {
  77. position: 'absolute',
  78. top: '50%',
  79. insetInlineStart: '50%',
  80. margin: calc(token.dotSize).mul(-1).div(2).equal()
  81. },
  82. [`${componentCls}-text`]: {
  83. position: 'absolute',
  84. top: '50%',
  85. width: '100%',
  86. textShadow: `0 1px 2px ${token.colorBgContainer}` // FIXME: shadow
  87. },
  88. [`&${componentCls}-show-text ${componentCls}-dot`]: {
  89. marginTop: calc(token.dotSize).div(2).mul(-1).sub(10).equal()
  90. },
  91. '&-sm': {
  92. [`${componentCls}-dot`]: {
  93. margin: calc(token.dotSizeSM).mul(-1).div(2).equal()
  94. },
  95. [`${componentCls}-text`]: {
  96. paddingTop: calc(calc(token.dotSizeSM).sub(token.fontSize)).div(2).add(2).equal()
  97. },
  98. [`&${componentCls}-show-text ${componentCls}-dot`]: {
  99. marginTop: calc(token.dotSizeSM).div(2).mul(-1).sub(10).equal()
  100. }
  101. },
  102. '&-lg': {
  103. [`${componentCls}-dot`]: {
  104. margin: calc(token.dotSizeLG).mul(-1).div(2).equal()
  105. },
  106. [`${componentCls}-text`]: {
  107. paddingTop: calc(calc(token.dotSizeLG).sub(token.fontSize)).div(2).add(2).equal()
  108. },
  109. [`&${componentCls}-show-text ${componentCls}-dot`]: {
  110. marginTop: calc(token.dotSizeLG).div(2).mul(-1).sub(10).equal()
  111. }
  112. }
  113. },
  114. [`${componentCls}-container`]: {
  115. position: 'relative',
  116. transition: `opacity ${token.motionDurationSlow}`,
  117. '&::after': {
  118. position: 'absolute',
  119. top: 0,
  120. insetInlineEnd: 0,
  121. bottom: 0,
  122. insetInlineStart: 0,
  123. zIndex: 10,
  124. width: '100%',
  125. height: '100%',
  126. background: token.colorBgContainer,
  127. opacity: 0,
  128. transition: `all ${token.motionDurationSlow}`,
  129. content: '""',
  130. pointerEvents: 'none'
  131. }
  132. },
  133. [`${componentCls}-blur`]: {
  134. clear: 'both',
  135. opacity: 0.5,
  136. userSelect: 'none',
  137. pointerEvents: 'none',
  138. '&::after': {
  139. opacity: 0.4,
  140. pointerEvents: 'auto'
  141. }
  142. }
  143. },
  144. // tip
  145. // ------------------------------
  146. '&-tip': {
  147. color: token.spinDotDefault
  148. },
  149. // holder
  150. // ------------------------------
  151. [`${componentCls}-dot-holder`]: {
  152. width: '1em',
  153. height: '1em',
  154. fontSize: token.dotSize,
  155. display: 'inline-block',
  156. transition: `transform ${token.motionDurationSlow} ease, opacity ${token.motionDurationSlow} ease`,
  157. transformOrigin: '50% 50%',
  158. lineHeight: 1,
  159. color: token.colorPrimary,
  160. '&-hidden': {
  161. transform: 'scale(0.3)',
  162. opacity: 0
  163. }
  164. },
  165. // progress
  166. // ------------------------------
  167. [`${componentCls}-dot-progress`]: {
  168. position: 'absolute',
  169. inset: 0
  170. },
  171. // dots
  172. // ------------------------------
  173. [`${componentCls}-dot`]: {
  174. position: 'relative',
  175. display: 'inline-block',
  176. fontSize: token.dotSize,
  177. width: '1em',
  178. height: '1em',
  179. '&-item': {
  180. position: 'absolute',
  181. display: 'block',
  182. width: calc(token.dotSize).sub(calc(token.marginXXS).div(2)).div(2).equal(),
  183. height: calc(token.dotSize).sub(calc(token.marginXXS).div(2)).div(2).equal(),
  184. background: 'currentColor',
  185. borderRadius: '100%',
  186. transform: 'scale(0.75)',
  187. transformOrigin: '50% 50%',
  188. opacity: 0.3,
  189. animationName: antSpinMove,
  190. animationDuration: '1s',
  191. animationIterationCount: 'infinite',
  192. animationTimingFunction: 'linear',
  193. animationDirection: 'alternate',
  194. '&:nth-child(1)': {
  195. top: 0,
  196. insetInlineStart: 0,
  197. animationDelay: '0s'
  198. },
  199. '&:nth-child(2)': {
  200. top: 0,
  201. insetInlineEnd: 0,
  202. animationDelay: '0.4s'
  203. },
  204. '&:nth-child(3)': {
  205. insetInlineEnd: 0,
  206. bottom: 0,
  207. animationDelay: '0.8s'
  208. },
  209. '&:nth-child(4)': {
  210. bottom: 0,
  211. insetInlineStart: 0,
  212. animationDelay: '1.2s'
  213. }
  214. },
  215. '&-spin': {
  216. transform: 'rotate(45deg)',
  217. animationName: antRotate,
  218. animationDuration: '1.2s',
  219. animationIterationCount: 'infinite',
  220. animationTimingFunction: 'linear'
  221. },
  222. '&-circle': {
  223. strokeLinecap: 'round',
  224. transition: ['stroke-dashoffset', 'stroke-dasharray', 'stroke', 'stroke-width', 'opacity'].map(item => `${item} ${token.motionDurationSlow} ease`).join(','),
  225. fillOpacity: 0,
  226. stroke: 'currentcolor'
  227. },
  228. '&-circle-bg': {
  229. stroke: token.colorFillSecondary
  230. }
  231. },
  232. // small
  233. [`&-sm ${componentCls}-dot`]: {
  234. '&, &-holder': {
  235. fontSize: token.dotSizeSM
  236. }
  237. },
  238. [`&-sm ${componentCls}-dot-holder`]: {
  239. i: {
  240. width: calc(calc(token.dotSizeSM).sub(calc(token.marginXXS).div(2))).div(2).equal(),
  241. height: calc(calc(token.dotSizeSM).sub(calc(token.marginXXS).div(2))).div(2).equal()
  242. }
  243. },
  244. // large
  245. [`&-lg ${componentCls}-dot`]: {
  246. '&, &-holder': {
  247. fontSize: token.dotSizeLG
  248. }
  249. },
  250. [`&-lg ${componentCls}-dot-holder`]: {
  251. i: {
  252. width: calc(calc(token.dotSizeLG).sub(token.marginXXS)).div(2).equal(),
  253. height: calc(calc(token.dotSizeLG).sub(token.marginXXS)).div(2).equal()
  254. }
  255. },
  256. [`&${componentCls}-show-text ${componentCls}-text`]: {
  257. display: 'block'
  258. }
  259. })
  260. };
  261. };
  262. export const prepareComponentToken = token => {
  263. const {
  264. controlHeightLG,
  265. controlHeight
  266. } = token;
  267. return {
  268. contentHeight: 400,
  269. dotSize: controlHeightLG / 2,
  270. dotSizeSM: controlHeightLG * 0.35,
  271. dotSizeLG: controlHeight
  272. };
  273. };
  274. // ============================== Export ==============================
  275. export default genStyleHooks('Spin', token => {
  276. const spinToken = mergeToken(token, {
  277. spinDotDefault: token.colorTextDescription
  278. });
  279. return genSpinStyle(spinToken);
  280. }, prepareComponentToken);