/
Spinner.tsx
100 lines (87 loc) · 2.14 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import PropTypes from 'prop-types';
import classNames from 'classnames';
import React from 'react';
import { useBootstrapPrefix } from './ThemeProvider';
import { BsPrefixPropsWithChildren } from './helpers';
import { Variant } from './types';
export interface SpinnerProps
extends React.HTMLAttributes<HTMLElement>,
BsPrefixPropsWithChildren {
animation: 'border' | 'grow';
role?: string;
size?: 'sm';
variant?: Variant;
}
const propTypes = {
/**
* @default 'spinner'
*/
bsPrefix: PropTypes.string,
/**
* The visual color style of the spinner
*
* @type {('primary'|'secondary'|'success'|'danger'|'warning'|'info'|'light'|'dark')}
*/
variant: PropTypes.string,
/**
* Changes the animation style of the spinner.
*
* @type {('border'|'grow')}
* @default true
*/
animation: PropTypes.oneOf(['border', 'grow']).isRequired,
/**
* Component size variations.
*
* @type {('sm')}
*/
size: PropTypes.string,
/**
* This component may be used to wrap child elements or components.
*/
children: PropTypes.element,
/**
* An ARIA accessible role applied to the Menu component. This should generally be set to 'status'
*/
role: PropTypes.string,
/**
* @default div
*/
as: PropTypes.elementType,
};
const Spinner = React.forwardRef(
(
{
bsPrefix,
variant,
animation,
size,
children,
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
as: Component = 'div',
className,
...props
}: SpinnerProps,
ref,
) => {
bsPrefix = useBootstrapPrefix(bsPrefix, 'spinner');
const bsSpinnerPrefix = `${bsPrefix}-${animation}`;
return (
<Component
ref={ref}
{...props}
className={classNames(
className,
bsSpinnerPrefix,
size && `${bsSpinnerPrefix}-${size}`,
variant && `text-${variant}`,
)}
>
{children}
</Component>
);
},
);
Spinner.propTypes = propTypes as any;
Spinner.displayName = 'Spinner';
export default Spinner;