Skip to content

Commit

Permalink
menu dynamic opening and closing
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasgabriel18 committed Dec 8, 2023
1 parent 4763dc8 commit 899bad8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 30 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"react-papaparse": "^4.1.0",
"react-router-dom": "^6.15.0",
"react-scripts": "5.0.1",
"react-transition-group": "^4.4.5",
"serve": "^14.2.1",
"typescript": "^4.9.5"
},
Expand Down
17 changes: 17 additions & 0 deletions src/components/menu/menu.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.menu-enter {
max-width: 0;
}

.menu-enter-active {
transition: max-width 700ms;
max-width: 100%;
}

.menu-exit {
max-width: 100%;
}

.menu-exit-active {
transition: max-width 600ms;
max-width: 0;
}
70 changes: 40 additions & 30 deletions src/components/menu/menu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState } from "react";
import { HiOutlineMenu, HiOutlineX } from "react-icons/hi"; // Importando ícones do React Icons
import { Link } from "react-router-dom";
import { CSSTransition } from "react-transition-group";
import "./menu.css";

export function Menu() {
const [isExpanded, setIsExpanded] = useState(false);
Expand All @@ -10,35 +12,43 @@ export function Menu() {
};

return (
<nav
className={`text-white fixed top-0 left-0 bottom-0 z-50 overflow-y-auto ${
isExpanded ? "bg-gray-800 overflow-y-auto w-64" : "overflow-hidden"
}`}
>
<div className="flex justify-between items-center p-4">
<div className={`text-2xl font-bold ${isExpanded ? "" : "sr-only"}`}>
Menu
</div>
<button
className="text-white focus:outline-none focus:text-white"
onClick={toggleMenu}
>
{isExpanded ? (
<HiOutlineX className="h-6 w-6" />
) : (
<HiOutlineMenu className="h-6 w-6" />
)}
</button>
</div>
<ul className={`p-4 ${isExpanded ? "" : "hidden"}`}>
<li className={`my-2`}>
{" "}
<Link to="/">Classificar</Link>
</li>
<li className={`my-2`}>
<Link to="/train">Treinar</Link>
</li>
</ul>
</nav>
<>
<button
className="text-white fixed top-0 left-0 p-4 focus:outline-none focus:text-white"
onClick={toggleMenu}
>
{isExpanded ? (
<HiOutlineX className="h-6 w-6" />
) : (
<HiOutlineMenu className="h-6 w-6" />
)}
</button>
<CSSTransition
in={isExpanded}
timeout={500}
classNames="menu"
unmountOnExit
>
<nav className="text-white fixed top-0 left-0 bottom-0 z-50 overflow-y-auto w-64 bg-gray-800">
<div className="p-4 flex justify-between items-center">
<div className="text-2xl font-bold">Menu</div>
<button
className="text-white focus:outline-none p-2"
onClick={toggleMenu}
>
<HiOutlineX className="h-6 w-6" />
</button>
</div>
<ul className="p-4">
<li className="my-2">
<Link to="/">Classificar</Link>
</li>
<li className="my-2">
<Link to="/train">Treinar</Link>
</li>
</ul>
</nav>
</CSSTransition>
</>
);
}

0 comments on commit 899bad8

Please sign in to comment.