summaryrefslogtreecommitdiffhomepage
path: root/gui/src/renderer/components/SecuredLabel.tsx
blob: fc91a9777363a049d794bbcb57d2d4f3345301d6 (plain)
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
import * as React from 'react';
import { Component, Styles, Text, Types } from 'reactxp';
import { messages } from '../../shared/gettext';

export enum SecuredDisplayStyle {
  secured,
  blocked,
  securing,
  unsecured,
}

interface IProps {
  displayStyle: SecuredDisplayStyle;
  style: Types.TextStyleRuleSet;
}

const styles = {
  securing: Styles.createTextStyle({
    color: 'rgb(255, 255, 255)', // white
  }),
  secured: Styles.createTextStyle({
    color: 'rgb(68, 173, 77)', // green
  }),
  unsecured: Styles.createTextStyle({
    color: 'rgb(227, 64, 57)', // red
  }),
};

export default class SecuredLabel extends Component<IProps> {
  public render() {
    return <Text style={[this.props.style, this.getTextStyle()]}>{this.getText()}</Text>;
  }

  private getText() {
    switch (this.props.displayStyle) {
      case SecuredDisplayStyle.secured:
        return messages.gettext('SECURE CONNECTION');

      case SecuredDisplayStyle.blocked:
        return messages.gettext('BLOCKED CONNECTION');

      case SecuredDisplayStyle.securing:
        return messages.gettext('CREATING SECURE CONNECTION');

      case SecuredDisplayStyle.unsecured:
        return messages.gettext('UNSECURED CONNECTION');
    }
  }

  private getTextStyle() {
    switch (this.props.displayStyle) {
      case SecuredDisplayStyle.secured:
      case SecuredDisplayStyle.blocked:
        return styles.secured;

      case SecuredDisplayStyle.securing:
        return styles.securing;

      case SecuredDisplayStyle.unsecured:
        return styles.unsecured;
    }
  }
}