2021-04-21 13:53:23 +00:00
|
|
|
import React from "react"
|
|
|
|
import Style from "./ButtonSidebar.module.css"
|
|
|
|
import classNames from "classnames"
|
2021-05-22 02:17:02 +00:00
|
|
|
import makeIcon from "../../utils/makeIcon"
|
2021-04-21 16:00:21 +00:00
|
|
|
import { Link } from "react-router-dom"
|
|
|
|
import { useRouteMatch } from "react-router"
|
2021-04-21 13:53:23 +00:00
|
|
|
|
|
|
|
|
2021-04-23 00:18:06 +00:00
|
|
|
/**
|
2021-04-26 16:36:41 +00:00
|
|
|
* A button residing in the {@link Sidebar}, used to switch between pages.
|
2021-04-23 00:18:06 +00:00
|
|
|
*
|
|
|
|
* @param icon - The FontAwesome IconDefinition of the icon that should be rendered in the button.
|
|
|
|
* @param children - The contents of the button.
|
|
|
|
* @param to - The path of the page the user should be redirected to when clicking on the button.
|
|
|
|
* @param className - Additional class(es) to add to the button.
|
|
|
|
* @param props - Additional props to pass to the button.
|
|
|
|
* @returns {JSX.Element}
|
|
|
|
* @constructor
|
|
|
|
*/
|
2021-04-21 16:00:21 +00:00
|
|
|
export default function ButtonSidebar({ icon, children, to, className, ...props }) {
|
|
|
|
const match = useRouteMatch({
|
|
|
|
path: to,
|
|
|
|
strict: true,
|
|
|
|
exact: true,
|
2021-05-11 14:37:15 +00:00
|
|
|
})
|
2021-04-21 16:00:21 +00:00
|
|
|
|
|
|
|
if(match) {
|
|
|
|
className = classNames(Style.Active, className)
|
|
|
|
}
|
|
|
|
|
2021-04-21 13:53:23 +00:00
|
|
|
return (
|
2021-04-21 16:00:21 +00:00
|
|
|
<Link to={to} className={Style.ButtonLink}>
|
2021-05-18 15:51:36 +00:00
|
|
|
<div className={classNames(Style.ButtonSidebar, "Clickable", className)} {...props}>
|
2021-05-23 14:20:53 +00:00
|
|
|
{makeIcon(icon, { className: Style.ButtonIcon })}
|
2021-04-21 16:00:21 +00:00
|
|
|
<div className={Style.ButtonText}>
|
|
|
|
{children}
|
|
|
|
</div>
|
2021-04-21 13:53:23 +00:00
|
|
|
</div>
|
2021-04-21 16:00:21 +00:00
|
|
|
</Link>
|
2021-04-21 13:53:23 +00:00
|
|
|
)
|
|
|
|
}
|