Skip to content

Commit

Permalink
Update TOCChapter.tsx
Browse files Browse the repository at this point in the history
Signed-off-by: Vivek Vishal <vishalvivek488@gmail.com>
  • Loading branch information
vishalvivekm authored Jan 31, 2025
1 parent 92bcc03 commit d866582
Showing 1 changed file with 52 additions and 30 deletions.
82 changes: 52 additions & 30 deletions src/custom/TOCChapter/TOCChapter.tsx
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

View workflow job for this annotation

GitHub Actions / lint (16)

'Link' is defined but never used

Check failure on line 5 in src/custom/TOCChapter/TOCChapter.tsx

View workflow job for this annotation

GitHub Actions / lint (18)

'Link' is defined but never used

Check failure on line 5 in src/custom/TOCChapter/TOCChapter.tsx

View workflow job for this annotation

GitHub Actions / lint (20)

'Link' is defined but never used

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;

0 comments on commit d866582

Please sign in to comment.