import * as _ from 'lodash'; import * as React from 'react'; import { Link as ScrollLink, animateScroll, } from 'react-scroll'; import {Link} from 'react-router-dom'; import {HashLink} from 'react-router-hash-link'; import AppBar from 'material-ui/AppBar'; import Drawer from 'material-ui/Drawer'; import MenuItem from 'material-ui/MenuItem'; import {colors} from 'material-ui/styles'; import ReactTooltip = require('react-tooltip'); import {configs} from 'ts/utils/configs'; import {constants} from 'ts/utils/constants'; import {Identicon} from 'ts/components/ui/identicon'; import {NestedSidebarMenu} from 'ts/pages/shared/nested_sidebar_menu'; import {typeDocUtils} from 'ts/utils/typedoc_utils'; import {PortalMenu} from 'ts/components/portal_menu'; import {Styles, TypeDocNode, MenuSubsectionsBySection, WebsitePaths, Docs} from 'ts/types'; import {TopBarMenuItem} from 'ts/components/top_bar_menu_item'; import {DropDownMenuItem} from 'ts/components/ui/drop_down_menu_item'; const CUSTOM_DARK_GRAY = '#231F20'; const SECTION_HEADER_COLOR = 'rgb(234, 234, 234)'; interface TopBarProps { userAddress?: string; blockchainIsLoaded: boolean; location: Location; docsVersion?: string; availableDocVersions?: string[]; menuSubsectionsBySection?: MenuSubsectionsBySection; shouldFullWidth?: boolean; doc?: Docs; style?: React.CSSProperties; isNightVersion?: boolean; } interface TopBarState { isDrawerOpen: boolean; } const styles: Styles = { address: { marginRight: 12, overflow: 'hidden', paddingTop: 4, textOverflow: 'ellipsis', whiteSpace: 'nowrap', width: 70, }, addressPopover: { backgroundColor: colors.blueGrey500, color: 'white', padding: 3, }, topBar: { backgroundColor: 'white', height: 59, width: '100%', position: 'fixed', top: 0, zIndex: 1100, paddingBottom: 1, }, bottomBar: { boxShadow: 'rgba(0, 0, 0, 0.187647) 0px 1px 3px', }, menuItem: { fontSize: 14, color: CUSTOM_DARK_GRAY, paddingTop: 6, paddingBottom: 6, marginTop: 17, cursor: 'pointer', fontWeight: 400, }, }; export class TopBar extends React.Component { public static defaultProps: Partial = { shouldFullWidth: false, style: {}, isNightVersion: false, }; constructor(props: TopBarProps) { super(props); this.state = { isDrawerOpen: false, }; } public render() { const isNightVersion = this.props.isNightVersion; const isFullWidthPage = this.props.shouldFullWidth; const parentClassNames = `flex mx-auto ${isFullWidthPage ? 'pl2' : 'max-width-4'}`; const developerSectionMenuItems = [ , , , , , ]; const bottomBorderStyle = this.shouldDisplayBottomBar() ? styles.bottomBar : {}; const fullWithClassNames = isFullWidthPage ? 'pr4' : ''; const logoUrl = isNightVersion ? '/images/protocol_logo_white.png' : '/images/protocol_logo_black.png'; return (
{!this.isViewingPortal() &&
} {this.props.blockchainIsLoaded && !_.isEmpty(this.props.userAddress) &&
{this.renderUser()}
} {!this.isViewingPortal() &&
}
{this.renderDrawer()}
); } private renderDrawer() { return ( {this.renderPortalMenu()} {this.renderDocsMenu()} {this.renderWiki()}
Website
Home Wiki {!this.isViewing0xjsDocs() && 0x.js Docs } {!this.isViewingSmartContractsDocs() && Smart Contract Docs } {!this.isViewingPortal() && Portal DApp } Whitepaper About Blog FAQ
); } private renderDocsMenu() { if (!this.isViewing0xjsDocs() && !this.isViewingSmartContractsDocs()) { return; } const topLevelMenu = this.isViewing0xjsDocs() ? typeDocUtils.getFinal0xjsMenu(this.props.docsVersion) : constants.menuSmartContracts; const sectionTitle = this.isViewing0xjsDocs() ? '0x.js Docs' : 'Smart contract Docs'; return (
{sectionTitle}
); } private renderWiki() { if (!this.isViewingWiki()) { return; } return (
0x Protocol Wiki
); } private renderPortalMenu() { if (!this.isViewingPortal()) { return; } return (
Portal DApp
); } private renderUser() { const userAddress = this.props.userAddress; const identiconDiameter = 26; return (
{!_.isEmpty(userAddress) ? userAddress : ''}
{userAddress}
); } private onMenuButtonClick() { this.setState({ isDrawerOpen: !this.state.isDrawerOpen, }); } private isViewingPortal() { return _.includes(this.props.location.pathname, WebsitePaths.Portal); } private isViewingFAQ() { return _.includes(this.props.location.pathname, WebsitePaths.FAQ); } private isViewing0xjsDocs() { return _.includes(this.props.location.pathname, WebsitePaths.ZeroExJs); } private isViewingSmartContractsDocs() { return _.includes(this.props.location.pathname, WebsitePaths.SmartContracts); } private isViewingWiki() { return _.includes(this.props.location.pathname, WebsitePaths.Wiki); } private shouldDisplayBottomBar() { return this.isViewingWiki() || this.isViewing0xjsDocs() || this.isViewingFAQ() || this.isViewingSmartContractsDocs(); } }