Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use isOpen prop instead of toggler #47

Merged
merged 1 commit into from
Oct 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions web/src/components/navbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
Nav,
NavLink,
UncontrolledTooltip,
UncontrolledCollapse,
Row,
Col,
Button,
Collapse,
} from 'reactstrap';

import Logo from 'assets/img/logo.png';
Expand Down Expand Up @@ -48,17 +48,15 @@ OutsideLink.defaultProps = {
tooltipText: '',
};

const ResponsiveCollapse = ({ children }) => {
const ResponsiveCollapse = ({ children, isCollapseOpen, setIsCollapseOpen }) => {
const [collapseClass, setCollapseClass] = useState('');
const [isCollapseOpen, setIsCollapseOpen] = useState(false);

return (
<React.Fragment>
<button className="navbar-toggler" id="navbar_global" onClick={() => setIsCollapseOpen(!isCollapseOpen)}>
<button className="navbar-toggler" onClick={() => setIsCollapseOpen(!isCollapseOpen)}>
<span className="navbar-toggler-icon" />
</button>
<UncontrolledCollapse
toggler="#navbar_global"
<Collapse
navbar
isOpen={isCollapseOpen}
className={collapseClass}
Expand All @@ -77,20 +75,15 @@ const ResponsiveCollapse = ({ children }) => {
</Link>
</Col>
<Col className="collapse-close" xs="6">
<Button
color="link"
className="navbar-toggler"
id="navbar_global"
onClick={() => setIsCollapseOpen(false)}
>
<Button color="link" className="navbar-toggler" onClick={() => setIsCollapseOpen(false)}>
<span />
<span />
</Button>
</Col>
</Row>
</div>
{children}
</UncontrolledCollapse>
</Collapse>
</React.Fragment>
);
};
Expand All @@ -100,6 +93,7 @@ ResponsiveCollapse.propTypes = {
};

const Navbar = () => {
const [isCollapseOpen, setIsCollapseOpen] = useState(false);
const navbarstrapRef = useRef();
useEffect(() => {
const headroom = new Headroom(navbarstrapRef.current);
Expand All @@ -115,24 +109,24 @@ const Navbar = () => {
<img alt="Polydodo" src={Logo} />
</NavbarBrand>

<ResponsiveCollapse>
<ResponsiveCollapse isCollapseOpen={isCollapseOpen} setIsCollapseOpen={setIsCollapseOpen}>
<Nav className="navbar-nav-hover align-items-lg-center" navbar>
<NavItem>
<NavLink to="/" tag={Link} id="navbar_global">
<NavItem onClick={() => setIsCollapseOpen(false)}>
<NavLink to="/" tag={Link}>
{text['navbar_home']}
</NavLink>
</NavItem>
<NavItem>
<NavItem onClick={() => setIsCollapseOpen(false)}>
<NavLink to="/record-my-sleep" tag={Link}>
{text['navbar_record']}
</NavLink>
</NavItem>
<NavItem>
<NavItem onClick={() => setIsCollapseOpen(false)}>
<NavLink to="/analyze-my-sleep" tag={Link}>
{text['navbar_analyze']}
</NavLink>
</NavItem>
<NavItem>
<NavItem onClick={() => setIsCollapseOpen(false)}>
<NavLink to="/performance" tag={Link}>
{text['navbar_performance']}
</NavLink>
Expand Down