summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-10-15 11:25:31 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-10-16 10:38:11 -0300
commit4c21251d6e1782ec949144010d5956ea3adb4489 (patch)
tree23f1b1a5d752e33868f5adb9bc4434f2f35e905f
parent43dfaeddf5e70c8cb667b5385eba1645553a5c3e (diff)
downloadmullvadvpn-4c21251d6e1782ec949144010d5956ea3adb4489.tar.xz
mullvadvpn-4c21251d6e1782ec949144010d5956ea3adb4489.zip
Create `ConnectionInfo` component
-rw-r--r--gui/packages/components/src/ConnectionInfo.tsx105
1 files changed, 105 insertions, 0 deletions
diff --git a/gui/packages/components/src/ConnectionInfo.tsx b/gui/packages/components/src/ConnectionInfo.tsx
new file mode 100644
index 0000000000..b22c510c23
--- /dev/null
+++ b/gui/packages/components/src/ConnectionInfo.tsx
@@ -0,0 +1,105 @@
+import * as React from 'react';
+import { Component, Styles, Text, View } from 'reactxp';
+import { default as Accordion } from './Accordion';
+
+const styles = {
+ toggle: Styles.createTextStyle({
+ fontFamily: 'Open Sans',
+ fontSize: 14,
+ fontWeight: '800',
+ color: 'rgb(255, 255, 255, 0.4)',
+ paddingBottom: 2,
+ }),
+ content: Styles.createTextStyle({
+ fontFamily: 'Open Sans',
+ fontSize: 16,
+ fontWeight: '800',
+ color: 'rgb(255, 255, 255)',
+ paddingBottom: 2,
+ }),
+};
+
+interface IInAddress {
+ ip: string;
+ port: number;
+ protocol: string;
+}
+
+interface IOutAddress {
+ ipv4: string | null;
+ ipv6: string | null;
+}
+
+interface IProps {
+ inAddress: IInAddress;
+ outAddress: IOutAddress;
+ startExpanded: boolean;
+ onToggle: (expanded: boolean) => void;
+}
+
+interface IState {
+ expanded: boolean;
+}
+
+export default class ConnectionInfo extends Component<IProps, IState> {
+ public static defaultProps = {
+ inAddress: {
+ ip: null,
+ port: null,
+ protocol: null,
+ },
+ outAddress: null,
+ startExpanded: false,
+ onToggle: (_: boolean) => {},
+ };
+
+ constructor(props: IProps) {
+ super(props);
+
+ this.state = {
+ expanded: props.startExpanded,
+ };
+ }
+
+ public render() {
+ return (
+ <View>
+ <Accordion height={this.state.expanded ? 'auto' : 0}>
+ <Text style={styles.content}>{this.inAddress()}</Text>
+ <Text style={styles.content}>{this.outAddress()}</Text>
+ </Accordion>
+ <Text style={styles.toggle} onPress={() => this.toggle()}>
+ {this.state.expanded ? 'LESS' : 'MORE'}
+ </Text>
+ </View>
+ );
+ }
+
+ private toggle() {
+ this.setState((state, props) => {
+ const expanded = !state.expanded;
+
+ props.onToggle(expanded);
+
+ return { expanded };
+ });
+ }
+
+ private inAddress() {
+ const { ip, port, protocol } = this.props.inAddress;
+
+ return (
+ 'IN: ' + (ip || '<unknown>') + (port ? `:${port}` : '') + (protocol ? ` - ${protocol}` : '')
+ );
+ }
+
+ private outAddress() {
+ const { ipv4, ipv6 } = this.props.outAddress;
+
+ if (ipv4 || ipv6) {
+ return `OUT: ${ipv4}` + (ipv6 ? ` / ${ipv6}` : '');
+ } else {
+ return '';
+ }
+ }
+}