aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/workspaces/components/WorkspaceServiceListItem.tsx
blob: a56e5802fb736e98c2d3d40569b64d4e65ed0d00 (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
61
62
63
64
65
66
67
68
import classnames from 'classnames';
import { noop } from 'lodash';
import { observer } from 'mobx-react';
import { Component, type ReactElement } from 'react';
import withStyles, { type WithStylesProps } from 'react-jss';
import ServiceIcon from '../../../components/ui/ServiceIcon';
import Toggle from '../../../components/ui/toggle';
import type Service from '../../../models/Service';

const styles = theme => ({
  listItem: {
    height: theme.workspaces.settings.listItems.height,
    borderBottom: `1px solid ${theme.workspaces.settings.listItems.borderColor}`,
    display: 'flex',
    alignItems: 'center',
  },
  serviceIcon: {
    padding: theme.workspaces.settings.listItems.padding,
  },
  toggle: {
    height: 'auto',
    margin: 0,
  },
  label: {
    padding: theme.workspaces.settings.listItems.padding,
    flexGrow: 1,
  },
  disabledLabel: {
    color: theme.workspaces.settings.listItems.disabled.color,
  },
});

interface IProps extends WithStylesProps<typeof styles> {
  isInWorkspace: boolean;
  onToggle: () => void;
  service: Service;
}

@observer
class WorkspaceServiceListItem extends Component<IProps> {
  render(): ReactElement {
    const { classes, isInWorkspace, onToggle, service } = this.props;
    return (
      // onclick in below div used to fix bug raised under toggle duplicate component removal
      // eslint-disable-next-line jsx-a11y/no-static-element-interactions
      <div className={classes.listItem} onClick={onToggle} onKeyDown={noop}>
        <ServiceIcon className={classes.serviceIcon} service={service} />
        <span
          className={classnames([
            classes.label,
            service.isEnabled ? null : classes.disabledLabel,
          ])}
        >
          {service.name}
        </span>
        <Toggle
          className={classes.toggle}
          checked={isInWorkspace}
          onChange={onToggle}
        />
      </div>
    );
  }
}

export default withStyles(styles, { injectTheme: true })(
  WorkspaceServiceListItem,
);