aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/ui/loader/index.tsx
blob: 8757985b9e2002ced8ac22947bb0b04842fcb997 (plain) (blame)
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
import classnames from 'classnames';
import { inject } from 'mobx-react';
import { Component } from 'react';
import injectStyle, { type WithStylesProps } from 'react-jss';
import { Oval } from 'react-loader-spinner';
import type { FerdiumStores } from '../../../@types/stores.types';
import { DEFAULT_LOADER_COLOR } from '../../../config';

const styles = () => ({
  container: {
    position: 'relative',
    display: 'flex',
    justifyContent: 'center',
    alignItems: 'center',
    height: 'inherit',
  },
});

interface IProps extends WithStylesProps<typeof styles> {
  className?: string;
  color?: string;
  size?: number;
  loaded?: boolean;
  stores?: FerdiumStores;
}

@inject('stores')
class LoaderComponent extends Component<IProps> {
  render() {
    const {
      classes,
      className,
      size = 100,
      color = this.props.stores?.settings.app.accentColor,
      loaded = false,
    } = this.props;
    const loaderColor = color ?? DEFAULT_LOADER_COLOR;

    return (
      <div
        className={classnames({
          [classes.container]: true,
          [`${className}`]: className,
        })}
        data-type="franz-loader"
      >
        <Oval
          strokeWidth={5}
          color={loaderColor}
          secondaryColor={loaderColor}
          height={size}
          width={size}
          visible={!loaded}
        />
      </div>
    );
  }
}

export default injectStyle(styles, { injectTheme: true })(LoaderComponent);