aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/ui/ServiceIcon.js
blob: b05d791be373d4a11354b373b5773a0e4ddfbb3e (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 { Component } from 'react';
import PropTypes from 'prop-types';
import { observer } from 'mobx-react';
import injectSheet from 'react-jss';
import classnames from 'classnames';

import ServiceModel from '../../models/Service';

const styles = theme => ({
  root: {
    height: 'auto',
  },
  icon: {
    width: theme.serviceIcon.width,
  },
  isCustomIcon: {
    width: theme.serviceIcon.isCustom.width,
    border: theme.serviceIcon.isCustom.border,
    borderRadius: theme.serviceIcon.isCustom.borderRadius,
  },
  isDisabled: {
    filter: 'grayscale(100%)',
    opacity: '.5',
  },
});

// Should this file be converted into the coding style similar to './toggle/index.tsx'?
class ServiceIcon extends Component {
  static propTypes = {
    classes: PropTypes.object.isRequired,
    service: PropTypes.instanceOf(ServiceModel).isRequired,
    className: PropTypes.string,
  };

  static defaultProps = {
    className: '',
  };

  render() {
    const { classes, className, service } = this.props;

    return (
      <div className={classnames([classes.root, className])}>
        <img
          src={service.icon}
          className={classnames([
            classes.icon,
            service.isEnabled ? null : classes.isDisabled,
            service.hasCustomIcon ? classes.isCustomIcon : null,
          ])}
          alt=""
        />
      </div>
    );
  }
}

export default injectSheet(styles, { injectTheme: true })(
  observer(ServiceIcon),
);