-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSpinnerButton.tsx
37 lines (34 loc) · 967 Bytes
/
SpinnerButton.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
import { FC } from 'react';
import { Button, ButtonProps, Spinner, SpinnerProps } from 'react-bootstrap';
export interface SpinnerButtonProps
extends ButtonProps,
Pick<SpinnerProps, 'animation'> {
loading?: boolean;
}
export const SpinnerButton: FC<SpinnerButtonProps> = ({
animation,
loading,
disabled,
children,
...props
}) => (
<Button {...props} disabled={loading || disabled}>
{loading && (
<>
<Spinner
as="span"
className={children ? 'me-2' : ''}
size="sm"
animation={animation}
role="status"
aria-hidden="true"
/>
{!children && (
<span className="visually-hidden">Loading...</span>
)}
</>
)}
{children}
</Button>
);
SpinnerButton.displayName = 'SpinnerButton';