Skip to content

Commit e6d83c8

Browse files
committed
rewrite Spinner component to typescript
1 parent 3bb2927 commit e6d83c8

File tree

3 files changed

+45
-45
lines changed

3 files changed

+45
-45
lines changed

react/components/EXPERIMENTAL_Table/Sections/Loading.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { FC } from 'react'
22

3-
import Spinner from '../../Spinner/index.js'
3+
import Spinner from '../../Spinner'
44
import useTableMotion from '../hooks/useTableMotion'
55
import { E2ETestable } from '../types'
66

react/components/Spinner/index.js react/components/Spinner/index.tsx

+42-42
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
1-
import React from 'react'
1+
import React, { FC } from 'react'
22
import PropTypes from 'prop-types'
3+
import classNames from 'classnames'
34

45
import { baseClassname } from '../icon/utils'
56

67
const radius = 40
78
const circ = 2 * radius * Math.PI
89

9-
class Spinner extends React.Component {
10-
render() {
11-
const { color, size, block } = this.props
10+
const propTypes = {
11+
/** Color of the spinner */
12+
color: PropTypes.string,
13+
/** Size (diameter) of the spinner */
14+
size: PropTypes.number,
15+
/** Sets the display to block */
16+
block: PropTypes.bool,
17+
}
18+
19+
type Props = PropTypes.InferProps<typeof propTypes>
1220

13-
return (
14-
<svg
15-
className={`${baseClassname('spinner')} ${
16-
!color ? 'c-action-primary' : ''
17-
} ${block ? 'db' : ''}`}
18-
xmlns="http://www.w3.org/2000/svg"
19-
viewBox="0 0 100 100"
20-
preserveAspectRatio="xMidYMid"
21-
height={size}
22-
width={size}
23-
>
24-
<style>
25-
{`
21+
const Spinner: FC<Props> = ({ color, size, block }: Props) => (
22+
<svg
23+
className={classNames(`${baseClassname('spinner')}`, {
24+
'c-action-primary': !color,
25+
db: block,
26+
})}
27+
xmlns="http://www.w3.org/2000/svg"
28+
viewBox="0 0 100 100"
29+
preserveAspectRatio="xMidYMid"
30+
height={size}
31+
width={size}
32+
>
33+
<style>
34+
{`
2635
@keyframes vtex-spinner-rotate {
2736
from {
2837
transform-origin: 50% 50%;
@@ -50,33 +59,24 @@ class Spinner extends React.Component {
5059
animation: vtex-spinner-fill 1.25s infinite cubic-bezier(0.455, 0.030, 0.515, 0.955), vtex-spinner-rotate 0.625s infinite linear;
5160
}
5261
`}
53-
</style>
62+
</style>
5463

55-
<circle
56-
className="vtex-spinner_circle"
57-
cx="50"
58-
cy="50"
59-
fill="none"
60-
r={radius}
61-
stroke={color || 'currentColor'}
62-
strokeWidth="10"
63-
strokeDasharray={`0 0 ${circ * 0.75} ${circ}`}
64-
strokeLinecap="round"
65-
strokeDashoffset="1"
66-
/>
67-
</svg>
68-
)
69-
}
70-
}
64+
<circle
65+
className="vtex-spinner_circle"
66+
cx="50"
67+
cy="50"
68+
fill="none"
69+
r={radius}
70+
stroke={color ?? 'currentColor'}
71+
strokeWidth="10"
72+
strokeDasharray={`0 0 ${circ * 0.75} ${circ}`}
73+
strokeLinecap="round"
74+
strokeDashoffset="1"
75+
/>
76+
</svg>
77+
)
7178

72-
Spinner.propTypes = {
73-
/** Color of the spinner */
74-
color: PropTypes.string,
75-
/** Size (diameter) of the spinner */
76-
size: PropTypes.number,
77-
/** Sets the display to block */
78-
block: PropTypes.bool,
79-
}
79+
Spinner.propTypes = propTypes
8080

8181
Spinner.defaultProps = {
8282
block: false,

styleguide.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ module.exports = {
9797
'react/components/EmptyState/index.js',
9898
'react/components/FilterBar/index.js',
9999
'react/components/FilterOptions/index.js',
100-
'react/components/Spinner/index.js',
100+
'react/components/Spinner/index.tsx',
101101
'react/components/Table/index.js',
102102
'react/components/Tag/index.js',
103103
'react/components/Progress/index.tsx',
@@ -147,7 +147,7 @@ module.exports = {
147147
name: 'Notification',
148148
components: [
149149
'react/components/Alert/index.js',
150-
'react/components/Spinner/index.js',
150+
'react/components/Spinner/index.tsx',
151151
'react/components/ToastProvider/index.js',
152152
],
153153
},

0 commit comments

Comments
 (0)