Bootstrap's jQuery collapse (`data-toggle="collapse"` in Navigation.js, plus the per-NavItem `data-target=".navbar-collapse.show"` auto-close) disappears when we drop `alexwine:bootstrap-4` for `bootstrap@5`. Replace it with a React `useState` that toggles `.show`, and close the mobile menu via an onClick on the nav <ul>. Works on the current BS4 CSS (`.collapse.show` is pure CSS; jQuery only added the height animation) and removes one of the two jQuery/BS4 JS blockers to the CSS swap (the home carousel is the other). Also drops the dead sr-only toggler button that targeted a non-existent id. No CSS changes.
69 lines
3.4 KiB
JavaScript
69 lines
3.4 KiB
JavaScript
/* eslint-disable import/no-absolute-path */
|
|
|
|
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { Link } from 'react-router-dom';
|
|
import { LinkContainer } from 'react-router-bootstrap';
|
|
import { Trans, withTranslation } from 'react-i18next';
|
|
import { testId } from '/imports/ui/components/Utils/TestUtils';
|
|
/* import BetaRibbon from '../../components/BetaRibbon/BetaRibbon'; */
|
|
import PublicNavigation from '../PublicNavigation/PublicNavigation';
|
|
import AuthenticatedNavigation from '../AuthenticatedNavigation/AuthenticatedNavigation';
|
|
import NavItem from '../NavItem/NavItem';
|
|
|
|
import './Navigation.scss';
|
|
|
|
// removed class: fixed-top
|
|
// md instead of lg: no menu in medium
|
|
//
|
|
// Bootstrap 4→5 prep: the collapse used to be driven by Bootstrap's jQuery JS
|
|
// (`data-toggle="collapse"`), which goes away when we drop `alexwine:bootstrap-4`
|
|
// for `bootstrap@5`. Toggling the `.show` class from React state removes that
|
|
// dependency and keeps working on the current BS4 CSS (`.collapse.show` is pure
|
|
// CSS; jQuery only added the height animation). Clicking a nav link collapses the
|
|
// mobile menu again — the old per-NavItem `data-target=".navbar-collapse.show"`.
|
|
const Navigation = ({ name = '', ...props }) => {
|
|
const [open, setOpen] = React.useState(false);
|
|
const close = () => setOpen(false);
|
|
return (
|
|
<nav className="navbar navbar-expand-lg navbar-dark bg-dark">
|
|
<div style={{ overflow: 'hidden' } /* for ribbon */} className="container">
|
|
{/* <BetaRibbon /> */}
|
|
<Link to="/" className={`navbar-brand ${window.location.pathname === '/' ? 'hide-brand' : ''}`} >
|
|
{props.t('AppNameFull')}
|
|
</Link>
|
|
<button className="navbar-toggler" type="button" onClick={() => setOpen(o => !o)} aria-controls="navbarNavDropdown" aria-expanded={open} aria-label="Toggle navigation">
|
|
<span className="navbar-toggler-icon" />
|
|
</button>
|
|
<div className={`collapse navbar-collapse${open ? ' show' : ''}`} id="navbarNavDropdown">
|
|
{/* onClick closes the mobile menu when a main nav link is tapped */}
|
|
<ul className="navbar-nav ml-auto " onClick={close}>
|
|
{/* <LinkContainer className="nav-item" anchorClassName="nav-link" to="/sandbox">
|
|
<NavItem eventKey={1.1} href="/sandbox">Sandbox</NavItem>
|
|
</LinkContainer> */}
|
|
<LinkContainer id={testId('subscriptions')} className="nav-item" anchorClassName="nav-link" to="/subscriptions">
|
|
<NavItem eventKey={1.2} href="/subscriptions">
|
|
{props.authenticated ? <Trans>Mis zonas</Trans> : <Trans>Participar</Trans>}
|
|
</NavItem>
|
|
</LinkContainer>
|
|
<LinkContainer id={testId('moniZones')} className="nav-item" anchorClassName="nav-link" to="/zones">
|
|
<NavItem eventKey={2} href="/zones">{props.t('Zonas vigiladas')}</NavItem>
|
|
</LinkContainer>
|
|
<LinkContainer id={testId('activeFires')} className="nav-item" anchorClassName="nav-link" to="/fires">
|
|
<NavItem eventKey={2.1} href="/fires">{props.t('activeFires')}</NavItem>
|
|
</LinkContainer>
|
|
|
|
</ul>
|
|
{!props.authenticated ? <PublicNavigation /> : <AuthenticatedNavigation name={name} {...props} />}
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
);
|
|
};
|
|
|
|
Navigation.propTypes = {
|
|
t: PropTypes.func.isRequired,
|
|
authenticated: PropTypes.bool.isRequired
|
|
};
|
|
|
|
export default withTranslation()(Navigation);
|