summaryrefslogtreecommitdiffhomepage
path: root/gui/src/renderer/components/ConnectionPanelDisclosure.tsx
blob: 17c3dc9919cbec5f700439754a0f06a1a248434b (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
64
65
66
67
68
69
70
71
72
73
import * as React from 'react';
import { Component, Styles, Text, Types, View } from 'reactxp';
import ImageView from './ImageView';

const styles = {
  container: Styles.createViewStyle({
    flexDirection: 'row',
    alignItems: 'center',
  }),
  caption: {
    base: Styles.createTextStyle({
      fontFamily: 'Open Sans',
      fontSize: 15,
      fontWeight: '600',
      lineHeight: 20,
      color: 'rgb(255, 255, 255, 0.4)',
    }),
    hovered: Styles.createTextStyle({
      color: 'rgb(255, 255, 255)',
    }),
  },
};

interface IProps {
  pointsUp: boolean;
  onToggle?: () => void;
  children: React.ReactText;
  style?: Types.ViewStyleRuleSet | Types.ViewStyleRuleSet[];
}

interface IState {
  isHovered: boolean;
}

export default class ConnectionPanelDisclosure extends Component<IProps, IState> {
  constructor(props: IProps) {
    super(props);

    this.state = {
      isHovered: false,
    };
  }

  public render() {
    const tintColor = this.state.isHovered ? 'rgb(255, 255, 255)' : 'rgb(255, 255, 255, 0.4)';
    const textHoverStyle =
      this.props.pointsUp || this.state.isHovered ? styles.caption.hovered : undefined;

    return (
      <View
        style={[styles.container, this.props.style]}
        onMouseEnter={this.onMouseEnter}
        onMouseLeave={this.onMouseLeave}
        onPress={this.props.onToggle}>
        <Text style={[styles.caption.base, textHoverStyle]}>{this.props.children}</Text>
        <ImageView
          source={this.props.pointsUp ? 'icon-chevron-up' : 'icon-chevron-down'}
          width={24}
          height={24}
          tintColor={tintColor}
        />
      </View>
    );
  }

  private onMouseEnter = () => {
    this.setState({ isHovered: true });
  };

  private onMouseLeave = () => {
    this.setState({ isHovered: false });
  };
}