import React, {useState} from 'react'; import {Link, useIntl} from 'gatsby-plugin-intl'; import { Header, NavMenuButton, PrimaryNav, Grid, NavDropDownButton, Menu, } from '@trussworks/react-uswds'; import BetaBanner from '../BetaBanner'; import J40MainGridContainer from '../J40MainGridContainer'; import GovernmentBanner from '../GovernmentBanner'; import Language from '../Language'; import {useWindowSize} from 'react-use'; // @ts-ignore import siteLogo from '../../images/j40-logo-v2.png'; import * as styles from './J40Header.module.scss'; import * as COMMON_COPY from '../../data/copy/common'; import {PAGES_ENDPOINTS} from '../../data/constants'; /** * The J40Header component will control how the header looks for both mobile and desktop * * The Header is defined as * 1. Two rows of Banners (ie, official gov website and beta site) * 2. Logo and Nav Links Row * 3. Any Alerts * * @return {JSX.Element} */ const J40Header = () => { const intl = useIntl(); const {width} = useWindowSize(); // Logo text const logoLine1 = intl.formatMessage(COMMON_COPY.HEADER.TITLE_LINE_1); const logoLine2 = intl.formatMessage(COMMON_COPY.HEADER.TITLE_LINE_2); /** * State variable to control the toggling of mobile menu button */ const [mobileNavOpen, setMobileNavOpen] = useState(false); const toggleMobileNav = (): void => setMobileNavOpen((prevOpen) => !prevOpen); /** * State variable to hold the open/close state of each nav dropdown. This will allow for two * dropdown that are being used, each corresponding to an index in the state array: * * index 0 = Data & Methodology dropdown (being used) * index 1 = About dropdown (removed for now) */ const [isOpen, setIsOpen] = useState([true]); const onToggle = (index: number): void => { setIsOpen((prevIsOpen) => { const newIsOpen = [true]; newIsOpen[index] = !prevIsOpen[index]; return newIsOpen; }); }; /** * On mobile, the Methodology & Data page should have two sub-nav links. This defines * the array that will hold these links */ const methPageSubNavLinks = [ {intl.formatMessage(COMMON_COPY.HEADER.METHODOLOGY)} , {intl.formatMessage(COMMON_COPY.HEADER.DOWNLOADS)} , // // {intl.formatMessage(COMMON_COPY.HEADER.TSD)} // , ]; /** * In the future, we may want to add sub-pages to the About page. This array will * define the sub-pages for the About page. */ // const aboutSubNavLinks = [ // // {intl.formatMessage(COMMON_COPY.HEADER.ABOUT)} // , // // {intl.formatMessage(COMMON_COPY.HEADER.FAQs)} // , // // {intl.formatMessage(COMMON_COPY.HEADER.PUBLIC_ENG)} // , // ]; /** * This is the array that holds the navigation links and eventually is the one * that is passed to the render function. It only defines Explore, About and * Contact. * * The Methodology & Data link is passed in depending on screen size. * * For mobile: the Methodology & Data link should have sub-pages * For desktop: the Methodology & Data link should NOT have sub-pages */ const navLinks = [ {intl.formatMessage(COMMON_COPY.HEADER.EXPLORE)} , {intl.formatMessage(COMMON_COPY.HEADER.ABOUT)} , {intl.formatMessage(COMMON_COPY.HEADER.CONTACT)} ,