index.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 antSpinMove = new Keyframes('antSpinMove', {
  6. to: {
  7. opacity: 1
  8. }
  9. });
  10. const antRotate = new Keyframes('antRotate', {
  11. to: {
  12. transform: 'rotate(405deg)'
  13. }
  14. });
  15. const genSpinStyle = token => ({
  16. [`${token.componentCls}`]: _extends(_extends({}, resetComponent(token)), {
  17. position: 'absolute',
  18. display: 'none',
  19. color: token.colorPrimary,
  20. textAlign: 'center',
  21. verticalAlign: 'middle',
  22. opacity: 0,
  23. transition: `transform ${token.motionDurationSlow} ${token.motionEaseInOutCirc}`,
  24. '&-spinning': {
  25. position: 'static',
  26. display: 'inline-block',
  27. opacity: 1
  28. },
  29. '&-nested-loading': {
  30. position: 'relative',
  31. [`> div > ${token.componentCls}`]: {
  32. position: 'absolute',
  33. top: 0,
  34. insetInlineStart: 0,
  35. zIndex: 4,
  36. display: 'block',
  37. width: '100%',
  38. height: '100%',
  39. maxHeight: token.contentHeight,
  40. [`${token.componentCls}-dot`]: {
  41. position: 'absolute',
  42. top: '50%',
  43. insetInlineStart: '50%',
  44. margin: -token.spinDotSize / 2
  45. },
  46. [`${token.componentCls}-text`]: {
  47. position: 'absolute',
  48. top: '50%',
  49. width: '100%',
  50. paddingTop: (token.spinDotSize - token.fontSize) / 2 + 2,
  51. textShadow: `0 1px 2px ${token.colorBgContainer}` // FIXME: shadow
  52. },
  53. [`&${token.componentCls}-show-text ${token.componentCls}-dot`]: {
  54. marginTop: -(token.spinDotSize / 2) - 10
  55. },
  56. '&-sm': {
  57. [`${token.componentCls}-dot`]: {
  58. margin: -token.spinDotSizeSM / 2
  59. },
  60. [`${token.componentCls}-text`]: {
  61. paddingTop: (token.spinDotSizeSM - token.fontSize) / 2 + 2
  62. },
  63. [`&${token.componentCls}-show-text ${token.componentCls}-dot`]: {
  64. marginTop: -(token.spinDotSizeSM / 2) - 10
  65. }
  66. },
  67. '&-lg': {
  68. [`${token.componentCls}-dot`]: {
  69. margin: -(token.spinDotSizeLG / 2)
  70. },
  71. [`${token.componentCls}-text`]: {
  72. paddingTop: (token.spinDotSizeLG - token.fontSize) / 2 + 2
  73. },
  74. [`&${token.componentCls}-show-text ${token.componentCls}-dot`]: {
  75. marginTop: -(token.spinDotSizeLG / 2) - 10
  76. }
  77. }
  78. },
  79. [`${token.componentCls}-container`]: {
  80. position: 'relative',
  81. transition: `opacity ${token.motionDurationSlow}`,
  82. '&::after': {
  83. position: 'absolute',
  84. top: 0,
  85. insetInlineEnd: 0,
  86. bottom: 0,
  87. insetInlineStart: 0,
  88. zIndex: 10,
  89. width: '100%',
  90. height: '100%',
  91. background: token.colorBgContainer,
  92. opacity: 0,
  93. transition: `all ${token.motionDurationSlow}`,
  94. content: '""',
  95. pointerEvents: 'none'
  96. }
  97. },
  98. [`${token.componentCls}-blur`]: {
  99. clear: 'both',
  100. opacity: 0.5,
  101. userSelect: 'none',
  102. pointerEvents: 'none',
  103. [`&::after`]: {
  104. opacity: 0.4,
  105. pointerEvents: 'auto'
  106. }
  107. }
  108. },
  109. // tip
  110. // ------------------------------
  111. [`&-tip`]: {
  112. color: token.spinDotDefault
  113. },
  114. // dots
  115. // ------------------------------
  116. [`${token.componentCls}-dot`]: {
  117. position: 'relative',
  118. display: 'inline-block',
  119. fontSize: token.spinDotSize,
  120. width: '1em',
  121. height: '1em',
  122. '&-item': {
  123. position: 'absolute',
  124. display: 'block',
  125. width: (token.spinDotSize - token.marginXXS / 2) / 2,
  126. height: (token.spinDotSize - token.marginXXS / 2) / 2,
  127. backgroundColor: token.colorPrimary,
  128. borderRadius: '100%',
  129. transform: 'scale(0.75)',
  130. transformOrigin: '50% 50%',
  131. opacity: 0.3,
  132. animationName: antSpinMove,
  133. animationDuration: '1s',
  134. animationIterationCount: 'infinite',
  135. animationTimingFunction: 'linear',
  136. animationDirection: 'alternate',
  137. '&:nth-child(1)': {
  138. top: 0,
  139. insetInlineStart: 0
  140. },
  141. '&:nth-child(2)': {
  142. top: 0,
  143. insetInlineEnd: 0,
  144. animationDelay: '0.4s'
  145. },
  146. '&:nth-child(3)': {
  147. insetInlineEnd: 0,
  148. bottom: 0,
  149. animationDelay: '0.8s'
  150. },
  151. '&:nth-child(4)': {
  152. bottom: 0,
  153. insetInlineStart: 0,
  154. animationDelay: '1.2s'
  155. }
  156. },
  157. '&-spin': {
  158. transform: 'rotate(45deg)',
  159. animationName: antRotate,
  160. animationDuration: '1.2s',
  161. animationIterationCount: 'infinite',
  162. animationTimingFunction: 'linear'
  163. }
  164. },
  165. // Sizes
  166. // ------------------------------
  167. // small
  168. [`&-sm ${token.componentCls}-dot`]: {
  169. fontSize: token.spinDotSizeSM,
  170. i: {
  171. width: (token.spinDotSizeSM - token.marginXXS / 2) / 2,
  172. height: (token.spinDotSizeSM - token.marginXXS / 2) / 2
  173. }
  174. },
  175. // large
  176. [`&-lg ${token.componentCls}-dot`]: {
  177. fontSize: token.spinDotSizeLG,
  178. i: {
  179. width: (token.spinDotSizeLG - token.marginXXS) / 2,
  180. height: (token.spinDotSizeLG - token.marginXXS) / 2
  181. }
  182. },
  183. [`&${token.componentCls}-show-text ${token.componentCls}-text`]: {
  184. display: 'block'
  185. }
  186. })
  187. });
  188. // ============================== Export ==============================
  189. export default genComponentStyleHook('Spin', token => {
  190. const spinToken = mergeToken(token, {
  191. spinDotDefault: token.colorTextDescription,
  192. spinDotSize: token.controlHeightLG / 2,
  193. spinDotSizeSM: token.controlHeightLG * 0.35,
  194. spinDotSizeLG: token.controlHeight
  195. });
  196. return [genSpinStyle(spinToken)];
  197. }, {
  198. contentHeight: 400
  199. });