1- import React , { SVGAttributes } from 'react'
2- import { keyframes } from '@emotion/react'
3-
1+ import React from 'react'
42import type { ThemeUICSSObject } from '@theme-ui/css'
53
64import { Box , BoxOwnProps , BoxProps } from './Box'
75import type { ForwardRef } from './types'
86import { __internalProps } from './util'
97
10- const spin = keyframes ( {
11- from : {
12- transform : 'rotate(0deg)' ,
13- } ,
14- to : {
15- transform : 'rotate(360deg)' ,
16- } ,
17- } )
18-
198export interface SpinnerProps
209 extends Omit <
2110 React . ComponentPropsWithRef < 'svg' > ,
2211 'opacity' | 'color' | 'css' | 'sx' | 'strokeWidth'
2312 > ,
2413 BoxOwnProps {
25- size ?: number | string
14+ size ?: number
2615 strokeWidth ?: number
2716 title ?: string
2817 duration ?: number
@@ -34,37 +23,17 @@ export const Spinner: ForwardRef<SVGSVGElement, SpinnerProps> =
3423 size = 48 ,
3524 strokeWidth = 4 ,
3625 max = 1 ,
37- title = 'Loading... ' ,
38- duration = 500 ,
26+ title = 'Loading' ,
27+ duration = 750 ,
3928 ...props
4029 } ,
4130 ref
4231 ) {
43- const r = 16 - strokeWidth
44- const C = 2 * r * Math . PI
45- const offset = C - ( 1 / 4 ) * C
46-
4732 const __css : ThemeUICSSObject = {
4833 color : 'primary' ,
4934 overflow : 'visible' ,
5035 }
5136
52- const circleProps : SVGAttributes < SVGCircleElement > = {
53- cx : 16 ,
54- cy : 16 ,
55- r,
56- strokeDasharray : C ,
57- strokeDashoffset : offset ,
58- }
59-
60- const __circleCss : ThemeUICSSObject = {
61- transformOrigin : '50% 50%' ,
62- animationName : spin . toString ( ) ,
63- animationTimingFunction : 'linear' ,
64- animationDuration : duration + 'ms' ,
65- animationIterationCount : 'infinite' ,
66- }
67-
6837 const svgProps = {
6938 strokeWidth,
7039
@@ -77,6 +46,14 @@ export const Spinner: ForwardRef<SVGSVGElement, SpinnerProps> =
7746 role : 'img' ,
7847 }
7948
49+ const circleProps = {
50+ strokeWidth,
51+ r : 16 - strokeWidth ,
52+ cx : 16 ,
53+ cy : 16 ,
54+ fill : 'none' ,
55+ }
56+
8057 return (
8158 < Box
8259 ref = { ref }
@@ -86,14 +63,18 @@ export const Spinner: ForwardRef<SVGSVGElement, SpinnerProps> =
8663 { ...__internalProps ( { __css } ) }
8764 >
8865 < title > { title } </ title >
89- < circle cx = { 16 } cy = { 16 } r = { r } opacity = { 1 / 8 } />
90- < Box
91- as = "circle"
92- { ...( circleProps as { } ) }
93- { ...__internalProps ( {
94- __css : __circleCss ,
95- } ) }
96- />
66+ < circle { ...circleProps } opacity = { 1 / 8 } />
67+ < circle { ...circleProps } strokeDasharray = "20 110" >
68+ < animateTransform
69+ attributeName = "transform"
70+ attributeType = "XML"
71+ type = "rotate"
72+ from = "0 16 16"
73+ to = "360 16 16"
74+ dur = { `${ duration } ms` }
75+ repeatCount = "indefinite"
76+ />
77+ </ circle >
9778 </ Box >
9879 )
9980 } )
0 commit comments