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

Make VuiAppSideNav collapsible #65

Merged
merged 3 commits into from
Jul 14, 2023
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
15 changes: 15 additions & 0 deletions src/docs/pages/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import {
VuiButtonSecondary,
VuiFlexContainer,
VuiFlexItem,
VuiHorizontalRule,
VuiSelect,
VuiSpacer,
VuiText,
VuiTextColor,
VuiTitle
} from "../../../lib";
import "./appExample.scss";
Expand Down Expand Up @@ -58,6 +61,18 @@ export const App = () => {
{ name: "Page 3", path: "/" },
{ name: "Page 4", path: "/" }
]}
navContent={
<>
<VuiSpacer size="l" />
<VuiHorizontalRule />
<VuiSpacer size="l" />
<VuiText>
<p>
<VuiTextColor color="subdued">Made with love on Terra</VuiTextColor>
</p>
</VuiText>
</>
}
>
<VuiAppContent className="appExampleContent" fullWidth={isFullWidth} padding={padding}>
<VuiButtonSecondary color="primary" onClick={() => setIsFullWidth(!isFullWidth)}>
Expand Down
8 changes: 5 additions & 3 deletions src/lib/components/app/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { VuiAppSideNav, Props as VuiAppSideNavProps } from "./AppSideNav";
type Props = {
children: React.ReactNode;
navItems?: VuiAppSideNavProps["items"];
nav?: React.ReactNode;
navContent?: React.ReactNode;
};

export const VuiAppLayout = ({ children, navItems, nav }: Props) => {
export const VuiAppLayout = ({ children, navItems, navContent }: Props) => {
return (
<div className="vuiAppLayout">
<div className="vuiAppLayout__sideNav">{navItems ? <VuiAppSideNav items={navItems} /> : nav}</div>
<div className="vuiAppLayout__sideNav">
<VuiAppSideNav items={navItems} content={navContent} />
</div>

<div className="vuiAppLayout__content">{children}</div>
</div>
Expand Down
44 changes: 41 additions & 3 deletions src/lib/components/app/AppSideNav.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import classNames from "classnames";
import { useState } from "react";
import { Link, useLocation } from "react-router-dom";
import { VuiIconButton } from "../button/IconButton";
import { VuiIcon } from "../icon/Icon";
import { BiChevronRight } from "react-icons/bi";

export type TreeItem = {
name: string;
Expand All @@ -8,7 +12,8 @@ export type TreeItem = {
};

export type Props = {
items: Array<TreeItem>;
items?: Array<TreeItem>;
content?: React.ReactNode;
};

const buildItems = (items: Array<TreeItem>, currentPath: string) => {
Expand Down Expand Up @@ -36,7 +41,40 @@ const buildItems = (items: Array<TreeItem>, currentPath: string) => {
});
};

export const VuiAppSideNav = ({ items }: Props) => {
export const VuiAppSideNav = ({ items = [], content }: Props) => {
const [isCollapsed, setIsCollapsed] = useState(false);
const location = useLocation();
return <div className="appSideNav">{buildItems(items, location.pathname)}</div>;

const classes = classNames("appSideNav", {
"appSideNav-isCollapsed": isCollapsed
});

return (
<div className={classes}>
<div className="appSideNav__inner">
{isCollapsed ? (
<VuiIconButton
onClick={() => setIsCollapsed(false)}
className="appSideNavExpandButton"
color="normal"
icon={
<VuiIcon>
<BiChevronRight />
</VuiIcon>
}
/>
) : (
<>
<button className="appSideNavCollapseButton" onClick={() => setIsCollapsed(true)}>
Collapse nav
</button>

{buildItems(items, location.pathname)}

{content}
</>
)}
</div>
</div>
);
};
1 change: 0 additions & 1 deletion src/lib/components/app/appLayout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
}

.vuiAppLayout__sideNav {
padding: 0 $sizeM 0;
border-right: 1px solid $colorMediumShade;
flex-shrink: 0;
overflow-y: auto;
Expand Down
39 changes: 38 additions & 1 deletion src/lib/components/app/appSideNav.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
$appSideNavWidth: 200px;

.appSideNav {
padding: $sizeXl $sizeM;
width: $appSideNavWidth;
overflow-x: hidden;
transition: all $transitionSpeed;
}

.appSideNav__inner {
width: $appSideNavWidth;
padding: $sizeL $sizeM * 2 $sizeXl;
margin-bottom: $sizeXxl * 4;
transition: all $transitionSpeed;
}

.appSideNav-isCollapsed {
width: 60px;

.appSideNav__inner {
padding-left: $sizeM;
}
}

.appSideNavCollapseButton {
display: block;
color: $colorSubdued;
font-size: $fontSizeXs;
text-decoration: none;
padding: 0 $sizeM;
margin-left: -$sizeM;
margin-bottom: $sizeM;

&:hover {
color: $colorPrimary;
text-decoration: underline;
}
}

.appSideNavExpandButton {
margin-top: -$sizeXxs;
}

.appSideNavSection + .appSideNavSection {
Expand Down