-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useState } from "react"; | ||
import MenuList from "./MenuList"; | ||
import { FaMinus, FaPlus } from "react-icons/fa"; | ||
|
||
function MenuItem({ item }) { | ||
const [displayCurrentChildren, setDisplayCurrentChildren] = useState({}); | ||
|
||
function handleToggleChildren(getCurrentLabel) { | ||
setDisplayCurrentChildren({ | ||
...displayCurrentChildren, | ||
[getCurrentLabel]: !displayCurrentChildren[getCurrentLabel], | ||
}); | ||
} | ||
|
||
return ( | ||
<li> | ||
<div | ||
className="flex gap-4 cursor-pointer" | ||
onClick={() => handleToggleChildren(item.label)} | ||
> | ||
<p>{item.label}</p> | ||
{item && item.children && item.children.length ? ( | ||
<span className="flex justify-center items-center"> | ||
{displayCurrentChildren[item.label] ? <FaMinus className="text-xs"/> : <FaPlus className="text-xs" />} | ||
</span> | ||
) : null} | ||
</div> | ||
|
||
{item && | ||
item.children && | ||
item.children.length > 0 && | ||
displayCurrentChildren[item.label] ? ( | ||
<MenuList list={item.children} /> | ||
) : null} | ||
</li> | ||
); | ||
} | ||
|
||
export default MenuItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import MenuItem from "./MenuItem"; | ||
|
||
function MenuList({ list = [] }) { | ||
return ( | ||
<ul className="menu-list container"> | ||
{list && list.length | ||
? list.map((listItem, index) => ( | ||
<MenuItem key={index} item={listItem} /> | ||
)) | ||
: null} | ||
</ul> | ||
); | ||
} | ||
|
||
export default MenuList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import MenuList from "./MenuList" | ||
|
||
function TreeView({menus = []}) { | ||
return ( | ||
<div className="container"> | ||
<MenuList list={menus} /> | ||
</div> | ||
) | ||
} | ||
|
||
export default TreeView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
export const menus = [ | ||
{ | ||
label: "Home", | ||
to: "/", | ||
}, | ||
{ | ||
label: "Profile", | ||
to: "/profile", | ||
children: [ | ||
{ | ||
label: "Details", | ||
to: "details", | ||
children: [ | ||
{ | ||
label: "Location", | ||
to: "location", | ||
children: [ | ||
{ | ||
label: "City", | ||
to: "city", | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
label: "Settings", | ||
to: "/settings", | ||
children: [ | ||
{ | ||
label: "Account", | ||
to: "account", | ||
}, | ||
{ | ||
label: "Security", | ||
to: "security", | ||
children: [ | ||
{ | ||
label: "Login", | ||
to: "login", | ||
}, | ||
{ | ||
label: "Register", | ||
to: "register", | ||
children: [ | ||
{ | ||
label: "Random data", | ||
to: "", | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
export default menus; |