UNPKG

@mongodb-js/mongodb-ui-components

Version:

A collection of frequently used functional UI components found on mongodb properties

101 lines (89 loc) 2.46 kB
'use strict'; import React, { Component } from 'react'; import { hamburgerIcon } from '../nav-icons'; export default class MiddlePanel extends Component { constructor(props) { super(props); this.state = { isMobile: this.props.isMobile, activeSection: this.props.activeSection || -1 }; this.renderSection = this.renderSection.bind(this); } componentWillReceiveProps(newProps) { this.setState({ activeSection: newProps.activeSection, isMobile: newProps.isMobile }); } onTabSelect(i, e) { e.preventDefault(); if (this.state.activeSection === i) { i = -1; } this.props.setActiveSection(i); this.setState({ activeSection: i }); return false; } renderSection(section, i) { const active = this.state.activeSection; return React.createElement( 'li', { key: i, className: `m-nav-middle-li ${active === i ? 'm-nav-middle-li-on' : ''}` }, React.createElement( 'a', { href: section.href, onClick: !section.isLink && this.onTabSelect.bind(this, i) }, section.text, section.extraText && React.createElement( 'span', { className: 'extra-text' }, section.extraText ) ) ); } render() { return React.createElement( 'div', { className: 'm-nav-middle' }, React.createElement( 'ul', { className: 'm-nav-flex-space' }, React.createElement( 'a', { href: this.props.logoLink || '/', className: 'm-nav-flex-y' }, React.createElement( 'li', { className: 'm-nav-logo' }, React.createElement('img', { src: this.props.logoUrl }) ), React.createElement( 'li', { className: 'm-nav-tagline' }, this.props.tagline || 'For Giant Ideas' ) ), React.createElement( 'div', { className: 'm-nav-middle-lists m-nav-flex-xy', style: this.state.isMobile ? { display: 'none' } : null }, this.props.sections.map(this.renderSection) ), React.createElement( 'li', { onClick: this.props.toggle, className: 'm-nav-middle-toggle' }, React.createElement( 'button', null, hamburgerIcon ) ) ) ); } }