NaveBar [html_css_javascript]
Published: 2023-07-31 18:10:16

Html:

```
 <div class="sidebar active">
        <div class="top">
            <div class="logo">
                <i class="bx bxl-codepen"></i>
                <span>CodeCommerce</span>
            </div>
            <i class="bx bx-menu" id="menu_sidebar" ></i>
        </div>
        <div class="user">  
            <img src="https://github.com/DevJanderson.png" alt="Use" class="user-img">
            <div>
                <p class="bold">Janderson L.</p>
                <p>Admin</p>
            </div>
        </div>
        <ul>
            <li>
                <a href="#">
                    <i class="bx bxs-grid-alt"></i>
                    <span class="nav-item">Dashboard</span>
                </a>
                <span class="tooltip">Dashboard</span>
            </li>
            <li>
                <a href="#">
                    <i class="bx bxs-shopping-bag"></i>
                    <span class="nav-item">Product</span>
                </a>
                <span class="tooltip">Product</span>
            </li>
            <li>
                <a href="#">
                    <i class="bx bx-list-check"></i>
                    <span class="nav-item">Categories</span>
                    <span class="tooltip">Categories</span>
                </a>
                
            </li>
        </ul>
    </div>
    <div class="main-content">
        <div class="container">
            <h1>Code commerce</h1>
        </div>
    </div>
```
Css:

```
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: sans-serif;
}

.user-img {
    width: 50px;
    border-radius: 100%;
    border: 1px solid #eee;
}

/* Ver depois se vai ser necessário? */
.sidebar {
    position: absolute;
    top: 0;
    left: 0;
    height: 100vh;
    width: 80px;
    background-color: rgb(105, 105, 89);
    padding: 0.4rem 0.8rem;
    transition:  all 0.5s ease;
}

.sidebar.active ~ .main-content {
    left: 250px;
    width: calc(100%-250px);
}

.sidebar.active {
    width: 250px;
}



/* O botão abre fecha */
.sidebar #menu_sidebar {
    position: absolute;
    color: white;
    top: .4rem;
    left: 50%;
    font-size: 1.2rem;
    line-height: 50px;
    transform: translateX(-50%);
    cursor: pointer;
}

.sidebar.active #menu_sidebar {
    left: 90%;
}

/* deixa a logo e o texto invicivel para
    mostrar quando o botão for clickado
*/

.sidebar .top .logo {
    color: white;
    display: flex;
    height: 50px;
    width: 100%;
    align-items: center;
    pointer-events: none;
    opacity: 0;
}

.sidebar.active .top .logo {
    opacity: 1;
}

/* Almentar o tamanho o icone da logo */
.top .logo i {
    font-size: 2rem;
    margin-right: 5px;
}

/* Div do Usuário */
.user {
    display: flex;
    align-items: center;
    margin: 1rem 0;
}

.user p {
    color: white;
    opacity: 1;   
    margin-left: 1rem;
}

.bold {
    font-weight: 600;
    margin-bottom: 4px;
}

.sidebar p {
    opacity: 0;
}

.sidebar.active p {
    opacity: 1;
}

/* Lista da sidebar */
.sidebar ul li {
    position: relative;
    list-style-type: none;
    height: 50px;
    width: 90%;
    margin: 0.8rem auto;
    line-height: 50px;
}

.sidebar ul li a {
    color: white;
    display: flex;
    align-items: center;
    text-decoration: none;
    border-radius: 0.8rem;
}

.sidebar ul li a:hover {
    background-color: white;
    color: #12171e;
}

.sidebar ul li a i {
    min-width: 50px;
    text-align: center;
    height: 50px;
    border-radius: 12px;
    line-height: 50px;
}

/* ocultar o span do link */
.sidebar .nav-item {
    opacity: 0;
}

.sidebar.active .nav-item {
    opacity: 1;
}

/* Criar o efito tooltip */
.sidebar ul li .tooltip {
    position: absolute;
    left: 130px;
    top: 50%;
    transform:  translate(-50%, -50%);
    box-shadow: 0 0.5rem 0.8rem rgba(0, 0, 0, 0.2);
    border-radius: .6rem;
    padding:  .4rem 1.2rem;
    line-height: 1.8rem;
    z-index: 20;
    opacity: 0;
}

.sidebar ul li:hover .tooltip {
    opacity: 1;
}

.sidebar.active ul li .tooltip {
    display: none;
}
```

Javascript:

```
let menu_sidebar = document.querySelector('#menu_sidebar')
let sidebar = document.querySelector('.sidebar')

menu_sidebar.onclick = function() {
    sidebar.classList.toggle('active')
}
```