bootstrap: navbar collapse jQuery -> React state (BS4->5 prep)
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.
This commit is contained in:
parent
6b6f02d92d
commit
8dead27d22
3 changed files with 57 additions and 44 deletions
16
PENDIENTE.md
16
PENDIENTE.md
|
|
@ -68,11 +68,17 @@ React 19: el `<Blaze serverFacts>` de Status.js (`findDOMNode`), solo en `/statu
|
|||
- **Salto Bootstrap 4→5 (CSS/JS) pendiente:** react-bootstrap ya está en v2 y
|
||||
corre sobre el CSS Bootstrap 4 actual (`alexwine:bootstrap-4`) con un único
|
||||
shim `.form-label` en `forms.scss`. El salto a Bootstrap 5 npm está diferido
|
||||
porque el carrusel del home (`bootstrap-carousel-swipe`, jQuery/BS4) y el
|
||||
collapse del navbar dependen del JS jQuery de BS4 (`data-toggle`, `data-slide`).
|
||||
Al hacerlo: importar `bootstrap@5` SCSS+JS, reescribir el carrusel (BS5 trae
|
||||
swipe nativo → quitar el plugin), `data-toggle`→`data-bs-toggle`,
|
||||
`ml-auto`→`ms-auto`, revisar `new-age.scss`/`custom.scss`/`bootstrap-overrides.scss`.
|
||||
porque el carrusel del home (`bootstrap-carousel-swipe`, jQuery/BS4) depende del
|
||||
JS jQuery de BS4 (`data-slide`).
|
||||
- ✅ **Collapse del navbar migrado a React** (`Navigation.js` + `NavItem.js`):
|
||||
el `data-toggle="collapse"` jQuery se sustituyó por estado React (`useState`
|
||||
que alterna `.show`); funciona ya sobre el CSS BS4 y no depende del JS jQuery.
|
||||
*Verificar en staging el menú móvil (<lg): abrir/cerrar y cierre al pulsar un
|
||||
enlace.* Un blocker jQuery menos.
|
||||
- Falta: reescribir el carrusel (BS5 trae swipe nativo → quitar el plugin),
|
||||
importar `bootstrap@5` SCSS+JS, `data-slide`→`data-bs-slide`,
|
||||
`ml-auto`→`ms-auto`, `sr-only`→`visually-hidden`, revisar
|
||||
`new-age.scss`/`custom.scss`/`bootstrap-overrides.scss`.
|
||||
- **Limpieza menor:** migración 217 `// TODO remove falsepositives lowercase
|
||||
collection`; `prerender.js` gating comentado; sección per-fire del sitemap
|
||||
eliminada (era código muerto tras `firesMapEnabled=false`).
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ import PropTypes from 'prop-types';
|
|||
|
||||
// Self-contained NavItem. The old one wrapped react-bootstrap 0.31's
|
||||
// `SafeAnchor` + `createChainedFunction` (both gone in v2); the markup this
|
||||
// navbar needs is just an <li><a> that toggles the collapsed menu on click.
|
||||
// navbar needs is just an <li><a>. The mobile menu is now collapsed from React
|
||||
// state in Navigation (the parent <ul onClick>), so the old jQuery
|
||||
// `data-toggle="collapse"` / `data-target` hooks were dropped here.
|
||||
const propTypes = {
|
||||
active: PropTypes.bool,
|
||||
disabled: PropTypes.bool,
|
||||
|
|
@ -57,8 +59,6 @@ class NavItem extends React.Component {
|
|||
return (
|
||||
<li
|
||||
role="presentation"
|
||||
data-toggle="collapse"
|
||||
data-target=".navbar-collapse.show"
|
||||
className={classNames(className, { active, disabled })}
|
||||
style={style}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -15,44 +15,51 @@ import './Navigation.scss';
|
|||
|
||||
// removed class: fixed-top
|
||||
// md instead of lg: no menu in medium
|
||||
const Navigation = ({ name = '', ...props }) => (
|
||||
<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="sr-only navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span className="navbar-toggler-icon" />
|
||||
</button>
|
||||
<button className="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span className="navbar-toggler-icon" />
|
||||
</button>
|
||||
{/* <Navbar.Collapse> */}
|
||||
<div className="collapse navbar-collapse" id="navbarNavDropdown">
|
||||
<ul className="navbar-nav ml-auto ">
|
||||
{/* <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>
|
||||
//
|
||||
// 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} />}
|
||||
{/* </Navbar.Collapse> */}
|
||||
</ul>
|
||||
{!props.authenticated ? <PublicNavigation /> : <AuthenticatedNavigation name={name} {...props} />}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
</nav>
|
||||
);
|
||||
};
|
||||
|
||||
Navigation.propTypes = {
|
||||
t: PropTypes.func.isRequired,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue