-
-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: CheatSheet/HackBook | Add Responsive Design #583
Changes from 1 commit
db68fb5
d8c4abc
b89cc24
ce40521
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React, { useState } from "react"; | ||
import React, { useState, useEffect } from "react"; | ||
import { Wrapper } from "../Dashboard/Profile/ProfileElements"; | ||
import { | ||
LeftSection, | ||
|
@@ -13,9 +13,11 @@ import { | |
MarkdownPreview, | ||
MarkdownContainer, | ||
ToggleButton, | ||
ResponsiveToggleButton, | ||
HackBookTitleContainer, | ||
} from "./CheatSheetElements"; | ||
|
||
import { LuPanelRightOpen } from "react-icons/lu"; | ||
import { LuPanelBottomOpen, LuPanelBottomClose, LuPanelTopOpen, LuPanelTopClose } from "react-icons/lu"; | ||
|
||
const CheatSheet = ({ data, heading }) => { | ||
const hackBookData = data; | ||
|
@@ -37,6 +39,26 @@ const CheatSheet = ({ data, heading }) => { | |
setToggle(!toggle); | ||
}; | ||
|
||
const [isContentNavVisible, setIsContentNavVisible] = useState(true); | ||
useEffect(() => { | ||
const handleResize = () => { | ||
// Set isContentNavVisible to true when window width is greater than or equal to 600px | ||
setIsContentNavVisible(window.innerWidth >= 800); | ||
setToggle(true); | ||
}; | ||
|
||
// Attach the event listener | ||
window.addEventListener("resize", handleResize); | ||
|
||
// Initial check for the window width | ||
handleResize(); | ||
|
||
// Cleanup the event listener on component unmount | ||
return () => { | ||
window.removeEventListener("resize", handleResize); | ||
}; | ||
}, []); | ||
|
||
const handleFileClick = (title, fileName) => { | ||
const fileContent = hackBookData[title].find((file) => Object.keys(file)[0] === fileName); | ||
setSelectedFile({ | ||
|
@@ -51,48 +73,62 @@ const CheatSheet = ({ data, heading }) => { | |
{toggle && ( | ||
<LeftSection> | ||
<ContentNav> | ||
<HackBookTitle> {heading} </HackBookTitle> | ||
<ContentNavData> | ||
{Object.keys(hackBookData).map( | ||
(title, id) => | ||
hackBookData[title].length > 0 && ( | ||
<RoadmapDetails key={id}> | ||
<HackBookHeading> | ||
{title.replace(/[^a-zA-Z0-9]+/g, " ")} | ||
</HackBookHeading> | ||
{hackBookData[title].map( | ||
(file, fileId) => | ||
Object.keys(file)[0].endsWith(".md") && ( | ||
<RoadmapDetailsCard | ||
key={fileId} | ||
isSelected={ | ||
selectedFile && | ||
selectedFile.name === Object.keys(file)[0] | ||
} | ||
onClick={() => | ||
handleFileClick(title, Object.keys(file)[0]) | ||
} | ||
> | ||
{ | ||
Object.keys(file)[0] | ||
.replace(/.md/g, "") | ||
.replace(/[^a-zA-Z0-9]+/g, " ") | ||
// .toLowerCase() | ||
} | ||
</RoadmapDetailsCard> | ||
), | ||
)} | ||
</RoadmapDetails> | ||
), | ||
)} | ||
</ContentNavData> | ||
<HackBookTitleContainer> | ||
<HackBookTitle> {heading} </HackBookTitle> | ||
<ResponsiveToggleButton onClick={() => setIsContentNavVisible(!isContentNavVisible)}> | ||
{isContentNavVisible ? ( | ||
<LuPanelTopClose fontSize={"24px"} /> | ||
) : ( | ||
<LuPanelTopOpen fontSize={"24px"} /> | ||
)} | ||
</ResponsiveToggleButton> | ||
</HackBookTitleContainer> | ||
{isContentNavVisible && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you find the reason that on default this section is closing right away without clicking on the button? Recording.2024-02-02.170855.mp4There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason for this, was that initially the code was |
||
<ContentNavData> | ||
{Object.keys(hackBookData).map( | ||
(title, id) => | ||
hackBookData[title].length > 0 && ( | ||
<RoadmapDetails key={id}> | ||
<HackBookHeading> | ||
{title.replace(/[^a-zA-Z0-9]+/g, " ")} | ||
</HackBookHeading> | ||
{hackBookData[title].map( | ||
(file, fileId) => | ||
Object.keys(file)[0].endsWith(".md") && ( | ||
<RoadmapDetailsCard | ||
key={fileId} | ||
isSelected={ | ||
selectedFile && | ||
selectedFile.name === Object.keys(file)[0] | ||
} | ||
onClick={() => { | ||
handleFileClick(title, Object.keys(file)[0]); | ||
if (window.innerWidth < 800) { | ||
setIsContentNavVisible(false); | ||
} | ||
}} | ||
> | ||
{ | ||
Object.keys(file)[0] | ||
.replace(/.md/g, "") | ||
.replace(/[^a-zA-Z0-9]+/g, " ") | ||
// .toLowerCase() | ||
} | ||
</RoadmapDetailsCard> | ||
), | ||
)} | ||
</RoadmapDetails> | ||
), | ||
)} | ||
</ContentNavData> | ||
)} | ||
</ContentNav> | ||
</LeftSection> | ||
)} | ||
|
||
<ContentData> | ||
<ToggleButton onClick={handleToggle} size={20}> | ||
<LuPanelRightOpen /> | ||
{toggle ? <LuPanelBottomOpen fontSize={"20px"} /> : <LuPanelBottomClose fontSize={"20px"} />} | ||
</ToggleButton> | ||
{selectedFile && ( | ||
<MarkdownContainer> | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,7 +7,7 @@ export const LeftSection = styled.div` | |||||
width: 100%; | ||||||
flex: 1; | ||||||
|
||||||
@media (max-width: 600px) { | ||||||
@media (max-width: 800px) { | ||||||
max-width: 100%; | ||||||
} | ||||||
`; | ||||||
|
@@ -22,21 +22,26 @@ export const HackBookContainer = styled.div` | |||||
height: 100%; | ||||||
max-width: 1500px; | ||||||
|
||||||
@media (max-width: 600px) { | ||||||
@media (max-width: 800px) { | ||||||
/* Adjust styles for smaller screens */ | ||||||
flex-direction: column; | ||||||
max-width: 100%; | ||||||
} | ||||||
`; | ||||||
|
||||||
export const HackBookTitle = styled.h1` | ||||||
display: flex; | ||||||
width: 100%; | ||||||
font-size: 24px; | ||||||
padding: 15px 25px; | ||||||
text-align: center; | ||||||
margin-top: 7.5px; | ||||||
|
||||||
align-content: center; | ||||||
justify-content: center; | ||||||
background: #2f2f2f; | ||||||
font-family: "Poppins", sans-serif; | ||||||
@media (max-width: 800px) { | ||||||
width: 95%; | ||||||
} | ||||||
`; | ||||||
|
||||||
export const HackBookHeading = styled.p` | ||||||
|
@@ -120,14 +125,15 @@ export const ContentData = styled.div` | |||||
flex-direction: column; | ||||||
align-content: center; | ||||||
width: 100%; | ||||||
min-width: 200px; | ||||||
max-width: 1200px; | ||||||
border: #2f2f2f 1px solid; | ||||||
border-radius: 0 10px 10px 0; | ||||||
margin: 0 auto; | ||||||
height: 100%; | ||||||
|
||||||
@media (max-width: 600px) { | ||||||
max-width: 100%; | ||||||
@media (max-width: 800px) { | ||||||
max-width: 98%; | ||||||
border-radius: 0; | ||||||
} | ||||||
`; | ||||||
|
@@ -190,3 +196,24 @@ export const ToggleButton = styled.button` | |||||
display: block; | ||||||
} | ||||||
`; | ||||||
export const ResponsiveToggleButton = styled.button` | ||||||
display: none; | ||||||
width: 10%; | ||||||
@media (max-width: 800px) { | ||||||
display: flex; | ||||||
justify-content: flex-end; | ||||||
align-items: center; | ||||||
cursor: pointer; | ||||||
color: #f5f5f5; | ||||||
cursor: pointer; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
you accidentally wrote it twice |
||||||
z-index: 1; | ||||||
text-align: center; | ||||||
padding-right: 10px; | ||||||
} | ||||||
`; | ||||||
|
||||||
export const HackBookTitleContainer = styled.div` | ||||||
display: flex; | ||||||
background: #2f2f2f; | ||||||
height: 50px; | ||||||
`; |
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.
change the comment "to 800px"