-
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.
- The component was redone by separating the components well. -The jsdoc is also added - Accessibility has been greatly improved - ReadMe Improvement
- Loading branch information
Showing
9 changed files
with
414 additions
and
213 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// import PropTypes from 'prop-types'; | ||
/* eslint-disable react/prop-types */ | ||
|
||
import Item from "./Item"; | ||
|
||
/** | ||
* Represents a category within a selection menu. | ||
* | ||
* @component | ||
* @param {Object} props - The component properties. | ||
* @param {string} props.name - The name of the category. | ||
* @param {Array} props.list - The list of items within the category. | ||
* @param {function} props.itemCallback - The callback function triggered when an item within the category is selected. | ||
* @param {number} props.selected - The ID of the currently selected item. | ||
* @param {function} props.toggleOpen - Callback to toggle the open state of the menu. | ||
* @returns {JSX.Element} A component representing a category in the selection menu. | ||
*/ | ||
export default function Category({name, list, itemCallback, selected, toggleOpen}) { | ||
return ( | ||
<div className="category"> | ||
<div className="category-name">{name}</div> | ||
{/* Loop through the list to render items within the category */} | ||
{list.map((el, index) => { | ||
switch(el.type) { | ||
case "item": | ||
return <Item toggleOpen={toggleOpen} selected={el.id === selected} key={index} display={el.display} abbreviation={el.abbreviation} action={itemCallback} id={el.id} /> | ||
default: | ||
return false | ||
} | ||
})} | ||
</div> | ||
); | ||
} | ||
|
||
|
||
// Category.propTypes = { | ||
// name: PropTypes.string, | ||
// list: PropTypes.array, | ||
// itemCallback: PropTypes.func, | ||
// selected: PropTypes.bool, | ||
// toggleOpen: PropTypes.func | ||
// } |
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,50 @@ | ||
// import PropTypes from 'prop-types'; | ||
/* eslint-disable react/prop-types */ | ||
|
||
/** | ||
* Represents an item within a selection menu. | ||
* | ||
* @component | ||
* @param {Object} props - The component properties. | ||
* @param {function} props.action - The callback function triggered when the item is selected. | ||
* @param {string} props.display - The display text for the item. | ||
* @param {string} props.abbreviation - The abbreviated text for the item (optional). | ||
* @param {number} props.id - The unique identifier for the item. | ||
* @param {boolean} props.selected - Indicates whether the item is currently selected. | ||
* @param {function} props.toggleOpen - Callback to toggle the open state of the menu. | ||
* @returns {JSX.Element} A button representing the selectable item. | ||
*/ | ||
export default function Item({action, display, abbreviation, id, selected, toggleOpen}) { | ||
// Determine the displayed text based on abbreviation or display value | ||
let displayed = abbreviation ? abbreviation : display ? display : "error" | ||
return ( | ||
<button | ||
className={`item ${selected ? "selected" : ""}`} | ||
tabIndex={0} | ||
onKeyDown={(e) => { | ||
if (e.key === "Enter") { | ||
e.preventDefault() | ||
action(id) | ||
} | ||
}} onClick={(e) => { | ||
action(id) | ||
e.preventDefault() | ||
}} onFocus={() => { | ||
toggleOpen(true) | ||
}} onBlur={() => { | ||
toggleOpen(false) | ||
}}> | ||
{displayed} | ||
</button> | ||
); | ||
} | ||
|
||
|
||
// Item.propTypes = { | ||
// action: PropTypes.func, | ||
// display: PropTypes.string, | ||
// abbreviation: PropTypes.string, | ||
// id: PropTypes.number, | ||
// selected: PropTypes.bool, | ||
// toggleOpen: PropTypes.func | ||
// } |
Oops, something went wrong.