Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes sidebar when menu item is clicked #163

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions client/src/components/Sidebar/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
IconSpeakerphone,
IconSquareArrowRight,
} from '@tabler/icons-react';
import PropTypes from 'prop-types';

import { SidebarNavSection, SidebarLink } from './SidebarNavSection';

Expand Down Expand Up @@ -61,10 +62,15 @@ const sections = [
},
];

const SidebarProps = {
toggleSidebar: PropTypes.func,
};

/**
* Collapsible sidebar
* @param {PropTypes.InferProps<typeof SidebarProps>} props
*/
export function Sidebar() {
export function Sidebar({ toggleSidebar }) {
return (
<nav className={classes.navbar}>
<Group align="center" className={classes.title}>
Expand All @@ -84,9 +90,14 @@ export function Sidebar() {
{...item}
key={`section_${item.label}`}
initiallyOpened
toggleSidebar={toggleSidebar}
/>
) : (
<SidebarLink {...item} key={`header_${item.label}`} />
<SidebarLink
toggleSidebar={toggleSidebar}
{...item}
key={`header_${item.label}`}
/>
);
})}
</div>
Expand All @@ -96,6 +107,8 @@ export function Sidebar() {
);
}

Sidebar.propTypes = SidebarProps;

/**
*
*/
Expand Down
21 changes: 18 additions & 3 deletions client/src/components/Sidebar/SidebarNavSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const SidebarNavSectionProps = {
label: PropTypes.string.isRequired,
}),
),
toggleSidebar: PropTypes.func,
};
/**
* Sidebar section of sublinks with a collapsible accordion header
Expand All @@ -26,6 +27,7 @@ export function SidebarNavSection({
label,
initiallyOpened = false,
links = [],
toggleSidebar,
}) {
const [opened, setOpened] = useState(initiallyOpened);

Expand All @@ -48,7 +50,7 @@ export function SidebarNavSection({
<Collapse in={opened} className={classes.section}>
{links.map((link) => (
<div className={classes.sublink} key={link.label}>
<SidebarLink {...link} />
<SidebarLink toggleSidebar={toggleSidebar} {...link} />
</div>
))}
</Collapse>
Expand All @@ -63,17 +65,30 @@ const SidebarLinkProps = {
href: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
target: PropTypes.string,
toggleSidebar: PropTypes.func,
};

/**
* Navigation link for sidebar
* @param {PropTypes.InferProps<typeof SidebarLinkProps>} props
*/
export function SidebarLink({ icon, href, label, target = '_self' }) {
export function SidebarLink({
icon,
href,
label,
target = '_self',
toggleSidebar,
}) {
return (
<div className={classes.sublink}>
<div>{icon}</div>
<Text component={Link} className={classes.link} to={href} target={target}>
<Text
onClick={toggleSidebar}
component={Link}
className={classes.link}
to={href}
target={target}
>
{label}
</Text>
</div>
Expand Down
2 changes: 1 addition & 1 deletion client/src/stories/Header/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function Header({ user = null }) {
mx="-md"
scrollbars="y"
>
<Sidebar />
<Sidebar toggleSidebar={toggleDrawer} />
</ScrollArea>
</Drawer>
</Box>
Expand Down