generated from the-collab-lab/smart-shopping-list
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from the-collab-lab/sd-st-14.2
Issue #14.2 Implement Disclosure component with collapsible content
- Loading branch information
Showing
12 changed files
with
242 additions
and
99 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,29 @@ | ||
.Accordion { | ||
border: 1px solid #ccc; | ||
border-radius: 4px; | ||
margin-bottom: 10px; | ||
width: 70%; | ||
margin-left: auto; | ||
margin-right: auto; | ||
} | ||
|
||
.Disclosure-header { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
cursor: pointer; | ||
padding: 10px; | ||
border: none; | ||
border-bottom: 1px solid #ccc; | ||
width: 100%; | ||
} | ||
|
||
.list-item .share-icon { | ||
margin-left: auto; | ||
padding: 8px; | ||
cursor: pointer; | ||
} | ||
|
||
.share-icon:hover { | ||
transform: scale(1.2); | ||
} |
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,81 @@ | ||
// Allows users to expand and collapse content sections. | ||
//key features: toggles visibility of child elements based on open/closed | ||
// Uses a button to trigger the toggle(responds to both mouse and keyboard clicks) | ||
// Displays icon to indicate expand/colapsed (feel free to change icon if u like) | ||
// Manages accessibitity through aria attributes | ||
|
||
import { useEffect, useState } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { FaShareAlt } from 'react-icons/fa'; | ||
import './Disclosure.css'; | ||
|
||
export function Disclosure({ | ||
id, | ||
children, | ||
listofNames, | ||
iconExpanded, | ||
iconCollapsed, | ||
currentListPath, | ||
listpath, | ||
setListPath, | ||
}) { | ||
const navigate = useNavigate(); | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
useEffect(() => { | ||
if (currentListPath !== listpath) { | ||
setIsOpen(false); | ||
} | ||
}, [currentListPath]); | ||
|
||
const toggleDisclosure = (e) => { | ||
e.preventDefault(); | ||
if (isOpen) { | ||
setIsOpen(false); | ||
} else { | ||
setIsOpen(true); | ||
setListPath(listpath); | ||
} | ||
}; | ||
|
||
const handleKeyDown = (e) => { | ||
if ( | ||
e.keyCode === 13 || // Keycode for Enter key | ||
e.keyCode === 32 // Keycode for Spacebar key | ||
) { | ||
toggleDisclosure(e); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="Accordion" id={id}> | ||
<button | ||
className="Disclosure-header" | ||
id={`${id}-button`} | ||
onClick={toggleDisclosure} | ||
onKeyDown={handleKeyDown} | ||
aria-controls={`${id}-content`} | ||
aria-expanded={isOpen} | ||
> | ||
{isOpen ? iconExpanded : iconCollapsed} | ||
<span>{listofNames}</span> | ||
|
||
<FaShareAlt | ||
icon="fa-solid fa-share-nodes" | ||
className="share-icon" | ||
aria-label="Share" | ||
onClick={() => navigate('/manage-list')} | ||
/> | ||
</button> | ||
{isOpen && ( | ||
<div | ||
className="Disclosure-content" | ||
id={`${id}-content`} | ||
hidden={!isOpen} | ||
> | ||
{children} | ||
</div> | ||
)} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.Home button { | ||
border-radius: 5px; | ||
padding: 8px 12px; | ||
cursor: pointer; | ||
border: 1px solid #ccc; | ||
box-sizing: border-box; | ||
} | ||
|
||
input[type='text'] { | ||
padding: 10px; | ||
width: 70%; | ||
margin-right: 10px; | ||
font-size: 16px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
box-sizing: border-box; | ||
margin-top: 10px; | ||
} | ||
|
||
h1, | ||
h2, | ||
h3 { | ||
margin-bottom: 20px; | ||
} | ||
|
||
label { | ||
font-size: 20px; | ||
font-weight: bold; | ||
margin-bottom: 10px; | ||
margin-top: 20px; | ||
} |
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
Oops, something went wrong.