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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
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: 13,
fontWeight: '600',
color: 'rgb(255, 255, 255, 0.4)',
}),
hovered: Styles.createTextStyle({
color: 'rgb(255, 255, 255)',
}),
},
};
interface IProps {
onToggle?: (isOpen: boolean) => void;
defaultOpen?: boolean;
children: string;
style?: Types.ViewStyleRuleSet | Types.ViewStyleRuleSet[];
}
interface IState {
isHovered: boolean;
isOpen: boolean;
}
export default class ConnectionInfoDisclosure extends Component<IProps, IState> {
constructor(props: IProps) {
super(props);
this.state = {
isHovered: false,
isOpen: props.defaultOpen === true,
};
}
public render() {
const tintColor = this.state.isHovered ? 'rgb(255, 255, 255)' : 'rgb(255, 255, 255, 0.4)';
return (
<View
style={[styles.container, this.props.style]}
onMouseEnter={this.onMouseEnter}
onMouseLeave={this.onMouseLeave}
onPress={this.onToggle}>
<Text
style={[styles.caption.base, this.state.isHovered ? styles.caption.hovered : undefined]}>
{this.props.children}
</Text>
<ImageView
source={this.state.isOpen ? '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 });
};
private onToggle = () => {
this.setState(
(state) => ({
...state,
isOpen: !state.isOpen,
}),
() => {
if (this.props.onToggle) {
this.props.onToggle(this.state.isOpen);
}
},
);
};
}
|