|
1 |
| -import React from 'react' |
| 1 | +import React, { FC } from 'react' |
2 | 2 | import PropTypes from 'prop-types'
|
| 3 | +import classNames from 'classnames' |
3 | 4 |
|
4 | 5 | import { baseClassname } from '../icon/utils'
|
5 | 6 |
|
6 | 7 | const radius = 40
|
7 | 8 | const circ = 2 * radius * Math.PI
|
8 | 9 |
|
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> |
12 | 20 |
|
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 | + {` |
26 | 35 | @keyframes vtex-spinner-rotate {
|
27 | 36 | from {
|
28 | 37 | transform-origin: 50% 50%;
|
@@ -50,33 +59,24 @@ class Spinner extends React.Component {
|
50 | 59 | animation: vtex-spinner-fill 1.25s infinite cubic-bezier(0.455, 0.030, 0.515, 0.955), vtex-spinner-rotate 0.625s infinite linear;
|
51 | 60 | }
|
52 | 61 | `}
|
53 |
| - </style> |
| 62 | + </style> |
54 | 63 |
|
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 | +) |
71 | 78 |
|
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 |
80 | 80 |
|
81 | 81 | Spinner.defaultProps = {
|
82 | 82 | block: false,
|
|
0 commit comments