Skip to content

Commit 899bad8

Browse files
menu dynamic opening and closing
1 parent 4763dc8 commit 899bad8

File tree

4 files changed

+59
-30
lines changed

4 files changed

+59
-30
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"react-papaparse": "^4.1.0",
2525
"react-router-dom": "^6.15.0",
2626
"react-scripts": "5.0.1",
27+
"react-transition-group": "^4.4.5",
2728
"serve": "^14.2.1",
2829
"typescript": "^4.9.5"
2930
},

src/components/menu/menu.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.menu-enter {
2+
max-width: 0;
3+
}
4+
5+
.menu-enter-active {
6+
transition: max-width 700ms;
7+
max-width: 100%;
8+
}
9+
10+
.menu-exit {
11+
max-width: 100%;
12+
}
13+
14+
.menu-exit-active {
15+
transition: max-width 600ms;
16+
max-width: 0;
17+
}

src/components/menu/menu.tsx

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React, { useState } from "react";
22
import { HiOutlineMenu, HiOutlineX } from "react-icons/hi"; // Importando ícones do React Icons
33
import { Link } from "react-router-dom";
4+
import { CSSTransition } from "react-transition-group";
5+
import "./menu.css";
46

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

1214
return (
13-
<nav
14-
className={`text-white fixed top-0 left-0 bottom-0 z-50 overflow-y-auto ${
15-
isExpanded ? "bg-gray-800 overflow-y-auto w-64" : "overflow-hidden"
16-
}`}
17-
>
18-
<div className="flex justify-between items-center p-4">
19-
<div className={`text-2xl font-bold ${isExpanded ? "" : "sr-only"}`}>
20-
Menu
21-
</div>
22-
<button
23-
className="text-white focus:outline-none focus:text-white"
24-
onClick={toggleMenu}
25-
>
26-
{isExpanded ? (
27-
<HiOutlineX className="h-6 w-6" />
28-
) : (
29-
<HiOutlineMenu className="h-6 w-6" />
30-
)}
31-
</button>
32-
</div>
33-
<ul className={`p-4 ${isExpanded ? "" : "hidden"}`}>
34-
<li className={`my-2`}>
35-
{" "}
36-
<Link to="/">Classificar</Link>
37-
</li>
38-
<li className={`my-2`}>
39-
<Link to="/train">Treinar</Link>
40-
</li>
41-
</ul>
42-
</nav>
15+
<>
16+
<button
17+
className="text-white fixed top-0 left-0 p-4 focus:outline-none focus:text-white"
18+
onClick={toggleMenu}
19+
>
20+
{isExpanded ? (
21+
<HiOutlineX className="h-6 w-6" />
22+
) : (
23+
<HiOutlineMenu className="h-6 w-6" />
24+
)}
25+
</button>
26+
<CSSTransition
27+
in={isExpanded}
28+
timeout={500}
29+
classNames="menu"
30+
unmountOnExit
31+
>
32+
<nav className="text-white fixed top-0 left-0 bottom-0 z-50 overflow-y-auto w-64 bg-gray-800">
33+
<div className="p-4 flex justify-between items-center">
34+
<div className="text-2xl font-bold">Menu</div>
35+
<button
36+
className="text-white focus:outline-none p-2"
37+
onClick={toggleMenu}
38+
>
39+
<HiOutlineX className="h-6 w-6" />
40+
</button>
41+
</div>
42+
<ul className="p-4">
43+
<li className="my-2">
44+
<Link to="/">Classificar</Link>
45+
</li>
46+
<li className="my-2">
47+
<Link to="/train">Treinar</Link>
48+
</li>
49+
</ul>
50+
</nav>
51+
</CSSTransition>
52+
</>
4353
);
4454
}

0 commit comments

Comments
 (0)