import React, { Component } from 'react' import Link from 'next/link' import LinkWrap from '@hashicorp/react-link-wrap' import InlineSvg from '@hashicorp/react-inline-svg' import caratIcon from './img/carat.svg?include' import downloadIcon from './img/download.svg?include' import githubIcon from './img/github.svg?include' class ProductSubnav extends Component { constructor(props) { super(props) this.state = { fixNav: true, menuOpen: false } this.toggleMenu = this.toggleMenu.bind(this) this.openSubmenu = this.openSubmenu.bind(this) this.closeSubmenu = this.closeSubmenu.bind(this) } toggleMenu() { this.setState({ menuOpen: !this.state.menuOpen }) } openSubmenu(e) { const dropdown = e.currentTarget.nextElementSibling dropdown && dropdown.classList.add('open') } closeSubmenu(e) { e.currentTarget.parentElement.classList.remove('open') } render() { const { rootUrl, buttonText, hideDownloadIcon, buttonExternal, links } = this.props const currentProduct = { slug: 'vault', siteUrl: 'https://www.vaultproject.io', downloadUrl: '/downloads', githubUrl: 'https://github.com/hashicorp/vault', colorLogo: { url: 'https://www.datocms-assets.com/2885/1509990185-vault-dark.svg', alt: 'Vault Logo' } } return (
{currentProduct.colorLogo.alt}

{currentProduct.slug.charAt(0).toUpperCase() + currentProduct.slug.slice(1)}

    {links.map(link => { if (link.title === '|') return
  • return link.links ? (
  • {link.title}
    • Back
    • {link.title}
    • {link.links.map(sublink => (
    • {sublink.title}
    • ))}
  • ) : (
  • {link.title}
  • ) })}
{currentProduct.githubUrl && ( GitHub )} {currentProduct.downloadUrl && ( {!hideDownloadIcon && } {buttonText || 'Download'} )}
{currentProduct.githubUrl && ( )} {currentProduct.downloadUrl && ( {!hideDownloadIcon && } {buttonText || 'Download'} )}
) } } // This function ensures that if the root url is the same as the link's url, // we strip the root and resolve from a relative path, so as to not redirect // from the local dev environment to production unexpectedly. function resolveLocalUrl(rootUrl, url) { const urlRegex = new RegExp(`^(?:http(?:s)*://)?(?:www.)?${rootUrl}`) return url.replace(/\.html$/, '').replace(urlRegex, '') } export default ProductSubnav