1 | import React, {PureComponent} from 'react';
|
2 | import classNames from 'classnames';
|
3 | import PropTypes from 'prop-types';
|
4 |
|
5 | import Theme from '../global/theme';
|
6 | import dataTests from '../global/data-tests';
|
7 |
|
8 | import styles from './loader-inline.css';
|
9 | import injectStyles from './inject-styles';
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export default class LoaderInline extends PureComponent {
|
16 | static Theme = Theme;
|
17 | static propTypes = {
|
18 | theme: PropTypes.oneOf(Object.values(Theme)),
|
19 | className: PropTypes.string,
|
20 | 'data-test': PropTypes.string,
|
21 | children: PropTypes.node
|
22 | };
|
23 |
|
24 | static defaultProps = {
|
25 | theme: Theme.LIGHT
|
26 | };
|
27 |
|
28 | componentDidMount() {
|
29 | injectStyles();
|
30 | }
|
31 |
|
32 | render() {
|
33 | const {className, theme, 'data-test': dataTest, children, ...restProps} = this.props;
|
34 |
|
35 | const classes = classNames(
|
36 | styles.loader,
|
37 | className,
|
38 | `${styles.loader}_${theme}`
|
39 | );
|
40 |
|
41 | const loader = (
|
42 | <div
|
43 | {...restProps}
|
44 | data-test={dataTests('ring-loader-inline', dataTest)}
|
45 | className={classes}
|
46 | />
|
47 | );
|
48 |
|
49 | return children ? (
|
50 | <>
|
51 | {loader}
|
52 | <span className={styles.children}>{children}</span>
|
53 | </>
|
54 | ) : loader;
|
55 | }
|
56 | }
|