-
-
Notifications
You must be signed in to change notification settings - Fork 752
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create dropdown for docs sidebar (#2328)
Co-authored-by: Lukasz Gornicki <[email protected]>
- Loading branch information
1 parent
ac21613
commit 9dea5f7
Showing
4 changed files
with
69 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function DocsArrow({ isDropDown, activeDropDownItem, onClick, className }) { | ||
return ( | ||
<div className={`w-6 my-auto p-2 rounded-md cursor-pointer ${isDropDown && 'hover:bg-gray-100'}`} onClick={isDropDown ? onClick : () => { }}> | ||
{isDropDown && <img src='/img/illustrations/icons/arrow.svg' className={`transition-transform w-fit m-auto duration-200 transform ${className} ${activeDropDownItem ? 'rotate-90' : ''}`} />} | ||
</div> | ||
); | ||
} |
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,34 @@ | ||
import { useState, useEffect } from "react"; | ||
import DocsNavItem from "./DocsNavItem"; | ||
import DocsArrow from "../icons/DocsArrow"; | ||
|
||
export default function SubCategoryDocsNav({ subCategory, activeItem, onClick }) { | ||
const [openSubCategoryChildren, setOpenSubCategoryChildren] = useState(activeItem.startsWith(subCategory.item.slug)); | ||
|
||
const onClickHandler = () => { | ||
setOpenSubCategoryChildren(!openSubCategoryChildren); | ||
onClick(); | ||
} | ||
|
||
useEffect(() => { | ||
setOpenSubCategoryChildren(activeItem.startsWith(subCategory.item.slug)); | ||
}, [activeItem]) | ||
|
||
return ( | ||
<li key={subCategory.item.title} data-testid="DocsNav-subitem"> | ||
<div className='flex gap-2'> | ||
<DocsArrow isDropDown={subCategory.children} activeDropDownItem={openSubCategoryChildren} onClick={() => setOpenSubCategoryChildren(!openSubCategoryChildren)} /> | ||
<DocsNavItem {...subCategory.item} activeSlug={activeItem} defaultClassName={`font-body text-sm text-black leading-8 ${subCategory.children ? 'hover:font-semibold' : 'hover:text-secondary-600'}`} inactiveClassName='font-regular' activeClassName={subCategory.children ? 'font-semibold' : 'text-secondary-600'} onClick={onClickHandler} /> | ||
</div> | ||
{openSubCategoryChildren && ( | ||
<ul className='border-l ml-8 border-gray-200 pl-4'> | ||
{subCategory.children && subCategory.children.map(subItem => ( | ||
<li key={subItem.title}> | ||
<DocsNavItem {...subItem} activeSlug={activeItem} defaultClassName='font-body text-sm text-gray-700 leading-7 hover:text-secondary-600' inactiveClassName='font-regular' activeClassName='text-secondary-600' onClick={onClick} /> | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</li> | ||
) | ||
} |