import * as React from 'react'; import { Component, Styles, Text, Types, View } from 'reactxp'; import { default as ConnectionInfoDisclosure } from './ConnectionInfoDisclosure'; const styles = { row: Styles.createViewStyle({ flexDirection: 'row', marginTop: 3, }), caption: Styles.createTextStyle({ fontFamily: 'Open Sans', fontSize: 13, fontWeight: '600', color: 'rgb(255, 255, 255)', flex: 0, flexBasis: 30, marginRight: 8, }), value: Styles.createTextStyle({ fontFamily: 'Open Sans', fontSize: 13, fontWeight: '600', color: 'rgb(255, 255, 255)', letterSpacing: -0.2, }), header: Styles.createViewStyle({ flexDirection: 'row', alignItems: 'center', }), hostname: Styles.createTextStyle({ fontFamily: 'Open Sans', fontSize: 16, lineHeight: 20, fontWeight: '600', color: 'rgb(255, 255, 255)', flex: 1, }), }; interface IInAddress { ip: string; port: number; protocol: string; } interface IOutAddress { ipv4?: string; ipv6?: string; } interface IProps { hostname?: string; inAddress?: IInAddress; outAddress?: IOutAddress; defaultOpen?: boolean; style?: Types.ViewStyleRuleSet | Types.ViewStyleRuleSet[]; onToggle?: (isOpen: boolean) => void; } interface IState { isOpen: boolean; } export default class ConnectionInfo extends Component { constructor(props: IProps) { super(props); this.state = { isOpen: props.defaultOpen === true, }; } public render() { const { inAddress, outAddress } = this.props; return ( {this.props.hostname || ''} {'Connection details'} {this.state.isOpen && ( {inAddress && ( {'In'} {`${inAddress.ip}:${inAddress.port} ${inAddress.protocol.toUpperCase()}`} )} {outAddress && (outAddress.ipv4 || outAddress.ipv6) && ( {'Out'} {outAddress.ipv4 && {outAddress.ipv4}} {outAddress.ipv6 && {outAddress.ipv6}} )} )} ); } private onToggle = (isOpen: boolean) => { this.setState( (state) => ({ ...state, isOpen }), () => { if (this.props.onToggle) { this.props.onToggle(isOpen); } }, ); }; }