您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Spinner.tsx 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import React from 'react';
  2. import { keyframes } from 'tss-react';
  3. import { makeStyles } from 'tss-react/mui';
  4. interface IProps {
  5. color?: string;
  6. size?: 'small' | 'medium' | 'large';
  7. }
  8. const SIZE = {
  9. small: 16,
  10. medium: 24,
  11. large: 48
  12. };
  13. const DEFAULT_COLOR = '#E6EDFA';
  14. const useStyles = makeStyles<{ color?: string; }>()((_, { color }) => {
  15. return {
  16. container: {
  17. verticalAlign: 'middle',
  18. opacity: 0,
  19. animation: `${keyframes`
  20. 0% {
  21. transform: rotate(50deg);
  22. opacity: 0;
  23. stroke-dashoffset: 60;
  24. }
  25. 100% {
  26. transform: rotate(230deg);
  27. opacity: 1;
  28. stroke-dashoffset: 50;
  29. }
  30. `} 1s forwards ease-in-out`
  31. },
  32. circle: {
  33. fill: 'none',
  34. stroke: color,
  35. strokeWidth: 1.5,
  36. strokeLinecap: 'round',
  37. strokeDasharray: 60,
  38. strokeDashoffset: 'inherit',
  39. transformOrigin: 'center',
  40. animation: `${keyframes`
  41. 0% {
  42. transform: rotate(0);
  43. }
  44. 100% {
  45. transform: rotate(360deg);
  46. }
  47. `} 0.86s forwards infinite`,
  48. animationDelay: '0ms',
  49. animationTimingFunction: 'cubic-bezier(0.4, 0.15, 0.6, 0.85)'
  50. }
  51. };
  52. });
  53. const Spinner = ({ color = DEFAULT_COLOR, size = 'medium' }: IProps) => {
  54. const { classes } = useStyles({ color });
  55. return (
  56. <svg
  57. className = { classes.container }
  58. focusable = 'false'
  59. height = { SIZE[size] }
  60. viewBox = '0 0 16 16'
  61. width = { SIZE[size] }
  62. xmlns = 'http://www.w3.org/2000/svg'>
  63. <circle
  64. className = { classes.circle }
  65. cx = '8'
  66. cy = '8'
  67. r = '7' />
  68. </svg>
  69. );
  70. };
  71. export default Spinner;