1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-22 13:04:19 +00:00

🔮 Add interactivity to sidebar buttons

This commit is contained in:
Stefano Pigozzi 2021-04-21 18:00:21 +02:00
parent 605d950817
commit 334bf6bbe3
Signed by untrusted user who does not match committer: steffo
GPG key ID: 6965406171929D01
4 changed files with 33 additions and 10 deletions

View file

@ -8,6 +8,7 @@ import Input from "./components/Input"
import InputWithIcon from "./components/InputWithIcon" import InputWithIcon from "./components/InputWithIcon"
import Layout from "./components/Layout" import Layout from "./components/Layout"
import ContextTheme from "./contexts/ContextTheme" import ContextTheme from "./contexts/ContextTheme"
import { BrowserRouter } from "react-router-dom"
export default function App() { export default function App() {
@ -15,6 +16,8 @@ export default function App() {
return ( return (
<ContextTheme.Provider value={theme}> <ContextTheme.Provider value={theme}>
<BrowserRouter>
<div className={classNames(Style.App, theme)}> <div className={classNames(Style.App, theme)}>
<Layout> <Layout>
<BoxWithHeader <BoxWithHeader
@ -40,6 +43,8 @@ export default function App() {
</BoxWithHeader> </BoxWithHeader>
</Layout> </Layout>
</div> </div>
</BrowserRouter>
</ContextTheme.Provider> </ContextTheme.Provider>
) )
} }

View file

@ -2,15 +2,29 @@ import React from "react"
import Style from "./ButtonSidebar.module.css" import Style from "./ButtonSidebar.module.css"
import classNames from "classnames" import classNames from "classnames"
import make_icon from "../utils/make_icon" import make_icon from "../utils/make_icon"
import { Link } from "react-router-dom"
import { useRouteMatch } from "react-router"
export default function ButtonSidebar({ icon, children, className, ...props }) { export default function ButtonSidebar({ icon, children, to, className, ...props }) {
const match = useRouteMatch({
path: to,
strict: true,
exact: true,
});
if(match) {
className = classNames(Style.Active, className)
}
return ( return (
<button className={classNames(Style.ButtonSidebar, className)} {...props}> <Link to={to} className={Style.ButtonLink}>
{make_icon(icon, Style.ButtonIcon)} <div className={classNames(Style.ButtonSidebar, className)} {...props}>
<div className={Style.ButtonText}> {make_icon(icon, Style.ButtonIcon)}
{children} <div className={Style.ButtonText}>
{children}
</div>
</div> </div>
</button> </Link>
) )
} }

View file

@ -1,3 +1,7 @@
.ButtonLink {
text-decoration: none;
}
.ButtonSidebar { .ButtonSidebar {
font-family: var(--font-title); font-family: var(--font-title);

View file

@ -11,10 +11,10 @@ export default function Sidebar({ children, className, ...props }) {
<div className={classNames(Style.Sidebar, className)} {...props}> <div className={classNames(Style.Sidebar, className)} {...props}>
{/* TODO: Aggiungere il logo qui! */} {/* TODO: Aggiungere il logo qui! */}
<Logo/> <Logo/>
<ButtonSidebar icon={faHome}>Dashboard</ButtonSidebar> <ButtonSidebar to={"/"} icon={faHome}>Dashboard</ButtonSidebar>
<ButtonSidebar icon={faFolder}>Repositories</ButtonSidebar> <ButtonSidebar to={"/repositories"} icon={faFolder}>Repositories</ButtonSidebar>
<ButtonSidebar icon={faExclamationTriangle}>Alerts</ButtonSidebar> <ButtonSidebar to={"/alerts"} icon={faExclamationTriangle}>Alerts</ButtonSidebar>
<ButtonSidebar icon={faCog}>Settings</ButtonSidebar> <ButtonSidebar to={"/settings"} icon={faCog}>Settings</ButtonSidebar>
{children} {children}
</div> </div>
) )