forked from layer5io/sistent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vivek Vishal <vishalvivek488@gmail.com>
- Loading branch information
1 parent
92bcc03
commit d866582
Showing
1 changed file
with
52 additions
and
30 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 |
---|---|---|
@@ -1,39 +1,61 @@ | ||
import React from 'react'; | ||
import React, { useState } from 'react'; | ||
import { TOCWrapper } from './style'; | ||
import { IoMdClose } from '@react-icons/all-files/io/IoMdClose'; | ||
import { IoIosArrowDropdownCircle } from '@react-icons/all-files/io/IoIosArrowDropdownCircle'; | ||
import { Link } from "@mui/material/"; | ||
Check failure on line 5 in src/custom/TOCChapter/TOCChapter.tsx
|
||
|
||
interface TOCProps { | ||
availableChapters: string[]; | ||
currentChapter: string | undefined | null; | ||
onClick: (item: string, e: React.MouseEvent<HTMLLIElement, MouseEvent>) => void; | ||
availableChapters: string[]; | ||
currentChapter: string | undefined | null; | ||
onClick: (item: string, e: React.MouseEvent<HTMLLIElement, MouseEvent>) => void; | ||
} | ||
|
||
const TOC: React.FC<TOCProps> = ({ availableChapters, currentChapter, onClick }) => { | ||
const reformatTOC = (data: string): string => { | ||
const words = data.split('-'); | ||
const formattedString = words | ||
.map((word) => word.charAt(0).toUpperCase() + word.slice(1)) | ||
.join(' '); | ||
return formattedString; | ||
}; | ||
return ( | ||
<TOCWrapper> | ||
<div className="toc-list"> | ||
<ul className={`toc-ul toc-ul-open`}> | ||
{availableChapters.map((item) => ( | ||
<li | ||
key={item} | ||
className={item + '.mdx' === currentChapter ? 'active-link' : ''} | ||
onClick={(e) => { | ||
onClick(item, e); | ||
}} | ||
> | ||
<p className="toc-item"> {reformatTOC(item)}</p> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
</TOCWrapper> | ||
); | ||
const [expand, setExpand] = useState(false); | ||
|
||
const reformatTOC = (data: string): string => { | ||
const words = data.split('-'); | ||
const formattedString = words | ||
.map((word) => word.charAt(0).toUpperCase() + word.slice(1)) | ||
.join(' '); | ||
return formattedString; | ||
}; | ||
|
||
return ( | ||
<TOCWrapper> | ||
<div className="chapter-back"> | ||
<h4 >{reformatTOC(currentChapter?.split(".mdx")[0] ?? '')}</h4> | ||
<div className="toc-toggle-btn"> | ||
{expand ? ( | ||
<IoMdClose | ||
className="toc-menu-icon" | ||
onClick={() => setExpand(!expand)} | ||
/> | ||
) : ( | ||
<IoIosArrowDropdownCircle | ||
className="toc-menu-icon" | ||
onClick={() => setExpand(!expand)} | ||
/> | ||
)} | ||
</div> | ||
</div> | ||
<div className="toc-list"> | ||
<ul className={`toc-ul ${expand ? 'toc-ul-open' : ''}`}> | ||
{availableChapters.map((item) => ( | ||
<li | ||
key={item} | ||
className={item + '.mdx' === currentChapter ? 'active-link' : ''} | ||
onClick={(e) => { | ||
onClick(item, e); | ||
}} | ||
> | ||
<p className="toc-item">{reformatTOC(item)}</p> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
</TOCWrapper> | ||
); | ||
}; | ||
|
||
export default TOC; |