amelia
amelia

Reputation: 31

onClick function doesn't work in javascript for my front-end developement

i am new to javascript and i am following a tutorial.

The capture bellow indicates the code i'm writing to create a responsive side bar that changes its wieth when i click on the toggle button.

When i press the toggle-menu-button nothing happens and i dont't know if i have an error in the onClick function or the condition can someone tell me what shoud i do ? Thank you.

this is the code:

import React, { useState } from "react";
import logo from "../assets/logo/total.jpg";
/**
 * @author
 * @function SideMenu
 */

const SideMenu  = (props) => {
    const [inactive, setInactive] = useState(false);
    return (
    <div className={'side-menu $ {inactive ? "inactive" : ""} '}>
                <div className="top-section">
                    <div className="logo">
                        <img src={logo} alt="total" />
                    </div>
                    <div
                    onClick={() => {
                        setInactive(!inactive);
                       }}
                    className="toggle-menu-btn">
                    <i class="bi bi-arrow-left-circle-fill"></i>
                    </div>
                </div>

                <div className="search-controller">
                    <button className="search-btn">
                    <i class="bi bi-search"></i>
                    </button>
                    <input type="text" placeholder="search" />
                </div>

                <div className="divider"></div>
    </div>
            );
                             };

export default SideMenu;
*{
  margin: 0;
  padding: 0;
}
ul{
  margin: 0;
  padding: 0;
}
li{
  list-style: none;
}
body{
  background-color: floralwhite; 
  font-family: 'Open Sans', sans-serif;
}

.side-menu{
   position: fixed;
   background: rgb(240, 218, 194);
   width: 300px;
   height: 100%;
   box-sizing: border-box;
   padding: 30px 20px;   
   transition: width .2s ease-in;
}

.side-menu.inactive {
  width: 80px;
}



.side-menu .top-section{
  position: relative;
}

.side-menu .top-section .logo{
  width: 40px;
  height: 40px;
  overflow: hidden;
  display: inline-block;
}

.side-menu .top-section .logo img{
max-width: 80%;
min-height: 100%;
}

.side-menu .top-section .toggle-menu-btn{
  color:rgba(129, 108, 51, 0.425);
  font-size: 20px;
  position: absolute;
  top: 50%;
  right: 0;
  transform:translateY(-50%);  
}

.side-menu.inactive .top-section .toggle-menu-btn{
  right: -50px;
}

.side-menu .search-controller{
  color: #666;
  position: relative;
  
}

.side-menu .search-controller  .search-btn{
  width: 40 px;
  height: 35 px;
  position: absolute;
  background:transparent;
  border: 0;
  font-size: 20px;
  color: #666;
  transform: translateY(35%);
  left: 10px;
}



.side-menu .search-controller input[type=text]{
  border: 0;
  outline: none;
  height: 35px;
  background: rgb(49, 30, 13, 0.219);
  border-radius: 5px;
  display: block;
  margin: 20px 0;
  width: 100%;
  box-sizing: border-box;
  padding-left: 40px;
  color: #000;
}

.side-menu .divider{
  width: 100%;
  height: 1px;
  border-radius: 1px;
  background: rgba(129, 108, 51, 0.425);
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
    <!--
      manifest.json provides metadata used when your web app is installed on a
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    -->
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
    <!--
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
    <title>Gestion de stations de carburants</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
  </body>
</html>

Upvotes: 1

Views: 257

Answers (1)

extradeck
extradeck

Reputation: 580

<div className={'side-menu $ {inactive ? "inactive" : ""} '}>

I think there is an error here. Do not use blank after $ in backticks.

<div className={`side-menu ${inactive ? "inactive" : ""} `}>

Upvotes: 1

Related Questions