-
-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Made the categories collapsible (#207)
* feat: Made the categories collapsible * Fixed the name of the SideNavbarCategory component * Fixed the gap between the categories
- Loading branch information
Showing
4 changed files
with
71 additions
and
20 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { FC, useEffect, useState } from "react"; | ||
import { FaAngleDown } from "react-icons/fa"; | ||
import { SideNavbarElement } from "./SideNavbarElement"; | ||
import type { ISidebar } from "../../types"; | ||
|
||
export const SideNavbarCategory: FC<{item: ISidebar, openByDefault: string}> = (props) => { | ||
const { item, openByDefault } = props; | ||
|
||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
useEffect(() => { | ||
if (openByDefault === item.category) { | ||
setIsOpen(true); | ||
} | ||
}, [item.category, openByDefault]); | ||
|
||
const handleToggle = () => { | ||
setIsOpen((prevState) => !prevState); | ||
} | ||
|
||
let subcategoryList = null; | ||
|
||
if (isOpen) { | ||
subcategoryList = ( | ||
<ul> | ||
{item.subcategory | ||
.sort((a, b) => | ||
a.name.toUpperCase() < b.name.toUpperCase() ? -1 : 1 | ||
) | ||
.map((list, i) => { | ||
return <li key={i}><SideNavbarElement {...list} /></li>; | ||
})} | ||
</ul> | ||
); | ||
} | ||
|
||
return ( | ||
<li> | ||
<button | ||
className="flex w-full cursor-pointer justify-between py-2 hover:text-violet-500 focus-visible:rounded-md focus-visible:outline-none focus-visible:ring focus-visible:ring-violet-500" | ||
onClick={handleToggle} | ||
> | ||
<h2 className="text-xl font-bold uppercase"> | ||
{item.category} | ||
</h2> | ||
<FaAngleDown className={`${isOpen && 'rotate-180'} self-center transition duration-300 ease-in-out`}/> | ||
</button> | ||
{subcategoryList} | ||
</li> | ||
); | ||
} |
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,17 @@ | ||
import { FC } from "react"; | ||
import type { ISidebar } from "../../types"; | ||
import { SideNavbarCategory } from "./SideNavbarCategory"; | ||
|
||
export const SideNavbarCategoryList: FC<{items: ISidebar[], openByDefault: string}> = (props) => { | ||
const { items, openByDefault } = props; | ||
|
||
return ( | ||
<ul className="mt-2 flex flex-col justify-center gap-4 px-4 pb-24"> | ||
{items.map((item, index) => { | ||
return ( | ||
<SideNavbarCategory key={index} item={item} openByDefault={openByDefault} /> | ||
); | ||
})} | ||
</ul> | ||
); | ||
}; |
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
fe20fab
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
linkshub – ./
linkshub-git-main-rupali-codes.vercel.app
linkshub.vercel.app
linkshub-rupali-codes.vercel.app