-
Notifications
You must be signed in to change notification settings - Fork 665
Expand file tree
/
Copy pathSpinner.tsx
More file actions
80 lines (72 loc) · 1.7 KB
/
Spinner.tsx
File metadata and controls
80 lines (72 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React from 'react'
import type { ThemeUICSSObject } from '@theme-ui/css'
import { Box, BoxOwnProps, BoxProps } from './Box'
import type { ForwardRef } from './types'
import { __internalProps } from './util'
export interface SpinnerProps
extends Omit<
React.ComponentPropsWithRef<'svg'>,
'opacity' | 'color' | 'css' | 'sx' | 'strokeWidth'
>,
BoxOwnProps {
size?: number
strokeWidth?: number
title?: string
duration?: number
}
export const Spinner: ForwardRef<SVGSVGElement, SpinnerProps> =
React.forwardRef(function Spinner(
{
size = 48,
strokeWidth = 4,
max = 1,
title = 'Loading',
duration = 750,
...props
},
ref
) {
const __css: ThemeUICSSObject = {
color: 'primary',
overflow: 'visible',
}
const svgProps = {
strokeWidth,
viewBox: '0 0 32 32',
width: size,
height: size,
fill: 'none',
stroke: 'currentColor',
role: 'img',
}
const circleProps = {
strokeWidth,
r: 16 - strokeWidth,
cx: 16,
cy: 16,
fill: 'none',
}
return (
<Box
ref={ref}
as="svg"
{...(svgProps as {})}
{...(props as BoxProps)}
{...__internalProps({ __css })}
>
<title>{title}</title>
<circle {...circleProps} opacity={1 / 8} />
<circle {...circleProps} strokeDasharray="20 110">
<animateTransform
attributeName="transform"
attributeType="XML"
type="rotate"
from="0 16 16"
to="360 16 16"
dur={`${duration}ms`}
repeatCount="indefinite"
/>
</circle>
</Box>
)
})