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:
parent
605d950817
commit
334bf6bbe3
4 changed files with 33 additions and 10 deletions
|
@ -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>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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}>
|
||||||
|
<div className={classNames(Style.ButtonSidebar, className)} {...props}>
|
||||||
{make_icon(icon, Style.ButtonIcon)}
|
{make_icon(icon, Style.ButtonIcon)}
|
||||||
<div className={Style.ButtonText}>
|
<div className={Style.ButtonText}>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</div>
|
||||||
|
</Link>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
.ButtonLink {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
.ButtonSidebar {
|
.ButtonSidebar {
|
||||||
font-family: var(--font-title);
|
font-family: var(--font-title);
|
||||||
|
|
||||||
|
|
|
@ -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>
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue