todos-contra-el-fuego-web/imports/ui/components/NavItem/NavItem.js
vjrj a1a1b9a801 deps: react-bootstrap 0.31 -> 2 (Bootstrap 5 CSS deferred as debt)
Removes the largest batch of React-19-blocking warnings: the 0.31
components (Grid, FormGroup, ControlLabel, Navbar.Header/Brand, Checkbox,
SafeAnchor) all leaned on legacy context / defaultProps.

29 files converted: Grid->Container, FormGroup/ControlLabel/FormControl/
HelpBlock -> Form.Group/Label/Control/Text, Checkbox -> Form.Check (label
as prop), bsStyle->variant (default->secondary), bsSize->size,
pull-right->float-end. Custom Col.js now re-exports v2's Col; custom
NavItem.js rewritten self-contained (no SafeAnchor/createChainedFunction);
Navigation.js drops react-bootstrap Navbar (raw markup anyway).

CSS stays on Bootstrap 4 (alexwine:bootstrap-4) for now: the BS4->5 jump
is entangled with the jQuery carousel/swipe + navbar-collapse and is
tracked as separate debt in UPGRADE.md. Only .form-label needed a shim
(forms.scss). Browser-verified home carousel+navbar, signup form + terms
checkbox, login form; REST smoke byte-identical.
2026-07-21 12:44:46 +02:00

81 lines
2 KiB
JavaScript

import classNames from 'classnames';
import React from 'react';
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.
const propTypes = {
active: PropTypes.bool,
disabled: PropTypes.bool,
role: PropTypes.string,
href: PropTypes.string,
onClick: PropTypes.func,
onSelect: PropTypes.func,
eventKey: PropTypes.any,
className: PropTypes.string,
anchorClassName: PropTypes.string,
style: PropTypes.object,
children: PropTypes.node
};
const defaultProps = {
active: false,
disabled: false
};
class NavItem extends React.Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
handleClick(e) {
const { disabled, onClick, onSelect, eventKey } = this.props;
if (disabled) {
e.preventDefault();
return;
}
if (onClick) onClick(e);
if (onSelect) {
e.preventDefault();
onSelect(eventKey, e);
}
}
render() {
const {
active, disabled, role, href, onClick, onSelect, eventKey,
className, anchorClassName, style, children, ...props
} = this.props;
const anchorProps = { ...props };
if (href) anchorProps.href = href;
anchorProps.role = role || (href === '#' ? 'button' : undefined);
if (role === 'tab') anchorProps['aria-selected'] = active;
return (
<li
role="presentation"
data-toggle="collapse"
data-target=".navbar-collapse.show"
className={classNames(className, { active, disabled })}
style={style}
>
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<a
{...anchorProps}
className={anchorClassName}
onClick={this.handleClick}
>
{children}
</a>
</li>
);
}
}
NavItem.propTypes = propTypes;
NavItem.defaultProps = defaultProps;
export default NavItem;