forked from primer/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spinner.tsx
57 lines (48 loc) · 1.24 KB
/
Spinner.tsx
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
import React from 'react'
import styled from 'styled-components'
import sx, {SxProp} from './sx'
import {ComponentProps} from './utils/types'
const sizeMap = {
small: '16px',
medium: '32px',
large: '64px'
}
export interface SpinnerInternalProps {
/** Sets the width and height of the spinner. */
size?: keyof typeof sizeMap
}
function Spinner({size: sizeKey = 'medium', ...props}: SpinnerInternalProps) {
const size = sizeMap[sizeKey]
return (
<svg height={size} width={size} viewBox="0 0 16 16" fill="none" {...props}>
<circle
cx="8"
cy="8"
r="7"
stroke="currentColor"
strokeOpacity="0.25"
strokeWidth="2"
vectorEffect="non-scaling-stroke"
/>
<path
d="M15 8a7.002 7.002 0 00-7-7"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
vectorEffect="non-scaling-stroke"
/>
</svg>
)
}
const StyledSpinner = styled(Spinner)<SxProp>`
@keyframes rotate-keyframes {
100% {
transform: rotate(360deg);
}
}
animation: rotate-keyframes 1s linear infinite;
${sx}
`
StyledSpinner.displayName = 'Spinner'
export type SpinnerProps = ComponentProps<typeof StyledSpinner>
export default StyledSpinner