How do I flex the contents of my navbar when I toggle the sidebar on/off in ReactJS? In my current website my sidebar overlaps the navbar so when I toggle it on, more than half of the title gets covered (sample1, sample2)
This is my Navbar.js
import React, { useState } from 'react'
import {Navbar, Container} from 'react-bootstrap'
import { Link } from 'react-router-dom';
import { useAuth } from "../contexts/AuthContext"
import './styles/styles.css';
import * as FaIcons from 'react-icons/fa';
import * as AiIcons from 'react-icons/ai';
import { IconContext } from 'react-icons';
import { SidebarItem } from './SidebarItem';
export default function Navubaru({component: Component, ...rest}) {
const { currentUser } = useAuth()
const [sidebar, setSidebar] = useState(false);
const showSidebar = () => setSidebar(!sidebar);
return (
<div>
<Navbar bg="myColor" variant="dark">
<IconContext.Provider value={{ color: '#fff' }}>
<Link to='#' className='menu-bars'>
<FaIcons.FaBars onClick={showSidebar} />
</Link>
<nav className={sidebar ? 'nav-menu active' : 'nav-menu'}>
<ul className='nav-menu-items' onClick={showSidebar}>
<li className='navbar-toggle'>
<Link to='#' className='menu-bars'>
<AiIcons.AiOutlineClose />
</Link>
</li>
{SidebarItem.map((item, index) => {
return (
<li key={index} className={item.cName}>
<Link to={item.path}>
{item.icon}
<span>{item.title}</span>
</Link>
</li>
);
})}
</ul>
</nav>
</IconContext.Provider>
<Container>
<Navbar.Brand href="/">Welcome to my Website</Navbar.Brand>
<Navbar.Toggle />
<Navbar.Collapse className="justify-content-end">
<Navbar.Text>
Signed in as: <a href="/">{currentUser && currentUser.email}</a>
</Navbar.Text>
</Navbar.Collapse>
</Container>
</Navbar>
</div>
)
}
I'd also like to flex/minimize the size of the main page when I toggle the sidebar if there's not much difference in the methods of doing it. I'd appreciate any help and thoughts given. Thank you
CodePudding user response:
You can set padding-left to the navbar's wrapper when sidebar is open and remove it when the sidebar close.
Here is an example navbar.