Skip to content
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

Update Sidebar.js #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions 13-stripe-submenus/final/src/Sidebar.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,53 @@
// Import React library for creating components
import React from 'react'

// Import FaTimes icon from react-icons library for the close button
import { FaTimes } from 'react-icons/fa'

// Import the custom hook to access global context
import { useGlobalContext } from './context'

// Import sublinks data
import sublinks from './data'

// Define the Sidebar component
const Sidebar = () => {
// Destructure `isSidebarOpen` and `closeSidebar` from global context
const { isSidebarOpen, closeSidebar } = useGlobalContext()

// Return the JSX for the Sidebar
return (
<div
// Dynamically assign class based on `isSidebarOpen` to show or hide the sidebar
className={`${
isSidebarOpen ? 'sidebar-wrapper show' : 'sidebar-wrapper'
}`}
>
{/* Sidebar container */}
<aside className='sidebar'>
{/* Close button for the sidebar */}
<button className='close-btn' onClick={closeSidebar}>
<FaTimes />
<FaTimes /> {/* Render the close icon */}
</button>

{/* Sidebar links section */}
<div className='sidebar-links'>
{/* Map through the sublinks data to generate sidebar content */}
{sublinks.map((item, index) => {
const { links, page } = item
const { links, page } = item // Destructure `links` and `page` from each sublink item
return (
// Render an article for each page
<article key={index}>
<h4>{page}</h4>
<h4>{page}</h4> {/* Render the page title */}
<div className='sidebar-sublinks'>
{/* Map through the links of each page */}
{links.map((link, index) => {
const { url, icon, label } = link
const { url, icon, label } = link // Destructure link properties
return (
// Render an anchor tag for each link
<a key={index} href={url}>
{icon}
{label}
{icon} {/* Render the link icon */}
{label} {/* Render the link label */}
</a>
)
})}
Expand All @@ -40,4 +61,5 @@ const Sidebar = () => {
)
}

// Export the Sidebar component
export default Sidebar