-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Commons): add support options to navbar
- Loading branch information
1 parent
a5a97b4
commit 1d0f881
Showing
3 changed files
with
140 additions
and
12 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
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
100 changes: 100 additions & 0 deletions
100
client/src/components/commons/CommonsNavbar/SupportDropdown.tsx
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,100 @@ | ||
import { Dropdown, Icon, Menu, } from "semantic-ui-react"; | ||
import { useState } from "react"; | ||
|
||
|
||
interface SupportDropdownProps { | ||
isMobile?: boolean; | ||
} | ||
|
||
const SupportDropdown: React.FC<SupportDropdownProps> = ({ isMobile = false }) => { | ||
const [mouseIndex, setMouseIndex] = useState(0); | ||
|
||
const itemsArr = [ | ||
{ | ||
name: "Knowledge Base", | ||
props: { | ||
key: "libretexts", | ||
as: "a", | ||
href: "https://commons.libretexts.org/insight", | ||
target: "_blank", | ||
rel: "noopener noreferrer", | ||
}, | ||
}, | ||
{ | ||
name: 'System Status', | ||
props: { | ||
key: "status", | ||
as: "a", | ||
href: "https://status.libretexts.org", | ||
target: "_blank", | ||
rel: "noopener noreferrer", | ||
}, | ||
}, | ||
{ | ||
name: "Contact Support", | ||
props: { | ||
key: "contact", | ||
as: "a", | ||
href: "https://commons.libretexts.org/support/contact", | ||
target: "_blank", | ||
rel: "noopener noreferrer", | ||
}, | ||
}, | ||
] | ||
|
||
if (isMobile) { | ||
return ( | ||
<Menu.Menu className="commons-mobilenav-commonslist"> | ||
{itemsArr.map((item) => ( | ||
<Menu.Item {...item.props}> | ||
{/* <Icon name="university" /> */} | ||
{item.name} | ||
</Menu.Item> | ||
))} | ||
</Menu.Menu> | ||
); | ||
} | ||
|
||
const handleKeyPress = (e: React.KeyboardEvent<HTMLDivElement>) => { | ||
if (e.key === 'ArrowDown') { | ||
setMouseIndex((prevIndex) => Math.min(prevIndex + 1, itemsArr.length - 1)); | ||
const element = document.getElementById("active"); | ||
if (element) { | ||
element?.scrollIntoView({ | ||
behavior: "auto", | ||
block: "start" | ||
}); | ||
} | ||
} else if (e.key === 'ArrowUp') { | ||
setMouseIndex((prevIndex) => Math.max(prevIndex - 1, 0)); | ||
const element = document.getElementById("active"); | ||
if (element) { | ||
element?.scrollIntoView({ | ||
behavior: "auto", | ||
block: "start" | ||
}); | ||
} | ||
} else if (e.key == "Enter") { | ||
window.location.href = itemsArr[mouseIndex].props.href; | ||
} | ||
}; | ||
|
||
|
||
|
||
return ( | ||
<div onKeyDown={handleKeyPress} className="flex flex-row items-center" > | ||
<Dropdown item text="Support"> | ||
<Dropdown.Menu direction="left" className="commons-desktopnav-commonslist" > | ||
{itemsArr.map((item, index) => ( | ||
<Dropdown.Item {...item.props} selected={index == mouseIndex} id={index == mouseIndex ? "active" : "inactive"} > | ||
{/* <Icon name="university" /> */} | ||
{item.name} | ||
</Dropdown.Item> | ||
))} | ||
</Dropdown.Menu> | ||
</Dropdown> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SupportDropdown; |